• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "system_ability_helper.h"
17 
18 #include "string_ex.h"
19 #include "if_system_ability_manager.h"
20 #include "iservice_registry.h"
21 #include "ipc_skeleton.h"
22 #include "app_log_wrapper.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 
GetSystemAbility(const int32_t systemAbilityId)27 sptr<IRemoteObject> SystemAbilityHelper::GetSystemAbility(const int32_t systemAbilityId)
28 {
29     sptr<ISystemAbilityManager> systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
30     if (!systemAbilityMgr) {
31         APP_LOGE("fail to get the system ability manager to get %{public}d proxy", systemAbilityId);
32         return nullptr;
33     }
34     return systemAbilityMgr->GetSystemAbility(systemAbilityId);
35 }
36 
AddSystemAbility(const int32_t systemAbilityId,const sptr<IRemoteObject> & systemAbility)37 bool SystemAbilityHelper::AddSystemAbility(const int32_t systemAbilityId, const sptr<IRemoteObject> &systemAbility)
38 {
39     sptr<ISystemAbilityManager> systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
40     if (systemAbilityMgr && (systemAbilityMgr->AddSystemAbility(systemAbilityId, systemAbility) == 0)) {
41         return true;
42     }
43     APP_LOGE("fail to register %{public}d to system ability manager", systemAbilityId);
44     return false;
45 }
46 
RemoveSystemAbility(const int32_t systemAbilityId)47 bool SystemAbilityHelper::RemoveSystemAbility(const int32_t systemAbilityId)
48 {
49     sptr<ISystemAbilityManager> systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
50     if (systemAbilityMgr && (systemAbilityMgr->RemoveSystemAbility(systemAbilityId) == 0)) {
51         return true;
52     }
53     APP_LOGE("fail to remove %{public}d from system ability manager", systemAbilityId);
54     return false;
55 }
56 
57 }  // namespace AppExecFwk
58 }  // namespace OHOS