1 /*
2  * Copyright (c) 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 "free_install_observer_stub.h"
17 
18 #include "hilog_tag_wrapper.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21 
22 namespace OHOS {
23 namespace AbilityRuntime {
FreeInstallObserverStub()24 FreeInstallObserverStub::FreeInstallObserverStub()
25 {}
26 
~FreeInstallObserverStub()27 FreeInstallObserverStub::~FreeInstallObserverStub()
28 {}
29 
OnInstallFinishedInner(MessageParcel & data,MessageParcel & reply)30 int FreeInstallObserverStub::OnInstallFinishedInner(MessageParcel &data, MessageParcel &reply)
31 {
32     std::string bundleName = data.ReadString();
33     std::string abilityName = data.ReadString();
34     std::string startTime = data.ReadString();
35     int resultCode = data.ReadInt32();
36 
37     OnInstallFinished(bundleName, abilityName, startTime, resultCode);
38     return NO_ERROR;
39 }
40 
OnInstallFinishedByUrlInner(MessageParcel & data,MessageParcel & reply)41 int FreeInstallObserverStub::OnInstallFinishedByUrlInner(MessageParcel &data, MessageParcel &reply)
42 {
43     std::string startTime = data.ReadString();
44     std::string url = data.ReadString();
45     int resultCode = data.ReadInt32();
46 
47     OnInstallFinishedByUrl(startTime, url, resultCode);
48     return NO_ERROR;
49 }
50 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)51 int FreeInstallObserverStub::OnRemoteRequest(
52     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
53 {
54     std::u16string descriptor = FreeInstallObserverStub::GetDescriptor();
55     std::u16string remoteDescriptor = data.ReadInterfaceToken();
56     if (descriptor != remoteDescriptor) {
57         TAG_LOGE(AAFwkTag::FREE_INSTALL, "descriptor is not equal remote");
58         return ERR_INVALID_STATE;
59     }
60 
61     switch (code) {
62         case IFreeInstallObserver::ON_INSTALL_FINISHED:
63             return OnInstallFinishedInner(data, reply);
64         case IFreeInstallObserver::ON_INSTALL_FINISHED_BY_URL:
65             return OnInstallFinishedByUrlInner(data, reply);
66     }
67 
68     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
69 }
70 } // namespace AbilityRuntime
71 } // namespace OHOS