diff options
3 files changed, 55 insertions, 8 deletions
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 8b11ef1..230f4af 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -159,8 +159,14 @@ <!-- Set to true to enable the user switcher on the keyguard. --> <bool name="config_keyguardUserSwitcher">false</bool> + <!-- Doze: does this device support STATE_DOZE and STATE_DOZE_SUSPEND? --> + <bool name="doze_display_state_supported">false</bool> + <!-- Doze: should the significant motion sensor be used as a tease signal? --> - <bool name="doze_tease_on_significant_motion">true</bool> + <bool name="doze_tease_on_significant_motion">false</bool> + + <!-- Doze: maximum brightness to use when teasing --> + <integer name="doze_tease_brightness">80</integer> <!-- Volume: time to delay dismissing the volume panel after a click is performed --> <integer name="volume_panel_dismiss_delay">200</integer> 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() { |