• 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_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",
32             updateStatus, percent, resultMsg.c_str());
33     }
OnUpgradeDealLen(UpdateStatus updateStatus,int dealLen,const std::string & resultMsg)34     void OnUpgradeDealLen(UpdateStatus updateStatus, int dealLen, const std::string &resultMsg) override
35     {
36         printf("ProgressCallback progress %d dealLen %d msg %s\n",
37             updateStatus, dealLen, resultMsg.c_str());
38     }
39 };
40 
main(int argc,char ** argv)41 int main(int argc, char **argv)
42 {
43     if (argc != 2) { // 2: max para
44         printf("argc para error\n");
45         return -1;
46     }
47 
48     int32_t ret = SysInstallerKitsImpl::GetInstance().SysInstallerInit();
49     printf("SysInstallerInit ret:%d\n", ret);
50 
51     sptr<ISysInstallerCallbackFunc> callback = new ProcessCallback;
52     if (callback == nullptr) {
53         printf("callback new failed\n");
54         return -1;
55     }
56     SysInstallerKitsImpl::GetInstance().SetUpdateCallback(callback);
57 
58     printf("argv[1]:%d\n", atoi(argv[1]));
59     switch (atoi(argv[1])) {
60         case SysInstallerInterfaceCode::UPDATE_PACKAGE:
61             ret = SysInstallerKitsImpl::GetInstance().StartUpdatePackageZip("/data/ota_package/update.zip");
62             break;
63         case SysInstallerInterfaceCode::GET_UPDATE_STATUS:
64             ret = SysInstallerKitsImpl::GetInstance().GetUpdateStatus();
65             break;
66         case SysInstallerInterfaceCode::UPDATE_PARA_PACKAGE:
67             ret = SysInstallerKitsImpl::GetInstance().StartUpdateParaZip(
68                 "/data/ota_package/update_para.zip", "System", "/taboo");
69             break;
70         case SysInstallerInterfaceCode::DELETE_PARA_PACKAGE:
71             ret = SysInstallerKitsImpl::GetInstance().StartDeleteParaZip("System", "/taboo");
72             break;
73         case SysInstallerInterfaceCode::DECOMPRESS_ACC_PACKAGE:
74             ret = SysInstallerKitsImpl::GetInstance().AccDecompressAndVerifyPkg(
75                 "/data/ota_package/update.zip",
76                 "/data/ota_package/", 1);
77             break;
78         case SysInstallerInterfaceCode::DELETE_ACC_PACKAGE:
79             ret = SysInstallerKitsImpl::GetInstance().AccDeleteDir("/data/ota_package/");
80             break;
81         default:
82             break;
83     }
84 
85     return ret;
86 }
87