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