• 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 POWERMGR_POWER_MANAGER_POWER_SETTING_HELPER_H
17 #define POWERMGR_POWER_MANAGER_POWER_SETTING_HELPER_H
18 
19 #include "datashare_helper.h"
20 #include "errors.h"
21 #include "mutex"
22 #include "setting_observer.h"
23 
24 namespace OHOS {
25 namespace PowerMgr {
26 class SettingProvider : public NoCopyable {
27 public:
28     static SettingProvider& GetInstance(int32_t systemAbilityId);
29     ErrCode GetStringValue(const std::string& key, std::string& value);
30     ErrCode GetIntValue(const std::string& key, int32_t& value);
31     ErrCode GetLongValue(const std::string& key, int64_t& value);
32     ErrCode GetBoolValue(const std::string& key, bool& value);
33     ErrCode PutStringValue(const std::string& key, const std::string& value, bool needNotify = true);
34     ErrCode PutIntValue(const std::string& key, int32_t value, bool needNotify = true);
35     ErrCode PutLongValue(const std::string& key, int64_t value, bool needNotify = true);
36     ErrCode PutBoolValue(const std::string& key, bool value, bool needNotify = true);
37     bool IsValidKey(const std::string& key);
38     sptr<SettingObserver> CreateObserver(const std::string& key, SettingObserver::UpdateFunc& func);
39     ErrCode RegisterObserver(const sptr<SettingObserver>& observer);
40     ErrCode UnregisterObserver(const sptr<SettingObserver>& observer);
41 
42 protected:
43     ~SettingProvider() override;
44 
45 private:
46     static SettingProvider* instance_;
47     static std::mutex mutex_;
48     static sptr<IRemoteObject> remoteObj_;
49 
50     static void Initialize(int32_t systemAbilityId);
51     static std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
52     static bool ReleaseDataShareHelper(std::shared_ptr<DataShare::DataShareHelper>& helper);
53     static Uri AssembleUri(const std::string& key);
54 };
55 } // namespace PowerMgr
56 } // namespace OHOS
57 #endif // POWERMGR_POWER_MANAGER_POWER_SETTING_HELPER_H
58