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 int32_t Query(Uri uri, const std::string &key, std::string &value); 53 int32_t Insert(Uri uri, const std::string &key, const std::string &value); 54 int32_t 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 const std::string SETTING_KEY = "KEYWORD"; 61 const std::string SETTING_VALUE = "VALUE"; 62 const int32_t RDB_INVALID_VALUE = -1; 63 std::mutex mtx_; 64 }; 65 66 class SettingEventCode { 67 public: 68 static const int32_t BASE = 0x00050000; 69 static const int32_t MSG_AUTO_TIME = BASE + 0; 70 static const int32_t MSG_AUTO_TIMEZONE = BASE + 1; 71 static const int32_t MSG_AUTO_AIRPLANE_MODE = BASE + 2; 72 }; 73 74 class AutoTimeObserver : public AAFwk::DataAbilityObserverStub { 75 public: 76 AutoTimeObserver(std::shared_ptr<NetworkSearchHandler> &networkSearchHandler); 77 ~AutoTimeObserver() = default; 78 void OnChange() override; 79 80 private: 81 std::shared_ptr<NetworkSearchHandler> networkSearchHandler_; 82 }; 83 84 class AutoTimezoneObserver : public AAFwk::DataAbilityObserverStub { 85 public: 86 AutoTimezoneObserver(std::shared_ptr<NetworkSearchHandler> &networkSearchHandler); 87 ~AutoTimezoneObserver() = default; 88 void OnChange() override; 89 90 private: 91 std::shared_ptr<NetworkSearchHandler> networkSearchHandler_; 92 }; 93 94 class AirplaneModeObserver : public AAFwk::DataAbilityObserverStub { 95 public: 96 AirplaneModeObserver(std::shared_ptr<NetworkSearchHandler> &networkSearchHandler); 97 ~AirplaneModeObserver() = default; 98 void OnChange() override; 99 100 private: 101 std::shared_ptr<NetworkSearchHandler> networkSearchHandler_; 102 }; 103 } // namespace Telephony 104 } // namespace OHOS 105 #endif // NETWORK_SEARCH_SETTINGS_RDB_HELPER_H 106