1 /*
2 * Copyright (c) 2022 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 "atomic_service_status_callback_stub.h"
17
18 #include "ability_manager_interface.h"
19 #include "hilog_wrapper.h"
20 #include "ipc_types.h"
21 #include "message_parcel.h"
22
23 namespace OHOS {
24 namespace AAFwk {
AtomicServiceStatusCallbackStub()25 AtomicServiceStatusCallbackStub::AtomicServiceStatusCallbackStub()
26 {
27 vecMemberFunc_.resize(IAtomicServiceStatusCallbackCmd::CMD_MAX);
28 vecMemberFunc_[IAtomicServiceStatusCallbackCmd::ON_FREE_INSTALL_DONE] =
29 &AtomicServiceStatusCallbackStub::OnInstallFinishedInner;
30 vecMemberFunc_[IAtomicServiceStatusCallbackCmd::ON_REMOTE_FREE_INSTALL_DONE] =
31 &AtomicServiceStatusCallbackStub::OnRemoteInstallFinishedInner;
32 vecMemberFunc_[IAtomicServiceStatusCallbackCmd::ON_REMOVE_TIMEOUT_TASK] =
33 &AtomicServiceStatusCallbackStub::OnRemoveTimeoutTaskInner;
34 }
35
OnInstallFinishedInner(MessageParcel & data,MessageParcel & reply)36 int AtomicServiceStatusCallbackStub::OnInstallFinishedInner(MessageParcel &data, MessageParcel &reply)
37 {
38 auto resultCode = data.ReadInt32();
39 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
40 if (want == nullptr) {
41 HILOG_ERROR("AtomicServiceStatusCallbackStub want is nullptr");
42 return ERR_INVALID_VALUE;
43 }
44
45 auto userId = data.ReadInt32();
46 OnInstallFinished(resultCode, *want, userId);
47 return NO_ERROR;
48 }
49
OnRemoteInstallFinishedInner(MessageParcel & data,MessageParcel & reply)50 int AtomicServiceStatusCallbackStub::OnRemoteInstallFinishedInner(MessageParcel &data, MessageParcel &reply)
51 {
52 auto resultCode = data.ReadInt32();
53 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
54 if (want == nullptr) {
55 HILOG_ERROR("AtomicServiceStatusCallbackStub want is nullptr");
56 return ERR_INVALID_VALUE;
57 }
58
59 want->SetParam(FROM_REMOTE_KEY, true);
60 auto userId = data.ReadInt32();
61 OnRemoteInstallFinished(resultCode, *want, userId);
62 return NO_ERROR;
63 }
64
OnRemoveTimeoutTaskInner(MessageParcel & data,MessageParcel & reply)65 int AtomicServiceStatusCallbackStub::OnRemoveTimeoutTaskInner(MessageParcel &data, MessageParcel &reply)
66 {
67 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
68 if (want == nullptr) {
69 HILOG_ERROR("AtomicServiceStatusCallbackStub want is nullptr.");
70 return ERR_INVALID_VALUE;
71 }
72
73 OnRemoveTimeoutTask(*want);
74 return NO_ERROR;
75 }
76
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)77 int AtomicServiceStatusCallbackStub::OnRemoteRequest(
78 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
79 {
80 std::u16string descriptor = AtomicServiceStatusCallbackStub::GetDescriptor();
81 std::u16string remoteDescriptor = data.ReadInterfaceToken();
82 if (descriptor != remoteDescriptor) {
83 HILOG_ERROR("Local descriptor is not equal to remote");
84 return ERR_INVALID_STATE;
85 }
86
87 if (code < IAtomicServiceStatusCallbackCmd::CMD_MAX && code >= 0) {
88 auto memberFunc = vecMemberFunc_[code];
89 return (this->*memberFunc)(data, reply);
90 }
91
92 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
93 }
94 } // namespace AAFwk
95 } // namespace OHOS
96