1 /* 2 * Copyright (c) 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 "utils/app_mgr_util.h" 17 18 #include "sys_mgr_client.h" 19 #include "system_ability_definition.h" 20 21 namespace OHOS { 22 namespace AAFwk { 23 sptr<OHOS::AppExecFwk::IAppMgr> AppMgrUtil::appMgr_ = nullptr; 24 GetAppMgr()25OHOS::sptr<OHOS::AppExecFwk::IAppMgr> AppMgrUtil::GetAppMgr() 26 { 27 if (appMgr_) { 28 return appMgr_; 29 } 30 31 auto sysMgrClient = DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance(); 32 if (sysMgrClient == nullptr) { 33 return nullptr; 34 } 35 auto object = sysMgrClient->GetSystemAbility(APP_MGR_SERVICE_ID); 36 if (object == nullptr) { 37 return nullptr; 38 } 39 appMgr_ = OHOS::iface_cast<OHOS::AppExecFwk::IAppMgr>(object); 40 return appMgr_; 41 } 42 } // namespace AAFwk 43 } // namespace OHOS 44