• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "check_module_update.h"
17 
18 #include <cstring>
19 #include "module_update.h"
20 #include "securec.h"
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 namespace {
29 constexpr int SA_ARG_COUNT = 2;
30 constexpr const char *SA_PATH = "/system/bin/sa_main";
31 }
32 
CheckModuleUpdate(int argc,char ** argv)33 char *CheckModuleUpdate(int argc, char **argv)
34 {
35     if (argc >= SA_ARG_COUNT && std::strcmp(argv[0], SA_PATH) == 0) {
36         OHOS::SysInstaller::ModuleUpdate update;
37         std::string updateResult = update.CheckModuleUpdate(argv[1]);
38         if (updateResult.empty()) {
39             return nullptr;
40         }
41         size_t length = updateResult.size() + 1;
42         char *result = new (std::nothrow) char[length];
43         if (result == nullptr) {
44             return nullptr;
45         }
46         errno_t ret = strcpy_s(result, length, updateResult.c_str());
47         if (ret != EOK) {
48             return nullptr;
49         }
50         return result;
51     }
52     return nullptr;
53 }
54 
55 #ifdef __cplusplus
56 #if __cplusplus
57 }
58 #endif
59 #endif