• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 DMS_DATASHARE_MANAGER_H
17 #define DMS_DATASHARE_MANAGER_H
18 
19 #include <map>
20 
21 #include "datashare_helper.h"
22 #include "data_ability_observer_stub.h"
23 #include "single_instance.h"
24 
25 namespace OHOS {
26 namespace DistributedSchedule {
27 
28 class SettingObserver : public AAFwk::DataAbilityObserverStub {
29 public:
30     SettingObserver();
31     ~SettingObserver() override;
32     void OnChange() override;
33 
34     using ObserverCallback = std::function<void()>;
35     void SetObserverCallback(ObserverCallback &observerCallback);
36 private:
37     ObserverCallback observerCallback_  = nullptr;
38 };
39 
40 class DataShareManager {
41     DECLARE_SINGLE_INSTANCE(DataShareManager);
42 
43 public:
44     void RegisterObserver(const std::string &key, SettingObserver::ObserverCallback &observerCallback);
45     void UnregisterObserver(const std::string &key);
46     void UnInit();
47 
48     using ObserverCallback = std::function<void()>;
49 
50     int32_t GetLocalAccountId();
51     Uri AssembleUserSecureUri(int userId, const std::string& key);
52     std::atomic<bool> isCurrentContinueSwitchOn_ = true;
53     bool IsCurrentContinueSwitchOn();
54     void SetCurrentContinueSwitch(bool status);
55 
56 private:
57     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
58     void RegisterObserver(SettingObserver::ObserverCallback &observerCallback);
59 
60 private:
61     sptr<SettingObserver> observer_;
62     std::mutex observerMutex_;
63     std::mutex datashareMutex_;
64 };
65 } // namespace DistributedSchedule
66 } // namespace OHOS
67 
68 #endif // DMS_DATASHARE_MANAGER_H
69