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 <unistd.h>
17 
18 #include "if_system_ability_manager.h"
19 #include "iservice_registry.h"
20 #include "log/log.h"
21 #include "module_update_kits.h"
22 #include "module_update_kits_impl.h"
23 
24 using namespace OHOS;
25 using namespace Updater;
26 
main()27 int main()
28 {
29     InitUpdaterLogger("ModuleUpdaterClient", "", "", "");
30     sptr<ISystemAbilityManager> samgr = nullptr;
31     int32_t times = 30;
32     const int32_t wiat_time_ms = 100 * 1000;
33     int32_t duration = std::chrono::microseconds(wiat_time_ms).count();
34     LOG(INFO) << "waiting for samgr...";
35     while (times > 0) {
36         times--;
37         samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
38         if (samgr == nullptr) {
39             usleep(duration);
40         } else {
41             break;
42         }
43     }
44 
45     if (samgr == nullptr) {
46         LOG(ERROR) <<"ModuleUpdateInit wait samgr fail";
47         return -1;
48     }
49 
50     int32_t ret = OHOS::SysInstaller::ModuleUpdateKits::GetInstance().InitModuleUpdate();
51     LOG(INFO) << "ModuleUpdateInit ret: " << ret;
52     return ret;
53 }