1 /* 2 * Copyright (c) 2021-2022 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 INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H_ 17 #define INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H_ 18 19 #include <string> 20 #include <list> 21 22 #include "iremote_broker.h" 23 #include "iremote_object.h" 24 #include "iremote_proxy.h" 25 #include "isystem_ability_load_callback.h" 26 #include "isystem_ability_status_change.h" 27 28 namespace OHOS { 29 class ISystemAbilityManager : public IRemoteBroker { 30 public: 31 // Return list of all existing abilities. 32 virtual std::vector<std::u16string> ListSystemAbilities(unsigned int dumpFlags = DUMP_FLAG_PRIORITY_ALL) = 0; 33 34 enum { 35 SHEEFT_CRITICAL = 0, 36 SHEEFT_HIGH, 37 SHEEFT_NORMAL, 38 SHEEFT_DEFAULT, 39 SHEEFT_PROTO, 40 }; 41 42 static const unsigned int DUMP_FLAG_PRIORITY_CRITICAL = 1 << SHEEFT_CRITICAL; 43 static const unsigned int DUMP_FLAG_PRIORITY_HIGH = 1 << SHEEFT_HIGH; 44 static const unsigned int DUMP_FLAG_PRIORITY_NORMAL = 1 << SHEEFT_NORMAL; 45 46 static const unsigned int DUMP_FLAG_PRIORITY_DEFAULT = 1 << SHEEFT_DEFAULT; 47 static const unsigned int DUMP_FLAG_PRIORITY_ALL = DUMP_FLAG_PRIORITY_CRITICAL | 48 DUMP_FLAG_PRIORITY_HIGH | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PRIORITY_DEFAULT; 49 static const unsigned int DUMP_FLAG_PROTO = 1 << SHEEFT_PROTO; 50 51 enum { 52 GET_SYSTEM_ABILITY_TRANSACTION = 1, 53 CHECK_SYSTEM_ABILITY_TRANSACTION = 2, 54 ADD_SYSTEM_ABILITY_TRANSACTION = 3, 55 REMOVE_SYSTEM_ABILITY_TRANSACTION = 4, 56 LIST_SYSTEM_ABILITY_TRANSACTION = 5, 57 SUBSCRIBE_SYSTEM_ABILITY_TRANSACTION = 6, 58 LOAD_SYSTEM_ABILITY_TRANSACTION = 7, 59 LOAD_REMOTE_SYSTEM_ABILITY_TRANSACTION = 8, 60 CHECK_REMOTE_SYSTEM_ABILITY_TRANSACTION = 9, 61 ADD_ONDEMAND_SYSTEM_ABILITY_TRANSACTION = 10, 62 CHECK_SYSTEM_ABILITY_IMMEDIATELY_TRANSACTION = 12, 63 CHECK_ONDEMAND_SYSTEM_ABILITY_TRANSACTION = 15, 64 GET_SYSTEM_ABILITYINFOLIST_TRANSACTION = 17, 65 UNSUBSCRIBE_SYSTEM_ABILITY_TRANSACTION = 18, 66 ADD_SYSTEM_PROCESS_TRANSACTION = 20 67 }; 68 69 // Retrieve an existing ability, blocking for a few seconds if it doesn't ye exist. 70 virtual sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId) = 0; 71 72 // Retrieve an existing ability, no-blocking. 73 virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId) = 0; 74 75 // Remove an ability. 76 virtual int32_t RemoveSystemAbility(int32_t systemAbilityId) = 0; 77 78 virtual int32_t SubscribeSystemAbility(int32_t systemAbilityId, 79 const sptr<ISystemAbilityStatusChange>& listener) = 0; 80 virtual int32_t UnSubscribeSystemAbility(int32_t systemAbilityId, 81 const sptr<ISystemAbilityStatusChange>& listener) = 0; 82 83 // Retrieve an existing ability, blocking for a few seconds if it doesn't ye exist. 84 virtual sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; 85 86 // Retrieve an existing ability, no-blocking 87 virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0; 88 89 // Add ondemand ability info. 90 virtual int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId, 91 const std::u16string& localAbilityManagerName) = 0; 92 93 // Retrieve an ability, no-blocking. 94 virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, bool& isExist) = 0; 95 96 struct SAExtraProp { 97 SAExtraProp() = default; SAExtraPropSAExtraProp98 SAExtraProp(bool isDistributed, unsigned int dumpFlags, const std::u16string& capability, 99 const std::u16string& permission) 100 { 101 this->isDistributed = isDistributed; 102 this->dumpFlags = dumpFlags; 103 this->capability = capability; 104 this->permission = permission; 105 } 106 107 bool isDistributed = false; 108 unsigned int dumpFlags = DUMP_FLAG_PRIORITY_DEFAULT; 109 std::u16string capability; 110 std::u16string permission; 111 }; 112 virtual int32_t AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability, 113 const SAExtraProp& extraProp = SAExtraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u"")) = 0; 114 115 virtual int32_t AddSystemProcess(const std::u16string& procName, const sptr<IRemoteObject>& procObject) = 0; 116 virtual int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr<ISystemAbilityLoadCallback>& callback) = 0; 117 virtual int32_t LoadSystemAbility(int32_t systemAbilityId, const std::string& deviceId, 118 const sptr<ISystemAbilityLoadCallback>& callback) = 0; 119 public: 120 DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityManager"); 121 protected: 122 static constexpr int32_t FIRST_SYS_ABILITY_ID = 0x00000001; 123 static constexpr int32_t LAST_SYS_ABILITY_ID = 0x00ffffff; CheckInputSysAbilityId(int32_t sysAbilityId)124 bool CheckInputSysAbilityId(int32_t sysAbilityId) const 125 { 126 if (sysAbilityId >= FIRST_SYS_ABILITY_ID && sysAbilityId <= LAST_SYS_ABILITY_ID) { 127 return true; 128 } 129 return false; 130 } 131 static inline const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken"; 132 }; 133 } // namespace OHOS 134 135 #endif // !defined(INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H_ ) 136