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 "iservice_registry.h" 17 18 #include "assistant.h" 19 #include "hilog_wrapper.h" 20 #include "if_system_ability_manager_mock.h" 21 #include "ipc_skeleton.h" 22 #include "iremote_object.h" 23 24 namespace OHOS { 25 using namespace OHOS::FileAccessFwk; GetInstance()26SystemAbilityManagerClient& SystemAbilityManagerClient::GetInstance() 27 { 28 static auto instance = std::make_shared<SystemAbilityManagerClient>(); 29 return *instance; 30 } 31 GetSystemAbilityManager()32sptr<ISystemAbilityManager> SystemAbilityManagerClient::GetSystemAbilityManager() 33 { 34 if (Assistant::ins_ == nullptr) { 35 return false; 36 } 37 if (Assistant::ins_->Bool() == false) { 38 return nullptr; 39 } 40 41 std::lock_guard<std::mutex> lock(systemAbilityManagerLock_); 42 if (systemAbilityManager_ != nullptr) { 43 return systemAbilityManager_; 44 } 45 46 systemAbilityManager_ = sptr<ISystemAbilityManager>(new ISystemAbilityManagerMock()); 47 return systemAbilityManager_; 48 } 49 DestroySystemAbilityManagerObject()50void SystemAbilityManagerClient::DestroySystemAbilityManagerObject() 51 { 52 std::lock_guard<std::mutex> lock(systemAbilityManagerLock_); 53 systemAbilityManager_.clear(); 54 } 55 } // namespace OHOS