Add setting to go to sleep after long user inactivity

The European Commision prescribes an auto-standby feature for TV panels:
After some hours of inactivity, the device has to go from on-mode to
standby-mode or off-mode, or another condition not exceeding the
applicable requirements for standby-mode or for off-mode.

After a long time of no user activity the device should go to sleep,
even if wakelocks are held (eg. during video playback).

Test: 1. Set attentive timeout low, to 35s:
         `adb shell settings put secure attentive_timeout 35000`
      2. Play a YouTube video
      3. Observe warning dialog appearing after 5s
      4. Verify: Clicking a remote button or changing the setting higher hides
         the warning. Remote button press is consumed.
      5. Verify: After 35s of not pressing a button the device goes to sleep
      6. Verify: If "Stay awake" developer option is enabled, then
         warning is not displayed and device does not go to sleep after 35s
      7. Verify: No warning or sleep if setting is set to -1
Test: `atest frameworks/base/services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java`
Bug: 137633812
Change-Id: I551b6cffc336437fb1c5a00b4102f68ae0e003e9
This commit is contained in:
Robert Horvath
2019-07-10 10:46:38 +02:00
parent 94eebca44e
commit 5560f38654
23 changed files with 887 additions and 74 deletions

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 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.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sleep_warning_dialog_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@android:style/Theme.DeviceDefault.Dialog"
android:focusable="true">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:alpha="?android:backgroundDimAmount" />
<LinearLayout
android:layout_width="380dp"
android:layout_height="wrap_content"
android:background="@drawable/rounded_bg_full"
android:padding="16dp"
android:layout_margin="32dp"
android:layout_gravity="bottom|right"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/inattentive_sleep_warning_title"
android:layout_marginBottom="8dp"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Large"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/inattentive_sleep_warning_message"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"/>
</LinearLayout>
</FrameLayout>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 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.
-->
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sleep_warning_dialog_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@android:style/Theme.Material.Dialog"
android:focusable="true">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:alpha="?android:backgroundDimAmount" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_bg_full"
android:layout_margin="8dp"
android:padding="16dp"
android:layout_gravity="top"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/inattentive_sleep_warning_title"
android:layout_marginBottom="8dp"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="@android:style/TextAppearance.Material.Large"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/inattentive_sleep_warning_message"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="@android:style/TextAppearance.Material"/>
</LinearLayout>
</FrameLayout>

View File

@@ -281,6 +281,7 @@
<item>com.android.systemui.statusbar.phone.StatusBar</item>
<item>com.android.systemui.usb.StorageNotification</item>
<item>com.android.systemui.power.PowerUI</item>
<item>com.android.systemui.power.InattentiveSleepWarningController</item>
<item>com.android.systemui.media.RingtonePlayer</item>
<item>com.android.systemui.keyboard.KeyboardUI</item>
<item>com.android.systemui.pip.PipUI</item>

View File

@@ -2501,4 +2501,11 @@
<!-- Notification content text when switching to a default launcher that supports gesture navigation [CHAR LIMIT=NONE] -->
<string name="notification_content_gesture_nav_available">Go to Settings to update system navigation</string>
<!-- Title of the overlay warning the user to interact with the device or it will go to sleep. [CHAR LIMIT=25] -->
<string name="inattentive_sleep_warning_title">Standby</string>
<!-- Message of the overlay warning the user to interact with the device or it will go to sleep. [CHAR LIMIT=NONE] -->
<string name="inattentive_sleep_warning_message" product="tv">The Android TV device will soon turn off; press a button to keep it on.</string>
<!-- Message of the overlay warning the user to interact with the device or it will go to sleep. [CHAR LIMIT=NONE] -->
<string name="inattentive_sleep_warning_message" product="default">The device will soon turn off; press to keep it on.</string>
</resources>