1 /*
2  * Copyright (c) 2022-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_EXTENSION_INFO_H
17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_EXTENSION_INFO_H
18 
19 #include <map>
20 #include <string>
21 
22 #include "application_info.h"
23 #include "parcel.h"
24 #include "skill.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 enum ExtensionAbilityInfoFlag {
29     GET_EXTENSION_INFO_DEFAULT = 0x00000000,
30     GET_EXTENSION_INFO_WITH_PERMISSION = 0x00000002,
31     GET_EXTENSION_INFO_WITH_APPLICATION = 0x00000004,
32     GET_EXTENSION_INFO_WITH_METADATA = 0x00000020,
33     GET_EXTENSION_INFO_WITH_SKILL_URI = 0x00000200,
34     GET_EXTENSION_INFO_WITH_SKILL = 0x00000400,
35 };
36 
37 enum class GetExtensionAbilityInfoFlag {
38     GET_EXTENSION_ABILITY_INFO_DEFAULT = 0x00000000,
39     GET_EXTENSION_ABILITY_INFO_WITH_PERMISSION = 0x00000001,
40     GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION = 0x00000002,
41     GET_EXTENSION_ABILITY_INFO_WITH_METADATA = 0x00000004,
42     GET_EXTENSION_ABILITY_INFO_WITH_SKILL_URI = 0x00000008,
43     GET_EXTENSION_ABILITY_INFO_WITH_SKILL = 0x00000010,
44     // using this tag will only return the first system app, only for c++
45     // appIndex = 0,invalid input of other flag
46     // appIndex !=0,this flag is invalid
47     GET_EXTENSION_ABILITY_INFO_BY_TYPE_NAME = 0x80000000,
48 };
49 
50 enum class ExtensionAbilityType {
51     FORM = 0,
52     WORK_SCHEDULER = 1,
53     INPUTMETHOD = 2,
54     SERVICE = 3,
55     ACCESSIBILITY = 4,
56     DATASHARE = 5,
57     FILESHARE = 6,
58     STATICSUBSCRIBER = 7,
59     WALLPAPER = 8,
60     BACKUP = 9,
61     WINDOW = 10,
62     ENTERPRISE_ADMIN = 11,
63     FILEACCESS_EXTENSION = 12,
64     THUMBNAIL = 13,
65     PREVIEW = 14,
66     PRINT = 15,
67     SHARE = 16,
68     PUSH = 17,
69     DRIVER = 18,
70     ACTION = 19,
71     ADS_SERVICE = 20,
72     EMBEDDED_UI = 21,
73     INSIGHT_INTENT_UI = 22,
74     PHOTO_EDITOR = 23,
75     FENCE = 24,
76     CALLER_INFO_QUERY = 25,
77     UNSPECIFIED = 255,
78     UI = 256,
79     HMS_ACCOUNT = 257,
80     APP_ACCOUNT_AUTHORIZATION = 258,
81     ADS = 259,
82     REMOTE_NOTIFICATION = 260,
83     REMOTE_LOCATION = 261,
84     VOIP = 262,
85     ACCOUNTLOGOUT = 263,
86     STATUS_BAR_VIEW = 264,
87     LIVEVIEW_LOCKSCREEN = 265,
88     UI_SERVICE = 269,
89     SYSDIALOG_USERAUTH = 300,
90     SYSDIALOG_COMMON = 301,
91     SYSDIALOG_ATOMICSERVICEPANEL = 302,
92     SYSDIALOG_POWER = 303,
93     SYSDIALOG_MEETIMECALL = 304,
94     SYSDIALOG_MEETIMECONTACT = 305,
95     SYSDIALOG_MEETIMEMESSAGE = 306,
96     SYSDIALOG_PRINT = 307,
97     SYSPICKER_MEDIACONTROL = 400,
98     SYSPICKER_SHARE = 401,
99     SYSPICKER_MEETIMECONTACT = 402,
100     SYSPICKER_MEETIMECALLLOG = 403,
101     SYSPICKER_PHOTOPICKER = 404,
102     SYSPICKER_CAMERA = 405,
103     SYSPICKER_NAVIGATION = 406,
104     SYSPICKER_APPSELECTOR = 407,
105     SYSPICKER_FILEPICKER = 408,
106     SYSPICKER_AUDIOPICKER = 409,
107     SYS_COMMON_UI = 500,
108     AUTO_FILL_PASSWORD = 501,
109     VPN = 502,
110     AUTO_FILL_SMART = 503,
111     SYSPICKER_PHOTOEDITOR = 504,
112     SYS_VISUAL = 505,
113     RECENT_PHOTO = 506
114 };
115 
116 enum class CompileMode {
117     JS_BUNDLE = 0,
118     ES_MODULE,
119 };
120 
121 enum class ExtensionProcessMode {
122     UNDEFINED = -1,
123     INSTANCE = 0,
124     TYPE = 1,
125     BUNDLE = 2,
126     RUN_WITH_MAIN_PROCESS = 3,
127 };
128 
129 struct SkillUriForAbilityAndExtension {
130     std::string scheme;
131     std::string host;
132     std::string port;
133     std::string path;
134     std::string pathStartWith;
135     std::string pathRegex;
136     std::string type;
137     std::string utd;
138     int32_t maxFileSupported = 0;
139     std::string linkFeature;
140     bool isMatch = false;
141 };
142 
143 struct ExtensionAbilityInfo : public Parcelable {
144     std::string bundleName;
145     std::string moduleName;
146     std::string name;
147     std::string srcEntrance;
148     std::string icon;
149     uint32_t iconId = 0;
150     std::string label;
151     uint32_t labelId = 0;
152     std::string description;
153     uint32_t descriptionId = 0;
154     int32_t priority = 0;
155     std::vector<std::string> permissions;
156     std::string readPermission;
157     std::string writePermission;
158     std::string uri;
159     ExtensionAbilityType type = ExtensionAbilityType::UNSPECIFIED;
160     std::string extensionTypeName;
161     bool visible = false;
162     std::vector<Metadata> metadata;
163     ApplicationInfo applicationInfo;
164     ExtensionProcessMode extensionProcessMode = ExtensionProcessMode::UNDEFINED;
165     // set when install
166     std::string resourcePath;
167     std::string hapPath;
168     bool enabled = true;
169     std::string process;
170     CompileMode compileMode = CompileMode::JS_BUNDLE;
171     // for NAPI, save self query cache
172     int32_t uid = -1;
173     int32_t appIndex = 0;
174 
175     // for Check flags, add to abilityInfo and extensionAbilityInfo
176     std::vector<SkillUriForAbilityAndExtension> skillUri;
177     std::vector<Skill> skills;
178 
179     bool needCreateSandbox = false;
180     std::vector<std::string> dataGroupIds;
181     std::vector<std::string> validDataGroupIds;
182     std::string customProcess;
183 
184     bool ReadFromParcel(Parcel &parcel);
185     virtual bool Marshalling(Parcel &parcel) const override;
186     static ExtensionAbilityInfo *Unmarshalling(Parcel &parcel);
187     bool MarshallingSkillUri(Parcel &parcel, SkillUriForAbilityAndExtension uri) const;
188     void UpdateNeedCreateSandbox();
189 };
190 
191 ExtensionAbilityType ConvertToExtensionAbilityType(const std::string &type);
192 std::string ConvertToExtensionTypeName(ExtensionAbilityType type);
193 ExtensionProcessMode ConvertToExtensionProcessMode(const std::string &extensionProcessMode);
194 }  // namespace AppExecFwk
195 }  // namespace OHOS
196 #endif  // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_EXTENSION_INFO_H
197