[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-06-12。"],[],[],null,["# Distraction optimization in Car Settings\n\n*[Distraction optimization (DO)](/docs/automotive/driver_distraction/guidelines)*\nis provided as a tool to reduce the driver's interaction with the Settings app while a\ncar is moving. Some settings may need to be changed while driving, so the app isn't\ncompletely blocked. However, by default, most preferences are disabled with only key and\neasily updated preferences being enabled.\n\n**Figure 1.** Enabled apps while driving\n\nEntire activities can also be blocked if they aren't distraction optimized,\nas shown below. This method is currently used primarily for settings search.\n\n**Figure 2.** All activities blocked\n\nBasic customizations to the performance of DO can be done through configuration\noverlays. If you require more fine-grained customization, additional changes can\nbe made through code.\n\nHigh-level customization\n------------------------\n\nWhen a preference is disabled while driving, tapping on it displays a toast\nmessage stating that the preference isn't available while driving, provided the preference\nhas a preference controller attached to it. The message uses the\n`restricted_while_driving` string, which can be customized with an overlay\n(provided the string is less than the 60-character limit).\n\n**Figure 3.** Customized overlay\n\n\nThe entire DO framework can be disabled using [config_always_ignore_ux_restrictions](https://android.googlesource.com/platform/packages/apps/Car/Settings/+/refs/heads/android11-release/res/values/config.xml#90).\nSetting this to true means that the driver can interact with every aspect of the\nSettings app. \n\n```scdoc\n\u003cbool name=\"config_always_ignore_ux_restrictions\"\u003etrue\u003c/bool\u003e\n```\n\n\nIf the configuration above is set to false, the Settings app falls back to`\n`[config_ignore_ux_restrictions](https://android.googlesource.com/platform/packages/apps/Car/Settings/+/refs/heads/android11-release/res/values/config.xml#92)\nto determine which preferences should be enabled while driving. The strings provided here\nshould point to the strings defined in `preference_keys.xml.`\n| **Note:** Placing a preference key in `config_ignore_ux_restrictions` only enables that specific preference while driving. To ensure the user can actually interact with a preference, double-check that all preferences in the navigation hierarchy are listed in `config_ignore_ux_restrictions`.\n\n### Example\n\n\nTo show how to enable a deeply nested setting while driving, this example\ndemonstrates how to enable the Text-to-Speech (TTS) output settings. For this to work,\nadd all the settings in the hierarchy to [config_ignore_ux_restrictions](https://android.googlesource.com/platform/packages/apps/Car/Settings/+/refs/heads/android11-release/res/values/config.xml#92).\nThis includes the system, languages and input, and TTS preferences to the config, since our hierarchy is\nSystem-\\\u003eLanguages \\& Input-\\\u003eText-to-speech output. However, the preferences\nwithin the text-to-speech fragment is still disabled. To enable them, we\nneed to add the keys for the preferences we want to be accessible. In this\nexample, we want to enable the playback preferences but not the engine\npreference so we add `pk_tts_playback_group` to our config. \n\n```transact-sql\n\u003cstring-array name=\"config_ignore_ux_restrictions\"\u003e\n [...]\n \u003citem\u003e@string/pk_system_settings_entry\u003c/item\u003e\n \u003citem\u003e@string/pk_languages_and_input_settings\u003c/item\u003e\n \u003citem\u003e@string/pk_tts_settings_entry\u003c/item\u003e\n \u003citem\u003e@string/pk_tts_playback_group\u003c/item\u003e\n\u003c/string-array\u003e\n```\n\nDetailed customization\n----------------------\n\nThere are some preferences that might require more customized behavior than\nsimply enabling/disabling a preference based on the driving state. For example,\nBluetooth and Wi-Fi have already been modified to show saved Bluetooth devices or\nWi-Fi access points while driving.\n\nCurrently there's no configuration based solution to make these kinds of\nadjustments. Instead you can create a custom class that extends\nPreferenceController and overrides `onApplyUxRestrictions()` to make the desired\nchanges.\n| **Note:** `onApplyUxRestrictions()` is called after `updateState()` when the preference controller is refreshing the UI.\n\nWhen a custom preference controller is created, you can overlay the relevant XML file\nto replace the default preference controller with your own implementation.\n\n### Examples\n\nIn CarSettings, some preferences have this more customized behavior, which can be\nused as examples for additional customization. For example, in the [Wi-Fi access point list](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/apps/Car/Settings/src/com/android/car/settings/wifi/WifiEntryListPreferenceController.java), the\ndesired behavior is to only show saved access points while driving (and hiding the rest).\nTo achieve this, do the following: \n\n```text\n} else if (shouldApplyUxRestrictions(getUxRestrictions())) {\n wifiEntries = getCarWifiManager().getSavedWifiEntries();\n} else {\n wifiEntries = getCarWifiManager().getAllWifiEntries();\n}\n```\n\nBecause the access points that appear here are already restricted, you\ndon't want to apply additional `UxRestrictions` to these preferences.\nTherefore, override `onApplyUxRestrictions` and perform an intentional\nno-op: \n\n```transact-sql\n@Override\nprotected void onApplyUxRestrictions(CarUxRestrictions uxRestrictions) {\n // Since the list dynamically changes based on the UX restrictions, we\n // enable this fragment regardless of the restriction. Intentional no-op.\n}\n```\n\nAnother example is provided in [Bluetooth-bonded devices](https://android.googlesource.com/platform/packages/apps/Car/Settings/+/refs/heads/android11-release/src/com/android/car/settings/bluetooth/BluetoothBondedDevicesPreferenceController.java?rcl=f428a3d50e5c475f9b565a49d64e1223a53f6cee&l=85).\nTo continue to enable Bluetooth devices to be connected to and disconnected from but wanted to\ndisable the ability to access additional settings for these devices. To achieve this, we\nagain override `onApplyUxRestrictions` but this time, if the `NO_SETUP`\nrestriction is active, hide the secondary action on the preference. \n\n```transact-sql\n@Override\nprotected void onApplyUxRestrictions(CarUxRestrictions uxRestrictions) {\n super.onApplyUxRestrictions(uxRestrictions);\n if (CarUxRestrictionsHelper.isNoSetup(uxRestrictions)) {\n updateActionVisibility(getPreference(), /* isActionVisible= */ false);\n }\n}\n```"]]