summaryrefslogtreecommitdiffstats
path: root/tests/DozeTest
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2014-01-30 21:47:47 -0800
committerJeff Brown <jeffbrown@google.com>2014-02-20 13:39:13 -0800
commit2687550272ba061448f5d5b914700dc335299ee7 (patch)
treefc68c5ecec24ec2aa120ccf490d7a56573704a73 /tests/DozeTest
parentd43ad2f35abcc647f7985abd09ed9de5899faf18 (diff)
downloadframeworks_base-2687550272ba061448f5d5b914700dc335299ee7.zip
frameworks_base-2687550272ba061448f5d5b914700dc335299ee7.tar.gz
frameworks_base-2687550272ba061448f5d5b914700dc335299ee7.tar.bz2
Add a new "doze mode" based on Dream components.
When a doze component has been specified in a config.xml resource overlay, the power manager will try to start a preconfigured dream whenever it would have otherwise gone to sleep and turned the screen off. The dream should render whatever it intends to show then call startDozing() to tell the power manager to put the display into a low power "doze" state and allow the application processor to be suspended. The dream may wake up periodically using the alarm manager or other features to update the contents of the display. Added several new config.xml resources related to dreams and dozing. In particular for dozing there are two new resources that pertain to decoupling auto-suspend mode and interactive mode from the display state. This is a requirement to enable the application processor and other components to be suspended while dozing. Most devices do not support these features today. Consolidated the power manager's NAPPING and DREAMING states into one to simplify the logic. The NAPPING state was mostly superfluous and simply indicated that the power manager should attempt to start a new dream. This state is now tracked in the mSandmanSummoned field. Added a new DOZING state which is analoguous to DREAMING. The normal state transition is now: AWAKE -> DREAMING -> DOZING -> ASLEEP. The PowerManager.goToSleep() method now enters the DOZING state instead of immediately going to sleep. While in the doze state, the screen remains on. However, we actually tell the rest of the system that the screen is off. This is somewhat unfortunate but much of the system makes inappropriate assumptions about what it means for the screen to be on or off. In particular, screen on is usually taken to indicate an interactive state where the user is present but that's not at all true for dozing (and is only sometimes true while dreaming). We will probably need to add some more precise externally visible states at some point. The DozeHardware interface encapsulates a generic microcontroller interface to allow a doze dream for off-loading rendering or other functions while dozing. If the device possesses an MCU HAL for dozing then it is exposed to the DreamService here. Removed a number of catch blocks in DreamService that caught Throwable and attempted to cause the dream to finish itself. We actually just want to let the process crash. Cleanup will happen automatically if needed. Catching these exceptions results in mysterious undefined behavior and broken dreams. Bug: 12494706 Change-Id: Ie78336b37dde7250d1ce65b3d367879e3bfb2b8b
Diffstat (limited to 'tests/DozeTest')
-rw-r--r--tests/DozeTest/Android.mk14
-rw-r--r--tests/DozeTest/AndroidManifest.xml35
-rwxr-xr-xtests/DozeTest/res/drawable-hdpi/ic_app.pngbin0 -> 3608 bytes
-rw-r--r--tests/DozeTest/res/drawable-mdpi/ic_app.pngbin0 -> 5198 bytes
-rw-r--r--tests/DozeTest/res/layout/dream.xml41
-rw-r--r--tests/DozeTest/res/values/strings.xml25
-rw-r--r--tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java165
7 files changed, 280 insertions, 0 deletions
diff --git a/tests/DozeTest/Android.mk b/tests/DozeTest/Android.mk
new file mode 100644
index 0000000..01f10e5
--- /dev/null
+++ b/tests/DozeTest/Android.mk
@@ -0,0 +1,14 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := DozeTest
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/DozeTest/AndroidManifest.xml b/tests/DozeTest/AndroidManifest.xml
new file mode 100644
index 0000000..c199f69
--- /dev/null
+++ b/tests/DozeTest/AndroidManifest.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.dreams.dozetest">
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+
+ <application android:label="@string/app_name">
+ <service
+ android:name="DozeTestDream"
+ android:exported="true"
+ android:icon="@drawable/ic_app"
+ android:label="@string/doze_dream_name">
+ <!-- Commented out to prevent this dream from appearing in the list of
+ dreams that the user can select via the Settings application.
+ <intent-filter>
+ <action android:name="android.service.dreams.DreamService" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ -->
+ </service>
+ </application>
+</manifest>
diff --git a/tests/DozeTest/res/drawable-hdpi/ic_app.png b/tests/DozeTest/res/drawable-hdpi/ic_app.png
new file mode 100755
index 0000000..66a1984
--- /dev/null
+++ b/tests/DozeTest/res/drawable-hdpi/ic_app.png
Binary files differ
diff --git a/tests/DozeTest/res/drawable-mdpi/ic_app.png b/tests/DozeTest/res/drawable-mdpi/ic_app.png
new file mode 100644
index 0000000..5ae7701
--- /dev/null
+++ b/tests/DozeTest/res/drawable-mdpi/ic_app.png
Binary files differ
diff --git a/tests/DozeTest/res/layout/dream.xml b/tests/DozeTest/res/layout/dream.xml
new file mode 100644
index 0000000..1c8fd3f
--- /dev/null
+++ b/tests/DozeTest/res/layout/dream.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center_vertical"
+ android:orientation="vertical">
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/alarm_clock_label" />
+ <TextView android:id="@+id/alarm_clock"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ <Space
+ android:layout_width="match_parent"
+ android:layout_height="32dp" />
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/tick_clock_label" />
+ <TextClock android:id="@+id/tick_clock"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+</LinearLayout>
diff --git a/tests/DozeTest/res/values/strings.xml b/tests/DozeTest/res/values/strings.xml
new file mode 100644
index 0000000..f21911f
--- /dev/null
+++ b/tests/DozeTest/res/values/strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <!-- Name of the package of basic screensavers, shown in Settings > Apps. [CHAR LIMIT=40] -->
+ <string name="app_name">Doze Test</string>
+
+ <!-- Name of the screensaver. [CHAR LIMIT=40] -->
+ <string name="doze_dream_name">Doze Test</string>
+
+ <string name="alarm_clock_label">This clock is updated using the Alarm Manager</string>
+ <string name="tick_clock_label">This clock is updated using TIME_TICK Broadcasts</string>
+</resources>
diff --git a/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java b/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java
new file mode 100644
index 0000000..bf35db4
--- /dev/null
+++ b/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.dreams.dozetest;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+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.widget.TextView;
+
+import java.util.Date;
+
+/**
+ * Simple test for doze mode.
+ * <p>
+ * adb shell setprop debug.doze.component com.android.dreams.dozetest/.DozeTestDream
+ * </p>
+ */
+public class DozeTestDream extends DreamService {
+ private static final String TAG = DozeTestDream.class.getSimpleName();
+ private static final boolean DEBUG = false;
+
+ // Amount of time to allow to update the time shown on the screen before releasing
+ // the wakelock. This timeout is design to compensate for the fact that we don't
+ // currently have a way to know when time display contents have actually been
+ // refreshed once the dream has finished rendering a new frame.
+ private static final int UPDATE_TIME_TIMEOUT = 100;
+
+ // A doze hardware message string we use for end-to-end testing.
+ // Doesn't mean anything. Real hardware won't handle it.
+ private static final String TEST_PING_MESSAGE = "test.ping";
+
+ private PowerManager mPowerManager;
+ private PowerManager.WakeLock mWakeLock;
+ private AlarmManager mAlarmManager;
+ private PendingIntent mAlarmIntent;
+
+ private TextView mAlarmClock;
+
+ private final Date mTime = new Date();
+ private java.text.DateFormat mTimeFormat;
+
+ private boolean mDreaming;
+ private DozeHardware mDozeHardware;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+
+ mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
+ mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
+
+ mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
+
+ Intent intent = new Intent("com.android.dreams.dozetest.ACTION_ALARM");
+ intent.setPackage(getPackageName());
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(intent.getAction());
+ registerReceiver(mAlarmReceiver, filter);
+ mAlarmIntent = PendingIntent.getBroadcast(this, 0, intent,
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ unregisterReceiver(mAlarmReceiver);
+ mAlarmIntent.cancel();
+ }
+
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ setInteractive(false);
+ setLowProfile(true);
+ setFullscreen(true);
+ setContentView(R.layout.dream);
+
+ mAlarmClock = (TextView)findViewById(R.id.alarm_clock);
+
+ mTimeFormat = DateFormat.getTimeFormat(this);
+ }
+
+ @Override
+ public void onDreamingStarted() {
+ super.onDreamingStarted();
+
+ mDreaming = true;
+ mDozeHardware = getDozeHardware();
+
+ Log.d(TAG, "Dream started: canDoze=" + canDoze()
+ + ", dozeHardware=" + mDozeHardware);
+
+ performTimeUpdate();
+
+ if (mDozeHardware != null) {
+ mDozeHardware.sendMessage(TEST_PING_MESSAGE, null);
+ mDozeHardware.setEnableMcu(true);
+ }
+ startDozing();
+ }
+
+ @Override
+ public void onDreamingStopped() {
+ super.onDreamingStopped();
+
+ mDreaming = false;
+ if (mDozeHardware != null) {
+ mDozeHardware.setEnableMcu(false);
+ mDozeHardware = null;
+ }
+
+ Log.d(TAG, "Dream ended: isDozing=" + isDozing());
+
+ stopDozing();
+ cancelTimeUpdate();
+ }
+
+ private void performTimeUpdate() {
+ if (mDreaming) {
+ long now = System.currentTimeMillis();
+ now -= now % 60000; // back up to last minute boundary
+
+ mTime.setTime(now);
+ mAlarmClock.setText(mTimeFormat.format(mTime));
+
+ mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, now + 60000, mAlarmIntent);
+
+ mWakeLock.acquire(UPDATE_TIME_TIMEOUT);
+ }
+ }
+
+ private void cancelTimeUpdate() {
+ mAlarmManager.cancel(mAlarmIntent);
+ }
+
+ private final BroadcastReceiver mAlarmReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ performTimeUpdate();
+ }
+ };
+}