1 /* 2 * Copyright (c) 2022 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 UDMF_SERVICE_IMPL_H 17 #define UDMF_SERVICE_IMPL_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <vector> 23 24 #include "error_code.h" 25 #include "store_cache.h" 26 #include "udmf_service_stub.h" 27 #include "unified_data.h" 28 #include "unified_types.h" 29 #include "visibility.h" 30 #include "kv_store_delegate_manager.h" 31 namespace OHOS { 32 namespace UDMF { 33 /* 34 * UDMF server implementation 35 */ 36 class API_EXPORT UdmfServiceImpl final : public UdmfServiceStub { 37 public: 38 UdmfServiceImpl(); 39 ~UdmfServiceImpl() = default; 40 41 using DBLaunchParam = DistributedDB::AutoLaunchParam; 42 int32_t SetData(CustomOption &option, UnifiedData &unifiedData, std::string &key) override; 43 int32_t GetData(const QueryOption &query, UnifiedData &unifiedData) override; 44 int32_t GetBatchData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet) override; 45 int32_t UpdateData(const QueryOption &query, UnifiedData &unifiedData) override; 46 int32_t DeleteData(const QueryOption &query, std::vector<UnifiedData> &unifiedDataSet) override; 47 int32_t GetSummary(const QueryOption &query, Summary &summary) override; 48 int32_t AddPrivilege(const QueryOption &query, Privilege &privilege) override; 49 int32_t Sync(const QueryOption &query, const std::vector<std::string> &devices) override; 50 int32_t IsRemoteData(const QueryOption &query, bool &result) override; 51 int32_t SetAppShareOption(const std::string &intention, int32_t shareOption) override; 52 int32_t GetAppShareOption(const std::string &intention, int32_t &shareOption) override; 53 int32_t RemoveAppShareOption(const std::string &intention) override; 54 int32_t OnInitialize() override; 55 int32_t OnBind(const BindInfo &bindInfo) override; 56 int32_t ObtainAsynProcess(AsyncProcessInfo &processInfo) override; 57 int32_t ClearAsynProcessByKey(const std::string &businessUdKey) override; 58 int32_t ResolveAutoLaunch(const std::string &identifier, DBLaunchParam ¶m) override; 59 private: 60 int32_t SaveData(CustomOption &option, UnifiedData &unifiedData, std::string &key); 61 int32_t RetrieveData(const QueryOption &query, UnifiedData &unifiedData); 62 int32_t QueryDataCommon(const QueryOption &query, std::vector<UnifiedData> &dataSet, std::shared_ptr<Store> &store); 63 int32_t ProcessUri(const QueryOption &query, UnifiedData &unifiedData); 64 bool IsPermissionInCache(const QueryOption &query); 65 bool IsReadAndKeep(const std::vector<Privilege> &privileges, const QueryOption &query); 66 bool VerifyPermission(const std::string &permission, uint32_t callerTokenId); 67 bool HasDatahubPriviledge(const std::string &bundleName); 68 void RegisterAsyncProcessInfo(const std::string &businessUdKey); 69 int32_t ProcessCrossDeviceData(UnifiedData &unifiedData, std::vector<Uri> &uris); 70 71 class Factory { 72 public: 73 Factory(); 74 ~Factory(); 75 76 private: 77 std::shared_ptr<UdmfServiceImpl> product_; 78 }; 79 static Factory factory_; 80 std::map<std::string, Privilege> privilegeCache_; 81 std::shared_ptr<ExecutorPool> executors_; 82 83 std::mutex mutex_; 84 std::unordered_map<std::string, AsyncProcessInfo> asyncProcessInfoMap_; 85 }; 86 } // namespace UDMF 87 } // namespace OHOS 88 #endif // UDMF_SERVICE_IMPL_H 89