diff options
author | Jeff Brown <jeffbrown@google.com> | 2014-07-19 11:33:47 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2014-07-22 01:18:26 +0000 |
commit | 970d4132ea28e748c1010be39450a98bbf7466f3 (patch) | |
tree | 0bbaa479dbb4c9b9f8b49b9fe7e7344d7f0581cc /tests/DozeTest | |
parent | f89bff9ed875c1e3ad8e682e651c5994b246cc53 (diff) | |
download | frameworks_base-970d4132ea28e748c1010be39450a98bbf7466f3.zip frameworks_base-970d4132ea28e748c1010be39450a98bbf7466f3.tar.gz frameworks_base-970d4132ea28e748c1010be39450a98bbf7466f3.tar.bz2 |
Allow dreams to control screen state and brightness.
Added setDozeScreenState() and setDozeScreenBrightness() methods to
DreamService. The values specified here only take effect once
startDozing is called and can be changed while dozing.
This required some significant rework of the display power controller
but the result seems quite nice and better represents the policy
we want to apply.
Changed the test dream a little bit to make it flash the screen
every minute using the new functions.
Bug: 15903322
Change-Id: I83bcc34503f1b87727d2b2b3c0ef08507f9f0808
Diffstat (limited to 'tests/DozeTest')
-rw-r--r-- | tests/DozeTest/AndroidManifest.xml | 3 | ||||
-rw-r--r-- | tests/DozeTest/res/layout/dream.xml | 3 | ||||
-rw-r--r-- | tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java | 34 |
3 files changed, 37 insertions, 3 deletions
diff --git a/tests/DozeTest/AndroidManifest.xml b/tests/DozeTest/AndroidManifest.xml index c199f69..03778d6 100644 --- a/tests/DozeTest/AndroidManifest.xml +++ b/tests/DozeTest/AndroidManifest.xml @@ -22,7 +22,8 @@ android:name="DozeTestDream" android:exported="true" android:icon="@drawable/ic_app" - android:label="@string/doze_dream_name"> + android:label="@string/doze_dream_name" + android:permission="android.permission.BIND_DREAM_SERVICE"> <!-- Commented out to prevent this dream from appearing in the list of dreams that the user can select via the Settings application. <intent-filter> diff --git a/tests/DozeTest/res/layout/dream.xml b/tests/DozeTest/res/layout/dream.xml index 1c8fd3f..bced230 100644 --- a/tests/DozeTest/res/layout/dream.xml +++ b/tests/DozeTest/res/layout/dream.xml @@ -18,7 +18,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical" - android:orientation="vertical"> + android:orientation="vertical" + android:background="#bb2288"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" diff --git a/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java b/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java index a0b2d1a..f72e331 100644 --- a/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java +++ b/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java @@ -22,11 +22,13 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Handler; import android.os.PowerManager; import android.service.dreams.DozeHardware; import android.service.dreams.DreamService; import android.text.format.DateFormat; import android.util.Log; +import android.view.Display; import android.widget.TextView; import java.util.Date; @@ -51,10 +53,16 @@ public class DozeTestDream extends DreamService { // Doesn't mean anything. Real hardware won't handle it. private static final String TEST_PING_MESSAGE = "test.ping"; + // Not all hardware supports dozing. We should use Display.STATE_DOZE but + // for testing purposes it is convenient to use Display.STATE_ON so the + // test still works on hardware that does not support dozing. + private static final int DISPLAY_STATE_WHEN_DOZING = Display.STATE_ON; + private PowerManager mPowerManager; private PowerManager.WakeLock mWakeLock; private AlarmManager mAlarmManager; private PendingIntent mAlarmIntent; + private Handler mHandler = new Handler(); private TextView mAlarmClock; @@ -64,6 +72,8 @@ public class DozeTestDream extends DreamService { private boolean mDreaming; private DozeHardware mDozeHardware; + private long mLastTime = Long.MIN_VALUE; + @Override public void onCreate() { super.onCreate(); @@ -80,6 +90,8 @@ public class DozeTestDream extends DreamService { registerReceiver(mAlarmReceiver, filter); mAlarmIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); + + setDozeScreenState(DISPLAY_STATE_WHEN_DOZING); } @Override @@ -143,13 +155,33 @@ public class DozeTestDream extends DreamService { if (mDreaming) { long now = System.currentTimeMillis(); now -= now % 60000; // back up to last minute boundary + if (mLastTime == now) { + return; + } + mLastTime = now; mTime.setTime(now); mAlarmClock.setText(mTimeFormat.format(mTime)); mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, now + 60000, mAlarmIntent); - mWakeLock.acquire(UPDATE_TIME_TIMEOUT); + mWakeLock.acquire(UPDATE_TIME_TIMEOUT + 5000 /*for testing brightness*/); + + // flash the screen a bit to test these functions + setDozeScreenState(DISPLAY_STATE_WHEN_DOZING); + setDozeScreenBrightness(200); + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + setDozeScreenBrightness(50); + } + }, 2000); + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + setDozeScreenState(Display.STATE_OFF); + } + }, 5000); } } |