1 /*
2  * Copyright (c) 2022-2024 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_tag_wrapper.h"
20 
21 namespace OHOS {
22 namespace AAFwk {
AtomicServiceStatusCallbackStub()23 AtomicServiceStatusCallbackStub::AtomicServiceStatusCallbackStub() {}
24 
OnInstallFinishedInner(MessageParcel & data,MessageParcel & reply)25 int AtomicServiceStatusCallbackStub::OnInstallFinishedInner(MessageParcel &data, MessageParcel &reply)
26 {
27     auto resultCode = data.ReadInt32();
28     std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
29     if (want == nullptr) {
30         TAG_LOGE(AAFwkTag::ABILITYMGR, "AtomicServiceStatusCallbackStub want is nullptr");
31         return ERR_INVALID_VALUE;
32     }
33 
34     auto userId = data.ReadInt32();
35     OnInstallFinished(resultCode, *want, userId);
36     return NO_ERROR;
37 }
38 
OnRemoteInstallFinishedInner(MessageParcel & data,MessageParcel & reply)39 int AtomicServiceStatusCallbackStub::OnRemoteInstallFinishedInner(MessageParcel &data, MessageParcel &reply)
40 {
41     auto resultCode = data.ReadInt32();
42     std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
43     if (want == nullptr) {
44         TAG_LOGE(AAFwkTag::ABILITYMGR, "AtomicServiceStatusCallbackStub want is nullptr");
45         return ERR_INVALID_VALUE;
46     }
47 
48     want->SetParam(FROM_REMOTE_KEY, true);
49     auto userId = data.ReadInt32();
50     OnRemoteInstallFinished(resultCode, *want, userId);
51     return NO_ERROR;
52 }
53 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)54 int AtomicServiceStatusCallbackStub::OnRemoteRequest(
55     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
56 {
57     std::u16string descriptor = AtomicServiceStatusCallbackStub::GetDescriptor();
58     std::u16string remoteDescriptor = data.ReadInterfaceToken();
59     if (descriptor != remoteDescriptor) {
60         TAG_LOGE(AAFwkTag::ABILITYMGR, "Local descriptor is not equal to remote");
61         return ERR_INVALID_STATE;
62     }
63 
64     if (code < IAtomicServiceStatusCallbackCmd::CMD_MAX && code >= 0) {
65         switch (code) {
66             case IAtomicServiceStatusCallbackCmd::ON_FREE_INSTALL_DONE:
67                 return OnInstallFinishedInner(data, reply);
68                 break;
69             case IAtomicServiceStatusCallbackCmd::ON_REMOTE_FREE_INSTALL_DONE:
70                 return OnRemoteInstallFinishedInner(data, reply);
71                 break;
72         }
73     }
74 
75     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
76 }
77 }  // namespace AAFwk
78 }  // namespace OHOS
79