1 /* 2 * Copyright (c) 2024 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 #include "notification_trust_list.h" 16 17 #include "notification_extension_wrapper.h" 18 19 namespace OHOS { 20 namespace Notification { 21 22 constexpr static uint32_t LIVE_VIEW_INDEX = 0; 23 constexpr static uint32_t REMINDER_LIST_INDEX = 2; NotificationTrustList()24NotificationTrustList::NotificationTrustList() 25 { 26 GetCcmPrivilegesConfig(); 27 } 28 29 NotificationTrustList::~NotificationTrustList() = default; 30 GetCcmPrivilegesConfig()31void NotificationTrustList::GetCcmPrivilegesConfig() 32 { 33 nlohmann::json root; 34 std::string JsonPoint = "/"; 35 JsonPoint.append(NotificationConfigParse::APP_PRIVILEGES); 36 if (!NotificationConfigParse::GetInstance()->GetConfigJson(JsonPoint, root)) { 37 ANS_LOGE("Failed to get JsonPoint CCM config file."); 38 return; 39 } 40 if (!root.contains(NotificationConfigParse::APP_PRIVILEGES)) { 41 ANS_LOGW("not found jsonKey appPrivileges"); 42 return; 43 } 44 nlohmann::json affects = root[NotificationConfigParse::APP_PRIVILEGES]; 45 if (affects.is_null() || affects.empty()) { 46 ANS_LOGE("GetCcmPrivileges failed as invalid ccmPrivileges json."); 47 return; 48 } 49 for (auto &affect : affects.items()) { 50 std::string affects_value = affect.value().get<std::string>(); 51 if (affects_value[LIVE_VIEW_INDEX] != PRIVILEGES_BANNER_NOT_ALLOW) { 52 liveViewTrustlist_.insert(affect.key()); 53 } 54 if (affects_value.length() >= PRIVILEGES_CONFIG_MIN_LEN && 55 affects_value[PRIVILEGES_BANNER_INDEX] != PRIVILEGES_BANNER_NOT_ALLOW) { 56 notificationSlotFlagsTrustlist_.insert(affect.key()); 57 } 58 if (affects_value.length() >= REMINDER_LIST_INDEX + 1 && 59 affects_value[REMINDER_LIST_INDEX] != PRIVILEGES_BANNER_NOT_ALLOW) { 60 reminderTrustlist_.insert(affect.key()); 61 } 62 } 63 return; 64 } 65 IsLiveViewTrtust(const std::string bundleName)66bool NotificationTrustList::IsLiveViewTrtust(const std::string bundleName) 67 { 68 return liveViewTrustlist_.count(bundleName); 69 } 70 IsReminderTrustList(const std::string & bundleName)71bool NotificationTrustList::IsReminderTrustList(const std::string& bundleName) 72 { 73 return reminderTrustlist_.count(bundleName); 74 } 75 IsSlotFlagsTrustlistAsBundle(const sptr<NotificationBundleOption> & bundleOption)76bool NotificationTrustList::IsSlotFlagsTrustlistAsBundle(const sptr<NotificationBundleOption> &bundleOption) 77 { 78 if (notificationSlotFlagsTrustlist_.count(bundleOption->GetBundleName()) > 0) { 79 return true; 80 } 81 #ifdef ENABLE_ANS_EXT_WRAPPER 82 int32_t ctrlResult = EXTENTION_WRAPPER->BannerControl(bundleOption->GetBundleName()); 83 return (ctrlResult == ERR_OK) ? true : false; 84 #else 85 return false; 86 #endif 87 } 88 } // namespace Notification 89 } // namespace OHOS 90