• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "sys_mgr_client.h"
17 
18 #include "hilog_wrapper.h"
19 #include "if_system_ability_manager.h"
20 #include "ipc_skeleton.h"
21 #include "iservice_registry.h"
22 #include "string_ex.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
SysMrgClient()26 SysMrgClient::SysMrgClient() : abilityManager_(nullptr)
27 {}
28 
~SysMrgClient()29 SysMrgClient::~SysMrgClient()
30 {}
31 
32 /**
33  *
34  * Get the systemAbility by ID.
35  *
36  * @param systemAbilityId The ID of systemAbility which want to get.
37  */
GetSystemAbility(const int32_t systemAbilityId)38 sptr<IRemoteObject> SysMrgClient::GetSystemAbility(const int32_t systemAbilityId)
39 {
40     // use single instance of abilityManager_
41     if (abilityManager_ == nullptr) {
42         std::lock_guard<std::mutex> lock(saMutex_);
43         if (abilityManager_ == nullptr) {
44             abilityManager_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
45             if (abilityManager_ == nullptr) {
46                 HILOG_ERROR("fail to GetSystemAbility abilityManager_ == nullptr.");
47                 return nullptr;
48             }
49         }
50     }
51     return abilityManager_->GetSystemAbility(systemAbilityId);
52 }
53 
54 /**
55  *
56  * Register the systemAbility by ID.
57  *
58  * @param systemAbilityId The ID of systemAbility which want to register.
59  * @param broker The systemAbility which want to be registered.
60  */
RegisterSystemAbility(const int32_t systemAbilityId,sptr<IRemoteObject> broker)61 void SysMrgClient::RegisterSystemAbility(
62     const int32_t __attribute__((unused)) systemAbilityId, sptr<IRemoteObject> __attribute__((unused)) broker)
63 {
64     (void)servicesMap_;
65 }
66 
67 /**
68  *
69  * Unregister the systemAbility by ID.
70  *
71  * @param systemAbilityId The ID of systemAbility which want to unregister.
72  */
UnregisterSystemAbility(const int32_t systemAbilityId)73 void SysMrgClient::UnregisterSystemAbility(const int32_t systemAbilityId)
74 {}
75 }  // namespace AppExecFwk
76 }  // namespace OHOS
77