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 }
33
OnInstallFinishedInner(MessageParcel & data,MessageParcel & reply)34 int AtomicServiceStatusCallbackStub::OnInstallFinishedInner(MessageParcel &data, MessageParcel &reply)
35 {
36 auto resultCode = data.ReadInt32();
37 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
38 if (want == nullptr) {
39 HILOG_ERROR("AtomicServiceStatusCallbackStub want is nullptr");
40 return ERR_INVALID_VALUE;
41 }
42
43 auto userId = data.ReadInt32();
44 OnInstallFinished(resultCode, *want, userId);
45 return NO_ERROR;
46 }
47
OnRemoteInstallFinishedInner(MessageParcel & data,MessageParcel & reply)48 int AtomicServiceStatusCallbackStub::OnRemoteInstallFinishedInner(MessageParcel &data, MessageParcel &reply)
49 {
50 auto resultCode = data.ReadInt32();
51 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
52 if (want == nullptr) {
53 HILOG_ERROR("AtomicServiceStatusCallbackStub want is nullptr");
54 return ERR_INVALID_VALUE;
55 }
56
57 want->SetParam(FROM_REMOTE_KEY, true);
58 auto userId = data.ReadInt32();
59 OnRemoteInstallFinished(resultCode, *want, userId);
60 return NO_ERROR;
61 }
62
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)63 int AtomicServiceStatusCallbackStub::OnRemoteRequest(
64 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
65 {
66 std::u16string descriptor = AtomicServiceStatusCallbackStub::GetDescriptor();
67 std::u16string remoteDescriptor = data.ReadInterfaceToken();
68 if (descriptor != remoteDescriptor) {
69 HILOG_ERROR("Local descriptor is not equal to remote");
70 return ERR_INVALID_STATE;
71 }
72
73 if (code < IAtomicServiceStatusCallbackCmd::CMD_MAX && code >= 0) {
74 auto memberFunc = vecMemberFunc_[code];
75 return (this->*memberFunc)(data, reply);
76 }
77
78 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
79 }
80 } // namespace AAFwk
81 } // namespace OHOS
82