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 "quick_fix_utils.h" 17 18 #include "hilog_wrapper.h" 19 #include "if_system_ability_manager.h" 20 #include "iservice_registry.h" 21 #include "system_ability_definition.h" 22 23 namespace OHOS { 24 namespace AAFwk { GetRemoteObjectOfSystemAbility(const int32_t systemAbilityId)25sptr<IRemoteObject> QuickFixUtil::GetRemoteObjectOfSystemAbility(const int32_t systemAbilityId) 26 { 27 auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 28 if (systemAbilityMgr == nullptr) { 29 HILOG_ERROR("Failed to get SystemAbilityManager."); 30 return nullptr; 31 } 32 33 auto remoteObj = systemAbilityMgr->GetSystemAbility(systemAbilityId); 34 if (remoteObj == nullptr) { 35 HILOG_ERROR("Remote object is nullptr."); 36 return nullptr; 37 } 38 39 return remoteObj; 40 } 41 GetAppManagerProxy()42sptr<AppExecFwk::IAppMgr> QuickFixUtil::GetAppManagerProxy() 43 { 44 return iface_cast<AppExecFwk::IAppMgr>(GetRemoteObjectOfSystemAbility(APP_MGR_SERVICE_ID)); 45 } 46 GetBundleManagerProxy()47sptr<AppExecFwk::IBundleMgr> QuickFixUtil::GetBundleManagerProxy() 48 { 49 return iface_cast<AppExecFwk::IBundleMgr>(GetRemoteObjectOfSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID)); 50 } 51 GetBundleQuickFixMgrProxy()52sptr<AppExecFwk::IQuickFixManager> QuickFixUtil::GetBundleQuickFixMgrProxy() 53 { 54 HILOG_DEBUG("function called."); 55 auto bundleMgr = GetBundleManagerProxy(); 56 if (bundleMgr == nullptr) { 57 HILOG_ERROR("Failed to get bms."); 58 return nullptr; 59 } 60 61 auto bundleQuickFixMgr = bundleMgr->GetQuickFixManagerProxy(); 62 if (bundleQuickFixMgr == nullptr) { 63 HILOG_ERROR("Failed to get bundle quick fix manager."); 64 return nullptr; 65 } 66 67 HILOG_DEBUG("function finished."); 68 return bundleQuickFixMgr; 69 } 70 } // namespace AAFwk 71 } // namespace OHOS 72