• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 "disturb_manager.h"
17 
18 #include <functional>
19 #include <iomanip>
20 #include <sstream>
21 
22 #include "advanced_notification_service.h"
23 #include "notification_preferences.h"
24 #include "os_account_manager_helper.h"
25 
26 namespace OHOS {
27 namespace Notification {
HandleRemoveDoNotDisturbProfiles(MessageParcel & data,MessageParcel & reply)28 ErrCode DisturbManager::HandleRemoveDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply)
29 {
30     std::vector<sptr<NotificationDoNotDisturbProfile>> profiles;
31     if (!ReadParcelableVector(profiles, data)) {
32         ANS_LOGE("Read profiles failed.");
33         return ERR_ANS_PARCELABLE_FAILED;
34     }
35 
36     if (profiles.size() > MAX_STATUS_VECTOR_NUM) {
37         ANS_LOGE("The profiles is exceeds limit.");
38         return ERR_ANS_INVALID_PARAM;
39     }
40 
41     ErrCode result = RemoveDoNotDisturbProfilesSyncQueue(profiles);
42     if (!reply.WriteInt32(result)) {
43         ANS_LOGE("Write result failed, ErrCode is %{public}d", result);
44         return ERR_ANS_PARCELABLE_FAILED;
45     }
46     return ERR_OK;
47 }
48 
RemoveDoNotDisturbProfilesSyncQueue(const std::vector<sptr<NotificationDoNotDisturbProfile>> & profiles)49 ErrCode DisturbManager::RemoveDoNotDisturbProfilesSyncQueue(
50     const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles)
51 {
52     ANS_LOGD("Called.");
53 
54     int32_t userId = SUBSCRIBE_USER_INIT;
55     if (OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId) != ERR_OK) {
56         ANS_LOGW("No active user found.");
57         return ERR_ANS_GET_ACTIVE_USER_FAILED;
58     }
59     AdvancedNotificationService::GetInstance()->SubmitSyncTask(
60         std::bind([copyUserId = userId, copyProfiles = profiles]() {
61             ANS_LOGD("The ffrt enter.");
62             NotificationPreferences::GetInstance()->RemoveDoNotDisturbProfiles(copyUserId, copyProfiles);
63         }));
64     return ERR_OK;
65 }
66 }  // namespace Notification
67 }  // namespace OHOS
68