• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "permission_filter.h"
17 
18 #include "ans_inner_errors.h"
19 #include "ans_log_wrapper.h"
20 #include "bundle_manager_helper.h"
21 #include "notification_preferences.h"
22 
23 namespace OHOS {
24 namespace Notification {
OnStart()25 void PermissionFilter::OnStart()
26 {}
27 
OnStop()28 void PermissionFilter::OnStop()
29 {}
30 
OnPublish(const std::shared_ptr<NotificationRecord> & record)31 ErrCode PermissionFilter::OnPublish(const std::shared_ptr<NotificationRecord> &record)
32 {
33     bool enable = false;
34     ErrCode result =
35         NotificationPreferences::GetInstance().GetNotificationsEnabledForBundle(record->bundleOption, enable);
36     if (result == ERR_ANS_PREFERENCES_NOTIFICATION_BUNDLE_NOT_EXIST) {
37         result = ERR_OK;
38         std::shared_ptr<BundleManagerHelper> bundleManager = BundleManagerHelper::GetInstance();
39         if (bundleManager != nullptr) {
40             enable = bundleManager->CheckApiCompatibility(record->bundleOption);
41         }
42     }
43     if (result == ERR_OK) {
44         if (!enable) {
45             ANS_LOGE("Enable notifications for bundle is OFF");
46             return ERR_ANS_NOT_ALLOWED;
47         }
48 
49         if (record->notification->GetBundleName() != record->notification->GetCreateBundle()) {
50             // Publish as bundle
51         }
52     }
53     return result;
54 }
55 }  // namespace Notification
56 }  // namespace OHOS