1 /*
2  * Copyright (c) 2021 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 "notification_slot_filter.h"
17 
18 #include "ans_inner_errors.h"
19 #include "ans_log_wrapper.h"
20 #include "notification_preferences.h"
21 
22 namespace OHOS {
23 namespace Notification {
OnStart()24 void NotificationSlotFilter::OnStart()
25 {}
26 
OnStop()27 void NotificationSlotFilter::OnStop()
28 {}
29 
OnPublish(const std::shared_ptr<NotificationRecord> & record)30 ErrCode NotificationSlotFilter::OnPublish(const std::shared_ptr<NotificationRecord> &record)
31 {
32     if (record->slot != nullptr) {
33         if (record->slot->CanEnableLight()) {
34             record->notification->SetEnableLight(true);
35             record->notification->SetLedLightColor(record->slot->GetLedLightColor());
36         } else {
37             record->notification->SetEnableLight(false);
38         }
39 
40         if (record->slot->CanVibrate()) {
41             record->notification->SetEnableVibration(true);
42             record->notification->SetVibrationStyle(record->slot->GetVibrationStyle());
43         } else {
44             record->notification->SetEnableVibration(false);
45         }
46 
47         auto sound = record->slot->GetSound();
48         if (!sound.ToString().empty()) {
49             record->notification->SetEnableSound(true);
50             record->notification->SetSound(record->slot->GetSound());
51         } else {
52             record->notification->SetEnableSound(false);
53         }
54 
55         if (record->request->GetVisibleness() == NotificationConstant::VisiblenessType::NO_OVERRIDE) {
56             record->request->SetVisibleness(record->slot->GetLockScreenVisibleness());
57         }
58     } else {
59         ANS_LOGE("Non valid slot!");
60         return ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST;
61     }
62 
63     return ERR_OK;
64 }
65 }  // namespace Notification
66 }  // namespace OHOS