• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.content.Context;
20 import android.os.PowerManager;
21 
22 import com.android.internal.annotations.VisibleForTesting;
23 
24 /**
25  * This class manages the proximity sensor and allows callers to turn it on and off.
26  */
27 public class ProximitySensorManager extends CallsManagerListenerBase {
28 
29     private final CallsManager mCallsManager;
30     private final TelecomWakeLock mTelecomWakeLock;
31 
ProximitySensorManager(TelecomWakeLock telecomWakeLock, CallsManager callsManager)32     public ProximitySensorManager(TelecomWakeLock telecomWakeLock, CallsManager callsManager) {
33 
34         mTelecomWakeLock = telecomWakeLock;
35         mCallsManager = callsManager;
36         Log.d(this, "onCreate: mProximityWakeLock: ", mTelecomWakeLock);
37     }
38 
39     @Override
onCallRemoved(Call call)40     public void onCallRemoved(Call call) {
41         if (call.isExternalCall()) {
42             return;
43         }
44         if (mCallsManager.getCalls().isEmpty()) {
45             Log.i(this, "All calls removed, resetting proximity sensor to default state");
46             turnOff(true);
47         }
48         super.onCallRemoved(call);
49     }
50 
51     /**
52      * Turn the proximity sensor on.
53      */
54     @VisibleForTesting
turnOn()55     public void turnOn() {
56         if (mCallsManager.getCalls().isEmpty()) {
57             Log.w(this, "Asking to turn on prox sensor without a call? I don't think so.");
58             return;
59         }
60 
61         mTelecomWakeLock.acquire();
62     }
63 
64     /**
65      * Turn the proximity sensor off.
66      * @param screenOnImmediately
67      */
68     @VisibleForTesting
turnOff(boolean screenOnImmediately)69     public void turnOff(boolean screenOnImmediately) {
70         int flags = (screenOnImmediately ? 0 : PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY);
71         mTelecomWakeLock.release(flags);
72     }
73 }
74