diff options
author | Yorke Lee <yorkelee@google.com> | 2015-02-26 22:37:04 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-02-26 22:37:05 +0000 |
commit | 0531a915a1078b67f9ceec7db9910a9f7f54f94b (patch) | |
tree | b4143f80c177ef3c4b5e9476d233b8c3a041e627 /src/com/android/dialer/CallDetailActivity.java | |
parent | eb2097d840ac4e2f8709041cb7c9282697a309af (diff) | |
parent | 7151398929e487f7f74b285f3e4c478f95daa7c6 (diff) |
Merge "Use new PowerManager API to implement voicemail proximity"
Diffstat (limited to 'src/com/android/dialer/CallDetailActivity.java')
-rw-r--r-- | src/com/android/dialer/CallDetailActivity.java | 91 |
1 files changed, 29 insertions, 62 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index df8197a10..69242d3da 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, @@ -251,7 +195,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); @@ -752,18 +703,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() { |