1 /* 2 * Copyright (C) 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 #include "call_request_event_handler_helper.h" 16 17 #include <thread> 18 19 #include "telephony_errors.h" 20 #include "telephony_log_wrapper.h" 21 namespace OHOS { 22 namespace Telephony { 23 24 const std::string TASK_ID = "handler_restore_dialing_flag"; 25 const int32_t DELAY_TIME = 3000; 26 CallRequestEventHandlerHelper()27CallRequestEventHandlerHelper::CallRequestEventHandlerHelper() 28 { 29 auto runner = AppExecFwk::EventRunner::Create(TASK_ID); 30 if (callRequestEventHandler_ == nullptr) { 31 callRequestEventHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner); 32 } 33 if (callRequestEventHandler_ == nullptr) { 34 TELEPHONY_LOGE("init call request event handler failed"); 35 } 36 } 37 ~CallRequestEventHandlerHelper()38CallRequestEventHandlerHelper::~CallRequestEventHandlerHelper() {} 39 SetDialingCallProcessing()40int32_t CallRequestEventHandlerHelper::SetDialingCallProcessing() 41 { 42 TELEPHONY_LOGI("start restore dialing flag task"); 43 if (IsDialingCallProcessing()) { 44 auto task = [this]() { 45 RestoreDialingFlag(false); 46 }; 47 callRequestEventHandler_->RemoveTask(TASK_ID); 48 bool ret = callRequestEventHandler_->PostTask(task, TASK_ID, DELAY_TIME); 49 if (ret) { 50 TELEPHONY_LOGE("restore dialing flag task failed"); 51 return TELEPHONY_ERROR; 52 } 53 return TELEPHONY_SUCCESS; 54 } 55 return TELEPHONY_ERROR; 56 } 57 RemoveEventHandlerTask()58void CallRequestEventHandlerHelper::RemoveEventHandlerTask() 59 { 60 if (callRequestEventHandler_ != nullptr) { 61 callRequestEventHandler_->RemoveTask(TASK_ID); 62 } 63 } 64 RestoreDialingFlag(bool isDialingCallProcessing)65void CallRequestEventHandlerHelper::RestoreDialingFlag(bool isDialingCallProcessing) 66 { 67 if (isDialingCallProcessing != isDialingCallProcessing_) { 68 isDialingCallProcessing_ = isDialingCallProcessing; 69 } 70 TELEPHONY_LOGI("isDialingCallProcessing = %{public}d.", isDialingCallProcessing_); 71 } 72 IsDialingCallProcessing()73bool CallRequestEventHandlerHelper::IsDialingCallProcessing() 74 { 75 return isDialingCallProcessing_; 76 } 77 78 } // namespace Telephony 79 } // namespace OHOS 80