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 #ifndef ACCESS_TOKEN_ABILITY_MANAGER_ADAPTER_H 17 #define ACCESS_TOKEN_ABILITY_MANAGER_ADAPTER_H 18 19 #include <mutex> 20 #include "ability_manager_access_loader.h" 21 22 namespace OHOS { 23 namespace Security { 24 namespace AccessToken { 25 /** 26 * @class AbilityManagerAdapter 27 * AbilityManagerAdapter is used to access ability manager services. 28 */ 29 class AbilityManagerAdapter { 30 private: 31 AbilityManagerAdapter(); 32 virtual ~AbilityManagerAdapter(); 33 DISALLOW_COPY_AND_MOVE(AbilityManagerAdapter); 34 35 public: 36 static AbilityManagerAdapter& GetInstance(); 37 38 int32_t StartAbility(const InnerWant &innerWant, const sptr<IRemoteObject> &callerToken); 39 int32_t KillProcessForPermissionUpdate(uint32_t accessTokenId); 40 41 enum class Message { 42 START_ABILITY = 1001, 43 KILL_PROCESS_FOR_PERMISSION_UPDATE = 5300, 44 }; 45 46 private: 47 void InitProxy(); 48 49 class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient { 50 public: 51 AbilityMgrDeathRecipient() = default; 52 ~AbilityMgrDeathRecipient() override = default; 53 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 54 private: 55 DISALLOW_COPY_AND_MOVE(AbilityMgrDeathRecipient); 56 }; 57 58 sptr<IRemoteObject> GetProxy(); 59 void ReleaseProxy(const wptr<IRemoteObject>& remote); 60 61 std::mutex proxyMutex_; 62 sptr<IRemoteObject> proxy_ = nullptr; 63 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 64 }; 65 } // namespace AccessToken 66 } // namespace Security 67 } // namespace OHOS 68 #endif // ACCESS_TOKEN_ABILITY_MANAGER_ADAPTER_H 69