• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         CHECK_REMOTE_SYSTEM_ABILITY_TRANSACTION = 9,
60         ADD_ONDEMAND_SYSTEM_ABILITY_TRANSACTION = 10,
61         CHECK_SYSTEM_ABILITY_IMMEDIATELY_TRANSACTION = 12,
62         CHECK_ONDEMAND_SYSTEM_ABILITY_TRANSACTION = 15,
63         GET_SYSTEM_ABILITYINFOLIST_TRANSACTION = 17,
64         UNSUBSCRIBE_SYSTEM_ABILITY_TRANSACTION = 18,
65         ADD_SYSTEM_PROCESS_TRANSACTION = 20
66     };
67 
68     // Retrieve an existing ability, blocking for a few seconds if it doesn't ye exist.
69     virtual sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId) = 0;
70 
71     // Retrieve an existing ability, no-blocking.
72     virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId) = 0;
73 
74     // Remove an ability.
75     virtual int32_t RemoveSystemAbility(int32_t systemAbilityId) = 0;
76 
77     virtual int32_t SubscribeSystemAbility(int32_t systemAbilityId,
78         const sptr<ISystemAbilityStatusChange>& listener) = 0;
79     virtual int32_t UnSubscribeSystemAbility(int32_t systemAbilityId,
80         const sptr<ISystemAbilityStatusChange>& listener) = 0;
81 
82     // Retrieve an existing ability, blocking for a few seconds if it doesn't ye exist.
83     virtual sptr<IRemoteObject> GetSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0;
84 
85     // Retrieve an existing ability, no-blocking
86     virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) = 0;
87 
88     // Add ondemand ability info.
89     virtual int32_t AddOnDemandSystemAbilityInfo(int32_t systemAbilityId,
90         const std::u16string& localAbilityManagerName) = 0;
91 
92     // Retrieve an ability, no-blocking.
93     virtual sptr<IRemoteObject> CheckSystemAbility(int32_t systemAbilityId, bool& isExist) = 0;
94 
95     struct SAExtraProp {
96         SAExtraProp() = default;
SAExtraPropSAExtraProp97         SAExtraProp(bool isDistributed, unsigned int dumpFlags, const std::u16string& capability,
98             const std::u16string& permission)
99         {
100             this->isDistributed = isDistributed;
101             this->dumpFlags = dumpFlags;
102             this->capability = capability;
103             this->permission = permission;
104         }
105 
106         bool isDistributed = false;
107         unsigned int dumpFlags = DUMP_FLAG_PRIORITY_DEFAULT;
108         std::u16string capability;
109         std::u16string permission;
110     };
111     virtual int32_t AddSystemAbility(int32_t systemAbilityId, const sptr<IRemoteObject>& ability,
112         const SAExtraProp& extraProp = SAExtraProp(false, DUMP_FLAG_PRIORITY_DEFAULT, u"", u"")) = 0;
113 
114     virtual int32_t AddSystemProcess(const std::u16string& procName, const sptr<IRemoteObject>& procObject) = 0;
115     virtual int32_t LoadSystemAbility(int32_t systemAbilityId, const sptr<ISystemAbilityLoadCallback>& callback) = 0;
116 public:
117     DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.ISystemAbilityManager");
118 protected:
119     static constexpr int32_t FIRST_SYS_ABILITY_ID = 0x00000001;
120     static constexpr int32_t LAST_SYS_ABILITY_ID = 0x00ffffff;
CheckInputSysAbilityId(int32_t sysAbilityId)121     bool CheckInputSysAbilityId(int32_t sysAbilityId) const
122     {
123         if (sysAbilityId >= FIRST_SYS_ABILITY_ID && sysAbilityId <= LAST_SYS_ABILITY_ID) {
124             return true;
125         }
126         return false;
127     }
128     static inline const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
129 };
130 } // namespace OHOS
131 
132 #endif // !defined(INTERFACES_INNERKITS_SAMGR_INCLUDE_IF_SYSTEM_ABILITY_MANAGER_H_ )
133