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 "access_token_helper.h" 19 #include "ans_inner_errors.h" 20 #include "ans_permission_def.h" 21 #include "ipc_skeleton.h" 22 23 namespace OHOS { 24 namespace Notification { HandleDoesSupportDoNotDisturbMode(MessageParcel & data,MessageParcel & reply)25ErrCode DisturbManager::HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply) 26 { 27 bool support = false; 28 29 ErrCode result = DoesSupportDoNotDisturbModeInner(support); 30 if (!reply.WriteInt32(result)) { 31 ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write result failed, ErrCode=%{public}d", result); 32 return ERR_ANS_PARCELABLE_FAILED; 33 } 34 35 if (!reply.WriteBool(support)) { 36 ANS_LOGE("[HandleDoesSupportDoNotDisturbMode] fail: write doesSupport failed."); 37 return ERR_ANS_PARCELABLE_FAILED; 38 } 39 40 return ERR_OK; 41 } 42 DoesSupportDoNotDisturbModeInner(bool & doesSupport)43ErrCode DisturbManager::DoesSupportDoNotDisturbModeInner(bool &doesSupport) 44 { 45 bool isSubsystem = AccessTokenHelper::VerifyNativeToken(IPCSkeleton::GetCallingTokenID()); 46 if (!isSubsystem && !AccessTokenHelper::IsSystemApp()) { 47 return ERR_ANS_NON_SYSTEM_APP; 48 } 49 50 if (!AccessTokenHelper::CheckPermission(OHOS_PERMISSION_NOTIFICATION_CONTROLLER)) { 51 return ERR_ANS_PERMISSION_DENIED; 52 } 53 doesSupport = SUPPORT_DO_NOT_DISTRUB; 54 return ERR_OK; 55 } 56 } // namespace Notification 57 } // namespace OHOS 58