diff options
author | John Spurlock <jspurlock@google.com> | 2014-07-23 11:09:02 -0400 |
---|---|---|
committer | John Spurlock <jspurlock@google.com> | 2014-07-23 17:15:15 -0400 |
commit | ed69bd661f5152cdcb2d8359efb592234a45fc49 (patch) | |
tree | 634810b1fcec7f178813c7e9bb5a6a28641ad356 /packages/SystemUI/src/com | |
parent | 828b8800c0dab9555f8d09e5a20e469a4be2b833 (diff) | |
download | frameworks_base-ed69bd661f5152cdcb2d8359efb592234a45fc49.zip frameworks_base-ed69bd661f5152cdcb2d8359efb592234a45fc49.tar.gz frameworks_base-ed69bd661f5152cdcb2d8359efb592234a45fc49.tar.bz2 |
Doze: Manage screen state + brightness when teasing.
Bug:15863249
Change-Id: I2e9574afd58594d1895777024529e90815c66913
Diffstat (limited to 'packages/SystemUI/src/com')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/doze/DozeService.java | 46 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java | 9 |
2 files changed, 48 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java index 269b4ed..333b8b4 100644 --- a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java +++ b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java @@ -16,20 +16,27 @@ package com.android.systemui.doze; +import static android.os.PowerManager.BRIGHTNESS_OFF; +import static android.os.PowerManager.BRIGHTNESS_ON; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Resources; import android.hardware.Sensor; import android.hardware.SensorManager; import android.hardware.TriggerEvent; import android.hardware.TriggerEventListener; +import android.os.Handler; import android.os.PowerManager; import android.os.SystemProperties; import android.os.Vibrator; import android.service.dreams.DozeHardware; import android.service.dreams.DreamService; import android.util.Log; +import android.util.MathUtils; +import android.view.Display; import com.android.systemui.R; import com.android.systemui.SystemUIApplication; @@ -38,12 +45,14 @@ import java.io.FileDescriptor; import java.io.PrintWriter; public class DozeService extends DreamService { - private static final boolean DEBUG = false; + private static final String TAG = "DozeService"; + private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); private static final String TEASE_ACTION = "com.android.systemui.doze.tease"; - private final String mTag = String.format("DozeService.%08x", hashCode()); + private final String mTag = String.format(TAG + ".%08x", hashCode()); private final Context mContext = this; + private final Handler mHandler = new Handler(); private Host mHost; private DozeHardware mDozeHardware; @@ -51,10 +60,13 @@ public class DozeService extends DreamService { private Sensor mSigMotionSensor; private PowerManager mPowerManager; private PowerManager.WakeLock mWakeLock; + private int mMaxBrightness; private boolean mDreaming; private boolean mTeaseReceiverRegistered; private boolean mSigMotionConfigured; private boolean mSigMotionEnabled; + private boolean mDisplayStateSupported; + private int mDisplayStateWhenOn; public DozeService() { if (DEBUG) Log.d(mTag, "new DozeService()"); @@ -70,6 +82,8 @@ public class DozeService extends DreamService { pw.print(" mSigMotionSensor: "); pw.println(mSigMotionSensor); pw.print(" mSigMotionConfigured: "); pw.println(mSigMotionConfigured); pw.print(" mSigMotionEnabled: "); pw.println(mSigMotionEnabled); + pw.print(" mMaxBrightness: "); pw.println(mMaxBrightness); + pw.print(" mDisplayStateSupported: "); pw.println(mDisplayStateSupported); } @Override @@ -88,8 +102,16 @@ public class DozeService extends DreamService { mSigMotionSensor = mSensors.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION); mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mTag); + final Resources res = mContext.getResources(); mSigMotionConfigured = SystemProperties.getBoolean("doze.tease.sigmotion", - mContext.getResources().getBoolean(R.bool.doze_tease_on_significant_motion)); + res.getBoolean(R.bool.doze_tease_on_significant_motion)); + mDisplayStateSupported = SystemProperties.getBoolean("doze.display.supported", + res.getBoolean(R.bool.doze_display_state_supported)); + mMaxBrightness = MathUtils.constrain(res.getInteger(R.integer.doze_tease_brightness), + BRIGHTNESS_OFF, BRIGHTNESS_ON); + + mDisplayStateWhenOn = mDisplayStateSupported ? Display.STATE_DOZE : Display.STATE_ON; + setDozeScreenState(mDisplayStateWhenOn); } @Override @@ -112,9 +134,18 @@ public class DozeService extends DreamService { public void stayAwake(long millis) { if (mDreaming && millis > 0) { mWakeLock.acquire(millis); + setDozeScreenState(mDisplayStateWhenOn); + setDozeScreenBrightness(mMaxBrightness); + rescheduleOff(millis); } } + private void rescheduleOff(long millis) { + if (DEBUG) Log.d(TAG, "rescheduleOff millis=" + millis); + mHandler.removeCallbacks(mDisplayOff); + mHandler.postDelayed(mDisplayOff, millis); + } + public void startDozing() { if (DEBUG) Log.d(mTag, "startDozing mDreaming=" + mDreaming); if (!mDreaming) { @@ -225,6 +256,15 @@ public class DozeService extends DreamService { return sb.append(']').toString(); } + private final Runnable mDisplayOff = new Runnable() { + @Override + public void run() { + if (DEBUG) Log.d(TAG, "Display off"); + setDozeScreenState(Display.STATE_OFF); + setDozeScreenBrightness(PowerManager.BRIGHTNESS_DEFAULT); + } + }; + private final TriggerEventListener mSigMotionListener = new TriggerEventListener() { @Override public void onTrigger(TriggerEvent event) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java index c464f31..cf930bd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java @@ -44,12 +44,13 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener { private static final int TAG_KEY_ANIM = R.id.scrim; private static final int NUM_TEASES = 3; - private static final long TEASE_IN_ANIMATION_DURATION = 500; - private static final long TEASE_VISIBLE_DURATION = 3000; + private static final long TEASE_IN_ANIMATION_DURATION = 1000; + private static final long TEASE_VISIBLE_DURATION = 2000; private static final long TEASE_OUT_ANIMATION_DURATION = 1000; private static final long TEASE_INVISIBLE_DURATION = 1000; private static final long TEASE_DURATION = TEASE_IN_ANIMATION_DURATION + TEASE_VISIBLE_DURATION + TEASE_OUT_ANIMATION_DURATION + TEASE_INVISIBLE_DURATION; + private static final long PRE_TEASE_DELAY = 1000; private final View mScrimBehind; private final View mScrimInFront; @@ -128,8 +129,8 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener { public long tease() { if (!mDozing) return 0; mTeasesRemaining = NUM_TEASES; - mScrimInFront.post(mTeaseIn); - return NUM_TEASES * TEASE_DURATION; + mScrimInFront.postDelayed(mTeaseIn, PRE_TEASE_DELAY); + return PRE_TEASE_DELAY + NUM_TEASES * TEASE_DURATION; } private void cancelTeasing() { |