Mulai 27 Maret 2025, sebaiknya gunakan android-latest-release, bukan aosp-main, untuk mem-build dan berkontribusi pada AOSP. Untuk mengetahui informasi selengkapnya, lihat Perubahan pada AOSP.
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Di Android 11, tidur tidak memperhatikan adalah fitur hemat daya
yang memungkinkan waktu tunggu tidak aktif pengguna ditetapkan, lalu layar dinonaktifkan, meskipun
jendela dengan FLAG_KEEP_SCREEN_ON
terlihat atau wakelock level
FULL_WAKE_LOCK,
SCREEN_BRIGHT_WAKE_LOCK, atau
SCREEN_DIM_WAKE_LOCK
dipertahankan.
Wakelock dengan level PARTIAL_WAKE_LOCK tidak terpengaruh oleh fitur ini.
Sesaat sebelum waktu tunggu berakhir, pesan dapat ditampilkan yang memperingatkan
pengguna bahwa perangkat akan beralih ke mode tidur jika mereka tidak berinteraksi dengan perangkat.
Dalam konteks ini, aktivitas pengguna mengacu pada apa pun yang memicu panggilan ke
PowerManager#userActivity (tanpa tanda USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS), termasuk, tetapi tidak terbatas pada:
Berinteraksi dengan layar sentuh
Menekan tombol fisik
Peristiwa input dari aksesori eksternal (misalnya, keyboard yang terhubung, remote bluetooth,
remote IR)
Interaksi suara
Menerima pesan HDMI CEC tertentu, seperti One Touch Play
Memulai sesi transmisi baru
Penyesuaian
Jika fitur diaktifkan, perangkat akan menampilkan peringatan di layar setelah waktu tidak aktif
pengguna yang ditentukan. Jika tidak ada tindakan yang dilakukan, layar akan mati. Anda dapat menyesuaikan fitur
menggunakan opsi konfigurasi ini.
Mengonfigurasi waktu tunggu
Untuk mengonfigurasi waktu tunggu, perbarui elemen berikut di
frameworks/base/core/res/res/values/config.xml:
config_attentiveTimeout
Menentukan waktu default dalam milidetik untuk tidak adanya aktivitas pengguna, setelah itu layar akan dinonaktifkan
(meskipun wakelock layar sudah diterapkan).
Ditetapkan pada waktu build.
Jika nilainya antara 0 dan config_minimumScreenOffTimeout,
waktu tunggu ditetapkan ke config_minimumScreenOffTimeout untuk mencegah perangkat
menonaktifkan layarnya segera setelah aktif.
Default: -1, yang menonaktifkan fitur ini.
Mengganti waktu tunggu default
Untuk mengganti setelan waktu tunggu default, perbarui elemen berikut.
Settings.Secure.ATTENTIVE_TIMEOUT
Jika ditetapkan, akan mengganti waktu tunggu tidur tidak waspada default yang ditetapkan oleh
config_attentiveTimeout.
Dapat ditetapkan saat runtime.
Mengonfigurasi durasi sebelum peringatan muncul
Untuk mengonfigurasi durasi, perbarui elemen berikut di
frameworks/base/core/res/res/values/config.xml:
config_attentiveWarningDuration
Durasi waktu untuk menampilkan pesan peringatan kepada pengguna sebelum layar dinonaktifkan setelah
pengguna tidak aktif dalam waktu lama.
Nilainya harus jauh di bawah waktu tunggu tidur tidak memperhatikan yang ditetapkan. Jika tidak, dialog peringatan akan terus ditampilkan dan tidak dapat ditutup.
Default: 30000 (30 detik).
Menampilkan preferensi waktu tunggu di TvSettings
Untuk menampilkan preferensi waktu tunggu, perbarui elemen berikut di
packages/apps/TvSettings/Settings/res/values/config.xml:
config_show_standby_timeout
Menentukan apakah akan menampilkan item preferensi untuk mengizinkan penonaktifan layar selama pemutaran media.
Default: false.
Referensi untuk UI peringatan
Tata letak dialog peringatan ditentukan di
frameworks/base/packages/SystemUI/res/layout/inattentive_sleep_warning.xml.
String berikut untuk dialog ditentukan dalam
frameworks/base/packages/SystemUI/res/values/strings.xml dan
frameworks/base/packages/SystemUI/res-product/values/strings.xml.
inattentive_sleep_warning_title
inattentive_sleep_warning_message
Konfigurasi dan resource waktu build dapat diubah oleh overlay resource.
Implementasi
Aktifkan fitur menggunakan langkah-langkah berikut.
Ganti config_attentiveTimeout default.
Jika menggunakan TvSettings AOSP:
Nonaktifkan fitur di setelan dengan
mengganti config_show_standby_timeout.
Terapkan setelan Anda sendiri
yang menetapkan Settings.Secure.ATTENTIVE_TIMEOUT.
Validasi
Pengujian CTS untuk fitur ini berada di
cts/hostsidetests/os/src/android/os/cts/InattentiveSleepTests.java.
Contoh dan sumber
frameworks/base/packages/SystemUI/src/com/android/systemui/power/InattentiveSleepWarningView.java
berisi implementasi UI peringatan default.
packages/apps/TvSettings memberikan contoh cara mengekspos fitur di
setelan.
Contoh kasus pengujian manual
Pastikan setelan developer
stay_on_while_plugged_in nonaktif jika HAL kesehatan perangkat melaporkan bahwa perangkat memiliki
baterai (battery_present adalah true) karena hal ini dapat mencegah
fitur menonaktifkan layar. adb shell settings put global stay_on_while_plugged_in 0
Tetapkan waktu tunggu tidur yang tidak memperhatikan menjadi beberapa detik lebih lama dari durasi dialog peringatan. adb shell settings put secure attentive_timeout 32000
Mulai memutar video (untuk mendapatkan wakelock layar).
Pastikan dialog peringatan tidur muncul setelah beberapa detik.
Pastikan layar mati setelah waktu tunggu yang ditetapkan berakhir.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-27 UTC."],[],[],null,["# TV standby\n\nIn Android 11, inattentive sleep is a power-saving feature\nthat allows a user inactivity timeout to be set after which the screen turns off, even\nif windows with [FLAG_KEEP_SCREEN_ON](https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_KEEP_SCREEN_ON)\nare visible or wakelocks of level\n[FULL_WAKE_LOCK](https://developer.android.com/reference/android/os/PowerManager#FULL_WAKE_LOCK),\n[SCREEN_BRIGHT_WAKE_LOCK](https://developer.android.com/reference/android/os/PowerManager#SCREEN_BRIGHT_WAKE_LOCK) or\n[SCREEN_DIM_WAKE_LOCK](https://developer.android.com/reference/android/os/PowerManager#SCREEN_DIM_WAKE_LOCK)\nare held.\nWakelocks with level [PARTIAL_WAKE_LOCK](https://developer.android.com/reference/android/os/PowerManager#PARTIAL_WAKE_LOCK) aren't affected by this feature.\nShortly before the timeout expires, a message can be shown that warns\nthe user that the device will go to sleep if they don't interact with the device.\n\nIn this context, user activity refers to anything that triggers a call to\n`PowerManager#userActivity` (without the `USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS`\nflag), including but not limited to:\n\n- Interacting with the touchscreen\n- Pressing a physical button\n- Input events from an external accessory (for example, connected keyboard, bluetooth remote, IR remote)\n- Voice interaction\n- Receiving certain HDMI CEC messages, such as One Touch Play\n- Starting a new cast session\n\nCustomization\n-------------\n\nIf the feature is enabled, the device shows an onscreen warning after a specified time of\nuser inactivity. If no action is taken, the screen turns off. You can customize the feature\nusing these configuration options.\n| **Caution:** If a similar power-saving feature is already implemented, enabling this feature might lead to unintended consequences, such as duplicate warning UI.\n\n### Configure the timeout\n\nTo configure the timeout, update the following element in\n`frameworks/base/core/res/res/values/config.xml`:\n\n- `config_attentiveTimeout`\n - Specifies the default time in milliseconds of user inactivity after which the screen turns off (even if screen wakelocks are in place).\n - Set at build time.\n - If the value is between `0` and `config_minimumScreenOffTimeout`, the timeout is set to `config_minimumScreenOffTimeout` to prevent the device from turning off its screen shortly after waking up.\n - Default: `-1`, which disables this feature.\n\n### Override the default timeout\n\nTo override the default timeout setting, update the following element.\n\n- `Settings.Secure.ATTENTIVE_TIMEOUT`\n - If set, overrides the default inattentive sleep timeout set by `config_attentiveTimeout`.\n - Can be set at runtime.\n\n### Configure the duration before warning appears\n\nTo configure the duration, update the following element in\n`frameworks/base/core/res/res/values/config.xml`:\n\n- `config_attentiveWarningDuration`\n - How long to show a warning message to the user before the screen turns off after prolonged user inactivity.\n - The value should be well below the set inattentive sleep timeout, otherwise the warning dialog shows constantly and can't be dismissed.\n - Default: `30000` (30s).\n\n### Show the timeout preferences in TvSettings\n\nTo show the timeout preferences, update the following element in\n`packages/apps/TvSettings/Settings/res/values/config.xml`:\n\n- `config_show_standby_timeout`\n - Whether to show a preference item for allowing turning the screen off during media playback.\n - Default: `false`.\n\n### Resources for the warning UI\n\n- The layout of the warning dialog is defined in `frameworks/base/packages/SystemUI/res/layout/inattentive_sleep_warning.xml`.\n- The following strings for the dialog are defined in `frameworks/base/packages/SystemUI/res/values/strings.xml` and `frameworks/base/packages/SystemUI/res-product/values/strings.xml`.\n - `inattentive_sleep_warning_title`\n - `inattentive_sleep_warning_message`\n\nThe build time configurations and resources can be changed by resource overlays.\n\nImplementation\n--------------\n\nEnable the feature using the following.\n\n1. Override the default `config_attentiveTimeout`.\n2. If using the AOSP `TvSettings`:\n - Disable the feature in settings by overriding `config_show_standby_timeout`.\n - Implement your own settings that set `Settings.Secure.ATTENTIVE_TIMEOUT`.\n\nValidation\n----------\n\nThe CTS tests for the feature are at\n`cts/hostsidetests/os/src/android/os/cts/InattentiveSleepTests.java`.\n\nExamples and source\n-------------------\n\n- `frameworks/base/packages/SystemUI/src/com/android/systemui/power/InattentiveSleepWarningView.java` contains the default warning UI implementation.\n- `packages/apps/TvSettings` provides an example of how to expose the feature in settings.\n\nManual test case example\n------------------------\n\n1. Make sure the `stay_on_while_plugged_in`\n developer setting is off if the device's health HAL reports that the device has a\n battery (`battery_present` is `true`) as this might prevent the\n feature from turning off the screen. \n\n `adb shell settings put global stay_on_while_plugged_in 0`\n\n2. Set an inattentive sleep timeout to be a few seconds more than the warning dialog duration. \n `adb shell settings put secure attentive_timeout 32000`\n3. Start playing back a video (to acquire a screen wakelock).\n4. Verify that the sleep warning dialog appears after a few seconds.\n5. Verify that the screen turns off after the set timeout expires."]]