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_callback.h"
17 #include "sys_installer_kits_impl.h"
18 #include "sys_installer_sa_ipc_interface_code.h"
19 #include "isys_installer_callback_func.h"
20
21 using namespace OHOS;
22 using namespace std;
23 using namespace OHOS::SysInstaller;
24
25 class ProcessCallback : public ISysInstallerCallbackFunc {
26 public:
27 ProcessCallback() = default;
28 ~ProcessCallback() = default;
OnUpgradeProgress(UpdateStatus updateStatus,int percent,const std::string & resultMsg)29 void OnUpgradeProgress(UpdateStatus updateStatus, int percent, const std::string &resultMsg) override
30 {
31 printf("ProgressCallback progress %d percent %d msg %s\n", updateStatus, percent, resultMsg.c_str());
32 }
33 };
34
main(int argc,char ** argv)35 int main(int argc, char **argv)
36 {
37 if (argc != 2) { // 2: max para
38 printf("argc para error\n");
39 return -1;
40 }
41
42 int32_t ret = SysInstallerKitsImpl::GetInstance().SysInstallerInit();
43 printf("SysInstallerInit ret:%d\n", ret);
44
45 sptr<ISysInstallerCallbackFunc> callback = new ProcessCallback;
46 if (callback == nullptr) {
47 printf("callback new failed\n");
48 return -1;
49 }
50 SysInstallerKitsImpl::GetInstance().SetUpdateCallback(callback);
51
52 printf("argv[1]:%d\n", atoi(argv[1]));
53 switch (atoi(argv[1])) {
54 case SysInstallerInterfaceCode::UPDATE_PACKAGE:
55 ret = SysInstallerKitsImpl::GetInstance().StartUpdatePackageZip("/data/ota_package/update.zip");
56 break;
57 case SysInstallerInterfaceCode::GET_UPDATE_STATUS:
58 ret = SysInstallerKitsImpl::GetInstance().GetUpdateStatus();
59 break;
60 case SysInstallerInterfaceCode::UPDATE_PARA_PACKAGE:
61 ret = SysInstallerKitsImpl::GetInstance().StartUpdateParaZip(
62 "/data/ota_package/update_para.zip", "System", "/taboo");
63 break;
64 case SysInstallerInterfaceCode::DELETE_PARA_PACKAGE:
65 ret = SysInstallerKitsImpl::GetInstance().StartDeleteParaZip("System", "/taboo");
66 break;
67 default:
68 break;
69 }
70
71 return ret;
72 }
73