From 7151398929e487f7f74b285f3e4c478f95daa7c6 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Wed, 25 Feb 2015 20:23:53 -0800 Subject: Use new PowerManager API to implement voicemail proximity This allows us to fully blank out the screen instead of faking a black screen leaving the nav bar and notification bar active. Bug: 11734938 Change-Id: I716642fa7f85776d1701d3b95736065dec4d2eac --- src/com/android/dialer/CallDetailActivity.java | 91 ++++++++------------------ 1 file changed, 29 insertions(+), 62 deletions(-) (limited to 'src/com/android/dialer/CallDetailActivity.java') diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index fb663d729..08c9e029b 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -27,6 +27,7 @@ import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.os.PowerManager; import android.provider.CallLog; import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; @@ -83,11 +84,6 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A'; private static final char POP_DIRECTIONAL_FORMATTING = '\u202C'; - /** The time to wait before enabling the blank the screen due to the proximity sensor. */ - private static final long PROXIMITY_BLANK_DELAY_MILLIS = 100; - /** The time to wait before disabling the blank the screen due to the proximity sensor. */ - private static final long PROXIMITY_UNBLANK_DELAY_MILLIS = 500; - /** The enumeration of {@link AsyncTask} objects used in this class. */ public enum Tasks { MARK_VOICEMAIL_READ, @@ -144,59 +140,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware /** Whether we should show "remove from call log" in the options menu. */ private boolean mHasRemoveFromCallLogOption; - private ProximitySensorManager mProximitySensorManager; - private final ProximitySensorListener mProximitySensorListener = new ProximitySensorListener(); - - /** Listener to changes in the proximity sensor state. */ - private class ProximitySensorListener implements ProximitySensorManager.Listener { - /** Used to show a blank view and hide the action bar. */ - private final Runnable mBlankRunnable = new Runnable() { - @Override - public void run() { - View blankView = findViewById(R.id.blank); - blankView.setVisibility(View.VISIBLE); - getActionBar().hide(); - } - }; - /** Used to remove the blank view and show the action bar. */ - private final Runnable mUnblankRunnable = new Runnable() { - @Override - public void run() { - View blankView = findViewById(R.id.blank); - blankView.setVisibility(View.GONE); - getActionBar().show(); - } - }; - - @Override - public synchronized void onNear() { - clearPendingRequests(); - postDelayed(mBlankRunnable, PROXIMITY_BLANK_DELAY_MILLIS); - } - - @Override - public synchronized void onFar() { - clearPendingRequests(); - postDelayed(mUnblankRunnable, PROXIMITY_UNBLANK_DELAY_MILLIS); - } - - /** Removed any delayed requests that may be pending. */ - public synchronized void clearPendingRequests() { - View blankView = findViewById(R.id.blank); - blankView.removeCallbacks(mBlankRunnable); - blankView.removeCallbacks(mUnblankRunnable); - } - - /** Post a {@link Runnable} with a delay on the main thread. */ - private synchronized void postDelayed(Runnable runnable, long delayMillis) { - // Post these instead of executing immediately so that: - // - They are guaranteed to be executed on the main thread. - // - If the sensor values changes rapidly for some time, the UI will not be - // updated immediately. - View blankView = findViewById(R.id.blank); - blankView.postDelayed(runnable, delayMillis); - } - } + private PowerManager.WakeLock mProximityWakeLock; static final String[] CALL_LOG_PROJECTION = new String[] { CallLog.Calls.DATE, @@ -250,7 +194,14 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware mAccountLabel = (TextView) findViewById(R.id.phone_account_label); mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); mContactPhotoManager = ContactPhotoManager.getInstance(this); - mProximitySensorManager = new ProximitySensorManager(this, mProximitySensorListener); + final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); + if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) { + mProximityWakeLock = powerManager.newWakeLock( + PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG); + } else { + mProximityWakeLock = null; + } + mContactInfoHelper = new ContactInfoHelper(this, GeoUtil.getCurrentCountryIso(this)); getActionBar().setDisplayHomeAsUpEnabled(true); @@ -751,18 +702,34 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware protected void onPause() { // Immediately stop the proximity sensor. disableProximitySensor(false); - mProximitySensorListener.clearPendingRequests(); super.onPause(); } @Override public void enableProximitySensor() { - mProximitySensorManager.enable(); + if (mProximityWakeLock == null) { + return; + } + if (!mProximityWakeLock.isHeld()) { + Log.i(TAG, "Acquiring proximity wake lock"); + mProximityWakeLock.acquire(); + } else { + Log.i(TAG, "Proximity wake lock already acquired"); + } } @Override public void disableProximitySensor(boolean waitForFarState) { - mProximitySensorManager.disable(waitForFarState); + if (mProximityWakeLock == null) { + return; + } + if (mProximityWakeLock.isHeld()) { + Log.i(TAG, "Releasing proximity wake lock"); + int flags = (waitForFarState ? PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY : 0); + mProximityWakeLock.release(flags); + } else { + Log.i(TAG, "Proximity wake lock already released"); + } } private void closeSystemDialogs() { -- cgit v1.2.3