自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
隐私指示标志
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
利用 Android 6 及更高版本中的运行时权限,用户可以控制何时允许通过设备麦克风录制音频或通过设备摄像头录制视频。用户必须先通过系统显示的对话框向应用授予或拒绝授予权限,然后应用才能录制。
在应用通过摄像头和麦克风应用操作权限使用专用数据源时,Android 12 会显示指示标志,以便用户了解此情况。应用操作记录对运行时权限保护的 API 的访问权限。
应用操作会跟踪 activity 状态和单个 API 调用的次数,并与 Android 12 中的麦克风和摄像头指示标志交互,以便在应用访问用户设备上的音频和摄像头数据时向用户显示。当用户点击麦克风或摄像头指示标志时,他们会看到哪些应用访问过其数据。所有 OEM 都必须启用此功能。
指示标志可见性要求
以下是搭载 Android 12 或更高版本的设备对麦克风和摄像头指示标志的要求:
- 指示标志必须显示在状态栏中,并保持在视觉上最显眼(例如,显示在右上角最右侧的位置)。
- 指示标志必须始终位于相同的位置,并且在启动时不得被应用阻止。
- 这两个指示标志必须采用绿色(或绿色的变体)。
- 点击其中一个或两个指示标志必须呈现执行以下操作的应用归因方式通知:
- 显示使用麦克风和/或摄像头的应用的名称
- 显示过去 15 秒内使用过麦克风和/或摄像头的应用的名称
- 将用户引导至设置中的应用权限页面
使用情况和功能
在 Android 12 中,界面会区分正在运行使用情况和近期使用情况。如果使用情况被系统标记为“正在运行”或使用时间少于 5 秒,则会被视为“有效”。
- 每当应用具有用户敏感的麦克风或摄像头访问权限时,就会显示状态栏图标。
- 用户可以点击这些图标,查看哪些应用正在使用麦克风和/或摄像头。
图 1. 麦克风和摄像头使用中指示标志表明访问权限有效(右上角)
只要指标标志显示,访问权限就会被视为有效。首先显示图标,然后转换为圆点,直到应用删除或关闭为止。
当用户打开“快捷设置”并点按指示标志时,系统会显示一个对话框,其中显示应用是否正在使用摄像头和/或麦克风。
图 2.有效和近期访问权限指示标志
图 2 中的图像显示了正在运行的应用在过去 5 秒内访问数据时的有效访问权限指示标志。
近期访问权限指示标志显示应用在过去 15 秒内访问过数据,但应用未处于活跃状态。对话框中会显示所有活跃应用,但只有一个应用显示为近期访问权限的来源,即使有多个应用在前 15 秒内访问过数据也是如此。除非用户关闭通知对话框,否则访问权限视图将保持冻结状态。
投放并启用
PermissionManager
类提供了用于填充对话框的方法,该对话框位于系统界面中。
- 系统界面会对设备配置开关做出反应:
privacy/mic_camera_indicators_enabled
。
- 这种切换是必要的,因为有两辆单独的送货车辆,按以下顺序排列:
- 投放。
- 启用。
- 如果
PermissionManager
中的方法无法提供所需的数据,系统界面不得崩溃。
处理流程
权限指示标志功能有三个主要部分:
- 应用
- 指示标志(由 SystemUI 处理)
- 确定哪些应用正在使用数据的方式
PermissionController
提供了确定哪些应用正在使用数据的机制。SystemUI 使用私有数据监听应用。SystemUI 会在顶部导航栏中显示与所用权限对应的图标。当用户点击某个图标时,PermissionController
会显示与使用情况相关的数据。
图 3. 系统组件和(界面)转换流程
图 3 中的编号转换如下所述:
1- 应用向系统请求私有数据。
2- 系统会检查权限。如果授予相应权限,系统会通知数据提供方,并在应用操作中记录使用情况
3- 数据提供方会向应用提供数据。
4-5 用户点击图标。系统界面从 PermissionManager
请求数据,并向用户呈现对话框。
处理详情
- 应用使用麦克风和摄像头,分别调用
AppOpsManager.startOp
、stopOp
和/或 noteOp
。这将在系统服务器中创建应用操作记录。
- 系统界面使用
AppOpsManager.OnOpActiveChangedInternalListener
和 OnOpNotedListener
监听器监听新的应用操作。出现新的用法(通过调用 startOp
或 noteOp
)时,系统界面会验证使用情况是否是通过系统应用。
- 如果系统界面验证了系统应用的使用情况,并且如果需要验证麦克风的使用情况,则系统界面会检查麦克风是否已静音。
- 如果系统界面验证非系统应用的使用情况(对于麦克风使用情况,麦克风未静音;对于摄像头使用情况,摄像头已开启),则会显示代表此类使用情况的图标。
如果系统界面收到未设置时长的 noteOp
,则会显示图标至少 5 秒。否则,此图标会显示,直到接收 stopOp
或显示 5 秒(以较短者为准)。用户点击图标会启动一个 intent,该 intent 会转到 PermissionController
以启动对话框。
PermissionController
会加载麦克风和摄像头的所有近期使用情况。它会检查其中任何一个是否正在运行,或是否正在系统界面所设置的时间范围内运行。如果找到匹配项,它会显示使用该权限的应用名称以及该应用使用的权限。
由于 Android 12 及更高版本中的这项变更,某些应用必须更改其行为或实现特殊行为。
在使用 Android Google 搜索应用 (AGSA) 和 Google 移动服务 (GMS) 时,Telephony 必须实现权限使用情况(以便将致电中单独的麦克风堆栈考虑在内)。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-09。
[[["易于理解","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-09。"],[],[],null,["# Privacy indicators\n\nRuntime permissions in Android 6 and higher give users control over when they\nallow audio from a device's microphone or video from a device's camera to be\nrecorded. Before an app can record, a user must either grant or deny it\npermission through a dialog the system presents.\n\nAndroid 12 provides users with transparency by\ndisplaying indicators when an app uses a *private* data source through the cameras\nand microphone [app-op permissions](https://developer.android.com/reference/android/app/AppOpsManager#app-op-permissions).\nApp-ops record accesses to runtime permission-protected APIs.\n\nApp-op tracks both the activity status and the number of individual API calls,\nand interacts with the microphone and camera indicators in Android 12\nto show users when apps have accessed audio and camera data on their devices.\nWhen users click the microphone or camera indicators, they see which apps have\naccessed their data. This feature is mandatory for all OEMs.\n\nIndicator visibility requirements\n---------------------------------\n\nThese are the requirements for microphone and camera indicators on devices\nrunning on Android 12 or higher:\n\n- The indicators must appear in the status bar, and retain the highest visual priority (for example, located at the rightmost position in the top-right corner).\n- The indicators must be consistently located in the same position, and must not be blocked by an app when it launches.\n- Both indicators *must* be green (or a variation of green) in color.\n- Clicking one or both indicators *must* render an app attribution affordance notification that does the following:\n - Displays the name of the app that's using the microphone and (or) camera\n - Displays the name of the app which used the microphone and (or) camera within the last 15 seconds\n - Takes users to the app permission page in **Settings**\n\nUsage and features\n------------------\n\nIn Android 12, the UI distinguishes between\nrunning usages and recent usages. Usages are considered active if they're either\nmarked by the system as running, or are less than 5 seconds old.\n\n- Status bar icons show each time an app has ongoing user-sensitive microphone or camera access.\n- Users can click these icons and see which apps are accessing the microphone, the camera, or both.\n\n**Figure 1.** Microphone and camera in-use indicators showing active access (top-right corner)\n\nAccess is considered active for as long as the indicators show. An icon shows\nfirst, then transitions to a dot that persists until the app is either dismissed\nor closed.\n\nWhen a user opens Quick Settings and then taps the indicators, a dialog appears\nthat shows whether the app is using the camera, the microphone, or both.\n\n**Figure 2.** Active and recent access indicators\n\nThe image in **Figure 2** shows active access indicators when data has been\naccessed in the past 5 seconds by a running app.\n\nRecent access indicators show that data was accessed by an app during the prior\n15 seconds, but that the app isn't active. All active apps show in the\ndialogue, but only one app shows as the source of recent access, even when more\nthan 1 app accessed data within a prior 15 second time-frame. The access view\nremains frozen until the user dismisses the notification dialog.\n\n### Deliver and enable\n\nThe `PermissionManager` class provides a method to populate the dialog, which\nresides in System UI.\n\n- System UI reacts to a device configuration switch: `privacy/mic_camera_indicators_enabled`.\n- The switch is necessary because there are two separate delivery vehicles, in this order:\n 1. Deliver.\n 2. Enable.\n- The System UI must not crash if the method in `PermissionManager` can't provide the needed data.\n\nProcess flow\n------------\n\nThe Permission Indicator functionality has three main parts:\n\n- The apps\n- The indicators (handled by SystemUI)\n- A way to determine which apps are using the data\n\nThe `PermissionController` provides the mechanism to determine which apps are\nusing data. SystemUI listens for apps using private data. The SystemUI shows an\nicon in the top navigation bar that corresponds to the permissions used. The\n`PermissionController` displays data about usages when a user clicks an icon.\n\n**Figure 3.** System components and (UI) transitions flow\n\nThe numbered transitions in **Figure 3** are described below:\n\n**1-** An app requests private data from the system.\n\n**2-** The system checks permissions. If the permissions are allowed, the system\nnotifies the data provider, and notes the usage in app-ops\n\n**3-** The data provider gives data to the app.\n\n**4-5** The user clicks the icons. System UI requests data from the\n`PermissionManager` and presents the dialog to the user.\n\n### Process details\n\n1. Apps use the microphone and camera, calling`AppOpsManager.startOp`, `stopOp`, and (or) `noteOp`. This creates app-op records in the system server.\n2. The System UI listens for new app-ops using the `AppOpsManager.OnOpActiveChangedInternalListener` and `OnOpNotedListener` listeners. When a new usage comes in (through a call to either `startOp` or `noteOp`), the System UI verifies that the usage is by a system app.\n3. If System UI verifies system app usage, and if the usage is for the microphone, System UI checks if the microphone is muted.\n4. If System UI verifies non-system app usage, (and, for microphone usage, that the microphone is unmuted; for camera usage, that the camera is toggled on), it shows an icon reflecting such usage.\n\nIf System UI receives a `noteOp`, which has no duration, it shows the icon for\nat least 5 seconds. Otherwise, the icon shows either until it receives a\n`stopOp`, or for 5 seconds, whichever is longer. The user clicking an icon\ninitiates an intent that goes to the `PermissionController` to start the Dialog.\n\nThe `PermissionController` loads all recent usage for microphone and camera. It\nchecks if any of those are running, or were running within the timeframe\nset by System UI. If it finds a match, it displays the name of the app\nthat used the permission, and which permissions the app used.\n\nBecause of this change in Android 12 and higher,\nsome apps must either change their behavior or implement special behavior.\n\nTelephony must implement permission usage (to account for the separate\nmicrophone stack used in phone calls), while working with Android Google Search\napp (AGSA) and Google Mobile Services (GMS)."]]