1 /* 2 * Copyright (c) 2023-2025 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_ABILITY_AUTO_STARTUP_CLIENT_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_CLIENT_H 18 19 #include <mutex> 20 21 #include "ability_manager_errors.h" 22 #include "ability_manager_interface.h" 23 #include "auto_startup_info.h" 24 #include "iremote_object.h" 25 26 namespace OHOS { 27 namespace AAFwk { 28 using AutoStartupInfo = AbilityRuntime::AutoStartupInfo; 29 /** 30 * @class AbilityAutoStartupClient 31 * AbilityAutoStartupClient is used to access ability manager services. 32 */ 33 class AbilityAutoStartupClient { 34 public: 35 AbilityAutoStartupClient(); 36 virtual ~AbilityAutoStartupClient(); 37 static std::shared_ptr<AbilityAutoStartupClient> GetInstance(); 38 39 /** 40 * Connect ability manager service. 41 * 42 * @return Returns ERR_OK on success, others on failure. 43 */ 44 ErrCode Connect(); 45 /** 46 * @brief Set application auto start up state by EDM. 47 * @param info The auto startup info, include bundle name, module name, ability name. 48 * @param flag Indicate whether the application is prohibited from changing the auto start up state. 49 * @return Returns ERR_OK on success, others on failure. 50 */ 51 ErrCode SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag); 52 53 /** 54 * @brief Cancel application auto start up state by EDM. 55 * @param info The auto startup info, include bundle name, module name, ability name. 56 * @param flag Indicate whether the application is prohibited from changing the auto start up state. 57 * @return Returns ERR_OK on success, others on failure. 58 */ 59 ErrCode CancelApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag); 60 61 /** 62 * @brief Query all auto startup state applications. 63 * @param infoList Output parameters, return auto startup info list. 64 * @return Returns ERR_OK on success, others on failure. 65 */ 66 ErrCode QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList); 67 68 private: 69 class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient { 70 public: 71 AbilityMgrDeathRecipient() = default; 72 ~AbilityMgrDeathRecipient() = default; 73 void OnRemoteDied(const wptr<IRemoteObject>& remote) override; 74 private: 75 DISALLOW_COPY_AND_MOVE(AbilityMgrDeathRecipient); 76 }; 77 78 sptr<IAbilityManager> GetAbilityManager(); 79 void ResetProxy(wptr<IRemoteObject> remote); 80 81 static std::recursive_mutex mutex_; 82 static std::shared_ptr<AbilityAutoStartupClient> instance_; 83 sptr<IAbilityManager> proxy_; 84 sptr<IRemoteObject::DeathRecipient> deathRecipient_; 85 }; 86 } // namespace AAFwk 87 } // namespace OHOS 88 #endif // OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_CLIENT_H 89