1 /* 2 * Copyright (c) 2023 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 #ifndef OHOS_ABILITY_RUNTIME_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SR_SAMGR_HELPER_H 17 #define OHOS_ABILITY_RUNTIME_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SR_SAMGR_HELPER_H 18 19 #include <singleton.h> 20 21 #include "bundle_mgr_interface.h" 22 23 namespace OHOS { 24 namespace AbilityRuntime { 25 using namespace OHOS::AppExecFwk; 26 27 /** 28 * @class SystemAbilityManager Helper 29 * Bms helpler. 30 */ 31 class SrSamgrHelper final : public DelayedRefSingleton<SrSamgrHelper> { 32 DECLARE_DELAYED_REF_SINGLETON(SrSamgrHelper) 33 34 public: 35 DISALLOW_COPY_AND_MOVE(SrSamgrHelper); 36 37 /** 38 * @brief Acquire a bundle manager, if it not existed, 39 * @return returns the bundle manager ipc object, or nullptr for failed. 40 */ 41 sptr<IBundleMgr> GetBundleMgr(); 42 43 /** 44 * @brief Get current active userId, 45 * @return current active userId. 46 */ 47 static int32_t GetCurrentActiveUserId(); 48 49 private: 50 class BmsDeathRecipient : public IRemoteObject::DeathRecipient { 51 public: 52 BmsDeathRecipient() = default; 53 virtual ~BmsDeathRecipient() = default; 54 55 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 56 }; 57 58 void ConnectBundleMgrLocked(); 59 void ResetProxy(const wptr<IRemoteObject> &remote); 60 61 std::mutex bundleMgrMutex_; 62 sptr<IBundleMgr> iBundleMgr_ = nullptr; 63 sptr<IRemoteObject::DeathRecipient> deathRecipient_; // bms death recipient. 64 }; 65 } // namespace AbilityRuntime 66 } // namespace OHOS 67 68 #endif // OHOS_ABILITY_RUNTIME_SERVICE_ROUTER_FRAMEWORK_SERVICES_INCLUDE_SR_SAMGR_HELPER_H 69