1 /*
2  * Copyright (c) 2021-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 FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_ABILITY_INFO_H
17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_ABILITY_INFO_H
18 
19 #include <string>
20 #include <unordered_set>
21 
22 #include "parcel.h"
23 #include "application_info.h"
24 #include "extension_ability_info.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 enum AbilityInfoFlag : uint16_t {
29     GET_ABILITY_INFO_DEFAULT = 0x00000000,
30     GET_ABILITY_INFO_WITH_PERMISSION = 0x00000002,
31     GET_ABILITY_INFO_WITH_APPLICATION = 0x00000004,
32     GET_ABILITY_INFO_WITH_METADATA = 0x00000020,
33     GET_ABILITY_INFO_SYSTEMAPP_ONLY = 0x00000080,
34     GET_ABILITY_INFO_WITH_DISABLE = 0x00000100,
35     GET_ABILITY_INFO_WITH_SKILL_URI = 0x00000200,
36     GET_ABILITY_INFO_WITH_SKILL = 0x00000400
37 };
38 
39 enum class GetAbilityInfoFlag : uint16_t {
40     GET_ABILITY_INFO_DEFAULT = 0x00000000,
41     GET_ABILITY_INFO_WITH_PERMISSION = 0x00000001,
42     GET_ABILITY_INFO_WITH_APPLICATION = 0x00000002,
43     GET_ABILITY_INFO_WITH_METADATA = 0x00000004,
44     GET_ABILITY_INFO_WITH_DISABLE = 0x00000008,
45     GET_ABILITY_INFO_ONLY_SYSTEM_APP = 0x00000010,
46     GET_ABILITY_INFO_WITH_SKILL_URI = 0x00000020,
47     GET_ABILITY_INFO_WITH_APP_LINKING = 0x00000040,
48     GET_ABILITY_INFO_WITH_SKILL = 0x00000080
49 };
50 
51 enum class AbilityType {
52     UNKNOWN = 0,
53     PAGE,
54     SERVICE,
55     DATA,
56     FORM,
57     EXTENSION,
58 };
59 
60 enum class BackgroundMode {
61     DEFAULT = 0,
62     DATA_TRANSFER = 1 << 0,
63     AUDIO_PLAYBACK = 1 << 1,
64     AUDIO_RECORDING = 1 << 2,
65     LOCATION = 1 << 3,
66     BLUETOOTH_INTERACTION = 1 << 4,
67     MULTI_DEVICE_CONNECTION = 1 << 5,
68     WIFI_INTERACTION = 1 << 6,
69     VOIP = 1 << 7,
70     TASK_KEEPING = 1 << 8,
71 };
72 
73 enum class AbilitySubType {
74     UNSPECIFIED = 0,
75     CA,
76 };
77 
78 enum class DisplayOrientation {
79     UNSPECIFIED = 0,
80     LANDSCAPE,
81     PORTRAIT,
82     FOLLOWRECENT,
83     LANDSCAPE_INVERTED,
84     PORTRAIT_INVERTED,
85     AUTO_ROTATION,
86     AUTO_ROTATION_LANDSCAPE,
87     AUTO_ROTATION_PORTRAIT,
88     AUTO_ROTATION_RESTRICTED,
89     AUTO_ROTATION_LANDSCAPE_RESTRICTED,
90     AUTO_ROTATION_PORTRAIT_RESTRICTED,
91     LOCKED,
92     AUTO_ROTATION_UNSPECIFIED,
93     FOLLOW_DESKTOP,
94 };
95 
96 enum class LaunchMode {
97     SINGLETON = 0,
98     STANDARD,  // support more than one instance
99     SPECIFIED,
100 };
101 
102 enum class SupportWindowMode {
103     FULLSCREEN = 0,
104     SPLIT,
105     FLOATING,
106 };
107 
108 enum class LinkType : uint8_t {
109     DEEP_LINK = 0,
110     APP_LINK,
111     DEFAULT_APP,
112 };
113 
114 struct AbilityInfo;
115 
116 /*
117 * According to Ability profile 1.0
118 */
119 struct CompatibleAbilityInfo : public Parcelable {
120     // deprecated: ability code class simple name, use 'className' instead.
121     std::string package;
122     std::string name;
123     std::string label; // display name on screen.
124     std::string description;
125     std::string iconPath; // used as icon data (base64) for WEB Ability.
126     std::string uri; // uri of ability.
127     std::string moduleName; // indicates the name of the .hap package to which the capability belongs.
128     std::string process;
129     std::string targetAbility;
130     std::string appName;
131     std::string privacyUrl;
132     std::string privacyName;
133     std::string downloadUrl;
134     std::string versionName;
135     uint32_t backgroundModes = 0;
136     uint32_t packageSize = 0; // The size of the package that AbilityInfo.uri points to.
137     bool visible = false;
138     bool formEnabled = false;
139     bool multiUserShared = false;
140     // deprecated: remove this field in new package format.
141     AbilityType type = AbilityType::UNKNOWN;
142     AbilitySubType subType = AbilitySubType::UNSPECIFIED;
143     DisplayOrientation orientation = DisplayOrientation::UNSPECIFIED;
144     LaunchMode launchMode = LaunchMode::SINGLETON;
145     std::vector<std::string> permissions;
146     std::vector<std::string> deviceTypes;
147     std::vector<std::string> deviceCapabilities;
148     bool supportPipMode = false;
149     bool grantPermission = false;
150     std::string readPermission;
151     std::string writePermission;
152     std::string uriPermissionMode;
153     std::string uriPermissionPath;
154     bool directLaunch = true;
155 
156     // set when install
157     std::string bundleName; // bundle name which has this ability.
158     std::string className;  // the ability full class name.
159     std::string originalClassName; // the original ability full class name
160     std::string deviceId; // device UDID information.
161     CompatibleApplicationInfo applicationInfo;
162 
163     // form widget info
164     uint32_t formEntity = 1; // where form can be displayed
165     int32_t minFormHeight = 0; // minimum height of ability.
166     int32_t defaultFormHeight = 0; // default height of ability.
167     int32_t minFormWidth = 0; // minimum width of ability.
168     int32_t defaultFormWidth = 0; // default width of ability.
169 
170     uint32_t iconId = 0;
171     uint32_t labelId = 0;
172     uint32_t descriptionId = 0;
173     bool enabled = true;
174 
175     bool ReadFromParcel(Parcel& parcel);
176     virtual bool Marshalling(Parcel& parcel) const override;
177     static CompatibleAbilityInfo* Unmarshalling(Parcel& parcel);
178 
179     void ConvertToAbilityInfo(AbilityInfo& abilityInfo) const;
180 };
181 
182 // configuration information about an ability
183 struct AbilityInfo : public Parcelable {
184     std::string name;  // ability name, only the main class name
185     std::string label;
186     std::string description;
187     std::string iconPath;
188     uint32_t labelId = 0;
189     uint32_t descriptionId = 0;
190     uint32_t iconId = 0;
191     std::string theme;
192     bool visible = false;
193     std::string kind;  // ability category
194     AbilityType type = AbilityType::UNKNOWN;
195     ExtensionAbilityType extensionAbilityType = ExtensionAbilityType::UNSPECIFIED;
196     std::string extensionTypeName;
197     DisplayOrientation orientation = DisplayOrientation::UNSPECIFIED;
198     uint32_t orientationId = 0;
199     LaunchMode launchMode = LaunchMode::SINGLETON;
200     std::string srcPath;
201     std::string srcLanguage = "js";
202     std::vector<std::string> permissions;
203 
204     std::string process;
205     std::vector<std::string> deviceTypes;
206     std::vector<std::string> deviceCapabilities;
207     std::string uri;
208     std::string targetAbility;
209     ApplicationInfo applicationInfo;
210     bool isLauncherAbility = false;
211     bool isNativeAbility = false;
212     bool enabled = false;
213     bool supportPipMode = false;
214     bool formEnabled = false;
215     bool removeMissionAfterTerminate = false;
216     std::string readPermission;
217     std::string writePermission;
218     std::vector<std::string> configChanges;
219     uint32_t formEntity = 0;
220     int32_t minFormHeight = 0;
221     int32_t defaultFormHeight = 0;
222     int32_t minFormWidth = 0;
223     int32_t defaultFormWidth = 0;
224     MetaData metaData;
225     uint32_t backgroundModes = 0;
226 
227     // for Check flags, add to abilityInfo and extensionAbilityInfo
228     std::vector<SkillUriForAbilityAndExtension> skillUri;
229     std::vector<Skill> skills;
230 
231     // set when install
232     std::string package;  // the "module.package" in config.json
233     std::string bundleName;
234     std::string moduleName;       // the "module.name" in config.json
235     std::string applicationName;  // the "bundlename" in config.json
236 
237     std::string codePath;         // ability main code path with name
238     std::string resourcePath;     // resource path for resource init
239     std::string hapPath;
240 
241     std::string srcEntrance;
242     std::vector<Metadata> metadata;
243     bool isModuleJson = false;
244     bool isStageBasedModel = false;
245     bool continuable = false;
246     int32_t priority = 0;
247 
248     // configuration fields on startup page
249     std::string startWindowIcon;
250     uint32_t startWindowIconId = 0;
251     std::string startWindowBackground;
252     uint32_t startWindowBackgroundId = 0;
253     // whether to display in the missions list
254     bool excludeFromMissions = false;
255     bool unclearableMission = false;
256     bool excludeFromDock = false;
257     std::string preferMultiWindowOrientation = "default";
258     // whether to support recover UI interface
259     bool recoverable = false;
260     bool isolationProcess = false;
261 
262     // support windows mode
263     std::vector<SupportWindowMode> windowModes;
264     double maxWindowRatio = 0;
265     double minWindowRatio = 0;
266     uint32_t maxWindowWidth = 0;
267     uint32_t minWindowWidth = 0;
268     uint32_t maxWindowHeight = 0;
269     uint32_t minWindowHeight = 0;
270     // for NAPI, save self query cache
271     int32_t uid = -1;
272     CompileMode compileMode = CompileMode::JS_BUNDLE;
273     int32_t appIndex = 0;
274 
275     std::string originalBundleName;
276     std::string appName;
277     std::string privacyUrl;
278     std::string privacyName;
279     std::string downloadUrl;
280     std::string versionName;
281     std::string className;
282     std::string originalClassName;
283     std::string uriPermissionMode;
284     std::string uriPermissionPath;
285     uint32_t packageSize = 0;
286     bool multiUserShared = false;
287     bool grantPermission = false;
288     bool directLaunch = true;
289     AbilitySubType subType = AbilitySubType::UNSPECIFIED;
290     std::string libPath;
291     std::string deviceId;
292     int64_t installTime = 0;
293     std::vector<std::string> supportExtNames;
294     std::vector<std::string> supportMimeTypes;
295     std::vector<std::string> continueType;
296     std::unordered_set<std::string> continueBundleNames;
297     LinkType linkType = LinkType::DEEP_LINK;
298 
299     bool ReadFromParcel(Parcel &parcel);
300     virtual bool Marshalling(Parcel &parcel) const override;
301     static AbilityInfo *Unmarshalling(Parcel &parcel);
302     void Dump(std::string prefix, int fd);
303     void ConvertToCompatiableAbilityInfo(CompatibleAbilityInfo& compatibleAbilityInfo) const;
304 };
305 }  // namespace AppExecFwk
306 }  // namespace OHOS
307 #endif  // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_ABILITY_INFO_H
308