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_APPLICATION_INFO_H 17 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_APPLICATION_INFO_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 #include "bundle_constants.h" 24 #include "module_info.h" 25 #include "parcel.h" 26 #include "quick_fix/app_quick_fix.h" 27 28 namespace OHOS { 29 namespace AppExecFwk { 30 namespace { 31 constexpr const char* AVAILABLELEVEL_NORMAL = "normal"; 32 constexpr const char* DEFAULT_ENTITY_TYPE = "unspecified"; 33 constexpr const char* DEFAULT_COMPILE_SDK_TYPE = "OpenHarmony"; 34 } 35 enum ApplicationFlag { 36 GET_BASIC_APPLICATION_INFO = 0x00000000, 37 GET_APPLICATION_INFO_WITH_PERMISSION = 0x00000008, 38 GET_APPLICATION_INFO_WITH_METADATA = 0x00000040, 39 GET_APPLICATION_INFO_WITH_DISABLE = 0x00000200, 40 GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT = 0x00000400, 41 GET_ALL_APPLICATION_INFO = 0xFFFF0000, 42 }; 43 44 enum class GetApplicationFlag { 45 GET_APPLICATION_INFO_DEFAULT = 0x00000000, 46 GET_APPLICATION_INFO_WITH_PERMISSION = 0x00000001, 47 GET_APPLICATION_INFO_WITH_METADATA = 0x00000002, 48 GET_APPLICATION_INFO_WITH_DISABLE = 0x00000004, 49 }; 50 51 enum class GetDependentBundleInfoFlag { 52 GET_APP_CROSS_HSP_BUNDLE_INFO = 0x00000000, 53 GET_APP_SERVICE_HSP_BUNDLE_INFO = 0x00000001, 54 GET_ALL_DEPENDENT_BUNDLE_INFO = 0x00000002, 55 }; 56 57 enum class BundleType { 58 APP = 0, 59 ATOMIC_SERVICE = 1, 60 SHARED = 2, 61 APP_SERVICE_FWK = 3, 62 }; 63 64 enum class CompatiblePolicy { 65 NORMAL = 0, 66 BACKWARD_COMPATIBILITY = 1, 67 }; 68 69 enum class ApplicationReservedFlag { 70 ENCRYPTED_APPLICATION = 0x00000001, 71 }; 72 73 enum class MultiAppModeType : uint8_t { 74 UNSPECIFIED = 0, 75 MULTI_INSTANCE = 1, 76 APP_CLONE = 2, 77 }; 78 79 enum class ApplicationInfoFlag { 80 FLAG_INSTALLED = 0x00000001, 81 /** 82 * Indicates the installation source of pre-installed applications 83 * App upgrades will not change installation source 84 * FLAG_BOOT_INSTALLED App installed during first boot 85 * FLAG_OTA_INSTALLED App installed during OTA 86 * FLAG_RECOVER_INSTALLED App recover 87 */ 88 FLAG_BOOT_INSTALLED = 0x00000002, 89 FLAG_OTA_INSTALLED = 0x00000004, 90 FLAG_RECOVER_INSTALLED = 0x00000008, 91 FLAG_OTHER_INSTALLED = 0x00000010, 92 }; 93 94 struct MultiAppModeData : public Parcelable { 95 MultiAppModeType multiAppModeType = MultiAppModeType::UNSPECIFIED; 96 int32_t maxCount = 0; 97 bool ReadFromParcel(Parcel &parcel); 98 virtual bool Marshalling(Parcel &parcel) const override; 99 static MultiAppModeData *Unmarshalling(Parcel &parcel); 100 }; 101 102 struct Metadata : public Parcelable { 103 std::string name; 104 std::string value; 105 std::string resource; 106 Metadata() = default; 107 Metadata(const std::string ¶mName, const std::string ¶mValue, const std::string ¶mResource); 108 bool ReadFromParcel(Parcel &parcel); 109 virtual bool Marshalling(Parcel &parcel) const override; 110 static Metadata *Unmarshalling(Parcel &parcel); 111 }; 112 113 struct HnpPackage : public Parcelable { 114 std::string package; 115 std::string type; 116 117 bool ReadFromParcel(Parcel &parcel); 118 virtual bool Marshalling(Parcel &parcel) const override; 119 static HnpPackage *Unmarshalling(Parcel &parcel); 120 }; 121 122 struct CustomizeData : public Parcelable { 123 std::string name; 124 std::string value; 125 std::string extra; 126 CustomizeData() = default; 127 CustomizeData(std::string paramName, std::string paramValue, std::string paramExtra); 128 bool ReadFromParcel(Parcel &parcel); 129 virtual bool Marshalling(Parcel &parcel) const override; 130 static CustomizeData *Unmarshalling(Parcel &parcel); 131 }; 132 133 struct MetaData { 134 std::vector<CustomizeData> customizeData; 135 }; 136 137 struct Resource : public Parcelable { 138 /** the hap bundle name */ 139 std::string bundleName; 140 141 /** the hap module name */ 142 std::string moduleName; 143 144 /** the resource id in hap */ 145 uint32_t id = 0; 146 147 bool ReadFromParcel(Parcel &parcel); 148 virtual bool Marshalling(Parcel &parcel) const override; 149 static Resource *Unmarshalling(Parcel &parcel); 150 }; 151 152 struct ApplicationEnvironment : public Parcelable { 153 std::string name; 154 std::string value; 155 156 bool ReadFromParcel(Parcel &parcel); 157 virtual bool Marshalling(Parcel &parcel) const override; 158 static ApplicationEnvironment *Unmarshalling(Parcel &parcel); 159 }; 160 161 struct ApplicationInfo; 162 163 struct CompatibleApplicationInfo : public Parcelable { 164 // items set when installing. 165 std::string name; // application name. 166 std::string icon; // application icon resource index. 167 std::string label; // application name displayed to the user. 168 std::string description; // description of application. 169 std::string cpuAbi; // current device cpu abi. 170 std::string process; 171 bool isCompressNativeLibs = true; 172 173 uint32_t iconId = 0; 174 uint32_t labelId = 0; 175 uint32_t descriptionId = 0; 176 177 bool systemApp = false; 178 179 std::vector<std::string> permissions; 180 std::vector<ModuleInfo> moduleInfos; 181 182 int32_t supportedModes = 0; // supported modes. 183 bool enabled = true; 184 bool debug = false; 185 186 bool ReadFromParcel(Parcel& parcel); 187 virtual bool Marshalling(Parcel& parcel) const override; 188 static CompatibleApplicationInfo* Unmarshalling(Parcel& parcel); 189 void ConvertToApplicationInfo(ApplicationInfo& applicationInfo) const; 190 }; 191 192 // configuration information about an application 193 struct ApplicationInfo : public Parcelable { 194 std::string name; // application name is same to bundleName 195 std::string bundleName; 196 197 uint32_t versionCode = 0; 198 std::string versionName; 199 int32_t minCompatibleVersionCode = 0; 200 201 uint32_t apiCompatibleVersion = 0; 202 int32_t apiTargetVersion = 0; 203 int64_t crowdtestDeadline = Constants::INVALID_CROWDTEST_DEADLINE; 204 205 std::string iconPath; 206 uint32_t iconId = 0; 207 Resource iconResource; 208 209 std::string label; 210 uint32_t labelId = 0; 211 Resource labelResource; 212 213 std::string description; 214 uint32_t descriptionId = 0; 215 Resource descriptionResource; 216 217 bool keepAlive = false; 218 bool removable = true; 219 bool singleton = false; 220 bool userDataClearable = true; 221 bool allowAppRunWhenDeviceFirstLocked = false; 222 bool accessible = false; 223 bool runningResourcesApply = false; 224 bool associatedWakeUp = false; 225 bool hideDesktopIcon = false; 226 bool formVisibleNotify = false; 227 std::vector<std::string> allowCommonEvent; 228 std::vector<int32_t> resourcesApply; 229 230 bool isSystemApp = false; 231 bool isLauncherApp = false; 232 bool isFreeInstallApp = false; 233 bool asanEnabled = false; 234 std::string asanLogPath; 235 236 std::string codePath; 237 std::string dataDir; 238 std::string dataBaseDir; 239 std::string cacheDir; 240 std::string entryDir; 241 242 std::string apiReleaseType; 243 bool debug = false; 244 std::string deviceId; 245 bool distributedNotificationEnabled = true; 246 bool allowEnableNotification = false; 247 std::string entityType = DEFAULT_ENTITY_TYPE; 248 std::string process; 249 int32_t supportedModes = 0; // returns 0 if the application does not support the driving mode 250 std::string vendor; 251 bool gwpAsanEnabled = false; 252 253 // apl 254 std::string appPrivilegeLevel = AVAILABLELEVEL_NORMAL; 255 // provision 256 std::string appDistributionType = Constants::APP_DISTRIBUTION_TYPE_NONE; 257 std::string appProvisionType = Constants::APP_PROVISION_TYPE_RELEASE; 258 259 // user related fields, assign when calling the get interface 260 uint32_t accessTokenId = 0; 261 uint64_t accessTokenIdEx = 0; 262 bool enabled = false; 263 int32_t uid = -1; 264 int32_t appIndex = 0; 265 266 // native so 267 std::string nativeLibraryPath; 268 std::string cpuAbi; 269 std::string arkNativeFilePath; 270 std::string arkNativeFileAbi; 271 272 // assign when calling the get interface 273 std::vector<std::string> permissions; 274 std::vector<std::string> moduleSourceDirs; 275 std::vector<ModuleInfo> moduleInfos; 276 std::map<std::string, std::vector<HnpPackage>> hnpPackages; 277 std::map<std::string, std::vector<CustomizeData>> metaData; 278 std::map<std::string, std::vector<Metadata>> metadata; 279 // Installation-free 280 std::vector<std::string> targetBundleList; 281 282 std::string fingerprint; 283 // quick fix info 284 AppQuickFix appQuickFix; 285 286 std::string icon; 287 int32_t flags = 0; 288 std::string entryModuleName; 289 bool isCompressNativeLibs = true; 290 std::string signatureKey; 291 292 // switch 293 bool multiProjects = false; 294 295 // app detail ability 296 bool needAppDetail = false; 297 std::string appDetailAbilityLibraryPath; 298 299 // overlay installation 300 std::string targetBundleName; 301 int32_t targetPriority = 0; 302 int32_t overlayState = 0; 303 304 BundleType bundleType = BundleType::APP; 305 306 std::string compileSdkVersion; 307 std::string compileSdkType = DEFAULT_COMPILE_SDK_TYPE; 308 309 uint32_t applicationReservedFlag = 0; 310 bool tsanEnabled = false; 311 bool hwasanEnabled = false; 312 std::vector<ApplicationEnvironment> appEnvironments; 313 std::string organization; 314 315 MultiAppModeData multiAppMode; 316 int32_t maxChildProcess = 0; 317 318 std::string installSource; 319 bool cloudFileSyncEnabled = false; 320 321 std::string configuration; 322 323 int32_t applicationFlags = static_cast<uint32_t>(ApplicationInfoFlag::FLAG_INSTALLED); 324 325 bool ReadFromParcel(Parcel &parcel); 326 bool ReadMetaDataFromParcel(Parcel &parcel); 327 virtual bool Marshalling(Parcel &parcel) const override; 328 static ApplicationInfo *Unmarshalling(Parcel &parcel); 329 void Dump(std::string prefix, int fd); 330 void ConvertToCompatibleApplicationInfo(CompatibleApplicationInfo& compatibleApplicationInfo) const; 331 bool CheckNeedPreload(const std::string &moduleName) const; 332 }; 333 } // namespace AppExecFwk 334 } // namespace OHOS 335 #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_APPLICATION_INFO_H 336