1 /* 2 * Copyright (c) 2020 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 OHOS_GT_BUNDLE_MANAGER_SERVICE_H 17 #define OHOS_GT_BUNDLE_MANAGER_SERVICE_H 18 19 #include "adapter.h" 20 #include "bundle_info.h" 21 #include "bundle_map.h" 22 #include "cJSON.h" 23 #include "gt_bundle_installer.h" 24 #include "stdint.h" 25 #include "want.h" 26 #include "install_param.h" 27 #include "bundle_install_msg.h" 28 #include "bundle_manager.h" 29 #include "los_list.h" 30 #include "ohos_types.h" 31 32 namespace OHOS { 33 #define MAX_APP_FILE_PATH_LEN 100 34 struct ToBeInstalledApp { 35 bool isSystemApp; 36 bool isUpdated; 37 char *path; 38 char *installedPath; 39 char *appId; 40 }; 41 struct AppInfoList { 42 LOS_DL_LIST appDoubleList; 43 char filePath[MAX_APP_FILE_PATH_LEN]; 44 }; 45 46 typedef enum { 47 BUNDLE_INSTALL, 48 BUNDLE_UNINSTALL, 49 BUNDLE_UPDATE, 50 } BundleState; 51 52 class GtManagerService { 53 public: GetInstance()54 static GtManagerService &GetInstance() 55 { 56 static GtManagerService instance; 57 return instance; 58 } 59 bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback); 60 bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback); 61 uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo); 62 uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo& bundleInfo); 63 uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len); 64 void ScanPackages(); 65 BundleInfo *QueryBundleInfo(const char *bundleName); 66 void RemoveBundleInfo(const char *bundleName); 67 void AddBundleInfo(BundleInfo *info); 68 bool UpdateBundleInfo(BundleInfo *info); 69 uint32_t GetNumOfThirdBundles(); 70 void RemoveBundleResList(const char *bundleName); 71 void AddBundleResList(const BundleRes *bundleRes); 72 void ReportInstallProcess(const char *bundleName, uint8_t bundleStyle, uint8_t process); 73 void AddNumOfThirdBundles(); 74 void ReduceNumOfThirdBundles(); 75 int32_t ReportInstallCallback(uint8_t errCode, uint8_t installState, 76 uint8_t process, InstallerCallback installerCallback); 77 int32_t ReportUninstallCallback(uint8_t errCode, uint8_t installState, char *bundleName, 78 uint8_t process, InstallerCallback installerCallback); 79 bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); 80 uint32_t GetBundleSize(const char *bundleName); 81 bool RegisterInstallerCallback(InstallerCallback installerCallback); 82 83 private: 84 GtManagerService(); 85 ~GtManagerService(); 86 void ScanSystemApp(const cJSON *uninstallRecord, List<ToBeInstalledApp *> *systemPathList); 87 void ScanThirdApp(const char *appDir, const List<ToBeInstalledApp *> *systemPathList); 88 void InstallAllSystemBundle(InstallerCallback installerCallback); 89 bool ReloadBundleInfo(const char *profileDir, const char *appId, bool isSystemApp); 90 void ReloadEntireBundleInfo(const char *appPath, const char *bundleName, List<ToBeInstalledApp *> *systemPathList, 91 int32_t versionCode, uint8_t scanFlag); 92 bool CheckSystemBundleIsValid(const char *appPath, char **bundleName, int32_t &versionCode); 93 bool CheckThirdSystemBundleHasUninstalled(const char *bundleName, const cJSON *object); 94 void AddSystemAppPathList(const char *installedPath, const char *path, List<ToBeInstalledApp *> *systemPathList, 95 bool isSystemApp, bool isUpdated, const char *appId); 96 void RemoveSystemAppPathList(List<ToBeInstalledApp *> *systemPathList); 97 void ClearSystemBundleInstallMsg(); 98 #ifdef BC_TRANS_ENABLE 99 void TransformJsToBcWhenRestart(const char *codePath, const char *bundleName); 100 void TransformJsToBc(const char *codePath, const char *bundleJsonPath, cJSON *installRecordObj); 101 #endif 102 bool IsSystemBundleInstalledPath(const char *appPath, const List<ToBeInstalledApp *> *systemPathList); 103 AppInfoList *APP_InitAllAppInfo(void); 104 void APP_QueryAppInfo(const char *appDir, AppInfoList *list); 105 void APP_InsertAppInfo(char *filePath, AppInfoList *list); 106 void APP_FreeAllAppInfo(const AppInfoList *list); 107 void InstallPreBundle(List<ToBeInstalledApp *> systemPathList, InstallerCallback installerCallback); 108 109 GtBundleInstaller *installer_; 110 BundleMap *bundleMap_; 111 List<BundleRes *> *bundleResList_; 112 BundleInstallMsg *bundleInstallMsg_; 113 char *jsEngineVer_; 114 uint32_t installedThirdBundleNum_; 115 List<ToBeInstalledApp *> systemPathList_; 116 }; 117 } 118 119 extern "C" { 120 void EnableServiceWdg(void); 121 void DisableServiceWdg(void); 122 void SetCurrentBundle(const char *name); 123 const char *GetCurrentBundle(); 124 } 125 126 #endif // OHOS_GT_BUNDLE_MANAGER_SERVICE_H