• 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 #include "../advanced_notification_inline.cpp"
27 namespace OHOS {
28 namespace Notification {
HandleGetDoNotDisturbProfile(MessageParcel & data,MessageParcel & reply)29 ErrCode DisturbManager::HandleGetDoNotDisturbProfile(MessageParcel &data, MessageParcel &reply)
30 {
31     int64_t profileId = data.ReadInt64();
32     sptr<NotificationDoNotDisturbProfile> profile = nullptr;
33     ErrCode result = GetDoNotDisturbProfileInner(profileId, profile);
34     if (!reply.WriteInt32(result)) {
35         ANS_LOGE("HandleGetDoNotDisturbProfile write result failed, ErrCode=%{public}d", result);
36         return ERR_ANS_PARCELABLE_FAILED;
37     }
38 
39     if (result == ERR_OK) {
40         if (!reply.WriteParcelable(profile)) {
41             ANS_LOGE("HandleGetDoNotDisturbProfile write slot failed.");
42             return ERR_ANS_PARCELABLE_FAILED;
43         }
44     }
45     return ERR_OK;
46 }
47 
GetDoNotDisturbProfileInner(int64_t id,sptr<NotificationDoNotDisturbProfile> & profile)48 ErrCode DisturbManager::GetDoNotDisturbProfileInner(int64_t id, sptr<NotificationDoNotDisturbProfile> &profile)
49 {
50     int32_t userId = SUBSCRIBE_USER_INIT;
51     if (OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId) != ERR_OK) {
52         ANS_LOGW("No active user found.");
53         return ERR_ANS_GET_ACTIVE_USER_FAILED;
54     }
55 
56     profile = new (std::nothrow) NotificationDoNotDisturbProfile();
57     ErrCode result = NotificationPreferences::GetInstance()->GetDoNotDisturbProfile(id, userId, profile);
58     if (result != ERR_OK) {
59         ANS_LOGE("profile failed id: %{public}s, userid: %{public}d", std::to_string(id).c_str(), userId);
60     }
61     return result;
62 }
63 
64 }  // namespace Notification
65 }  // namespace OHOS
66