1 /*
2 * Copyright (c) 2021-2023 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 "advanced_notification_service.h"
17
18 #include <functional>
19 #include <iomanip>
20 #include <sstream>
21
22 #include "ability_context.h"
23 #include "ability_info.h"
24 #include "access_token_helper.h"
25 #include "accesstoken_kit.h"
26 #include "ans_const_define.h"
27 #include "ans_inner_errors.h"
28 #include "ans_log_wrapper.h"
29 #include "ans_watchdog.h"
30 #include "ans_permission_def.h"
31 #include "bundle_manager_helper.h"
32 #include "errors.h"
33 #include "notification_record.h"
34 #ifdef DEVICE_USAGE_STATISTICS_ENABLE
35 #include "bundle_active_client.h"
36 #endif
37 #include "common_event_manager.h"
38 #include "common_event_support.h"
39 #include "event_report.h"
40 #include "hitrace_meter_adapter.h"
41 #include "ipc_skeleton.h"
42 #include "nlohmann/json.hpp"
43 #include "notification_constant.h"
44 #include "notification_dialog_manager.h"
45 #include "notification_filter.h"
46 #include "notification_preferences.h"
47 #include "notification_request.h"
48 #include "notification_slot.h"
49 #include "notification_slot_filter.h"
50 #include "notification_subscriber_manager.h"
51 #include "notification_local_live_view_subscriber_manager.h"
52 #include "os_account_manager.h"
53 #include "parameters.h"
54 #include "permission_filter.h"
55 #include "push_callback_proxy.h"
56 #include "trigger_info.h"
57 #include "want_agent_helper.h"
58 #include "notification_timer_info.h"
59 #include "time_service_client.h"
60 #include "notification_config_parse.h"
61 #include "want_params_wrapper.h"
62
63 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
64 #include "distributed_notification_manager.h"
65 #include "distributed_preferences.h"
66 #include "distributed_screen_status_manager.h"
67 #endif
68
69 #include "advanced_notification_inline.cpp"
70
71 namespace OHOS {
72 namespace Notification {
73 namespace {
74
75 constexpr int32_t DEFAULT_RECENT_COUNT = 16;
76 constexpr int32_t DIALOG_DEFAULT_WIDTH = 400;
77 constexpr int32_t DIALOG_DEFAULT_HEIGHT = 240;
78 constexpr int32_t WINDOW_DEFAULT_WIDTH = 720;
79 constexpr int32_t WINDOW_DEFAULT_HEIGHT = 1280;
80 constexpr int32_t UI_HALF = 2;
81
82 const std::string NOTIFICATION_ANS_CHECK_SA_PERMISSION = "notification.ans.check.sa.permission";
83
84 } // namespace
85
86 sptr<AdvancedNotificationService> AdvancedNotificationService::instance_;
87 std::mutex AdvancedNotificationService::instanceMutex_;
88 std::mutex AdvancedNotificationService::pushMutex_;
89 std::map<std::string, uint32_t> slotFlagsDefaultMap_;
90
91 std::map<NotificationConstant::SlotType, sptr<IPushCallBack>> AdvancedNotificationService::pushCallBacks_;
92 std::map<NotificationConstant::SlotType, sptr<NotificationCheckRequest>> AdvancedNotificationService::checkRequests_;
93 std::string AdvancedNotificationService::supportCheckSaPermission_ = "false";
94
PrepareNotificationRequest(const sptr<NotificationRequest> & request)95 ErrCode AdvancedNotificationService::PrepareNotificationRequest(const sptr<NotificationRequest> &request)
96 {
97 ANS_LOGD("%{public}s", __FUNCTION__);
98
99 std::string bundle = GetClientBundleName();
100 if (bundle.empty()) {
101 return ERR_ANS_INVALID_BUNDLE;
102 }
103 if (request == nullptr) {
104 ANSR_LOGE("NotificationRequest object is nullptr");
105 return ERR_ANS_INVALID_PARAM;
106 }
107
108 if (request->IsAgentNotification()) {
109 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
110 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
111 return ERR_ANS_NON_SYSTEM_APP;
112 }
113
114 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER) ||
115 !CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER)) {
116 return ERR_ANS_PERMISSION_DENIED;
117 }
118
119 std::shared_ptr<BundleManagerHelper> bundleManager = BundleManagerHelper::GetInstance();
120 int32_t uid = -1;
121 if (bundleManager != nullptr) {
122 uid = bundleManager->GetDefaultUidByBundleName(request->GetOwnerBundleName(), request->GetOwnerUserId());
123 }
124 if (uid < 0) {
125 return ERR_ANS_INVALID_UID;
126 }
127 request->SetOwnerUid(uid);
128 } else {
129 request->SetOwnerBundleName(bundle);
130 }
131 request->SetCreatorBundleName(bundle);
132
133 int32_t uid = IPCSkeleton::GetCallingUid();
134 int32_t pid = IPCSkeleton::GetCallingPid();
135 request->SetCreatorUid(uid);
136 request->SetCreatorPid(pid);
137
138 int32_t userId = SUBSCRIBE_USER_INIT;
139 OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
140 request->SetCreatorUserId(userId);
141 ErrCode result = CheckPictureSize(request);
142
143 if (request->GetDeliveryTime() <= 0) {
144 request->SetDeliveryTime(GetCurrentTime());
145 }
146
147 SetRequestBySlotType(request);
148 FillActionButtons(request);
149
150 return result;
151 }
152
GetInstance()153 sptr<AdvancedNotificationService> AdvancedNotificationService::GetInstance()
154 {
155 std::lock_guard<std::mutex> lock(instanceMutex_);
156
157 if (instance_ == nullptr) {
158 instance_ = new (std::nothrow) AdvancedNotificationService();
159 if (instance_ == nullptr) {
160 ANS_LOGE("Failed to create AdvancedNotificationService instance");
161 return nullptr;
162 }
163 std::string configPath(NotificationConstant::NOTIFICATION_SLOTFLAG_CONFIG_PATH);
164 NotificationConfigFile::getNotificationSlotFlagConfig(configPath, slotFlagsDefaultMap_);
165 }
166
167 return instance_;
168 }
169
GetDefaultSlotConfig()170 std::map<std::string, uint32_t>& AdvancedNotificationService::GetDefaultSlotConfig()
171 {
172 return slotFlagsDefaultMap_;
173 }
174
175 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
InitDistributeCallBack()176 void AdvancedNotificationService::InitDistributeCallBack()
177 {
178 DistributedNotificationManager::IDistributedCallback distributedCallback = {
179 .OnPublish = std::bind(&AdvancedNotificationService::OnDistributedPublish,
180 this,
181 std::placeholders::_1,
182 std::placeholders::_2,
183 std::placeholders::_3),
184 .OnUpdate = std::bind(&AdvancedNotificationService::OnDistributedUpdate,
185 this,
186 std::placeholders::_1,
187 std::placeholders::_2,
188 std::placeholders::_3),
189 .OnDelete = std::bind(&AdvancedNotificationService::OnDistributedDelete,
190 this,
191 std::placeholders::_1,
192 std::placeholders::_2,
193 std::placeholders::_3,
194 std::placeholders::_4),
195 };
196 DistributedNotificationManager::GetInstance()->RegisterCallback(distributedCallback);
197 }
198 #endif
199
AdvancedNotificationService()200 AdvancedNotificationService::AdvancedNotificationService()
201 {
202 ANS_LOGI("constructor");
203 notificationSvrQueue_ = std::make_shared<ffrt::queue>("NotificationSvrMain");
204 if (!notificationSvrQueue_) {
205 ANS_LOGE("ffrt create failed!");
206 return;
207 }
208 recentInfo_ = std::make_shared<RecentInfo>();
209 distributedKvStoreDeathRecipient_ = std::make_shared<DistributedKvStoreDeathRecipient>(
210 std::bind(&AdvancedNotificationService::OnDistributedKvStoreDeathRecipient, this));
211 permissonFilter_ = std::make_shared<PermissionFilter>();
212 notificationSlotFilter_ = std::make_shared<NotificationSlotFilter>();
213 StartFilters();
214
215 std::function<void(const std::shared_ptr<NotificationSubscriberManager::SubscriberRecord> &)> callback =
216 std::bind(&AdvancedNotificationService::OnSubscriberAdd, this, std::placeholders::_1);
217 NotificationSubscriberManager::GetInstance()->RegisterOnSubscriberAddCallback(callback);
218
219 std::function<void()> recoverFunc = std::bind(&AdvancedNotificationService::RecoverLiveViewFromDb, this);
220 notificationSvrQueue_->submit(recoverFunc);
221
222 ISystemEvent iSystemEvent = {
223 std::bind(&AdvancedNotificationService::OnBundleRemoved, this, std::placeholders::_1),
224 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
225 std::bind(&AdvancedNotificationService::OnScreenOn, this),
226 std::bind(&AdvancedNotificationService::OnScreenOff, this),
227 #endif
228 std::bind(&AdvancedNotificationService::OnResourceRemove, this, std::placeholders::_1),
229 std::bind(&AdvancedNotificationService::OnBundleDataCleared, this, std::placeholders::_1),
230 std::bind(&AdvancedNotificationService::OnBundleDataAdd, this, std::placeholders::_1),
231 std::bind(&AdvancedNotificationService::OnBundleDataUpdate, this, std::placeholders::_1),
232 std::bind(&AdvancedNotificationService::OnBootSystemCompleted, this),
233 };
234 systemEventObserver_ = std::make_shared<SystemEventObserver>(iSystemEvent);
235
236 dataManager_.RegisterKvStoreServiceDeathRecipient(distributedKvStoreDeathRecipient_);
237 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
238 InitDistributeCallBack();
239 #endif
240 supportCheckSaPermission_ = OHOS::system::GetParameter(NOTIFICATION_ANS_CHECK_SA_PERMISSION, "false");
241 }
242
~AdvancedNotificationService()243 AdvancedNotificationService::~AdvancedNotificationService()
244 {
245 ANS_LOGI("deconstructor");
246 dataManager_.UnRegisterKvStoreServiceDeathRecipient(distributedKvStoreDeathRecipient_);
247 NotificationSubscriberManager::GetInstance()->UnRegisterOnSubscriberAddCallback();
248
249 StopFilters();
250 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
251 DistributedNotificationManager::GetInstance()->UngegisterCallback();
252 #endif
253 SelfClean();
254 slotFlagsDefaultMap_.clear();
255 }
256
SelfClean()257 void AdvancedNotificationService::SelfClean()
258 {
259 if (notificationSvrQueue_ != nullptr) {
260 notificationSvrQueue_.reset();
261 }
262
263 NotificationSubscriberManager::GetInstance()->ResetFfrtQueue();
264 DistributedNotificationManager::GetInstance()->ResetFfrtQueue();
265 NotificationLocalLiveViewSubscriberManager::GetInstance()->ResetFfrtQueue();
266 }
267
AssignToNotificationList(const std::shared_ptr<NotificationRecord> & record)268 ErrCode AdvancedNotificationService::AssignToNotificationList(const std::shared_ptr<NotificationRecord> &record)
269 {
270 ErrCode result = ERR_OK;
271 if (!IsNotificationExists(record->notification->GetKey())) {
272 result = FlowControl(record);
273 } else {
274 if (record->request->IsAlertOneTime()) {
275 record->notification->SetEnableLight(false);
276 record->notification->SetEnableSound(false);
277 record->notification->SetEnableVibration(false);
278 }
279 UpdateInNotificationList(record);
280 }
281 return result;
282 }
283
CancelPreparedNotification(int32_t notificationId,const std::string & label,const sptr<NotificationBundleOption> & bundleOption)284 ErrCode AdvancedNotificationService::CancelPreparedNotification(
285 int32_t notificationId, const std::string &label, const sptr<NotificationBundleOption> &bundleOption)
286 {
287 HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
288 if (bundleOption == nullptr) {
289 return ERR_ANS_INVALID_BUNDLE;
290 }
291
292 if (notificationSvrQueue_ == nullptr) {
293 ANS_LOGE("Serial queue is invalidity.");
294 return ERR_ANS_INVALID_PARAM;
295 }
296 ErrCode result = ERR_OK;
297 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
298 ANS_LOGD("ffrt enter!");
299 sptr<Notification> notification = nullptr;
300 result = RemoveFromNotificationList(bundleOption, label, notificationId, notification, true);
301 if (result != ERR_OK) {
302 return;
303 }
304
305 if (notification != nullptr) {
306 int32_t reason = NotificationConstant::APP_CANCEL_REASON_DELETE;
307 UpdateRecentNotification(notification, true, reason);
308 NotificationSubscriberManager::GetInstance()->NotifyCanceled(notification, nullptr, reason);
309 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
310 DoDistributedDelete("", "", notification);
311 #endif
312 }
313 }));
314 notificationSvrQueue_->wait(handler);
315 SendCancelHiSysEvent(notificationId, label, bundleOption, result);
316 return result;
317 }
318
PrepareNotificationInfo(const sptr<NotificationRequest> & request,sptr<NotificationBundleOption> & bundleOption)319 ErrCode AdvancedNotificationService::PrepareNotificationInfo(
320 const sptr<NotificationRequest> &request, sptr<NotificationBundleOption> &bundleOption)
321 {
322 HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
323 if (request == nullptr) {
324 ANS_LOGE("request is invalid.");
325 return ERR_ANS_INVALID_PARAM;
326 }
327 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
328 if ((request->GetSlotType() == NotificationConstant::SlotType::CUSTOM) &&
329 !AccessTokenHelper::IsSystemApp() && !isSubsystem) {
330 return ERR_ANS_NON_SYSTEM_APP;
331 }
332 ErrCode result = PrepareNotificationRequest(request);
333 if (result != ERR_OK) {
334 return result;
335 }
336
337 if (request->IsAgentNotification()) {
338 bundleOption = new (std::nothrow) NotificationBundleOption(request->GetOwnerBundleName(),
339 request->GetOwnerUid());
340 } else {
341 bundleOption = GenerateBundleOption();
342 }
343
344 if (bundleOption == nullptr) {
345 return ERR_ANS_INVALID_BUNDLE;
346 }
347 ANS_LOGI(
348 "bundleName=%{public}s, uid=%{public}d", (bundleOption->GetBundleName()).c_str(), bundleOption->GetUid());
349 return ERR_OK;
350 }
351
StartFinishTimer(const std::shared_ptr<NotificationRecord> & record,int64_t expiredTimePoint)352 ErrCode AdvancedNotificationService::StartFinishTimer(
353 const std::shared_ptr<NotificationRecord> &record, int64_t expiredTimePoint)
354 {
355 uint64_t timerId = StartAutoDelete(record->notification->GetKey(),
356 expiredTimePoint, NotificationConstant::APP_CANCEL_REASON_OTHER);
357 if (timerId == NotificationConstant::INVALID_TIMER_ID) {
358 ANS_LOGE("Start finish auto delete timer failed.");
359 return ERR_ANS_TASK_ERR;
360 }
361 record->notification->SetFinishTimer(timerId);
362 return ERR_OK;
363 }
364
SetFinishTimer(const std::shared_ptr<NotificationRecord> & record)365 ErrCode AdvancedNotificationService::SetFinishTimer(const std::shared_ptr<NotificationRecord> &record)
366 {
367 int64_t maxExpiredTime = GetCurrentTime() + NotificationConstant::MAX_FINISH_TIME;
368 auto result = StartFinishTimer(record, maxExpiredTime);
369 if (result != ERR_OK) {
370 return result;
371 }
372 record->request->SetFinishDeadLine(maxExpiredTime);
373 return ERR_OK;
374 }
375
CancelFinishTimer(const std::shared_ptr<NotificationRecord> & record)376 void AdvancedNotificationService::CancelFinishTimer(const std::shared_ptr<NotificationRecord> &record)
377 {
378 record->request->SetFinishDeadLine(0);
379 CancelAutoDeleteTimer(record->notification->GetFinishTimer());
380 record->notification->SetFinishTimer(NotificationConstant::INVALID_TIMER_ID);
381 }
382
StartUpdateTimer(const std::shared_ptr<NotificationRecord> & record,int64_t expireTimePoint)383 ErrCode AdvancedNotificationService::StartUpdateTimer(
384 const std::shared_ptr<NotificationRecord> &record, int64_t expireTimePoint)
385 {
386 uint64_t timerId = StartAutoDelete(record->notification->GetKey(),
387 expireTimePoint, NotificationConstant::APP_CANCEL_REASON_OTHER);
388 if (timerId == NotificationConstant::INVALID_TIMER_ID) {
389 ANS_LOGE("Start update auto delete timer failed.");
390 return ERR_ANS_TASK_ERR;
391 }
392 record->notification->SetUpdateTimer(timerId);
393 return ERR_OK;
394 }
395
SetUpdateTimer(const std::shared_ptr<NotificationRecord> & record)396 ErrCode AdvancedNotificationService::SetUpdateTimer(const std::shared_ptr<NotificationRecord> &record)
397 {
398 int64_t maxExpiredTime = GetCurrentTime() + NotificationConstant::MAX_UPDATE_TIME;
399 ErrCode result = StartUpdateTimer(record, maxExpiredTime);
400 if (result != ERR_OK) {
401 return result;
402 }
403 record->request->SetUpdateDeadLine(maxExpiredTime);
404 return ERR_OK;
405 }
406
CancelUpdateTimer(const std::shared_ptr<NotificationRecord> & record)407 void AdvancedNotificationService::CancelUpdateTimer(const std::shared_ptr<NotificationRecord> &record)
408 {
409 record->request->SetUpdateDeadLine(0);
410 CancelAutoDeleteTimer(record->notification->GetUpdateTimer());
411 record->notification->SetUpdateTimer(NotificationConstant::INVALID_TIMER_ID);
412 }
413
StartArchiveTimer(const std::shared_ptr<NotificationRecord> & record)414 void AdvancedNotificationService::StartArchiveTimer(const std::shared_ptr<NotificationRecord> &record)
415 {
416 auto deleteTime = record->request->GetAutoDeletedTime();
417 if (deleteTime == NotificationConstant::NO_DELAY_DELETE_TIME) {
418 TriggerAutoDelete(record->notification->GetKey(), NotificationConstant::APP_CANCEL_REASON_DELETE);
419 return;
420 }
421 if (deleteTime <= NotificationConstant::INVALID_AUTO_DELETE_TIME) {
422 deleteTime = NotificationConstant::DEFAULT_AUTO_DELETE_TIME;
423 }
424 int64_t maxExpiredTime = GetCurrentTime() +
425 NotificationConstant::SECOND_TO_MS * deleteTime;
426 uint64_t timerId = StartAutoDelete(record->notification->GetKey(),
427 maxExpiredTime, NotificationConstant::APP_CANCEL_REASON_DELETE);
428 if (timerId == NotificationConstant::INVALID_TIMER_ID) {
429 ANS_LOGE("Start archive auto delete timer failed.");
430 }
431 record->notification->SetArchiveTimer(timerId);
432 }
433
CancelArchiveTimer(const std::shared_ptr<NotificationRecord> & record)434 void AdvancedNotificationService::CancelArchiveTimer(const std::shared_ptr<NotificationRecord> &record)
435 {
436 record->request->SetArchiveDeadLine(0);
437 CancelAutoDeleteTimer(record->notification->GetArchiveTimer());
438 record->notification->SetArchiveTimer(NotificationConstant::INVALID_TIMER_ID);
439 }
440
FillNotificationRecord(const NotificationRequestDb & requestdbObj,std::shared_ptr<NotificationRecord> record)441 ErrCode AdvancedNotificationService::FillNotificationRecord(
442 const NotificationRequestDb &requestdbObj, std::shared_ptr<NotificationRecord> record)
443 {
444 if (requestdbObj.request == nullptr || requestdbObj.bundleOption == nullptr || record == nullptr) {
445 ANS_LOGE("Invalid param.");
446 return ERR_ANS_INVALID_PARAM;
447 }
448
449 record->request = requestdbObj.request;
450 record->notification = new (std::nothrow) Notification(requestdbObj.request);
451 if (record->notification == nullptr) {
452 ANS_LOGE("Failed to create notification.");
453 return ERR_ANS_NO_MEMORY;
454 }
455 SetNotificationRemindType(record->notification, true);
456
457 record->bundleOption = requestdbObj.bundleOption;
458 ErrCode ret = AssignValidNotificationSlot(record);
459 if (ret != ERR_OK) {
460 ANS_LOGE("Assign valid notification slot failed!");
461 return ret;
462 }
463
464 return ERR_OK;
465 }
466
MakeNotificationRecord(const sptr<NotificationRequest> & request,const sptr<NotificationBundleOption> & bundleOption)467 std::shared_ptr<NotificationRecord> AdvancedNotificationService::MakeNotificationRecord(
468 const sptr<NotificationRequest> &request, const sptr<NotificationBundleOption> &bundleOption)
469 {
470 auto record = std::make_shared<NotificationRecord>();
471 record->request = request;
472 record->notification = new (std::nothrow) Notification(request);
473 if (record->notification == nullptr) {
474 ANS_LOGE("Failed to create notification.");
475 return nullptr;
476 }
477 record->bundleOption = bundleOption;
478 SetNotificationRemindType(record->notification, true);
479 return record;
480 }
481
PublishPreparedNotification(const sptr<NotificationRequest> & request,const sptr<NotificationBundleOption> & bundleOption)482 ErrCode AdvancedNotificationService::PublishPreparedNotification(
483 const sptr<NotificationRequest> &request, const sptr<NotificationBundleOption> &bundleOption)
484 {
485 HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
486 ANS_LOGI("PublishPreparedNotification");
487
488 auto record = MakeNotificationRecord(request, bundleOption);
489 if (record == nullptr) {
490 return ERR_ANS_NO_MEMORY;
491 }
492
493 if (notificationSvrQueue_ == nullptr) {
494 ANS_LOGE("Serial queue is invalid.");
495 return ERR_ANS_INVALID_PARAM;
496 }
497
498 ErrCode result = ERR_OK;
499 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
500 ANS_LOGD("ffrt enter!");
501 result = AssignValidNotificationSlot(record);
502 if (result != ERR_OK) {
503 ANS_LOGE("Can not assign valid slot!");
504 return;
505 }
506
507 result = Filter(record);
508 if (result != ERR_OK) {
509 ANS_LOGE("Reject by filters: %{public}d", result);
510 return;
511 }
512
513 result = AssignToNotificationList(record);
514 if (result != ERR_OK) {
515 return;
516 }
517
518 UpdateRecentNotification(record->notification, false, 0);
519 sptr<NotificationSortingMap> sortingMap = GenerateSortingMap();
520 ReportInfoToResourceSchedule(request->GetCreatorUserId(), bundleOption->GetBundleName());
521 if (IsNeedNotifyConsumed(record->request)) {
522 NotificationSubscriberManager::GetInstance()->NotifyConsumed(record->notification, sortingMap);
523 }
524 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
525 if (!request->IsAgentNotification()) {
526 DoDistributedPublish(bundleOption, record);
527 }
528 #endif
529 NotificationRequestDb requestDb = { .request = record->request, .bundleOption = bundleOption};
530 UpdateNotificationTimerInfo(record);
531 result = SetNotificationRequestToDb(requestDb);
532 }));
533 notificationSvrQueue_->wait(handler);
534 // live view handled in UpdateNotificationTimerInfo, ignore here.
535 if ((record->request->GetAutoDeletedTime() > GetCurrentTime()) && !record->request->IsCommonLiveView()) {
536 StartAutoDelete(record->notification->GetKey(),
537 record->request->GetAutoDeletedTime(), NotificationConstant::APP_CANCEL_REASON_DELETE);
538 }
539 return result;
540 }
541
ReportInfoToResourceSchedule(const int32_t userId,const std::string & bundleName)542 void AdvancedNotificationService::ReportInfoToResourceSchedule(const int32_t userId, const std::string &bundleName)
543 {
544 #ifdef DEVICE_USAGE_STATISTICS_ENABLE
545 DeviceUsageStats::BundleActiveEvent event(DeviceUsageStats::BundleActiveEvent::NOTIFICATION_SEEN, bundleName);
546 DeviceUsageStats::BundleActiveClient::GetInstance().ReportEvent(event, userId);
547 #endif
548 }
549
IsNotificationExists(const std::string & key)550 bool AdvancedNotificationService::IsNotificationExists(const std::string &key)
551 {
552 bool isExists = false;
553
554 for (auto item : notificationList_) {
555 if (item->notification->GetKey() == key) {
556 isExists = true;
557 break;
558 }
559 }
560
561 return isExists;
562 }
563
Filter(const std::shared_ptr<NotificationRecord> & record,bool isRecover)564 ErrCode AdvancedNotificationService::Filter(const std::shared_ptr<NotificationRecord> &record, bool isRecover)
565 {
566 ErrCode result = ERR_OK;
567
568 if (!isRecover) {
569 auto oldRecord = GetFromNotificationList(record->notification->GetKey());
570 result = record->request->CheckNotificationRequest((oldRecord == nullptr) ? nullptr : oldRecord->request);
571 if (result != ERR_OK) {
572 ANS_LOGE("Notification(key %{public}s) isn't ready on publish failed with %{public}d.",
573 record->notification->GetKey().c_str(), result);
574 return result;
575 }
576 }
577
578 if (permissonFilter_ == nullptr || notificationSlotFilter_ == nullptr) {
579 ANS_LOGE("Filter is invalid.");
580 return ERR_ANS_INVALID_PARAM;
581 }
582
583 result = permissonFilter_->OnPublish(record);
584 if (result != ERR_OK) {
585 ANS_LOGE("Permission filter on publish failed with %{public}d.", result);
586 return result;
587 }
588
589 result = notificationSlotFilter_->OnPublish(record);
590 if (result != ERR_OK) {
591 ANS_LOGE("Notification slot filter on publish failed with %{public}d.", result);
592 return result;
593 }
594
595 return ERR_OK;
596 }
597
AddToNotificationList(const std::shared_ptr<NotificationRecord> & record)598 void AdvancedNotificationService::AddToNotificationList(const std::shared_ptr<NotificationRecord> &record)
599 {
600 notificationList_.push_back(record);
601 SortNotificationList();
602 }
603
UpdateInNotificationList(const std::shared_ptr<NotificationRecord> & record)604 void AdvancedNotificationService::UpdateInNotificationList(const std::shared_ptr<NotificationRecord> &record)
605 {
606 auto iter = notificationList_.begin();
607 while (iter != notificationList_.end()) {
608 if ((*iter)->notification->GetKey() == record->notification->GetKey()) {
609 record->request->FillMissingParameters((*iter)->request);
610 record->notification->SetUpdateTimer((*iter)->notification->GetUpdateTimer());
611 record->notification->SetFinishTimer((*iter)->notification->GetFinishTimer());
612 *iter = record;
613 break;
614 }
615 iter++;
616 }
617
618 SortNotificationList();
619 }
620
SortNotificationList()621 void AdvancedNotificationService::SortNotificationList()
622 {
623 notificationList_.sort(AdvancedNotificationService::NotificationCompare);
624 }
625
NotificationCompare(const std::shared_ptr<NotificationRecord> & first,const std::shared_ptr<NotificationRecord> & second)626 bool AdvancedNotificationService::NotificationCompare(
627 const std::shared_ptr<NotificationRecord> &first, const std::shared_ptr<NotificationRecord> &second)
628 {
629 // sorting notifications by create time
630 return (first->request->GetCreateTime() < second->request->GetCreateTime());
631 }
632
StartFilters()633 void AdvancedNotificationService::StartFilters()
634 {
635 if (permissonFilter_ != nullptr) {
636 permissonFilter_->OnStart();
637 }
638
639 if (notificationSlotFilter_ != nullptr) {
640 notificationSlotFilter_->OnStart();
641 }
642 }
643
StopFilters()644 void AdvancedNotificationService::StopFilters()
645 {
646 if (permissonFilter_ != nullptr) {
647 permissonFilter_->OnStop();
648 }
649
650 if (notificationSlotFilter_ != nullptr) {
651 notificationSlotFilter_->OnStop();
652 }
653 }
654
GetActiveNotifications(std::vector<sptr<NotificationRequest>> & notifications)655 ErrCode AdvancedNotificationService::GetActiveNotifications(std::vector<sptr<NotificationRequest>> ¬ifications)
656 {
657 ANS_LOGD("%{public}s", __FUNCTION__);
658
659 sptr<NotificationBundleOption> bundleOption = GenerateBundleOption();
660 if (bundleOption == nullptr) {
661 return ERR_ANS_INVALID_BUNDLE;
662 }
663
664 if (notificationSvrQueue_ == nullptr) {
665 ANS_LOGE("Serial queue is invalidated.");
666 return ERR_ANS_INVALID_PARAM;
667 }
668 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
669 ANS_LOGD("ffrt enter!");
670 notifications.clear();
671 for (auto record : notificationList_) {
672 if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) &&
673 (record->bundleOption->GetUid() == bundleOption->GetUid())) {
674 notifications.push_back(record->request);
675 }
676 }
677 }));
678 notificationSvrQueue_->wait(handler);
679 return ERR_OK;
680 }
681
GetActiveNotificationNums(uint64_t & num)682 ErrCode AdvancedNotificationService::GetActiveNotificationNums(uint64_t &num)
683 {
684 ANS_LOGD("%{public}s", __FUNCTION__);
685
686 sptr<NotificationBundleOption> bundleOption = GenerateBundleOption();
687 if (bundleOption == nullptr) {
688 ANS_LOGD("BundleOption is nullptr.");
689 return ERR_ANS_INVALID_BUNDLE;
690 }
691
692 if (notificationSvrQueue_ == nullptr) {
693 ANS_LOGE("Serial queue is invalid.");
694 return ERR_ANS_INVALID_PARAM;
695 }
696 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
697 ANS_LOGD("ffrt enter!");
698 size_t count = 0;
699 for (auto record : notificationList_) {
700 if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) &&
701 (record->bundleOption->GetUid() == bundleOption->GetUid())) {
702 count += 1;
703 }
704 }
705 num = static_cast<uint64_t>(count);
706 }));
707 notificationSvrQueue_->wait(handler);
708 return ERR_OK;
709 }
710
SetNotificationAgent(const std::string & agent)711 ErrCode AdvancedNotificationService::SetNotificationAgent(const std::string &agent)
712 {
713 return ERR_INVALID_OPERATION;
714 }
715
GetNotificationAgent(std::string & agent)716 ErrCode AdvancedNotificationService::GetNotificationAgent(std::string &agent)
717 {
718 return ERR_INVALID_OPERATION;
719 }
720
CanPublishAsBundle(const std::string & representativeBundle,bool & canPublish)721 ErrCode AdvancedNotificationService::CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish)
722 {
723 return ERR_INVALID_OPERATION;
724 }
725
GetBundleImportance(int32_t & importance)726 ErrCode AdvancedNotificationService::GetBundleImportance(int32_t &importance)
727 {
728 ANS_LOGD("%{public}s", __FUNCTION__);
729
730 sptr<NotificationBundleOption> bundleOption = GenerateBundleOption();
731 if (bundleOption == nullptr) {
732 ANS_LOGD("GenerateBundleOption failed.");
733 return ERR_ANS_INVALID_BUNDLE;
734 }
735
736 if (notificationSvrQueue_ == nullptr) {
737 ANS_LOGE("Serial queue is invalid.");
738 return ERR_ANS_INVALID_PARAM;
739 }
740 ErrCode result = ERR_OK;
741 ffrt::task_handle handler = notificationSvrQueue_->submit_h(
742 std::bind([&]() {
743 ANS_LOGD("ffrt enter!");
744 result = NotificationPreferences::GetInstance().GetImportance(bundleOption, importance);
745 }));
746 notificationSvrQueue_->wait(handler);
747 return result;
748 }
749
HasNotificationPolicyAccessPermission(bool & granted)750 ErrCode AdvancedNotificationService::HasNotificationPolicyAccessPermission(bool &granted)
751 {
752 return ERR_OK;
753 }
754
GetNotificationKeys(const sptr<NotificationBundleOption> & bundleOption)755 std::vector<std::string> AdvancedNotificationService::GetNotificationKeys(
756 const sptr<NotificationBundleOption> &bundleOption)
757 {
758 std::vector<std::string> keys;
759
760 for (auto record : notificationList_) {
761 if ((bundleOption != nullptr) && (record->bundleOption->GetBundleName() != bundleOption->GetBundleName()) &&
762 (record->bundleOption->GetUid() != bundleOption->GetUid())) {
763 continue;
764 }
765 keys.push_back(record->notification->GetKey());
766 }
767
768 return keys;
769 }
770
RemoveFromNotificationList(const sptr<NotificationBundleOption> & bundleOption,const std::string & label,int32_t notificationId,sptr<Notification> & notification,bool isCancel)771 ErrCode AdvancedNotificationService::RemoveFromNotificationList(const sptr<NotificationBundleOption> &bundleOption,
772 const std::string &label, int32_t notificationId, sptr<Notification> ¬ification, bool isCancel)
773 {
774 for (auto record : notificationList_) {
775 if ((record->bundleOption->GetBundleName() == bundleOption->GetBundleName()) &&
776 (record->bundleOption->GetUid() == bundleOption->GetUid()) &&
777 (record->notification->GetLabel() == label) &&
778 (record->notification->GetId() == notificationId)
779 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
780 && record->deviceId.empty()
781 #endif
782 ) {
783 if (!isCancel && !record->notification->IsRemoveAllowed()) {
784 return ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED;
785 }
786 notification = record->notification;
787 // delete or delete all, call the function
788 if (!isCancel) {
789 TriggerRemoveWantAgent(record->request);
790 }
791
792 ProcForDeleteLiveView(record);
793 notificationList_.remove(record);
794 return ERR_OK;
795 }
796 }
797
798 return ERR_ANS_NOTIFICATION_NOT_EXISTS;
799 }
800
RemoveFromNotificationList(const std::string & key,sptr<Notification> & notification,bool isCancel,int32_t removeReason)801 ErrCode AdvancedNotificationService::RemoveFromNotificationList(
802 const std::string &key, sptr<Notification> ¬ification, bool isCancel, int32_t removeReason)
803 {
804 for (auto record : notificationList_) {
805 if (record->notification->GetKey() != key) {
806 continue;
807 }
808
809 if (!isCancel && !record->notification->IsRemoveAllowed()) {
810 return ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED;
811 }
812 notification = record->notification;
813 // delete or delete all, call the function
814 if (removeReason != NotificationConstant::CLICK_REASON_DELETE) {
815 ProcForDeleteLiveView(record);
816 if (!isCancel) {
817 TriggerRemoveWantAgent(record->request);
818 }
819 }
820
821 notificationList_.remove(record);
822 return ERR_OK;
823 }
824
825 return ERR_ANS_NOTIFICATION_NOT_EXISTS;
826 }
827
RemoveFromNotificationListForDeleteAll(const std::string & key,const int32_t & userId,sptr<Notification> & notification)828 ErrCode AdvancedNotificationService::RemoveFromNotificationListForDeleteAll(
829 const std::string &key, const int32_t &userId, sptr<Notification> ¬ification)
830 {
831 for (auto record : notificationList_) {
832 if ((record->notification->GetKey() == key) && (record->notification->GetUserId() == userId)) {
833 if (!record->notification->IsRemoveAllowed()) {
834 return ERR_ANS_NOTIFICATION_IS_UNALLOWED_REMOVEALLOWED;
835 }
836 if (record->request->IsUnremovable()) {
837 return ERR_ANS_NOTIFICATION_IS_UNREMOVABLE;
838 }
839
840 ProcForDeleteLiveView(record);
841
842 notification = record->notification;
843 notificationList_.remove(record);
844 return ERR_OK;
845 }
846 }
847
848 return ERR_ANS_NOTIFICATION_NOT_EXISTS;
849 }
850
GetFromNotificationList(const std::string & key)851 std::shared_ptr<NotificationRecord> AdvancedNotificationService::GetFromNotificationList(const std::string &key)
852 {
853 for (auto item : notificationList_) {
854 if (item->notification->GetKey() == key) {
855 return item;
856 }
857 }
858 return nullptr;
859 }
860
GetAllActiveNotifications(std::vector<sptr<Notification>> & notifications)861 ErrCode AdvancedNotificationService::GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ifications)
862 {
863 ANS_LOGD("%{public}s", __FUNCTION__);
864
865 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
866 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
867 return ERR_ANS_NON_SYSTEM_APP;
868 }
869
870 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
871 ANS_LOGD("CheckPermission failed.");
872 return ERR_ANS_PERMISSION_DENIED;
873 }
874
875 if (notificationSvrQueue_ == nullptr) {
876 ANS_LOGE("Serial queue is invalidity.");
877 return ERR_ANS_INVALID_PARAM;
878 }
879 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
880 ANS_LOGD("ffrt enter!");
881 notifications.clear();
882 for (auto record : notificationList_) {
883 if (record->notification != nullptr && record->notification->request_ != nullptr) {
884 notifications.push_back(record->notification);
885 }
886 }
887 }));
888 notificationSvrQueue_->wait(handler);
889 return ERR_OK;
890 }
891
IsContained(const std::vector<std::string> & vec,const std::string & target)892 inline bool IsContained(const std::vector<std::string> &vec, const std::string &target)
893 {
894 bool isContained = false;
895
896 auto iter = vec.begin();
897 while (iter != vec.end()) {
898 if (*iter == target) {
899 isContained = true;
900 break;
901 }
902 iter++;
903 }
904
905 return isContained;
906 }
907
GetSpecialActiveNotifications(const std::vector<std::string> & key,std::vector<sptr<Notification>> & notifications)908 ErrCode AdvancedNotificationService::GetSpecialActiveNotifications(
909 const std::vector<std::string> &key, std::vector<sptr<Notification>> ¬ifications)
910 {
911 ANS_LOGD("%{public}s", __FUNCTION__);
912
913 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
914 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
915 return ERR_ANS_NON_SYSTEM_APP;
916 }
917
918 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
919 ANS_LOGD("Check permission is false.");
920 return ERR_ANS_PERMISSION_DENIED;
921 }
922
923 if (notificationSvrQueue_ == nullptr) {
924 ANS_LOGE("Serial queue is invalid.");
925 return ERR_ANS_INVALID_PARAM;
926 }
927 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
928 ANS_LOGD("ffrt enter!");
929 for (auto record : notificationList_) {
930 if (IsContained(key, record->notification->GetKey())) {
931 notifications.push_back(record->notification);
932 }
933 }
934 }));
935 notificationSvrQueue_->wait(handler);
936 return ERR_OK;
937 }
938
GetRecordFromNotificationList(int32_t notificationId,int32_t uid,const std::string & label,const std::string & bundleName)939 std::shared_ptr<NotificationRecord> AdvancedNotificationService::GetRecordFromNotificationList(
940 int32_t notificationId, int32_t uid, const std::string &label, const std::string &bundleName)
941 {
942 for (auto &record : notificationList_) {
943 if ((record->notification->GetLabel() == label) &&
944 (record->notification->GetId() == notificationId) &&
945 (record->bundleOption->GetUid() == uid) &&
946 (record->bundleOption->GetBundleName() == bundleName)) {
947 return record;
948 }
949 }
950 return nullptr;
951 }
952
SetRecentNotificationCount(const std::string arg)953 ErrCode AdvancedNotificationService::SetRecentNotificationCount(const std::string arg)
954 {
955 ANS_LOGD("%{public}s arg = %{public}s", __FUNCTION__, arg.c_str());
956 int32_t count = atoi(arg.c_str());
957 if ((count < NOTIFICATION_MIN_COUNT) || (count > NOTIFICATION_MAX_COUNT)) {
958 return ERR_ANS_INVALID_PARAM;
959 }
960
961 recentInfo_->recentCount = count;
962 while (recentInfo_->list.size() > recentInfo_->recentCount) {
963 recentInfo_->list.pop_back();
964 }
965 return ERR_OK;
966 }
967
UpdateRecentNotification(sptr<Notification> & notification,bool isDelete,int32_t reason)968 void AdvancedNotificationService::UpdateRecentNotification(sptr<Notification> ¬ification,
969 bool isDelete, int32_t reason)
970 {
971 for (auto recentNotification : recentInfo_->list) {
972 if (recentNotification->notification->GetKey() == notification->GetKey()) {
973 if (!isDelete) {
974 recentInfo_->list.remove(recentNotification);
975 recentNotification->isActive = true;
976 recentNotification->notification = notification;
977 recentInfo_->list.emplace_front(recentNotification);
978 } else {
979 recentNotification->isActive = false;
980 recentNotification->deleteReason = reason;
981 recentNotification->deleteTime = GetNowSysTime();
982 }
983 return;
984 }
985 }
986
987 if (!isDelete) {
988 if (recentInfo_->list.size() >= recentInfo_->recentCount) {
989 recentInfo_->list.pop_back();
990 }
991 auto recentNotification = std::make_shared<RecentNotification>();
992 recentNotification->isActive = true;
993 recentNotification->notification = notification;
994 recentInfo_->list.emplace_front(recentNotification);
995 }
996 }
SortNotificationsByLevelAndTime(const std::shared_ptr<NotificationRecord> & first,const std::shared_ptr<NotificationRecord> & second)997 static bool SortNotificationsByLevelAndTime(
998 const std::shared_ptr<NotificationRecord> &first, const std::shared_ptr<NotificationRecord> &second)
999 {
1000 if (first->slot->GetLevel() != second->slot->GetLevel()) {
1001 return (first->slot->GetLevel() < second->slot->GetLevel());
1002 }
1003 return (first->request->GetCreateTime() < second->request->GetCreateTime());
1004 }
1005
FlowControl(const std::shared_ptr<NotificationRecord> & record)1006 ErrCode AdvancedNotificationService::FlowControl(const std::shared_ptr<NotificationRecord> &record)
1007 {
1008 std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
1009 RemoveExpired(flowControlTimestampList_, now);
1010 if (flowControlTimestampList_.size() >= MAX_ACTIVE_NUM_PERSECOND) {
1011 return ERR_ANS_OVER_MAX_ACTIVE_PERSECOND;
1012 }
1013
1014 flowControlTimestampList_.push_back(now);
1015
1016 std::list<std::shared_ptr<NotificationRecord>> bundleList;
1017 for (auto item : notificationList_) {
1018 if (record->notification->GetBundleName() == item->notification->GetBundleName()) {
1019 bundleList.push_back(item);
1020 }
1021 }
1022
1023 std::shared_ptr<NotificationRecord> recordToRemove;
1024 if (bundleList.size() >= MAX_ACTIVE_NUM_PERAPP) {
1025 bundleList.sort(SortNotificationsByLevelAndTime);
1026 recordToRemove = bundleList.front();
1027 SendFlowControlOccurHiSysEvent(recordToRemove);
1028 notificationList_.remove(bundleList.front());
1029 }
1030
1031 if (notificationList_.size() >= MAX_ACTIVE_NUM) {
1032 if (bundleList.size() > 0) {
1033 bundleList.sort(SortNotificationsByLevelAndTime);
1034 recordToRemove = bundleList.front();
1035 SendFlowControlOccurHiSysEvent(recordToRemove);
1036 notificationList_.remove(bundleList.front());
1037 } else {
1038 std::list<std::shared_ptr<NotificationRecord>> sorted = notificationList_;
1039 sorted.sort(SortNotificationsByLevelAndTime);
1040 recordToRemove = sorted.front();
1041 SendFlowControlOccurHiSysEvent(recordToRemove);
1042 notificationList_.remove(sorted.front());
1043 }
1044 }
1045
1046 AddToNotificationList(record);
1047
1048 return ERR_OK;
1049 }
1050
IsDistributedEnabled(bool & enabled)1051 ErrCode AdvancedNotificationService::IsDistributedEnabled(bool &enabled)
1052 {
1053 ANS_LOGD("%{public}s", __FUNCTION__);
1054 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1055 if (notificationSvrQueue_ == nullptr) {
1056 ANS_LOGE("Serial queue is invalid.");
1057 return ERR_ANS_INVALID_PARAM;
1058 }
1059 ErrCode result = ERR_OK;
1060 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
1061 ANS_LOGD("ffrt enter!");
1062 result = DistributedPreferences::GetInstance()->GetDistributedEnable(enabled);
1063 if (result != ERR_OK) {
1064 result = ERR_OK;
1065 enabled = false;
1066 }
1067 }));
1068 notificationSvrQueue_->wait(handler);
1069 return result;
1070 #else
1071 return ERR_INVALID_OPERATION;
1072 #endif
1073 }
1074
EnableDistributed(bool enabled)1075 ErrCode AdvancedNotificationService::EnableDistributed(bool enabled)
1076 {
1077 ANS_LOGD("%{public}s", __FUNCTION__);
1078
1079 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1080 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
1081 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
1082 ANS_LOGD("VerifyNativeToken and IsSystemApp is false.");
1083 return ERR_ANS_NON_SYSTEM_APP;
1084 }
1085
1086 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
1087 return ERR_ANS_PERMISSION_DENIED;
1088 }
1089
1090 if (notificationSvrQueue_ == nullptr) {
1091 ANS_LOGE("Serial queue is invalidity.");
1092 return ERR_ANS_INVALID_PARAM;
1093 }
1094 ErrCode result = ERR_OK;
1095 ffrt::task_handle handler = notificationSvrQueue_->submit_h(
1096 std::bind([&]() {
1097 result = DistributedPreferences::GetInstance()->SetDistributedEnable(enabled);
1098 ANS_LOGE("ffrt enter!");
1099 }));
1100 notificationSvrQueue_->wait(handler);
1101 return result;
1102 #else
1103 return ERR_INVALID_OPERATION;
1104 #endif
1105 }
1106
EnableDistributedByBundle(const sptr<NotificationBundleOption> & bundleOption,bool enabled)1107 ErrCode AdvancedNotificationService::EnableDistributedByBundle(
1108 const sptr<NotificationBundleOption> &bundleOption, bool enabled)
1109 {
1110 ANS_LOGD("%{public}s", __FUNCTION__);
1111
1112 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1113 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
1114 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
1115 return ERR_ANS_NON_SYSTEM_APP;
1116 }
1117
1118 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
1119 ANS_LOGD("CheckPermission is false.");
1120 return ERR_ANS_PERMISSION_DENIED;
1121 }
1122
1123 sptr<NotificationBundleOption> bundle = GenerateValidBundleOption(bundleOption);
1124 if (bundle == nullptr) {
1125 ANS_LOGD("Create bundle failed.");
1126 return ERR_ANS_INVALID_BUNDLE;
1127 }
1128
1129 bool appInfoEnable = true;
1130 GetDistributedEnableInApplicationInfo(bundle, appInfoEnable);
1131 if (!appInfoEnable) {
1132 ANS_LOGD("Get from bms is %{public}d", appInfoEnable);
1133 return ERR_ANS_PERMISSION_DENIED;
1134 }
1135
1136 if (notificationSvrQueue_ == nullptr) {
1137 ANS_LOGE("Serial queue is invalid.");
1138 return ERR_ANS_INVALID_PARAM;
1139 }
1140 ErrCode result = ERR_OK;
1141 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
1142 ANS_LOGD("ffrt enter!");
1143 result = DistributedPreferences::GetInstance()->SetDistributedBundleEnable(bundle, enabled);
1144 if (result != ERR_OK) {
1145 result = ERR_OK;
1146 enabled = false;
1147 }
1148 }));
1149 notificationSvrQueue_->wait(handler);
1150 return result;
1151 #else
1152 return ERR_INVALID_OPERATION;
1153 #endif
1154 }
1155
EnableDistributedSelf(const bool enabled)1156 ErrCode AdvancedNotificationService::EnableDistributedSelf(const bool enabled)
1157 {
1158 ANS_LOGD("%{public}s", __FUNCTION__);
1159 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1160 sptr<NotificationBundleOption> bundleOption = GenerateBundleOption();
1161 if (bundleOption == nullptr) {
1162 return ERR_ANS_INVALID_BUNDLE;
1163 }
1164
1165 bool appInfoEnable = true;
1166 GetDistributedEnableInApplicationInfo(bundleOption, appInfoEnable);
1167 if (!appInfoEnable) {
1168 ANS_LOGD("Get from bms is %{public}d", appInfoEnable);
1169 return ERR_ANS_PERMISSION_DENIED;
1170 }
1171
1172 if (notificationSvrQueue_ == nullptr) {
1173 ANS_LOGE("notificationSvrQueue_ is nullptr.");
1174 return ERR_ANS_INVALID_PARAM;
1175 }
1176 ErrCode result = ERR_OK;
1177 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind(
1178 [&]() {
1179 ANS_LOGD("ffrt enter!");
1180 result = DistributedPreferences::GetInstance()->SetDistributedBundleEnable(bundleOption, enabled);
1181 }));
1182 notificationSvrQueue_->wait(handler);
1183 return result;
1184 #else
1185 return ERR_INVALID_OPERATION;
1186 #endif
1187 }
1188
IsDistributedEnableByBundle(const sptr<NotificationBundleOption> & bundleOption,bool & enabled)1189 ErrCode AdvancedNotificationService::IsDistributedEnableByBundle(
1190 const sptr<NotificationBundleOption> &bundleOption, bool &enabled)
1191 {
1192 ANS_LOGD("%{public}s", __FUNCTION__);
1193
1194 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1195 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
1196 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
1197 return ERR_ANS_NON_SYSTEM_APP;
1198 }
1199
1200 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
1201 return ERR_ANS_PERMISSION_DENIED;
1202 }
1203
1204 sptr<NotificationBundleOption> bundle = GenerateValidBundleOption(bundleOption);
1205 if (bundle == nullptr) {
1206 ANS_LOGD("Failed to create bundle.");
1207 return ERR_ANS_INVALID_BUNDLE;
1208 }
1209
1210 bool appInfoEnable = true;
1211 GetDistributedEnableInApplicationInfo(bundle, appInfoEnable);
1212 if (!appInfoEnable) {
1213 ANS_LOGD("Get from bms is %{public}d", appInfoEnable);
1214 enabled = appInfoEnable;
1215 return ERR_OK;
1216 }
1217
1218 if (notificationSvrQueue_ == nullptr) {
1219 ANS_LOGE("Serial queue is invalid.");
1220 return ERR_ANS_INVALID_PARAM;
1221 }
1222 ErrCode result = ERR_OK;
1223 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
1224 ANS_LOGD("ffrt enter!");
1225 result = DistributedPreferences::GetInstance()->GetDistributedBundleEnable(bundle, enabled);
1226 if (result != ERR_OK) {
1227 result = ERR_OK;
1228 enabled = false;
1229 }
1230 }));
1231 notificationSvrQueue_->wait(handler);
1232 return result;
1233 #else
1234 return ERR_INVALID_OPERATION;
1235 #endif
1236 }
1237
SetDoNotDisturbDate(const int32_t & userId,const sptr<NotificationDoNotDisturbDate> & date)1238 ErrCode AdvancedNotificationService::SetDoNotDisturbDate(const int32_t &userId,
1239 const sptr<NotificationDoNotDisturbDate> &date)
1240 {
1241 ANS_LOGD("%{public}s", __FUNCTION__);
1242
1243 if (userId <= SUBSCRIBE_USER_INIT) {
1244 ANS_LOGE("Input userId is invalidity.");
1245 return ERR_ANS_INVALID_PARAM;
1246 }
1247
1248 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
1249 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
1250 return ERR_ANS_NON_SYSTEM_APP;
1251 }
1252
1253 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
1254 return ERR_ANS_PERMISSION_DENIED;
1255 }
1256
1257 return SetDoNotDisturbDateByUser(userId, date);
1258 }
1259
GetDoNotDisturbDate(const int32_t & userId,sptr<NotificationDoNotDisturbDate> & date)1260 ErrCode AdvancedNotificationService::GetDoNotDisturbDate(const int32_t &userId,
1261 sptr<NotificationDoNotDisturbDate> &date)
1262 {
1263 ANS_LOGD("%{public}s", __FUNCTION__);
1264
1265 if (userId <= SUBSCRIBE_USER_INIT) {
1266 ANS_LOGE("Input userId is invalid.");
1267 return ERR_ANS_INVALID_PARAM;
1268 }
1269
1270 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
1271 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
1272 return ERR_ANS_NON_SYSTEM_APP;
1273 }
1274
1275 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
1276 return ERR_ANS_PERMISSION_DENIED;
1277 }
1278
1279 return GetDoNotDisturbDateByUser(userId, date);
1280 }
1281
GetHasPoppedDialog(const sptr<NotificationBundleOption> bundleOption,bool & hasPopped)1282 ErrCode AdvancedNotificationService::GetHasPoppedDialog(
1283 const sptr<NotificationBundleOption> bundleOption, bool &hasPopped)
1284 {
1285 ANS_LOGD("%{public}s", __FUNCTION__);
1286 if (notificationSvrQueue_ == nullptr) {
1287 ANS_LOGE("Serial queue is invalid.");
1288 return ERR_ANS_INVALID_PARAM;
1289 }
1290 ErrCode result = ERR_OK;
1291 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
1292 result = NotificationPreferences::GetInstance().GetHasPoppedDialog(bundleOption, hasPopped);
1293 }));
1294 notificationSvrQueue_->wait(handler);
1295 return result;
1296 }
1297
SetSyncNotificationEnabledWithoutApp(const int32_t userId,const bool enabled)1298 ErrCode AdvancedNotificationService::SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled)
1299 {
1300 ANS_LOGD("userId: %{public}d, enabled: %{public}d", userId, enabled);
1301
1302 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1303 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
1304 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
1305 return ERR_ANS_NON_SYSTEM_APP;
1306 }
1307
1308 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
1309 ANS_LOGD("CheckPermission is false.");
1310 return ERR_ANS_PERMISSION_DENIED;
1311 }
1312
1313 if (notificationSvrQueue_ == nullptr) {
1314 ANS_LOGE("Serial queue is invalidity.");
1315 return ERR_ANS_INVALID_PARAM;
1316 }
1317 ErrCode result = ERR_OK;
1318 ffrt::task_handle handler = notificationSvrQueue_->submit_h(
1319 std::bind([&]() {
1320 ANS_LOGD("ffrt enter!");
1321 result = DistributedPreferences::GetInstance()->SetSyncEnabledWithoutApp(userId, enabled);
1322 }));
1323 notificationSvrQueue_->wait(handler);
1324 return result;
1325 #else
1326 return ERR_INVALID_OPERATION;
1327 #endif
1328 }
1329
GetSyncNotificationEnabledWithoutApp(const int32_t userId,bool & enabled)1330 ErrCode AdvancedNotificationService::GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled)
1331 {
1332 ANS_LOGD("userId: %{public}d", userId);
1333
1334 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1335 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID());
1336 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) {
1337 return ERR_ANS_NON_SYSTEM_APP;
1338 }
1339
1340 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
1341 return ERR_ANS_PERMISSION_DENIED;
1342 }
1343
1344 if (notificationSvrQueue_ == nullptr) {
1345 ANS_LOGE("Serial queue is invalid.");
1346 return ERR_ANS_INVALID_PARAM;
1347 }
1348 ErrCode result = ERR_OK;
1349 ffrt::task_handle handler = notificationSvrQueue_->submit_h(
1350 std::bind([&]() {
1351 ANS_LOGD("ffrt enter!");
1352 result = DistributedPreferences::GetInstance()->GetSyncEnabledWithoutApp(userId, enabled);
1353 }));
1354 notificationSvrQueue_->wait(handler);
1355 return result;
1356 #else
1357 return ERR_INVALID_OPERATION;
1358 #endif
1359 }
1360
ResetPushCallbackProxy()1361 void AdvancedNotificationService::ResetPushCallbackProxy()
1362 {
1363 ANS_LOGD("enter");
1364 std::lock_guard<std::mutex> lock(pushMutex_);
1365 if (pushCallBacks_.empty()) {
1366 ANS_LOGE("invalid proxy state");
1367 return;
1368 }
1369 for (auto it = pushCallBacks_.begin(); it != pushCallBacks_.end(); it++) {
1370 if (it->second->AsObject() == nullptr) {
1371 ANS_LOGE("invalid proxy state");
1372 } else {
1373 it->second->AsObject()->RemoveDeathRecipient(pushRecipient_);
1374 }
1375 }
1376 pushCallBacks_.clear();
1377 }
1378
RegisterPushCallback(const sptr<IRemoteObject> & pushCallback,const sptr<NotificationCheckRequest> & notificationCheckRequest)1379 ErrCode AdvancedNotificationService::RegisterPushCallback(
1380 const sptr<IRemoteObject> &pushCallback, const sptr<NotificationCheckRequest> ¬ificationCheckRequest)
1381 {
1382 if (!AccessTokenHelper::IsSystemApp()) {
1383 ANS_LOGW("Not system app!");
1384 return ERR_ANS_NON_SYSTEM_APP;
1385 }
1386
1387 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER)) {
1388 ANS_LOGW("Not have OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER approval!");
1389 return ERR_ANS_PERMISSION_DENIED;
1390 }
1391
1392 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
1393 ANS_LOGW("Not have OHOS_PERMISSION_NOTIFICATION_CONTROLLER Permission!");
1394 return ERR_ANS_PERMISSION_DENIED;
1395 }
1396
1397 if (pushCallback == nullptr) {
1398 ANS_LOGW("pushCallback is null.");
1399 return ERR_INVALID_VALUE;
1400 }
1401
1402 if (notificationCheckRequest == nullptr) {
1403 ANS_LOGW("notificationCheckRequest is null.");
1404 return ERR_INVALID_VALUE;
1405 }
1406
1407 pushRecipient_ = new (std::nothrow) PushCallbackRecipient();
1408 if (!pushRecipient_) {
1409 ANS_LOGE("Failed to create death Recipient ptr PushCallbackRecipient!");
1410 return ERR_NO_INIT;
1411 }
1412 pushCallback->AddDeathRecipient(pushRecipient_);
1413
1414 sptr<IPushCallBack> pushCallBack = iface_cast<IPushCallBack>(pushCallback);
1415 NotificationConstant::SlotType slotType = notificationCheckRequest->GetSlotType();
1416 int32_t uid = IPCSkeleton::GetCallingUid();
1417
1418 if (pushCallBacks_.find(slotType) != pushCallBacks_.end()) {
1419 if (checkRequests_[slotType]->GetUid() != uid) {
1420 return ERROR_INTERNAL_ERROR;
1421 }
1422 }
1423
1424 pushCallBacks_.insert_or_assign(slotType, pushCallBack);
1425 ANS_LOGD("insert pushCallBack, slot type %{public}d", slotType);
1426 notificationCheckRequest->SetUid(uid);
1427 checkRequests_.insert_or_assign(slotType, notificationCheckRequest);
1428 ANS_LOGD("insert notificationCheckRequest, slot type %{public}d, content type %{public}d",
1429 slotType, notificationCheckRequest->GetContentType());
1430
1431 ANS_LOGD("end");
1432 return ERR_OK;
1433 }
1434
UnregisterPushCallback()1435 ErrCode AdvancedNotificationService::UnregisterPushCallback()
1436 {
1437 if (!AccessTokenHelper::IsSystemApp()) {
1438 ANS_LOGW("Not system app!");
1439 return ERR_ANS_NON_SYSTEM_APP;
1440 }
1441
1442 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER)) {
1443 ANS_LOGW("Not have OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER Permission!");
1444 return ERR_ANS_PERMISSION_DENIED;
1445 }
1446
1447 if (!CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) {
1448 ANS_LOGW("Not have OHOS_PERMISSION_NOTIFICATION_CONTROLLER Permission!");
1449 return ERR_ANS_PERMISSION_DENIED;
1450 }
1451
1452 if (pushCallBacks_.empty()) {
1453 ANS_LOGE("The registration callback has not been processed yet.");
1454 return ERR_INVALID_OPERATION;
1455 }
1456
1457 pushCallBacks_.clear();
1458
1459 ANS_LOGD("end");
1460 return ERR_OK;
1461 }
1462
IsNeedPushCheck(const sptr<NotificationRequest> & request)1463 bool AdvancedNotificationService::IsNeedPushCheck(const sptr<NotificationRequest> &request)
1464 {
1465 NotificationConstant::SlotType slotType = request->GetSlotType();
1466 NotificationContent::Type contentType = request->GetNotificationType();
1467 ANS_LOGD("NotificationRequest slotType:%{public}d, contentType:%{public}d", slotType, contentType);
1468 if (AccessTokenHelper::IsSystemApp()) {
1469 ANS_LOGI("System applications do not require push check.");
1470 return false;
1471 }
1472
1473 if (request->IsCommonLiveView()) {
1474 std::shared_ptr<NotificationContent> content = request->GetContent();
1475 auto liveViewContent = std::static_pointer_cast<NotificationLiveViewContent>(content->GetNotificationContent());
1476 auto status = liveViewContent->GetLiveViewStatus();
1477 if (status != NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_CREATE) {
1478 ANS_LOGI("Status of common live view is not create, no need to check.");
1479 return false;
1480 }
1481 ANS_LOGI("Common live view requires push check.");
1482 return true;
1483 }
1484
1485 if (pushCallBacks_.find(slotType) == pushCallBacks_.end()) {
1486 ANS_LOGI("pushCallback Unregistered, no need to check.");
1487 return false;
1488 }
1489
1490 if (contentType == checkRequests_[slotType]->GetContentType()) {
1491 ANS_LOGI("Need push check.");
1492 return true;
1493 }
1494 return false;
1495 }
1496
FillExtraInfoToJson(const sptr<NotificationRequest> & request,sptr<NotificationCheckRequest> & checkRequest,nlohmann::json & jsonObject)1497 void AdvancedNotificationService::FillExtraInfoToJson(
1498 const sptr<NotificationRequest> &request, sptr<NotificationCheckRequest> &checkRequest, nlohmann::json &jsonObject)
1499 {
1500 std::shared_ptr<NotificationContent> content = request->GetContent();
1501 auto liveViewContent = std::static_pointer_cast<NotificationLiveViewContent>(content->GetNotificationContent());
1502 auto extraInfo = liveViewContent->GetExtraInfo();
1503 if (extraInfo == nullptr) {
1504 return;
1505 }
1506
1507 std::shared_ptr<AAFwk::WantParams> checkExtraInfo = std::make_shared<AAFwk::WantParams>();
1508 if (checkExtraInfo == nullptr) {
1509 return;
1510 }
1511
1512 if (checkRequest->GetExtraKeys().size() == 0) {
1513 checkExtraInfo = extraInfo;
1514 } else {
1515 for (auto key : checkRequest->GetExtraKeys()) {
1516 if (extraInfo->HasParam(key)) {
1517 checkExtraInfo->SetParam(key, extraInfo->GetParam(key));
1518 }
1519 }
1520 }
1521
1522 if (checkExtraInfo) {
1523 AAFwk::WantParamWrapper wWrapper(*checkExtraInfo);
1524 jsonObject["extraInfo"] = wWrapper.ToString();
1525 }
1526 }
1527
PushCheck(const sptr<NotificationRequest> & request)1528 ErrCode AdvancedNotificationService::PushCheck(const sptr<NotificationRequest> &request)
1529 {
1530 ANS_LOGD("start.");
1531 if (pushCallBacks_.find(request->GetSlotType()) == pushCallBacks_.end()) {
1532 return ERR_ANS_PUSH_CHECK_UNREGISTERED;
1533 }
1534 sptr<IPushCallBack> pushCallBack = pushCallBacks_[request->GetSlotType()];
1535 sptr<NotificationCheckRequest> checkRequest = checkRequests_[request->GetSlotType()];
1536 if (request->GetCreatorUid() == checkRequest->GetUid()) {
1537 return ERR_OK;
1538 }
1539
1540 nlohmann::json jsonObject;
1541 jsonObject["pkgName"] = request->GetCreatorBundleName();
1542 jsonObject["notifyId"] = request->GetNotificationId();
1543 jsonObject["contentType"] = static_cast<int32_t>(request->GetNotificationType());
1544 jsonObject["creatorUserId"] = request->GetCreatorUserId();
1545 jsonObject["slotType"] = static_cast<int32_t>(request->GetSlotType());
1546 jsonObject["label"] = request->GetLabel();
1547 if (request->IsCommonLiveView()) {
1548 FillExtraInfoToJson(request, checkRequest, jsonObject);
1549 }
1550
1551 ErrCode result = pushCallBack->OnCheckNotification(jsonObject.dump(), nullptr);
1552 return result;
1553 }
1554
TriggerAutoDelete(const std::string & hashCode,int32_t reason)1555 void AdvancedNotificationService::TriggerAutoDelete(const std::string &hashCode, int32_t reason)
1556 {
1557 ANS_LOGD("Enter");
1558
1559 for (const auto &record : notificationList_) {
1560 if (!record->request) {
1561 continue;
1562 }
1563
1564 if (record->notification->GetKey() == hashCode) {
1565 UpdateRecentNotification(record->notification, true, reason);
1566 NotificationSubscriberManager::GetInstance()->NotifyCanceled(record->notification, nullptr, reason);
1567 ProcForDeleteLiveView(record);
1568 notificationList_.remove(record);
1569 break;
1570 }
1571 }
1572 }
1573
CreateDialogManager()1574 bool AdvancedNotificationService::CreateDialogManager()
1575 {
1576 static std::mutex dialogManagerMutex_;
1577 std::lock_guard<std::mutex> lock(dialogManagerMutex_);
1578 if (dialogManager_ == nullptr) {
1579 dialogManager_ = std::make_unique<NotificationDialogManager>(*this);
1580 if (!dialogManager_->Init()) {
1581 dialogManager_ = nullptr;
1582 return false;
1583 }
1584 }
1585 return true;
1586 }
1587
FillActionButtons(const sptr<NotificationRequest> & request)1588 void AdvancedNotificationService::FillActionButtons(const sptr<NotificationRequest> &request)
1589 {
1590 if (request->IsCoverActionButtons()) {
1591 ANS_LOGD("Cover old action buttons.");
1592 return;
1593 }
1594
1595 if (notificationSvrQueue_ == nullptr) {
1596 ANS_LOGE("Serial queue is invalid.");
1597 return;
1598 }
1599
1600 ffrt::task_handle handler = notificationSvrQueue_->submit_h(std::bind([&]() {
1601 ANS_LOGD("ffrt enter!");
1602 auto iter = notificationList_.begin();
1603 while (iter != notificationList_.end()) {
1604 if ((*iter)->request->GetKey() == request->GetKey()) {
1605 break;
1606 }
1607 iter++;
1608 }
1609
1610 if (iter == notificationList_.end()) {
1611 ANS_LOGD("No old action buttons.");
1612 return;
1613 }
1614
1615 for (auto actionButton : (*iter)->request->GetActionButtons()) {
1616 request->AddActionButton(actionButton);
1617 }
1618 }));
1619 notificationSvrQueue_->wait(handler);
1620 }
1621
IsNeedNotifyConsumed(const sptr<NotificationRequest> & request)1622 bool AdvancedNotificationService::IsNeedNotifyConsumed(const sptr<NotificationRequest> &request)
1623 {
1624 if (!request->IsCommonLiveView()) {
1625 return true;
1626 }
1627
1628 auto content = request->GetContent()->GetNotificationContent();
1629 auto liveViewContent = std::static_pointer_cast<NotificationLiveViewContent>(content);
1630 auto status = liveViewContent->GetLiveViewStatus();
1631 if (status != NotificationLiveViewContent::LiveViewStatus::LIVE_VIEW_END) {
1632 return true;
1633 }
1634
1635 auto deleteTime = request->GetAutoDeletedTime();
1636 return deleteTime != NotificationConstant::NO_DELAY_DELETE_TIME;
1637 }
1638
OnRemoteDied(const wptr<IRemoteObject> & remote)1639 void PushCallbackRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
1640 {
1641 ANS_LOGI("Push Callback died, remove the proxy object");
1642 AdvancedNotificationService::GetInstance()->ResetPushCallbackProxy();
1643 }
1644
PushCallbackRecipient()1645 PushCallbackRecipient::PushCallbackRecipient() {}
1646
~PushCallbackRecipient()1647 PushCallbackRecipient::~PushCallbackRecipient() {}
1648 } // namespace Notification
1649 } // namespace OHOS
1650