• 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 NETWORK_SEARCH_SETTINGS_RDB_HELPER_H
17 #define NETWORK_SEARCH_SETTINGS_RDB_HELPER_H
18 
19 #include <memory>
20 #include <singleton.h>
21 #include <utility>
22 
23 #include "datashare_helper.h"
24 #include "datashare_predicates.h"
25 #include "datashare_result_set.h"
26 #include "datashare_values_bucket.h"
27 #include "data_ability_observer_stub.h"
28 #include "iservice_registry.h"
29 #include "result_set.h"
30 #include "system_ability_definition.h"
31 #include "uri.h"
32 
33 #include "network_search_handler.h"
34 
35 namespace OHOS {
36 namespace Telephony {
37 class SettingUtils : public DelayedSingleton<SettingUtils> {
38     DECLARE_DELAYED_SINGLETON(SettingUtils);
39 public:
40     static const std::string NETWORK_SEARCH_SETTING_URI;
41     static const std::string NETWORK_SEARCH_SETTING_AUTO_TIME_URI;
42     static const std::string NETWORK_SEARCH_SETTING_AUTO_TIMEZONE_URI;
43     static const std::string NETWORK_SEARCH_SETTING_AIRPLANE_MODE_URI;
44     static const std::string NETWORK_SEARCH_SETTING_PREFERRED_NETWORK_MODE_URI;
45     static const std::string SETTINGS_NETWORK_SEARCH_AUTO_TIME;
46     static const std::string SETTINGS_NETWORK_SEARCH_AUTO_TIMEZONE;
47     static const std::string SETTINGS_NETWORK_SEARCH_AIRPLANE_MODE;
48     static const std::string SETTINGS_NETWORK_SEARCH_PREFERRED_NETWORK_MODE;
49 
50     bool RegisterSettingsObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver);
51     bool UnRegisterSettingsObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver);
52     bool Query(Uri uri, const std::string &key, std::string &value);
53     bool Insert(Uri uri, const std::string &key, const std::string &value);
54     bool Update(Uri uri, const std::string &key, const std::string &value);
55 
56 private:
57     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
58 
59 private:
60     std::shared_ptr<DataShare::DataShareHelper> settingHelper_;
61     const std::string SETTING_KEY = "KEYWORD";
62     const std::string SETTING_VALUE = "VALUE";
63     const int32_t RDB_INVALID_VALUE = -1;
64     std::mutex mtx_;
65 };
66 
67 class SettingEventCode {
68 public:
69     static const int32_t BASE = 0x00050000;
70     static const int32_t MSG_AUTO_TIME = BASE + 0;
71     static const int32_t MSG_AUTO_TIMEZONE = BASE + 1;
72     static const int32_t MSG_AUTO_AIRPLANE_MODE = BASE + 2;
73 };
74 
75 class AutoTimeObserver : public AAFwk::DataAbilityObserverStub {
76 public:
77     AutoTimeObserver(std::shared_ptr<NetworkSearchHandler> &networkSearchHandler);
78     ~AutoTimeObserver() = default;
79     void OnChange() override;
80 
81 private:
82     std::shared_ptr<NetworkSearchHandler> networkSearchHandler_;
83 };
84 
85 class AutoTimezoneObserver : public AAFwk::DataAbilityObserverStub {
86 public:
87     AutoTimezoneObserver(std::shared_ptr<NetworkSearchHandler> &networkSearchHandler);
88     ~AutoTimezoneObserver() = default;
89     void OnChange() override;
90 
91 private:
92     std::shared_ptr<NetworkSearchHandler> networkSearchHandler_;
93 };
94 
95 class AirplaneModeObserver : public AAFwk::DataAbilityObserverStub {
96 public:
97     AirplaneModeObserver(std::shared_ptr<NetworkSearchHandler> &networkSearchHandler);
98     ~AirplaneModeObserver() = default;
99     void OnChange() override;
100 
101 private:
102     std::shared_ptr<NetworkSearchHandler> networkSearchHandler_;
103 };
104 } // namespace Telephony
105 } // namespace OHOS
106 #endif // NETWORK_SEARCH_SETTINGS_RDB_HELPER_H
107