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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_PREFERENCES_INFO_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_PREFERENCES_INFO_H 18 19 #include <map> 20 #include <string> 21 22 #include "ans_inner_errors.h" 23 24 namespace OHOS { 25 namespace Notification { 26 class DistributedPreferencesInfo { 27 public: 28 DistributedPreferencesInfo(); 29 ~DistributedPreferencesInfo(); 30 31 /** 32 * @brief Set whether the device supports distributed notifications. 33 * 34 * @param enable Specifies whether to enable the device to support distributed notification. 35 */ 36 void SetDistributedEnable(bool enable); 37 38 /** 39 * @brief Check if the device supports distributed notification. 40 * 41 * @return True if the device supports distributed notification; false otherwise. 42 */ 43 bool GetDistributedEnable(); 44 45 /** 46 * @brief Set whether an application supports distributed notifications. 47 * 48 * @param bundleName Indicates the bundle name of an application. 49 * @param uid Indicates the uid of an application. 50 * @param enable Specifies whether to enable an application to support distributed notification. 51 */ 52 void SetDistributedBundleEnable(const std::string &bundleName, int32_t uid, bool enable); 53 54 /** 55 * @brief Check whether an application supports distributed notifications. 56 * 57 * @param bundleName Indicates the bundle name of an application. 58 * @param uid Indicates the uid of an application. 59 * @return True if the application supports distributed notification; false otherwise. 60 */ 61 bool GetDistributedBundleEnable(const std::string &bundleName, int32_t uid); 62 63 /** 64 * @brief Remove the setting of whether the application supports distributed notification. 65 * 66 * @param bundleName Indicates the bundle name of an application. 67 * @param uid Indicates the uid of an application. 68 */ 69 void DeleteDistributedBundleInfo(const std::string &bundleName, int32_t uid); 70 71 /** 72 * @brief Set whether to sync notifications to devices that do not have the app installed. 73 * 74 * @param userId Indicates the specific user. 75 * @param enabled Allow or disallow sync notifications. 76 */ 77 void SetSyncEnabledWithoutApp(const int32_t userId, const bool enabled); 78 ErrCode GetSyncEnabledWithoutApp(const int32_t userId, bool &enabled); 79 80 private: 81 bool distributedEnable_ = false; 82 std::map<std::pair<const std::string, int32_t>, bool> bundleEnable_; 83 std::map<int32_t, bool> enabledWithoutApp_; 84 }; 85 } // namespace Notification 86 } // namespace OHOS 87 88 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_DISTRIBUTED_INCLUDE_PREFERENCES_INFO_H