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 "edm_app_manager_impl.h" 17 18 #include "system_ability_definition.h" 19 20 #include "edm_log.h" 21 #include "edm_sys_manager.h" 22 23 namespace OHOS { 24 namespace EDM { RegisterApplicationStateObserver(const sptr<AppExecFwk::IApplicationStateObserver> & observer)25ErrCode EdmAppManagerImpl::RegisterApplicationStateObserver( 26 const sptr<AppExecFwk::IApplicationStateObserver>& observer) 27 { 28 auto remoteObject = EdmSysManager::GetRemoteObjectOfSystemAbility(OHOS::APP_MGR_SERVICE_ID); 29 sptr<AppExecFwk::IAppMgr> proxy = iface_cast<AppExecFwk::IAppMgr>(remoteObject); 30 if (proxy && !proxy->RegisterApplicationStateObserver(observer)) { 31 EDMLOGI("EdmAppManagerImpl::RegisterApplicationStateObserver success."); 32 return ERR_OK; 33 } 34 EDMLOGE("EdmAppManagerImpl::RegisterApplicationStateObserver failed."); 35 return ERR_APPLICATION_SERVICE_ABNORMALLY; 36 } 37 UnregisterApplicationStateObserver(const sptr<AppExecFwk::IApplicationStateObserver> & observer)38ErrCode EdmAppManagerImpl::UnregisterApplicationStateObserver( 39 const sptr<AppExecFwk::IApplicationStateObserver>& observer) 40 { 41 auto remoteObject = EdmSysManager::GetRemoteObjectOfSystemAbility(OHOS::APP_MGR_SERVICE_ID); 42 sptr<AppExecFwk::IAppMgr> proxy = iface_cast<AppExecFwk::IAppMgr>(remoteObject); 43 if (proxy && !proxy->UnregisterApplicationStateObserver(observer)) { 44 EDMLOGI("EdmAppManagerImpl::UnregisterApplicationStateObserver success."); 45 return ERR_OK; 46 } 47 EDMLOGE("EdmAppManagerImpl::UnregisterApplicationStateObserver failed."); 48 return ERR_APPLICATION_SERVICE_ABNORMALLY; 49 } 50 } // namespace EDM 51 } // namespace OHOS