自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
在驾车会话之间保持热点
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页介绍了如何让用户在驾驶会话之间保持热点连接,类似于 AAOS 中的 Wi-Fi 驾驶体验。
public class CarSettings {
...
@SystemApi
public static final class Global {
...
/**
* Enables persistent tethering when set to {@code "true"}.
*
* <p>When enabled, tethering is started when the car is started given
* that the hotspot was enabled at shutdown and all tethering sessions
* will remain on even if no devices are connected to it.
*
* <p>When disabled, hotspot will turn off automatically if no devices
* are connected and will no longer persist through drives.
*
* @hide
*/
@SystemApi
public static final String ENABLE_PERSISTENT_TETHERING =
"android.car.ENABLE_PERSISTENT_TETHERING";
}
}
如需保留网络共享,请通过 Settings API 使用 ENABLE_PERSISTENT_TETHERING
,该 API 还可用于查询。
权限
CarWifiManager API 的使用受到限制。创建此新权限是为了保护访问权限。
public boolean canControlPersistApSettings() { ... }
此权限的保护级别如下:
是否新权限 |
权限 |
保护级别 |
是 |
READ_PERSIST_TETHERING_SETTINGS |
签名 | 特许 |
保留行为默认为“不受支持”。资源叠加层 (config_enablePersistTetheringCapabilities
) 已配置为阻止保留网络共享。如需有意保留网络共享功能,即使用户的偏好为选择启用此功能,也要将值设为 true
来明确启用此功能,因为具有 WRITE_SECURE_SETTINGS
权限的其他系统应用也可以控制此设置。
以下 API 可确定该行为是否已启用。在更改 ENABLE_PERSISTENT_TETHERING
之前调用此 API。
/**
* CarWifiManager provides API to allow for applications to perform Wi-Fi specific
* operations.
*
* @hide
*/
@SystemApi
public final class CarWifiManager extends CarManagerBase {
/**
* Returns {@code true} if the persist tethering settings are able to be
* changed.
*
* @hide
*/
@SystemApi
@RequiresPermission(Car.PERMISSION_READ_PERSIST_TETHERING_SETTINGS)
public boolean canControlPersistApSettings() { ... }
}
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","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-03-26。"],[],[],null,["# Maintain hotspots between driving sessions\n\nThis page describes how you can set up users to maintain hotspots between\ndriving sessions, similar to the Wi-Fi driving experience in AAOS. \n\n public class CarSettings {\n ...\n\n @SystemApi\n public static final class Global {\n ...\n\n /**\n * Enables persistent tethering when set to {@code \"true\"}.\n *\n * \u003cp\u003eWhen enabled, tethering is started when the car is started given\n * that the hotspot was enabled at shutdown and all tethering sessions\n * will remain on even if no devices are connected to it.\n *\n * \u003cp\u003eWhen disabled, hotspot will turn off automatically if no devices\n * are connected and will no longer persist through drives.\n *\n * @hide\n */\n @SystemApi\n public static final String ENABLE_PERSISTENT_TETHERING =\n \"android.car.ENABLE_PERSISTENT_TETHERING\";\n }\n }\n\nTo persist tethering, use `ENABLE_PERSISTENT_TETHERING` through the\n[Settings API](https://developer.android.com/reference/android/provider/Settings.Global#public-methods),\nwhich can also be used to query.\n\n### Permissions\n\nUse of the CarWifiManager API is restricted. This new permission is created to\nguard access. \n\n public boolean canControlPersistApSettings() { ... }\n\nProtection levels for this permission are:\n\n| New permission | Permission | Protection level |\n|----------------|-----------------------------------|-------------------------|\n| Yes | `READ_PERSIST_TETHERING_SETTINGS` | Signature \\| Privileged |\n\nThe persist behavior defaults to *not supported.* A resource overlay\n([`config_enablePersistTetheringCapabilities`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/services/Car/service/res/values/config.xml;l=644)) is configured to block the\nability to persist tethering. To intentionally persist tethering, set the\nvalue to `true` to enable the feature on top of the user preference\nopt-in since other system apps with the `WRITE_SECURE_SETTINGS` permission can\nalso control this setting.\n\nThe following API determines if the behavior is enabled. Call this API before\nyou change `ENABLE_PERSISTENT_TETHERING`. \n\n /**\n * CarWifiManager provides API to allow for applications to perform Wi-Fi specific\n * operations.\n *\n * @hide\n */\n @SystemApi\n public final class CarWifiManager extends CarManagerBase {\n /**\n * Returns {@code true} if the persist tethering settings are able to be\n * changed.\n *\n * @hide\n */\n @SystemApi\n @RequiresPermission(Car.PERMISSION_READ_PERSIST_TETHERING_SETTINGS)\n public boolean canControlPersistApSettings() { ... }\n }"]]