diff options
| author | maxwen <max.weninger@gmail.com> | 2018-01-07 16:24:08 +0100 |
|---|---|---|
| committer | Semavi Ulusoy <doc.divxm@gmail.com> | 2022-09-13 10:40:39 +0300 |
| commit | bfc8367ef8f57e45f82a15035921ea9e9005d089 (patch) | |
| tree | e0c5ca899fbf356be1dbc7377c7796aa7ca12865 | |
| parent | 8067dc9cd398212059ad96aed579a29cdfdb071f (diff) | |
Dialer: Add option to disable proximity sensor
* Provide a switch for end user to disable proximity sensor
while calling/incall.
Change-Id: I086b1db64af820cbc3c111c5caed46391e40664c
| -rw-r--r-- | java/com/android/dialer/app/res/values/aicp_strings.xml | 4 | ||||
| -rw-r--r-- | java/com/android/dialer/app/res/xml/other_settings.xml | 6 | ||||
| -rw-r--r-- | java/com/android/incallui/ProximitySensor.java | 36 |
3 files changed, 35 insertions, 11 deletions
diff --git a/java/com/android/dialer/app/res/values/aicp_strings.xml b/java/com/android/dialer/app/res/values/aicp_strings.xml index efdfd7a01..6511529cf 100644 --- a/java/com/android/dialer/app/res/values/aicp_strings.xml +++ b/java/com/android/dialer/app/res/values/aicp_strings.xml @@ -74,4 +74,8 @@ <!-- Dialer postcall --> <string name="enable_post_call_title">Post call snackbar</string> <string name="enable_post_call_summary">Enable post call notifications at the bottom of screen</string> + + <!-- Disable proximity sensor --> + <string name="disable_proximity_sensor_title">Disable proximity sensor</string> + <string name="disable_proximity_sensor_summary">Do not turn off touchscreen and display in call based on proximity sensor</string> </resources> diff --git a/java/com/android/dialer/app/res/xml/other_settings.xml b/java/com/android/dialer/app/res/xml/other_settings.xml index 12f98601b..43fd76a9e 100644 --- a/java/com/android/dialer/app/res/xml/other_settings.xml +++ b/java/com/android/dialer/app/res/xml/other_settings.xml @@ -23,4 +23,10 @@ android:title="@string/enable_post_call_title"
android:summary="@string/enable_post_call_summary" />
+ <SwitchPreference + android:defaultValue="false" + android:key="disable_proximity_sensor_key" + android:title="@string/disable_proximity_sensor_title" + android:summary="@string/disable_proximity_sensor_summary" /> + </PreferenceScreen> diff --git a/java/com/android/incallui/ProximitySensor.java b/java/com/android/incallui/ProximitySensor.java index df06db52c..b825b2371 100644 --- a/java/com/android/incallui/ProximitySensor.java +++ b/java/com/android/incallui/ProximitySensor.java @@ -39,6 +39,8 @@ import com.android.incallui.audiomode.AudioModeProvider; import com.android.incallui.audiomode.AudioModeProvider.AudioModeListener; import com.android.incallui.call.CallList; import com.android.incallui.call.DialerCall; +import com.android.dialer.app.settings.OtherSettingsFragment; +import android.preference.PreferenceManager; /** * Class manages the proximity sensor for the in-call UI. We enable the proximity sensor while the @@ -51,6 +53,7 @@ public class ProximitySensor implements AccelerometerListener.ChangeListener, InCallStateListener, AudioModeListener, SensorEventListener { private static final String TAG = ProximitySensor.class.getSimpleName(); + private static final String PREF_KEY_DISABLE_PROXI_SENSOR = "disable_proximity_sensor_key"; private final PowerManager powerManager; private final PowerManager.WakeLock proximityWakeLock; @@ -73,7 +76,7 @@ public class ProximitySensor private boolean isRttCall; private Context context; - private SharedPreferences prefs; + private SharedPreferences mPrefs; private final Handler handler = new Handler(); private final Runnable activateSpeaker = new Runnable() { @@ -90,17 +93,23 @@ public class ProximitySensor Trace.beginSection("ProximitySensor.Constructor"); this.context = context; powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { + + mPrefs = PreferenceManager.getDefaultSharedPreferences(context); + final boolean mIsProximitySensorDisabled = mPrefs.getBoolean(PREF_KEY_DISABLE_PROXI_SENSOR, false); + + if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) + && !mIsProximitySensorDisabled) { proximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG); - } else { - LogUtil.i("ProximitySensor.constructor", "Device does not support proximity wake lock."); - proximityWakeLock = null; - } - if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); proxSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); + } else if (mIsProximitySensorDisabled) { + turnOffProximitySensor(true); // Ensure the wakelock is released before destroying it. + proximityWakeLock = null; + proxSensor = null; + sensorManager = null; } else { + proximityWakeLock = null; proxSensor = null; sensorManager = null; } @@ -115,7 +124,6 @@ public class ProximitySensor this.audioModeProvider = audioModeProvider; this.audioModeProvider.addListener(this); - prefs = PreferenceManager.getDefaultSharedPreferences(context); Trace.endSection(); } @@ -295,6 +303,12 @@ public class ProximitySensor Trace.beginSection("ProximitySensor.updateProximitySensorMode"); final int audioRoute = audioModeProvider.getAudioState().getRoute(); + final boolean mIsProximitySensorDisabled = mPrefs.getBoolean(PREF_KEY_DISABLE_PROXI_SENSOR, false); + + if (mIsProximitySensorDisabled) { + return; + } + boolean screenOnImmediately = (CallAudioState.ROUTE_WIRED_HEADSET == audioRoute || CallAudioState.ROUTE_SPEAKER == audioRoute @@ -357,11 +371,11 @@ public class ProximitySensor final int audioState = audioModeProvider.getAudioState().getRoute(); final boolean isProxSpeakerEnabled = - prefs.getBoolean("proximity_auto_speaker", false); + mPrefs.getBoolean("proximity_auto_speaker", false); final boolean proxSpeakerIncallOnlyPref = - prefs.getBoolean("proximity_auto_speaker_incall_only", false); + mPrefs.getBoolean("proximity_auto_speaker_incall_only", false); final int proxSpeakerDelay = Integer.valueOf( - prefs.getString("proximity_auto_speaker_delay", "3000")); + mPrefs.getString("proximity_auto_speaker_delay", "3000")); // if phone off hook (call in session), and prox speaker feature is on if (isPhoneOffhook && isProxSpeakerEnabled |
