1 /* 2 * Copyright (c) 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 DRIVER_BUNDLE_STATUS_CALLBACK_H 17 #define DRIVER_BUNDLE_STATUS_CALLBACK_H 18 19 #include <stdint.h> 20 #include <vector> 21 #include <map> 22 #include <iostream> 23 24 #include "bundle_info.h" 25 #include "bundle_mgr_proxy.h" 26 #include "extension_ability_info.h" 27 28 #include "ibus_extension.h" 29 namespace OHOS { 30 namespace ExternalDeviceManager { 31 using namespace std; 32 using namespace OHOS; 33 using namespace OHOS::AAFwk; 34 using namespace OHOS::AppExecFwk; 35 using namespace OHOS::ExternalDeviceManager; 36 37 enum { 38 ERR_DRV_STATUS_CALLBACK_ERROR = 1, 39 }; 40 41 enum ON_BUNDLE_STATUS { 42 BUNDLE_NULL, 43 BUNDLE_ADDED = 1, 44 BUNDLE_UPDATED, 45 BUNDLE_REMOVED, 46 }; 47 48 typedef int32_t(*PCALLBACKFUN)(int, int, const string &, const string &); 49 50 class DrvBundleStateCallback : public IBundleStatusCallback { 51 public: 52 DrvBundleStateCallback(); 53 ~DrvBundleStateCallback(); 54 55 void PrintTest(); 56 57 virtual void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, 58 const std::string &resultMsg, const std::string &bundleName) override; 59 60 /** 61 * @brief Called when a new application package has been installed on the device. 62 * @param bundleName Indicates the name of the bundle whose state has been installed. 63 * @param userId Indicates the id of the bundle whose state has been installed. 64 */ 65 virtual void OnBundleAdded(const std::string &bundleName, const int userId) override; 66 /** 67 * @brief Called when a new application package has been Updated on the device. 68 * @param bundleName Indicates the name of the bundle whose state has been Updated. 69 * @param userId Indicates the id of the bundle whose state has been Updated. 70 */ 71 virtual void OnBundleUpdated(const std::string &bundleName, const int userId) override; 72 /** 73 * @brief Called when a new application package has been Removed on the device. 74 * @param bundleName Indicates the name of the bundle whose state has been Removed. 75 * @param userId Indicates the id of the bundle whose state has been Removed. 76 */ 77 virtual void OnBundleRemoved(const std::string &bundleName, const int userId) override; 78 79 virtual sptr<IRemoteObject> AsObject() override; 80 81 bool GetAllDriverInfos(); 82 83 bool CheckBundleMgrProxyPermission(); 84 85 string GetStiching(); 86 87 PCALLBACKFUN m_pFun = nullptr; 88 private: 89 std::vector<ExtensionAbilityInfo> extensionInfos_; 90 std::map<string, DriverInfo> innerDrvInfos_; 91 std::map<string, DriverInfo> allDrvInfos_; 92 std::mutex bundleMgrMutex_; 93 sptr<IBundleMgr> bundleMgr_ = nullptr; 94 string stiching = "This is used for Name Stiching"; 95 bool initOnce = false; 96 97 ErrCode QueryExtensionAbilityInfos(const std::string &bundleName, const int userId); 98 bool ParseBaseDriverInfo(); 99 void ChangeValue(DriverInfo &tmpDrvInfo, std::vector<Metadata> &metadata); 100 void ClearDriverInfo(DriverInfo &tmpDrvInfo); 101 void ParseExtensionInfos(ExtensionAbilityType &type, 102 string &bundleName, string &abilityName); 103 sptr<OHOS::AppExecFwk::IBundleMgr> GetBundleMgrProxy(); 104 int32_t GetCurrentActiveUserId(); 105 void StorageHistoryDrvInfo(std::vector<BundleInfo> &bundleInfos); 106 107 void OnBundleDrvAdded(int bundleStatus); 108 void OnBundleDrvUpdated(int bundleStatus); 109 void OnBundleDrvRemoved(const std::string &bundleName); 110 }; 111 } // namespace 112 } 113 #endif // DRIVER_BUNDLE_STATUS_CALLBACK_H