1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "dms_free_install_callback_stub.h"
17
18 #include "dtbschedmgr_log.h"
19 #include "ipc_types.h"
20 #include "message_parcel.h"
21
22 namespace OHOS {
23 namespace DistributedSchedule {
24 namespace {
25 const std::string TAG = "DmsFreeInstallCallbackStub";
26 }
DmsFreeInstallCallbackStub()27 DmsFreeInstallCallbackStub::DmsFreeInstallCallbackStub()
28 {
29 memberFuncMap_[static_cast<uint32_t>(IDRreeInstallCallbackInterfaceCode::ON_FREE_INSTALL_DONE)] =
30 &DmsFreeInstallCallbackStub::OnInstallFinishedInner;
31 }
32
OnInstallFinishedInner(MessageParcel & data,MessageParcel & reply)33 int32_t DmsFreeInstallCallbackStub::OnInstallFinishedInner(MessageParcel& data, MessageParcel& reply)
34 {
35 auto resultCode = data.ReadInt32();
36 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
37 if (want == nullptr) {
38 HILOGE("want is nullptr");
39 return ERR_INVALID_VALUE;
40 }
41 int32_t requestCode = data.ReadInt32();
42 OnInstallFinished(*want, requestCode, resultCode);
43 return NO_ERROR;
44 }
45
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)46 int32_t DmsFreeInstallCallbackStub::OnRemoteRequest(
47 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
48 {
49 std::u16string descriptor = DmsFreeInstallCallbackStub::GetDescriptor();
50 std::u16string remoteDescriptor = data.ReadInterfaceToken();
51 if (descriptor != remoteDescriptor) {
52 HILOGE("Local descriptor is not equal to remote");
53 return ERR_INVALID_STATE;
54 }
55
56 auto it = memberFuncMap_.find(code);
57 if (it == memberFuncMap_.end()) {
58 HILOGE("Not found");
59 return ERR_INVALID_STATE;
60 }
61
62 return (this->*(it->second))(data, reply);
63 }
64 } // namespace DistributedSchedule
65 } // namespace OHOS
66