15ba71b47Sopenharmony_ci/* 25ba71b47Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 35ba71b47Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45ba71b47Sopenharmony_ci * you may not use this file except in compliance with the License. 55ba71b47Sopenharmony_ci * You may obtain a copy of the License at 65ba71b47Sopenharmony_ci * 75ba71b47Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85ba71b47Sopenharmony_ci * 95ba71b47Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105ba71b47Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115ba71b47Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125ba71b47Sopenharmony_ci * See the License for the specific language governing permissions and 135ba71b47Sopenharmony_ci * limitations under the License. 145ba71b47Sopenharmony_ci */ 155ba71b47Sopenharmony_ci 165ba71b47Sopenharmony_ci#include "local_abilitys.h" 175ba71b47Sopenharmony_ci 185ba71b47Sopenharmony_ciusing namespace std; 195ba71b47Sopenharmony_ciusing namespace OHOS::HiviewDFX; 205ba71b47Sopenharmony_ci 215ba71b47Sopenharmony_cinamespace OHOS { 225ba71b47Sopenharmony_ci#undef LOG_DOMAIN 235ba71b47Sopenharmony_ci#define LOG_DOMAIN 0xD001800 245ba71b47Sopenharmony_ci#undef LOG_TAG 255ba71b47Sopenharmony_ci#define LOG_TAG "SA" 265ba71b47Sopenharmony_ciLocalAbilitys& LocalAbilitys::GetInstance() 275ba71b47Sopenharmony_ci{ 285ba71b47Sopenharmony_ci static auto instance = new LocalAbilitys(); 295ba71b47Sopenharmony_ci return *instance; 305ba71b47Sopenharmony_ci} 315ba71b47Sopenharmony_ci 325ba71b47Sopenharmony_civoid LocalAbilitys::AddAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability) 335ba71b47Sopenharmony_ci{ 345ba71b47Sopenharmony_ci HILOG_DEBUG(LOG_CORE, "AddAbility to cache %{public}d", systemAbilityId); 355ba71b47Sopenharmony_ci std::lock_guard<std::mutex> autoLock(localSALock_); 365ba71b47Sopenharmony_ci localSAMap_[systemAbilityId] = ability; 375ba71b47Sopenharmony_ci} 385ba71b47Sopenharmony_ci 395ba71b47Sopenharmony_cisptr<IRemoteObject> LocalAbilitys::GetAbility(int32_t systemAbilityId) 405ba71b47Sopenharmony_ci{ 415ba71b47Sopenharmony_ci std::lock_guard<std::mutex> autoLock(localSALock_); 425ba71b47Sopenharmony_ci auto it = localSAMap_.find(systemAbilityId); 435ba71b47Sopenharmony_ci if (it != localSAMap_.end()) { 445ba71b47Sopenharmony_ci return it->second; 455ba71b47Sopenharmony_ci } 465ba71b47Sopenharmony_ci return nullptr; 475ba71b47Sopenharmony_ci} 485ba71b47Sopenharmony_ci 495ba71b47Sopenharmony_civoid LocalAbilitys::RemoveAbility(int32_t systemAbilityId) 505ba71b47Sopenharmony_ci{ 515ba71b47Sopenharmony_ci HILOG_DEBUG(LOG_CORE, "RemoveAbility from cache %{public}d", systemAbilityId); 525ba71b47Sopenharmony_ci std::lock_guard<std::mutex> autoLock(localSALock_); 535ba71b47Sopenharmony_ci auto it = localSAMap_.find(systemAbilityId); 545ba71b47Sopenharmony_ci if (it != localSAMap_.end()) { 555ba71b47Sopenharmony_ci localSAMap_.erase(systemAbilityId); 565ba71b47Sopenharmony_ci } 575ba71b47Sopenharmony_ci} 585ba71b47Sopenharmony_ci} 59