1 /* 2 * Copyright (c) 2020-2023 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 void RegisterListenCallbackFunc(const uint8_t resultCode, const void *resultMessage); 47 class GtManagerService { 48 public: GetInstance()49 static GtManagerService &GetInstance() 50 { 51 static GtManagerService instance; 52 return instance; 53 } 54 bool Install(const char *hapPath, const InstallParam *installParam, InstallerCallback installerCallback); 55 bool Uninstall(const char *bundleName, const InstallParam *installParam, InstallerCallback installerCallback); 56 uint8_t QueryAbilityInfo(const Want *want, AbilityInfo *abilityInfo); 57 uint8_t QueryAbilityInfos(const Want *want, AbilityInfo **abilityInfo, int32_t *len); 58 uint8_t GetBundleInfo(const char *bundleName, int32_t flags, BundleInfo &bundleInfo); 59 uint8_t GetBundleInfos(const int flags, BundleInfo **bundleInfos, int32_t *len); 60 uint8_t GetBundleInfosNoReplication(const int flags, BundleInfo **bundleInfos, int32_t *len); 61 void ScanPackages(); 62 BundleInfo *QueryBundleInfo(const char *bundleName); 63 void RemoveBundleInfo(const char *bundleName); 64 void AddBundleInfo(BundleInfo *info); 65 bool UpdateBundleInfo(BundleInfo *info); 66 uint32_t GetNumOfThirdBundles(); 67 void RemoveBundleResList(const char *bundleName); 68 void AddBundleResList(const BundleRes *bundleRes); 69 void UpdateBundleInfoList(); 70 void ReportInstallProcess(const char *bundleName, uint8_t bundleStyle, uint8_t process); 71 void AddNumOfThirdBundles(); 72 void ReduceNumOfThirdBundles(); 73 int32_t ReportInstallCallback( 74 uint8_t errCode, uint8_t installState, uint8_t process, InstallerCallback installerCallback); 75 int32_t ReportUninstallCallback( 76 uint8_t errCode, uint8_t installState, char *bundleName, uint8_t process, InstallerCallback installerCallback); 77 bool GetInstallState(const char *bundleName, InstallState *installState, uint8_t *installProcess); 78 uint32_t GetBundleSize(const char *bundleName); 79 bool RegisterInstallerCallback(InstallerCallback installerCallback); 80 PreAppList *InitPreAppInfo(void); 81 void InsertPreAppInfo(const char *filePath, PreAppList *list); 82 void SetPreAppInfo(PreAppList *list); 83 bool RegisterEvent(InstallerCallback installerCallback); 84 bool UnregisterEvent(InstallerCallback installerCallback); 85 86 private: 87 GtManagerService(); 88 ~GtManagerService(); 89 void ScanSystemApp(const cJSON *uninstallRecord, List<ToBeInstalledApp *> *systemPathList); 90 void ScanThirdApp(const char *appDir, const List<ToBeInstalledApp *> *systemPathList); 91 void InstallAllSystemBundle(InstallerCallback installerCallback); 92 bool ReloadBundleInfo(const char *profileDir, const char *appId, bool isSystemApp); 93 void ReloadEntireBundleInfo(const char *appPath, const char *bundleName, List<ToBeInstalledApp *> *systemPathList, 94 int32_t versionCode, uint8_t scanFlag); 95 bool CheckSystemBundleIsValid(const char *appPath, char **bundleName, int32_t &versionCode); 96 bool CheckThirdSystemBundleHasUninstalled(const char *bundleName, const cJSON *object); 97 void AddSystemAppPathList(const char *installedPath, const char *path, List<ToBeInstalledApp *> *systemPathList, 98 bool isSystemApp, bool isUpdated, const char *appId); 99 void RemoveSystemAppPathList(List<ToBeInstalledApp *> *systemPathList); 100 void ClearSystemBundleInstallMsg(); 101 void TransformJsToBcWhenRestart(const char *codePath, const char *bundleName); 102 void TransformJsToBc(const char *codePath, const char *bundleJsonPath, cJSON *installRecordObj); 103 bool IsSystemBundleInstalledPath(const char *appPath, const List<ToBeInstalledApp *> *systemPathList); 104 void InstallPreBundle(List<ToBeInstalledApp *> systemPathList, InstallerCallback installerCallback); 105 void QueryPreAppInfo(const char *appDir, PreAppList *list); 106 void FreePreAppInfo(const PreAppList *list); 107 int32_t ReportHceInstallCallback(uint8_t errCode, uint8_t installState, uint8_t process); 108 int32_t ReportHceUninstallCallback(uint8_t errCode, uint8_t installState, char *bundleName, uint8_t process); 109 static bool MatchSkills(const Want *want, Skill *const skills[]); 110 static bool isMatchActions(const char *actions, char *const skillActions[]); 111 static bool isMatchEntities(const char *entities, char *const skillEntities[]); 112 static bool isMatch(const char *dst, const char *src); 113 114 GtBundleInstaller *installer_; 115 BundleMap *bundleMap_; 116 List<BundleRes *> *bundleResList_; 117 BundleInstallMsg *bundleInstallMsg_; 118 char *jsEngineVer_; 119 uint32_t installedThirdBundleNum_; 120 List<ToBeInstalledApp *> systemPathList_; 121 PreAppList *preAppList_; 122 bool updateFlag_; 123 int32_t oldVersionCode_; 124 List<InstallerCallback> *listenList_; 125 }; 126 } 127 128 extern "C" { 129 void EnableServiceWdg(void); 130 void DisableServiceWdg(void); 131 void RefreshAllServiceTimeStamp(void); 132 void SetCurrentBundle(const char *name); 133 const char *GetCurrentBundle(); 134 } 135 136 #endif // OHOS_GT_BUNDLE_MANAGER_SERVICE_H