1 /* 2 * Copyright (c) 2024-2024 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 "common_notification_publish_process.h" 17 18 #include "access_token_helper.h" 19 #include "ans_log_wrapper.h" 20 21 namespace OHOS { 22 namespace Notification { 23 std::shared_ptr<CommonNotificationPublishProcess> CommonNotificationPublishProcess::instance_; 24 ffrt::mutex CommonNotificationPublishProcess::instanceMutex_; 25 GetInstance()26std::shared_ptr<CommonNotificationPublishProcess> CommonNotificationPublishProcess::GetInstance() 27 { 28 std::lock_guard<ffrt::mutex> lock(instanceMutex_); 29 30 if (instance_ == nullptr) { 31 instance_ = std::make_shared<CommonNotificationPublishProcess>(); 32 if (instance_ == nullptr) { 33 ANS_LOGE("null instance"); 34 return nullptr; 35 } 36 } 37 return instance_; 38 } 39 PublishNotificationByApp(const sptr<NotificationRequest> & request)40ErrCode CommonNotificationPublishProcess::PublishNotificationByApp(const sptr<NotificationRequest> &request) 41 { 42 ErrCode result = CommonPublishCheck(request); 43 if (result != ERR_OK) { 44 return result; 45 } 46 47 if (request->IsInProgress() && 48 !AccessTokenHelper::IsSystemApp()) { 49 request->SetInProgress(false); 50 } 51 52 result = CommonPublishProcess(request); 53 if (result != ERR_OK) { 54 return result; 55 } 56 return ERR_OK; 57 } 58 } // namespace Notification 59 } // namespace OHOS 60