Android 高级保护模式 (AAPM) 是 Android 16 中推出的一项新功能,旨在为面临风险的用户(例如记者和活动家)增强 Android 设备的安全性。它充当一个设置,用于实现一组预先确定的配置,旨在加强设备保护。 AAPM 会优先考虑安全性,而不是某些可能会降低的功能和易用性,这意味着某些功能可能会受到限制,以最大限度地缩小受攻击面。
影响
AAPM 会更改某些系统服务的行为,以增强安全性。如果您的应用面向注重安全性的用户,则必须适应这些限制。
- 系统信号:当用户启用 AAPM 时,系统会通知已订阅的应用,以便这些应用适应受限的环境。
- 所需的应用修改:您必须更新应用,以处理由 AAPM 触发的行为变更。例如,您的应用必须考虑以下情况:
- 停用 2G 和 WEP 网络连接。
- 屏蔽应用旁加载。
- 启用取证日志记录。
- 屏蔽来自未知号码的来电。
- 为即时通讯应用中的链接启用垃圾信息防护机制。
- 其他自定义缓解措施,以保护面临风险的用户
与 AAPM 集成
如需使用相关 API,需要声明以下权限。
获取权限
<uses-permission android:name="android.permission.QUERY_ADVANCED_PROTECTION_MODE" />
查看状态
检查用户是否已在设备中启用 AAPM。此操作通过使用 AdvancedProtectionManager 系统服务完成。
import android.security.advancedprotection.AdvancedProtectionManager
// ... inside your Activity or Service
val aapmManager = getSystemService(AdvancedProtectionManager::class.java)
if (aapmManager?.isAdvancedProtectionEnabled) {
// 🛡️ User is in Advanced Protection Mode.
// Engage shields: Disable risky features, enforce stricter authentication.
// TODO: Add Method which implements extra protections
}
监听运行时变更
用户可以在应用运行时开启或关闭 AAPM。注册回调 以接收实时更新。
import android.security.advancedprotection.AdvancedProtectionManager
import java.util.concurrent.Executor
// Define the callback
val aapmCallback = AdvancedProtectionManager.Callback { isEnabled ->
if (isEnabled) {
// TODO: User just engaged protections. Lock it down!
} else {
// TODO: User disabled protections. You may relax restrictions.
}
}
// Register the callback (for example, in onStart)
// Ensure you use the correct executor (for example, mainExecutor for UI updates)
aapmManager?.registerAdvancedProtectionCallback(mainExecutor, aapmCallback)