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