1 /* 2 * Copyright (c) 2021 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_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_DATA_STORAGE_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_DATA_STORAGE_H 18 19 #include <map> 20 21 #include "inner_bundle_info.h" 22 #include "bundle_data_storage_interface.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 27 class BundleDataStorage : public IBundleDataStorage { 28 public: 29 /** 30 * @brief Load all installed bundles data from KvStore to innerBundleInfos. 31 * @param infos Indicates the map to save all installed bundles. 32 * @return Returns true if the data is successfully loaded; returns false otherwise. 33 */ 34 virtual bool LoadAllData(std::map<std::string, std::map<std::string, InnerBundleInfo>> &infos); 35 /** 36 * @brief Save the bundle data corresponding to the device Id of the bundle name to KvStore. 37 * @param deviceId Indicates this device Id corresponding to the bundle name. 38 * @param innerBundleInfo Indicates the InnerBundleInfo object to be save. 39 * @return Returns true if the data is successfully saved; returns false otherwise. 40 */ 41 virtual bool SaveStorageBundleInfo(const std::string &deviceId, const InnerBundleInfo &innerBundleInfo); 42 /** 43 * @brief Delete the bundle data corresponding to the device Id of the bundle name to KvStore. 44 * @param deviceId Indicates this device Id corresponding to the bundle name. 45 * @param innerBundleInfo Indicates the InnerBundleInfo object to be Delete. 46 * @return Returns true if the data is successfully deleted; returns false otherwise. 47 */ 48 virtual bool DeleteStorageBundleInfo(const std::string &deviceId, const InnerBundleInfo &innerBundleInfo); 49 ResetKvStore()50 virtual bool ResetKvStore() { return true; } 51 private: 52 bool KeyToDeviceAndName(const std::string &key, std::string &deviceId, std::string &bundleName) const; 53 void DeviceAndNameToKey(const std::string &deviceId, const std::string &bundleName, std::string &key) const; 54 }; 55 56 } // namespace AppExecFwk 57 } // namespace OHOS 58 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_DATA_STORAGE_H 59