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 FLAG_PREINSTALLED_APP = 0x00000020, 93 FLAG_PREINSTALLED_APP_UPDATE = 0x00000040, 94 }; 95 96 struct MultiAppModeData : public Parcelable { 97 MultiAppModeType multiAppModeType = MultiAppModeType::UNSPECIFIED; 98 int32_t maxCount = 0; 99 bool ReadFromParcel(Parcel &parcel); 100 virtual bool Marshalling(Parcel &parcel) const override; 101 static MultiAppModeData *Unmarshalling(Parcel &parcel); 102 }; 103 104 struct Metadata : public Parcelable { 105 std::string name; 106 std::string value; 107 std::string resource; 108 Metadata() = default; 109 Metadata(const std::string ¶mName, const std::string ¶mValue, const std::string ¶mResource); 110 bool ReadFromParcel(Parcel &parcel); 111 virtual bool Marshalling(Parcel &parcel) const override; 112 static Metadata *Unmarshalling(Parcel &parcel); 113 }; 114 115 struct HnpPackage : public Parcelable { 116 std::string package; 117 std::string type; 118 119 bool ReadFromParcel(Parcel &parcel); 120 virtual bool Marshalling(Parcel &parcel) const override; 121 static HnpPackage *Unmarshalling(Parcel &parcel); 122 }; 123 124 struct CustomizeData : public Parcelable { 125 std::string name; 126 std::string value; 127 std::string extra; 128 CustomizeData() = default; 129 CustomizeData(std::string paramName, std::string paramValue, std::string paramExtra); 130 bool ReadFromParcel(Parcel &parcel); 131 virtual bool Marshalling(Parcel &parcel) const override; 132 static CustomizeData *Unmarshalling(Parcel &parcel); 133 }; 134 135 struct MetaData { 136 std::vector<CustomizeData> customizeData; 137 }; 138 139 struct Resource : public Parcelable { 140 /** the hap bundle name */ 141 std::string bundleName; 142 143 /** the hap module name */ 144 std::string moduleName; 145 146 /** the resource id in hap */ 147 uint32_t id = 0; 148 149 bool ReadFromParcel(Parcel &parcel); 150 virtual bool Marshalling(Parcel &parcel) const override; 151 static Resource *Unmarshalling(Parcel &parcel); 152 }; 153 154 struct ApplicationEnvironment : public Parcelable { 155 std::string name; 156 std::string value; 157 158 bool ReadFromParcel(Parcel &parcel); 159 virtual bool Marshalling(Parcel &parcel) const override; 160 static ApplicationEnvironment *Unmarshalling(Parcel &parcel); 161 }; 162 163 struct ApplicationInfo; 164 165 struct CompatibleApplicationInfo : public Parcelable { 166 // items set when installing. 167 std::string name; // application name. 168 std::string icon; // application icon resource index. 169 std::string label; // application name displayed to the user. 170 std::string description; // description of application. 171 std::string cpuAbi; // current device cpu abi. 172 std::string process; 173 bool isCompressNativeLibs = true; 174 175 uint32_t iconId = 0; 176 uint32_t labelId = 0; 177 uint32_t descriptionId = 0; 178 179 bool systemApp = false; 180 181 std::vector<std::string> permissions; 182 std::vector<ModuleInfo> moduleInfos; 183 184 int32_t supportedModes = 0; // supported modes. 185 bool enabled = true; 186 bool debug = false; 187 188 bool ReadFromParcel(Parcel& parcel); 189 virtual bool Marshalling(Parcel& parcel) const override; 190 static CompatibleApplicationInfo* Unmarshalling(Parcel& parcel); 191 void ConvertToApplicationInfo(ApplicationInfo& applicationInfo) const; 192 }; 193 194 // configuration information about an application 195 struct ApplicationInfo : public Parcelable { 196 std::string name; // application name is same to bundleName 197 std::string bundleName; 198 199 uint32_t versionCode = 0; 200 std::string versionName; 201 int32_t minCompatibleVersionCode = 0; 202 203 uint32_t apiCompatibleVersion = 0; 204 int32_t apiTargetVersion = 0; 205 int64_t crowdtestDeadline = Constants::INVALID_CROWDTEST_DEADLINE; 206 207 std::string iconPath; 208 uint32_t iconId = 0; 209 Resource iconResource; 210 211 std::string label; 212 uint32_t labelId = 0; 213 Resource labelResource; 214 215 std::string description; 216 uint32_t descriptionId = 0; 217 Resource descriptionResource; 218 219 bool keepAlive = false; 220 bool removable = true; 221 bool singleton = false; 222 bool userDataClearable = true; 223 bool allowAppRunWhenDeviceFirstLocked = false; 224 bool accessible = false; 225 bool runningResourcesApply = false; 226 bool associatedWakeUp = false; 227 bool hideDesktopIcon = false; 228 bool formVisibleNotify = false; 229 std::vector<std::string> allowCommonEvent; 230 std::vector<int32_t> resourcesApply; 231 232 bool isSystemApp = false; 233 bool isLauncherApp = false; 234 bool isFreeInstallApp = false; 235 bool asanEnabled = false; 236 std::string asanLogPath; 237 238 std::string codePath; 239 std::string dataDir; 240 std::string dataBaseDir; 241 std::string cacheDir; 242 std::string entryDir; 243 244 std::string apiReleaseType; 245 bool debug = false; 246 std::string deviceId; 247 bool distributedNotificationEnabled = true; 248 bool allowEnableNotification = false; 249 std::string entityType = DEFAULT_ENTITY_TYPE; 250 std::string process; 251 int32_t supportedModes = 0; // returns 0 if the application does not support the driving mode 252 std::string vendor; 253 bool gwpAsanEnabled = false; 254 255 // apl 256 std::string appPrivilegeLevel = AVAILABLELEVEL_NORMAL; 257 // provision 258 std::string appDistributionType = Constants::APP_DISTRIBUTION_TYPE_NONE; 259 std::string appProvisionType = Constants::APP_PROVISION_TYPE_RELEASE; 260 261 // user related fields, assign when calling the get interface 262 uint32_t accessTokenId = 0; 263 uint64_t accessTokenIdEx = 0; 264 bool enabled = false; 265 int32_t uid = -1; 266 int32_t appIndex = 0; 267 268 // native so 269 std::string nativeLibraryPath; 270 std::string cpuAbi; 271 std::string arkNativeFilePath; 272 std::string arkNativeFileAbi; 273 274 // assign when calling the get interface 275 std::vector<std::string> permissions; 276 std::vector<std::string> moduleSourceDirs; 277 std::vector<ModuleInfo> moduleInfos; 278 std::map<std::string, std::vector<HnpPackage>> hnpPackages; 279 std::map<std::string, std::vector<CustomizeData>> metaData; 280 std::map<std::string, std::vector<Metadata>> metadata; 281 // Installation-free 282 std::vector<std::string> targetBundleList; 283 284 std::string fingerprint; 285 // quick fix info 286 AppQuickFix appQuickFix; 287 288 std::string icon; 289 int32_t flags = 0; 290 std::string entryModuleName; 291 bool isCompressNativeLibs = true; 292 std::string signatureKey; 293 294 // switch 295 bool multiProjects = false; 296 297 // app detail ability 298 bool needAppDetail = false; 299 std::string appDetailAbilityLibraryPath; 300 301 // overlay installation 302 std::string targetBundleName; 303 int32_t targetPriority = 0; 304 int32_t overlayState = 0; 305 306 BundleType bundleType = BundleType::APP; 307 308 std::string compileSdkVersion; 309 std::string compileSdkType = DEFAULT_COMPILE_SDK_TYPE; 310 311 uint32_t applicationReservedFlag = 0; 312 bool tsanEnabled = false; 313 bool hwasanEnabled = false; 314 std::vector<ApplicationEnvironment> appEnvironments; 315 std::string organization; 316 317 MultiAppModeData multiAppMode; 318 int32_t maxChildProcess = 0; 319 320 std::string installSource; 321 bool cloudFileSyncEnabled = false; 322 323 std::string configuration; 324 325 int32_t applicationFlags = static_cast<uint32_t>(ApplicationInfoFlag::FLAG_INSTALLED); 326 327 bool ReadFromParcel(Parcel &parcel); 328 bool ReadMetaDataFromParcel(Parcel &parcel); 329 virtual bool Marshalling(Parcel &parcel) const override; 330 static ApplicationInfo *Unmarshalling(Parcel &parcel); 331 void Dump(std::string prefix, int fd); 332 void ConvertToCompatibleApplicationInfo(CompatibleApplicationInfo& compatibleApplicationInfo) const; 333 bool CheckNeedPreload(const std::string &moduleName) const; 334 }; 335 } // namespace AppExecFwk 336 } // namespace OHOS 337 #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_APPLICATION_INFO_H 338