1 /* 2 * Copyright (c) 2025 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 DATASHARESERVICE_PROXY_DATA_MANAGER_H 17 #define DATASHARESERVICE_PROXY_DATA_MANAGER_H 18 19 #include "bundle_mgr_proxy.h" 20 #include "dataproxy_handle_common.h" 21 #include "db_delegate.h" 22 23 namespace OHOS::DataShare { 24 25 class ProxyDataListNode final : public VersionData { 26 public: 27 ProxyDataListNode(); ProxyDataListNode(const std::vector<std::string> & uris,int32_t userId,uint32_t tokenId)28 ProxyDataListNode(const std::vector<std::string> &uris, int32_t userId, uint32_t tokenId) 29 : VersionData(0), uris(uris), userId(userId), tokenId(tokenId) {} 30 ~ProxyDataListNode() = default; 31 bool Marshal(json &node) const override; 32 bool Unmarshal(const json &node) override; 33 std::vector<std::string> uris; 34 int32_t userId = Id::INVALID_USER; 35 uint32_t tokenId = 0; 36 }; 37 38 class ProxyDataList final : public KvData { 39 public: 40 explicit ProxyDataList(const ProxyDataListNode &node); 41 ~ProxyDataList() = default; 42 static int32_t Query(uint32_t tokenId, int32_t userId, std::vector<std::string> &proxyDataList); 43 bool HasVersion() const override; 44 int GetVersion() const override; 45 std::string GetValue() const override; 46 47 private: 48 ProxyDataListNode value; 49 }; 50 51 class ProxyDataNode final : public VersionData { 52 public: 53 ProxyDataNode(); ProxyDataNode(const SerialDataShareProxyData proxyData,int32_t userId,uint32_t tokenId)54 ProxyDataNode(const SerialDataShareProxyData proxyData, int32_t userId, uint32_t tokenId) 55 : VersionData(0), proxyData(proxyData), userId(userId), tokenId(tokenId) {} 56 ~ProxyDataNode() = default; 57 bool Marshal(json &node) const override; 58 bool Unmarshal(const json &node) override; 59 SerialDataShareProxyData proxyData; 60 int32_t userId = Id::INVALID_USER; 61 uint32_t tokenId = 0; 62 }; 63 64 class PublishedProxyData final : public KvData { 65 public: 66 explicit PublishedProxyData(const ProxyDataNode &node); 67 ~PublishedProxyData() = default; 68 static int32_t Query(const std::string &uri, const BundleInfo &callerBundleInfo, DataShareProxyData &proxyData); 69 static int32_t Delete(const std::string &uri, const BundleInfo &callerBundleInfo, DataShareProxyData &oldProxyData, 70 DataShareObserver::ChangeType &type); 71 static int32_t Upsert(const DataShareProxyData &proxyData, const BundleInfo &callerBundleInfo, 72 DataShareObserver::ChangeType &type); 73 static bool VerifyPermission(const BundleInfo &callerBundleInfo, const ProxyDataNode &data); 74 bool HasVersion() const override; 75 int GetVersion() const override; 76 std::string GetValue() const override; 77 78 private: 79 static int32_t InsertProxyData(std::shared_ptr<KvDBDelegate> kvDelegate, const std::string &bundleName, 80 const int32_t &user, const uint32_t &tokenId, const DataShareProxyData &proxyData); 81 static int32_t UpdateProxyData(std::shared_ptr<KvDBDelegate> kvDelegate, const std::string &bundleName, 82 const int32_t &user, const uint32_t &tokenId, const DataShareProxyData &proxyData); 83 static int32_t PutIntoTable(std::shared_ptr<KvDBDelegate> kvDelegate, int32_t user, 84 uint32_t tokenId, const std::vector<std::string> &proxyDataList, const DataShareProxyData &proxyData); 85 static bool CheckAndCorrectProxyData(DataShareProxyData &proxyData); 86 ProxyDataNode value; 87 }; 88 89 class ProxyDataManager { 90 public: 91 static ProxyDataManager &GetInstance(); 92 void OnAppInstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); 93 void OnAppUpdate(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); 94 void OnAppUninstall(const std::string &bundleName, int32_t user, int32_t index, uint32_t tokenId); 95 96 private: 97 bool GetCrossAppSharedConfig(const std::string &bundleName, int32_t user, int32_t index, 98 std::vector<DataShareProxyData> &proxyDatas); 99 }; 100 } // namespace OHOS::DataShare 101 #endif // DATASHARESERVICE_PROXY_DATA_MANAGER_H