1 /*
2 * Copyright (C) 2021-2022 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 "incoming_call_wake_up.h"
17
18 #include "power_mgr_client.h"
19 #include "iservice_registry.h"
20 #include "system_ability.h"
21 #include "system_ability_definition.h"
22
23 #include "telephony_log_wrapper.h"
24
25 namespace OHOS {
26 namespace Telephony {
NewCallCreated(sptr<CallBase> & callObjectPtr)27 void IncomingCallWakeup::NewCallCreated(sptr<CallBase> &callObjectPtr)
28 {
29 // Should wake up the device and set the screen on while a new incoming call created.
30 if (callObjectPtr != nullptr && callObjectPtr->GetTelCallState() == TelCallState::CALL_STATUS_INCOMING) {
31 WakeupDevice();
32 }
33 }
34
WakeupDevice()35 void IncomingCallWakeup::WakeupDevice()
36 {
37 if (IsScreenOn()) {
38 TELEPHONY_LOGI("screen already up");
39 return;
40 }
41 PowerMgr::PowerMgrClient::GetInstance().WakeupDevice(
42 PowerMgr::WakeupDeviceType::WAKEUP_DEVICE_APPLICATION, wakeupReason_);
43 }
44
IsScreenOn()45 bool IncomingCallWakeup::IsScreenOn()
46 {
47 return PowerMgr::PowerMgrClient::GetInstance().IsScreenOn();
48 }
49
IsPowerAbilityExist()50 bool IncomingCallWakeup::IsPowerAbilityExist()
51 {
52 std::lock_guard<std::mutex> lock(mutex_);
53 sptr<ISystemAbilityManager> sysAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
54 if (!sysAbilityMgr) {
55 TELEPHONY_LOGE("system ability manager nullptr");
56 return false;
57 }
58 sptr<IRemoteObject> remote = sysAbilityMgr->CheckSystemAbility(POWER_MANAGER_SERVICE_ID);
59 if (!remote) {
60 TELEPHONY_LOGE("no power ability");
61 return false;
62 }
63 return true;
64 }
65
CallDestroyed(const DisconnectedDetails & details)66 void IncomingCallWakeup::CallDestroyed(const DisconnectedDetails &details) {}
67
IncomingCallActivated(sptr<CallBase> & callObjectPtr)68 void IncomingCallWakeup::IncomingCallActivated(sptr<CallBase> &callObjectPtr) {}
69
IncomingCallHungUp(sptr<CallBase> & callObjectPtr,bool isSendSms,std::string content)70 void IncomingCallWakeup::IncomingCallHungUp(sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content) {}
71
CallStateUpdated(sptr<CallBase> & callObjectPtr,TelCallState priorState,TelCallState nextState)72 void IncomingCallWakeup::CallStateUpdated(
73 sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
74 {}
75 } // namespace Telephony
76 } // namespace OHOS