A partire dal 27 marzo 2025, ti consigliamo di utilizzare android-latest-release anziché aosp-main per compilare e contribuire ad AOSP. Per ulteriori informazioni, vedi Modifiche ad AOSP.
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
In Android 11, la sospensione in caso di disattenzione è una funzionalità di risparmio energetico
che consente di impostare un timeout di inattività dell'utente dopo il quale lo schermo si spegne, anche
se le finestre con FLAG_KEEP_SCREEN_ON
sono visibili o se sono attivi wakelock di livello
FULL_WAKE_LOCK,
SCREEN_BRIGHT_WAKE_LOCK o
SCREEN_DIM_WAKE_LOCK.
I wakelock con livello PARTIAL_WAKE_LOCK non sono interessati da questa funzionalità.
Poco prima della scadenza del timeout, può essere visualizzato un messaggio che avvisa l'utente che il dispositivo entrerà in modalità di sospensione se non interagisce con esso.
In questo contesto, l'attività utente si riferisce a qualsiasi elemento che attiva una chiamata a PowerManager#userActivity (senza il flag USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS), inclusi, a titolo esemplificativo:
Interazione con il touchscreen
Premendo un pulsante fisico
Eventi di input da un accessorio esterno (ad esempio tastiera connessa, telecomando Bluetooth,
telecomando a infrarossi)
Interazione vocale
Ricezione di determinati messaggi HDMI-CEC, ad esempio One Touch Play
Avvio di una nuova sessione di trasmissione
Personalizzazione
Se la funzionalità è attiva, il dispositivo mostra un avviso sullo schermo dopo un determinato periodo di inattività dell'utente. Se non viene eseguita alcuna azione, lo schermo si spegne. Puoi personalizzare la funzionalità utilizzando queste opzioni di configurazione.
Configura il timeout
Per configurare il timeout, aggiorna il seguente elemento in
frameworks/base/core/res/res/values/config.xml:
config_attentiveTimeout
Specifica il tempo predefinito in millisecondi di inattività dell'utente trascorso il quale lo schermo si spegne
(anche se sono presenti wakelock dello schermo).
Impostato al momento della compilazione.
Se il valore è compreso tra 0 e config_minimumScreenOffTimeout,
il timeout viene impostato su config_minimumScreenOffTimeout per impedire al dispositivo di
disattivare lo schermo poco dopo il risveglio.
Valore predefinito: -1, che disattiva questa funzionalità.
Sostituisci il timeout predefinito
Per eseguire l'override dell'impostazione di timeout predefinita, aggiorna il seguente elemento.
Settings.Secure.ATTENTIVE_TIMEOUT
Se impostato, sostituisce il valore predefinito del timeout di sospensione per inattività impostato da
config_attentiveTimeout.
Può essere impostato in fase di runtime.
Configura la durata prima della visualizzazione dell'avviso
Per configurare la durata, aggiorna il seguente elemento in
frameworks/base/core/res/res/values/config.xml:
config_attentiveWarningDuration
Il tempo per cui mostrare un messaggio di avviso all'utente prima che lo schermo si spenga dopo un periodo di inattività prolungato.
Il valore deve essere molto inferiore al tempo di spegnimento per inattività impostato, altrimenti la finestra di dialogo di avviso viene visualizzata costantemente e non può essere ignorata.
Valore predefinito: 30000 (30 secondi).
Mostrare le preferenze di timeout in TvSettings
Per mostrare le preferenze di timeout, aggiorna il seguente elemento in
packages/apps/TvSettings/Settings/res/values/config.xml:
config_show_standby_timeout
Indica se mostrare un elemento di preferenza per consentire lo spegnimento dello schermo durante la riproduzione di contenuti multimediali.
Valore predefinito: false.
Risorse per l'interfaccia utente dell'avviso
Il layout della finestra di dialogo di avviso è definito in
frameworks/base/packages/SystemUI/res/layout/inattentive_sleep_warning.xml.
Le seguenti stringhe per la finestra di dialogo sono definite in
frameworks/base/packages/SystemUI/res/values/strings.xml e
frameworks/base/packages/SystemUI/res-product/values/strings.xml.
inattentive_sleep_warning_title
inattentive_sleep_warning_message
Le configurazioni e le risorse in fase di compilazione possono essere modificate dagli overlay delle risorse.
Implementazione
Attiva la funzionalità utilizzando quanto segue.
Sostituisci il valore predefinito config_attentiveTimeout.
Se utilizzi AOSP TvSettings:
Disattiva la funzionalità nelle impostazioni impostando config_show_standby_timeout.
Implementa le tue impostazioni
che impostano Settings.Secure.ATTENTIVE_TIMEOUT.
Convalida
I test CTS per la funzionalità sono disponibili al sito
cts/hostsidetests/os/src/android/os/cts/InattentiveSleepTests.java.
packages/apps/TvSettings fornisce un esempio di come mostrare la funzionalità nelle impostazioni.
Esempio di scenario di test manuale
Assicurati che l'impostazione per gli sviluppatori stay_on_while_plugged_in
sia disattivata se l'HAL di stato del dispositivo segnala che il dispositivo ha una batteria (battery_present è true), in quanto ciò potrebbe impedire alla funzionalità di spegnere lo schermo. adb shell settings put global stay_on_while_plugged_in 0
Imposta un timeout di sospensione per inattività di qualche secondo più lungo della durata della finestra di dialogo di avviso. adb shell settings put secure attentive_timeout 32000
Avvia la riproduzione di un video (per acquisire un blocco schermo).
Verifica che la finestra di dialogo di avviso di sospensione venga visualizzata dopo alcuni secondi.
Verifica che lo schermo si spenga al termine del timeout impostato.
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-07-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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."]]