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_->Bool() == false) { 35 return nullptr; 36 } 37 38 std::lock_guard<std::mutex> lock(systemAbilityManagerLock_); 39 if (systemAbilityManager_ != nullptr) { 40 return systemAbilityManager_; 41 } 42 43 systemAbilityManager_ = sptr<ISystemAbilityManager>(new ISystemAbilityManagerMock()); 44 return systemAbilityManager_; 45 } 46 DestroySystemAbilityManagerObject()47void SystemAbilityManagerClient::DestroySystemAbilityManagerObject() 48 { 49 std::lock_guard<std::mutex> lock(systemAbilityManagerLock_); 50 systemAbilityManager_.clear(); 51 } 52 } // namespace OHOS