Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.telecom; |
| 18 | |
Ihab Awad | a365390 | 2015-01-23 13:44:46 -0800 | [diff] [blame] | 19 | import com.android.internal.annotations.VisibleForTesting; |
Brad Ebinger | a3eccfe | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 20 | import android.telecom.Log; |
Ihab Awad | a365390 | 2015-01-23 13:44:46 -0800 | [diff] [blame] | 21 | |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 22 | /** |
| 23 | * Handles acquisition and release of wake locks relating to call state. |
| 24 | */ |
Ihab Awad | a365390 | 2015-01-23 13:44:46 -0800 | [diff] [blame] | 25 | @VisibleForTesting |
| 26 | public class InCallWakeLockController extends CallsManagerListenerBase { |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 27 | |
Brad Ebinger | 63a89f2 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 28 | private final TelecomWakeLock mTelecomWakeLock; |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 29 | private final CallsManager mCallsManager; |
| 30 | |
Ihab Awad | a365390 | 2015-01-23 13:44:46 -0800 | [diff] [blame] | 31 | @VisibleForTesting |
Brad Ebinger | 63a89f2 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 32 | public InCallWakeLockController(TelecomWakeLock telecomWakeLock, CallsManager callsManager) { |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 33 | mCallsManager = callsManager; |
| 34 | |
Brad Ebinger | 63a89f2 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 35 | mTelecomWakeLock = telecomWakeLock; |
| 36 | mTelecomWakeLock.setReferenceCounted(false); |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public void onCallAdded(Call call) { |
Tyler Gunn | f15dc33 | 2016-06-07 16:01:41 -0700 | [diff] [blame] | 41 | if (call.isExternalCall()) { |
| 42 | return; |
| 43 | } |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 44 | handleWakeLock(); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void onCallRemoved(Call call) { |
Tyler Gunn | f15dc33 | 2016-06-07 16:01:41 -0700 | [diff] [blame] | 49 | if (call.isExternalCall()) { |
| 50 | return; |
| 51 | } |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 52 | handleWakeLock(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void onCallStateChanged(Call call, int oldState, int newState) { |
Tyler Gunn | f15dc33 | 2016-06-07 16:01:41 -0700 | [diff] [blame] | 57 | if (call.isExternalCall()) { |
| 58 | return; |
| 59 | } |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 60 | handleWakeLock(); |
| 61 | } |
| 62 | |
| 63 | private void handleWakeLock() { |
| 64 | // We grab a full lock as long as there exists a ringing call. |
| 65 | Call ringingCall = mCallsManager.getRingingCall(); |
| 66 | if (ringingCall != null) { |
Brad Ebinger | 63a89f2 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 67 | mTelecomWakeLock.acquire(); |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 68 | Log.i(this, "Acquiring full wake lock"); |
Brad Ebinger | 63a89f2 | 2015-12-08 17:57:59 -0800 | [diff] [blame] | 69 | } else { |
| 70 | mTelecomWakeLock.release(0); |
Santos Cordon | 61e6f35 | 2014-12-03 02:53:34 -0800 | [diff] [blame] | 71 | Log.i(this, "Releasing full wake lock"); |
| 72 | } |
| 73 | } |
| 74 | } |