1 /*
2  * Copyright (c) 2022-2024 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 "quick_fix_utils.h"
17 
18 #include "bundle_mgr_helper.h"
19 #include "hilog_tag_wrapper.h"
20 #include "if_system_ability_manager.h"
21 #include "iservice_registry.h"
22 #include "singleton.h"
23 #include "system_ability_definition.h"
24 
25 namespace OHOS {
26 namespace AAFwk {
GetRemoteObjectOfSystemAbility(const int32_t systemAbilityId)27 sptr<IRemoteObject> QuickFixUtil::GetRemoteObjectOfSystemAbility(const int32_t systemAbilityId)
28 {
29     auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
30     if (systemAbilityMgr == nullptr) {
31         TAG_LOGE(AAFwkTag::QUICKFIX, "Failed to get SystemAbilityManager");
32         return nullptr;
33     }
34 
35     auto remoteObj = systemAbilityMgr->GetSystemAbility(systemAbilityId);
36     if (remoteObj == nullptr) {
37         TAG_LOGE(AAFwkTag::QUICKFIX, "Remote object is nullptr");
38         return nullptr;
39     }
40 
41     return remoteObj;
42 }
43 
GetAppManagerProxy()44 sptr<AppExecFwk::IAppMgr> QuickFixUtil::GetAppManagerProxy()
45 {
46     return iface_cast<AppExecFwk::IAppMgr>(GetRemoteObjectOfSystemAbility(APP_MGR_SERVICE_ID));
47 }
48 
GetBundleQuickFixMgrProxy()49 sptr<AppExecFwk::IQuickFixManager> QuickFixUtil::GetBundleQuickFixMgrProxy()
50 {
51     TAG_LOGD(AAFwkTag::QUICKFIX, "called");
52     auto bundleMgrHelper = DelayedSingleton<AppExecFwk::BundleMgrHelper>::GetInstance();
53     if (bundleMgrHelper == nullptr) {
54         TAG_LOGE(AAFwkTag::QUICKFIX, "The bundleMgrHelper is nullptr");
55         return nullptr;
56     }
57 
58     auto bundleQuickFixMgr = bundleMgrHelper->GetQuickFixManagerProxy();
59     if (bundleQuickFixMgr == nullptr) {
60         TAG_LOGE(AAFwkTag::QUICKFIX, "The bundleQuickFixMgr is nullptr");
61         return nullptr;
62     }
63 
64     return bundleQuickFixMgr;
65 }
66 } // namespace AAFwk
67 } // namespace OHOS
68