• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "free_install_status_callback_stub.h"
17 #include "hilog_wrapper.h"
18 #include "ipc_types.h"
19 #include "message_parcel.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
FreeInstallStatusCallBackStub()23 FreeInstallStatusCallBackStub::FreeInstallStatusCallBackStub()
24 {
25     vecMemberFunc_.resize(IFreeInstallStatusCallBackCmd::CMD_MAX);
26     vecMemberFunc_[IFreeInstallStatusCallBackCmd::ON_FREE_INSTALL_DONE] =
27         &FreeInstallStatusCallBackStub::OnInstallFinishedInner;
28 }
29 
OnInstallFinishedInner(MessageParcel & data,MessageParcel & reply)30 int32_t FreeInstallStatusCallBackStub::OnInstallFinishedInner(MessageParcel &data, MessageParcel &reply)
31 {
32     auto resultCode = data.ReadInt32();
33     std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
34     if (want == nullptr) {
35         HILOG_ERROR("FreeInstallStatusCallBackStub want is nullptr");
36         return ERR_INVALID_VALUE;
37     }
38 
39     auto userId = data.ReadInt32();
40     OnInstallFinished(resultCode, *want, userId);
41     return NO_ERROR;
42 }
43 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)44 int32_t FreeInstallStatusCallBackStub::OnRemoteRequest(
45     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
46 {
47     HILOG_INFO("OnRemoteRequest, code: %{public}d", code);
48     std::u16string descriptor = FreeInstallStatusCallBackStub::GetDescriptor();
49     std::u16string remoteDescriptor = data.ReadInterfaceToken();
50     if (descriptor != remoteDescriptor) {
51         HILOG_ERROR("Local descriptor is not equal to remote, descriptor: %{public}s, remoteDescriptor: %{public}s",
52             Str16ToStr8(descriptor).c_str(), Str16ToStr8(remoteDescriptor).c_str());
53         return ERR_INVALID_STATE;
54     }
55 
56     if (code < IFreeInstallStatusCallBackCmd::CMD_MAX && code >= 0) {
57         auto memberFunc = vecMemberFunc_[code];
58         return (this->*memberFunc)(data, reply);
59     }
60 
61     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
62 }
63 } // namespace AppExecFwk
64 } // namespace OHOS
65