• 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 "sys_installer_stub.h"
17 
18 #include <string_ex.h>
19 
20 #include "hap_token_info.h"
21 #include "ipc_skeleton.h"
22 #include "log/log.h"
23 #include "securec.h"
24 
25 namespace OHOS {
26 namespace SysInstaller {
27 using namespace std;
28 using namespace Updater;
29 using namespace std::placeholders;
30 
SysInstallerStub()31 SysInstallerStub::SysInstallerStub()
32 {
33     requestFuncMap_.emplace(ISysInstaller::SYS_INSTALLER_INIT,
34         bind(&SysInstallerStub::SysInstallerInitStub, this, _1, _2, _3, _4));
35     requestFuncMap_.emplace(ISysInstaller::UPDATE_PACKAGE,
36         bind(&SysInstallerStub::StartUpdatePackageZipStub, this, _1, _2, _3, _4));
37     requestFuncMap_.emplace(ISysInstaller::SET_UPDATE_CALLBACK,
38         bind(&SysInstallerStub::SetUpdateCallbackStub, this, _1, _2, _3, _4));
39     requestFuncMap_.emplace(ISysInstaller::GET_UPDATE_STATUS,
40         bind(&SysInstallerStub::GetUpdateStatusStub, this, _1, _2, _3, _4));
41     requestFuncMap_.emplace(ISysInstaller::UPDATE_PARA_PACKAGE,
42         bind(&SysInstallerStub::StartUpdateParaZipStub, this, _1, _2, _3, _4));
43 }
44 
~SysInstallerStub()45 SysInstallerStub::~SysInstallerStub()
46 {
47     requestFuncMap_.clear();
48 }
49 
SysInstallerInitStub(SysInstallerStub * service,MessageParcel & data,MessageParcel & reply,MessageOption & option)50 int32_t SysInstallerStub::SysInstallerInitStub(SysInstallerStub *service,
51     MessageParcel &data, MessageParcel &reply, MessageOption &option)
52 {
53     if (service == nullptr) {
54         LOG(ERROR) << "Invalid param";
55         return -1;
56     }
57     int ret = service->SysInstallerInit();
58     reply.WriteInt32(ret);
59     return 0;
60 }
61 
StartUpdatePackageZipStub(SysInstallerStub * service,MessageParcel & data,MessageParcel & reply,MessageOption & option)62 int32_t SysInstallerStub::StartUpdatePackageZipStub(SysInstallerStub *service,
63     MessageParcel &data, MessageParcel &reply, MessageOption &option)
64 {
65     if (service == nullptr) {
66         LOG(ERROR) << "Invalid param";
67         return -1;
68     }
69     string pkgPath = Str16ToStr8(data.ReadString16());
70     int ret = service->StartUpdatePackageZip(pkgPath);
71     reply.WriteInt32(ret);
72     return 0;
73 }
74 
SetUpdateCallbackStub(SysInstallerStub * service,MessageParcel & data,MessageParcel & reply,MessageOption & option)75 int32_t SysInstallerStub::SetUpdateCallbackStub(SysInstallerStub *service,
76     MessageParcel &data, MessageParcel &reply, MessageOption &option)
77 {
78     if (service == nullptr) {
79         LOG(ERROR) << "Invalid param";
80         return -1;
81     }
82     auto remote = data.ReadRemoteObject();
83     if (remote == nullptr) {
84         LOG(ERROR) << "Failed to read remote obj";
85         return -1;
86     }
87     int ret = service->SetUpdateCallback(iface_cast<ISysInstallerCallback>(remote));
88     reply.WriteInt32(ret);
89     return 0;
90 }
91 
GetUpdateStatusStub(SysInstallerStub * service,MessageParcel & data,MessageParcel & reply,MessageOption & option)92 int32_t SysInstallerStub::GetUpdateStatusStub(SysInstallerStub *service,
93     MessageParcel &data, MessageParcel &reply, MessageOption &option)
94 {
95     if (service == nullptr) {
96         LOG(ERROR) << "Invalid param";
97         return -1;
98     }
99     int32_t ret = service->GetUpdateStatus();
100     reply.WriteInt32(ret);
101     return 0;
102 }
103 
StartUpdateParaZipStub(SysInstallerStub * service,MessageParcel & data,MessageParcel & reply,MessageOption & option)104 int32_t SysInstallerStub::StartUpdateParaZipStub(SysInstallerStub *service,
105     MessageParcel &data, MessageParcel &reply, MessageOption &option)
106 {
107     if (service == nullptr) {
108         LOG(ERROR) << "Invalid param";
109         return -1;
110     }
111     string pkgPath = Str16ToStr8(data.ReadString16());
112     string location = Str16ToStr8(data.ReadString16());
113     string cfgDir = Str16ToStr8(data.ReadString16());
114     LOG(INFO) << "StartUpdateParaZipStub path:" << pkgPath << " location:" << location << " cfgDir:" << cfgDir;
115 
116     int32_t ret = service->StartUpdateParaZip(pkgPath, location, cfgDir);
117     reply.WriteInt32(ret);
118     return 0;
119 }
120 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)121 int32_t SysInstallerStub::OnRemoteRequest(uint32_t code,
122     MessageParcel &data, MessageParcel &reply, MessageOption &option)
123 {
124     if (data.ReadInterfaceToken() != GetDescriptor()) {
125         LOG(ERROR) << "SysInstallerStub ReadInterfaceToken fail";
126         return -1;
127     }
128 
129     LOG(INFO) << "OnRemoteRequest func code " << code;
130     auto inter = requestFuncMap_.find(code);
131     if (inter != requestFuncMap_.end()) {
132         return inter->second(this, data, reply, option);
133     }
134 
135     LOG(INFO) << "UpdateServiceStub OnRemoteRequest code " << code << "not found";
136     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
137 }
138 } // namespace SysInstaller
139 } // namespace OHOS