تغییرات رفتار: برنامه هایی که اندروید 16 یا بالاتر را هدف قرار می دهند

مانند نسخه‌های قبلی، اندروید ۱۶ شامل تغییرات رفتاری است که ممکن است بر برنامه شما تأثیر بگذارد. تغییرات رفتاری زیر منحصراً برای برنامه‌هایی اعمال می‌شود که اندروید ۱۶ یا بالاتر را هدف قرار می‌دهند. اگر برنامه شما اندروید ۱۶ یا بالاتر را هدف قرار می‌دهد، باید برنامه خود را برای پشتیبانی از این رفتارها، در صورت لزوم، اصلاح کنید.

حتماً فهرست تغییرات رفتاری که صرف نظر از targetSdkVersion برنامه شما، بر همه برنامه‌های در حال اجرا در اندروید ۱۶ تأثیر می‌گذارند را نیز بررسی کنید.

تجربه کاربری و رابط کاربری سیستم

اندروید ۱۶ (سطح API ۳۶) شامل تغییرات زیر است که برای ایجاد یک تجربه کاربری سازگارتر و شهودی‌تر در نظر گرفته شده‌اند.

کنار رفتن گزینه انصراف از لبه تا لبه

Android 15 强制执行全屏显示,但您的应用可以通过将 R.attr#windowOptOutEdgeToEdgeEnforcement 设置为 true 来选择停用此功能。对于以 Android 16(API 级别 36)为目标平台的应用,R.attr#windowOptOutEdgeToEdgeEnforcement 已被废弃并停用,并且您的应用无法选择不采用从边缘到边缘的布局。

  • 如果您的应用以 Android 16(API 级别 36)为目标平台,并且在 Android 15 设备上运行,则 R.attr#windowOptOutEdgeToEdgeEnforcement 会继续正常运行。
  • 如果您的应用以 Android 16(API 级别 36)为目标平台,并且在 Android 16 设备上运行,则 R.attr#windowOptOutEdgeToEdgeEnforcement 会被停用。

如需在 Android 16 中进行测试,请确保您的应用支持无边框设计,并移除所有 R.attr#windowOptOutEdgeToEdgeEnforcement 用法,以便您的应用在 Android 15 设备上也能支持无边框设计。如需支持从边缘到边缘的显示,请参阅 ComposeViews 指南。

مهاجرت یا انصراف برای بازگشت پیش‌بینی‌کننده الزامی است

对于以 Android 16(API 级别 36)或更高版本为目标平台且在搭载 Android 16 或更高版本的设备上运行的应用,预测性返回系统动画(返回主屏幕、跨任务和跨 activity)默认处于启用状态。此外,系统不再调用 onBackPressed,也不再调度 KeyEvent.KEYCODE_BACK

如果您的应用会拦截返回事件,但您尚未迁移到预测性返回,请更新应用以使用受支持的返回导航 API,或者通过在应用的 AndroidManifest.xml 文件的 <application><activity> 标记中将 android:enableOnBackInvokedCallback 属性设置为 false 来暂时选择停用。

预测性返回主页动画。
预测性跨 activity 动画。
预测性跨任务动画。

APIهای فونت Elegant منسوخ و غیرفعال شدند

Apps targeting Android 15 (API level 35) have the elegantTextHeight TextView attribute set to true by default, replacing the compact font with one that is much more readable. You could override this by setting the elegantTextHeight attribute to false.

Android 16 deprecates the elegantTextHeight attribute, and the attribute will be ignored once your app targets Android 16. The "UI fonts" controlled by these APIs are being discontinued, so you should adapt any layouts to ensure consistent and future proof text rendering in Arabic, Lao, Myanmar, Tamil, Gujarati, Kannada, Malayalam, Odia, Telugu or Thai.

elegantTextHeight behavior for apps targeting Android 14 (API level 34) and lower, or for apps targeting Android 15 (API level 35) that overrode the default by setting the elegantTextHeight attribute to false.
elegantTextHeight behavior for apps targeting Android 16 (API level 36), or for apps targeting Android 15 (API level 35) that didn't override the default by setting the elegantTextHeight attribute to false.

عملکرد اصلی

اندروید ۱۶ (سطح API ۳۶) شامل تغییرات زیر است که قابلیت‌های اصلی مختلف سیستم اندروید را اصلاح یا گسترش می‌دهد.

بهینه‌سازی زمان‌بندی کار با نرخ ثابت

قبل از هدف قرار دادن اندروید 16، زمانی که scheduleAtFixedRate اجرای یک کار را به دلیل خارج از چرخه حیات فرآیند معتبر از دست داد، همه اجراهای از دست رفته بلافاصله با بازگشت برنامه به چرخه حیات معتبر اجرا می شوند.

هنگام هدف قرار دادن Android 16، حداکثر یک اجرای از دست رفته scheduleAtFixedRate بلافاصله پس از بازگشت برنامه به چرخه حیات معتبر اجرا می شود. انتظار می رود این تغییر رفتار باعث بهبود عملکرد برنامه شود. این رفتار را در برنامه خود آزمایش کنید تا بررسی کنید آیا برنامه شما تحت تأثیر قرار گرفته است یا خیر. همچنین می‌توانید با استفاده از چارچوب سازگاری برنامه و فعال کردن پرچم سازگار STPE_SKIP_MULTIPLE_MISSED_PERIODIC_TASKS آزمایش کنید.

فاکتورهای شکل دستگاه

اندروید ۱۶ (سطح API ۳۶) شامل تغییرات زیر برای برنامه‌ها هنگام نمایش در دستگاه‌های صفحه نمایش بزرگ است.

طرح‌بندی‌های تطبیقی

现在,Android 应用可在各种设备(例如手机、平板电脑、可折叠设备、桌面设备、汽车和电视)上运行,并且在大屏设备上支持各种窗口模式(例如分屏和桌面窗口),因此开发者应构建能够适应任何屏幕和窗口尺寸的 Android 应用,无论设备方向如何。在当今的多设备世界中,限制屏幕方向和尺寸可调整性等范式过于严格。

忽略屏幕方向、尺寸可调整性和宽高比限制

对于以 Android 16(API 级别 36)为目标平台的应用,在最小宽度 >= 600dp 的显示屏上,屏幕方向、尺寸调整能力和宽高比限制不再适用。无论宽高比或用户偏好的屏幕方向如何,应用都会填满整个显示窗口,且不会采用竖屏模式。

此变更引入了新的标准平台行为。Android 正在向一种模型转变,在该模型中,应用需要适应各种屏幕方向、显示大小和宽高比。固定屏幕方向或有限的尺寸调整能力等限制会阻碍应用的适应性。使应用具有自适应性,以提供尽可能最佳的用户体验。

您还可以使用应用兼容性框架并启用 UNIVERSAL_RESIZABLE_BY_DEFAULT 兼容性标志来测试此行为。

常见的重大更改

忽略屏幕方向、可调整大小性和宽高比限制可能会影响应用在某些设备上的界面,尤其是那些专为锁定为纵向的小布局设计的元素,例如布局拉伸、动画和组件超出屏幕等问题。任何关于宽高比或屏幕方向的假设都可能导致应用出现视觉问题。详细了解如何避免这些问题并改进应用的自适应行为。

允许设备旋转会导致更多 activity 重新创建,如果未正确保留用户状态,可能会导致用户状态丢失。如需了解如何正确保存界面状态,请参阅保存界面状态

实现细节

在全屏模式和多窗口模式下,以下清单属性和运行时 API 会被大屏设备忽略:

系统会忽略 screenOrientationsetRequestedOrientation()getRequestedOrientation() 的以下值:

  • portrait
  • reversePortrait
  • sensorPortrait
  • userPortrait
  • landscape
  • reverseLandscape
  • sensorLandscape
  • userLandscape

对于显示屏可调整大小性,android:resizeableActivity="false"android:minAspectRatioandroid:maxAspectRatio 没有影响。

对于以 Android 16(API 级别 36)为目标平台的应用,默认情况下,大屏设备会忽略应用的屏幕方向、可调整尺寸性和宽高比限制,但尚未完全准备就绪的每个应用都可以选择停用此行为,从而暂时替换此行为(这会导致应用采用之前的行为,即放置在兼容模式下)。

异常

在以下情况下,Android 16 的屏幕方向、尺寸调整能力和宽高比限制不适用:

  • 游戏(基于 android:appCategory 标志)
  • 用户在设备的宽高比设置中明确选择启用应用的默认行为
  • 小于 sw600dp 的屏幕

暂时选择不接收

如需选择停用特定 activity,请声明 PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY 清单属性:

<activity ...>
  <property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY" android:value="true" />
  ...
</activity>

如果您的应用有太多部分尚未准备好支持 Android 16,您可以在应用级别应用同一属性,从而完全选择不启用该功能:

<application ...>
  <property android:name="android.window.PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY" android:value="true" />
</application>

سلامت و تناسب اندام

اندروید ۱۶ (سطح API ۳۶) شامل تغییرات زیر در رابطه با داده‌های سلامت و تناسب اندام است.

مجوزهای سلامت و تناسب اندام

For apps targeting Android 16 (API level 36) or higher, BODY_SENSORS permissions use more granular permissions under android.permissions.health, which Health Connect also uses. As of Android 16, any API previously requiring BODY_SENSORS or BODY_SENSORS_BACKGROUND requires the corresponding android.permissions.health permission instead. This affects the following data types, APIs, and foreground service types:

If your app uses these APIs, it should request the respective granular permissions:

These permissions are the same as those that guard access to reading data from Health Connect, the Android datastore for health, fitness, and wellness data.

Mobile apps

Mobile apps migrating to use the READ_HEART_RATE and other granular permissions must also declare an activity to display the app's privacy policy. This is the same requirement as Health Connect.

اتصال

اندروید ۱۶ (سطح API ۳۶) شامل تغییرات زیر در پشته بلوتوث برای بهبود اتصال با دستگاه‌های جانبی است.

اهداف جدید برای مدیریت از دست دادن اوراق قرضه و تغییرات رمزگذاری

作为改进了对键值对丢失的处理的一部分,Android 16 还引入了 2 个新 intent,以便应用更好地了解键值对丢失和加密更改。

以 Android 16 为目标平台的应用现在可以:

  • 在检测到远程键盘连接丢失时接收 ACTION_KEY_MISSING intent,以便提供更具信息量的用户反馈并采取适当的措施。
  • 每当链接的加密状态发生变化时,都会收到 ACTION_ENCRYPTION_CHANGE intent。这包括加密状态更改、加密算法更改和加密密钥大小更改。如果应用在稍后收到 ACTION_ENCRYPTION_CHANGE intent 时成功加密了链接,则必须将该绑定视为已恢复。

适应不同的 OEM 实现

虽然 Android 16 引入了这些新 intent,但其实现和广播可能会因不同的设备制造商 (OEM) 而异。为了确保您的应用在所有设备上都能提供一致且可靠的体验,开发者应设计其绑定丢失处理机制,以妥善适应这些潜在的变化。

我们建议您采用以下应用行为:

  • 如果广播 ACTION_KEY_MISSING intent:

    系统会断开 ACL(异步无连接)链接,但会保留设备的配对信息(如此处所述)。

    您的应用应将此 intent 用作检测配对丢失的主要信号,并在发起设备忘记或重新配对之前引导用户确认远程设备是否在范围内。

    如果设备在收到 ACTION_KEY_MISSING 后断开连接,您的应用应谨慎重新连接,因为设备可能已不再与系统绑定。

  • 如果未广播 ACTION_KEY_MISSING intent:

    ACL 链接将保持连接状态,系统会移除设备的配对信息,与 Android 15 中的行为相同。

    在这种情况下,您的应用应继续使用与之前的 Android 版本相同的现有配对丢失处理机制,以检测和管理配对丢失事件。

روش جدید برای حذف اتصال بلوتوث

All apps targeting Android 16 are now able to unpair bluetooth devices using a public API in CompanionDeviceManager. If a companion device is being managed as a CDM association, then the app can trigger bluetooth bond removal by using the new removeBond(int) API on the associated device. The app can monitor the bond state changes by listening to the bluetooth device broadcast event ACTION_BOND_STATE_CHANGED.

امنیت

اندروید ۱۶ (سطح API ۳۶) شامل تغییرات امنیتی زیر است.

قفل شدن نسخه MediaStore

برای برنامه‌هایی که اندروید 16 یا بالاتر را هدف قرار می‌دهند، MediaStore#getVersion() اکنون برای هر برنامه منحصر به فرد خواهد بود. این ویژگی های شناسایی را از رشته نسخه حذف می کند تا از سوء استفاده و استفاده از تکنیک های انگشت نگاری جلوگیری شود. برنامه ها نباید هیچ فرضی در مورد قالب این نسخه داشته باشند. برنامه‌ها از قبل باید هنگام استفاده از این API تغییرات نسخه را کنترل کنند و در بیشتر موارد نیازی به تغییر رفتار فعلی خود ندارند، مگر اینکه توسعه‌دهنده تلاش کرده باشد اطلاعات بیشتری را استنباط کند که فراتر از محدوده مورد نظر این API است.

مقاصد امن‌تر

The Safer Intents feature is a multi-phase security initiative designed to improve the security of Android's intent resolution mechanism. The goal is to protect apps from malicious actions by adding checks during intent processing and filtering intents that don't meet specific criteria.

In Android 15 the feature focused on the sending app, now with Android 16, shifts control to the receiving app, allowing developers to opt-in to strict intent resolution using their app manifest.

Two key changes are being implemented:

  1. Explicit Intents Must Match the Target Component's Intent Filter: If an intent explicitly targets a component, it should match that component's intent filter.

  2. Intents Without an Action Cannot Match any Intent Filter: Intents that don't have an action specified shouldn't be resolved to any intent filter.

These changes only apply when multiple apps are involved and don't affect intent handling within a single app.

Impact

The opt-in nature means that developers must explicitly enable it in their app manifest for it to take effect. As a result, the feature's impact will be limited to apps whose developers:

  • Are aware of the Safer Intents feature and its benefits.
  • Actively choose to incorporate stricter intent handling practices into their apps.

This opt-in approach minimizes the risk of breaking existing apps that may rely on the current less-secure intent resolution behavior.

While the initial impact in Android 16 may be limited, the Safer Intents initiative has a roadmap for broader impact in future Android releases. The plan is to eventually make strict intent resolution the default behavior.

The Safer Intents feature has the potential to significantly enhance the security of the Android ecosystem by making it more difficult for malicious apps to exploit vulnerabilities in the intent resolution mechanism.

However, the transition to opt-out and mandatory enforcement must be carefully managed to address potential compatibility issues with existing apps.

Implementation

Developers need to explicitly enable stricter intent matching using the intentMatchingFlags attribute in their app manifest. Here is an example where the feature is opt-in for the entire app, but disabled/opt-out on a receiver:

<application android:intentMatchingFlags="enforceIntentFilter">
    <receiver android:name=".MyBroadcastReceiver" android:exported="true" android:intentMatchingFlags="none">
        <intent-filter>
            <action android:name="com.example.MY_CUSTOM_ACTION" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.example.MY_ANOTHER_CUSTOM_ACTION" />
        </intent-filter>
    </receiver>
</application>

More on the supported flags:

Flag Name Description
enforceIntentFilter Enforces stricter matching for incoming intents
none Disables all special matching rules for incoming intents. When specifying multiple flags, conflicting values are resolved by giving precedence to the "none" flag
allowNullAction Relaxes the matching rules to allow intents without an action to match. This flag to be used in conjunction with "enforceIntentFilter" to achieve a specific behavior

Testing and Debugging

When the enforcement is active, apps should function correctly if the intent caller has properly populated the intent. However, blocked intents will trigger warning log messages like "Intent does not match component's intent filter:" and "Access blocked:" with the tag "PackageManager." This indicates a potential issue that could impact the app and requires attention.

Logcat filter:

tag=:PackageManager & (message:"Intent does not match component's intent filter:" | message: "Access blocked:")

فیلتر کردن فراخوانی‌های سیستمی GPU

To harden the Mali GPU surface, Mali GPU IOCTLs that have been deprecated or are intended solely for GPU development have been blocked in production builds. Additionally, IOCTLs used for GPU profiling have been restricted to the shell process or debuggable applications. Refer to the SAC update for more details on the platform-level policy.

This change takes place on Pixel devices using the Mali GPU (Pixel 6-9). Arm has provided official categorization of their IOCTLs in Documentation/ioctl-categories.rst of their r54p2 release. This list will continue to be maintained in future driver releases.

This change does not impact supported graphics APIs (including Vulkan and OpenGL), and is not expected to impact developers or existing applications. GPU profiling tools such as the Streamline Performance Analyzer and the Android GPU Inspector won't be affected.

Testing

If you see a SELinux denial similar to the following, it is likely your application has been impacted by this change:

06-30 10:47:18.617 20360 20360 W roidJUnitRunner: type=1400 audit(0.0:85): avc:  denied  { ioctl }
for  path="/dev/mali0" dev="tmpfs" ino=1188 ioctlcmd=0x8023
scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:gpu_device:s0 tclass=chr_file
permissive=0 app=com.google.android.selinux.pts

If your application needs to use blocked IOCTLs, please file a bug and assign it to android-partner-security@google.com.

FAQ

  1. Does this policy change apply to all OEMs? This change will be opt-in, but available to any OEMs who would like to use this hardening method. Instructions for implementing the change can be found in the implementation documentation.

  2. Is it mandatory to make changes in the OEM codebase to implement this, or does it come with a new AOSP release by default? The platform-level change will come with a new AOSP release by default. Vendors may opt-in to this change in their codebase if they would like to apply it.

  3. Are SoCs responsible for keeping the IOCTL list up to date? For example, if my device uses an ARM Mali GPU, would I need to reach out to ARM for any of the changes? Individual SoCs must update their IOCTL lists per device upon driver release. For example, ARM will update their published IOCTL list upon driver updates. However, OEMs should make sure that they incorporate the updates in their SEPolicy, and add any selected custom IOCTLs to the lists as needed.

  4. Does this change apply to all Pixel in-market devices automatically, or is a user action required to toggle something to apply this change? This change applies to all Pixel in-market devices using the Mali GPU (Pixel 6-9). No user action is required to apply this change.

  5. Will use of this policy impact the performance of the kernel driver? This policy was tested on the Mali GPU using GFXBench, and no measurable change to GPU performance was observed.

  6. Is it necessary for the IOCTL list to align with the current userspace and kernel driver versions? Yes, the list of allowed IOCTLs must be synchronized with the IOCTLs supported by both the userspace and kernel drivers. If the IOCTLs in the user space or kernel driver are updated, the SEPolicy IOCTL list must be updated to match.

  7. ARM has categorized IOCTLs as 'restricted' / 'instrumentation', but we want to use some of them in production use-cases, and/or deny others. Individual OEMs/SoCs are responsible for deciding on how to categorize the IOCTLs they use, based on the configuration of their userspace Mali libraries. ARM's list can be used to help decide on these, but each OEM/SoC's use-case may be different.

حریم خصوصی

اندروید ۱۶ (سطح API ۳۶) شامل تغییرات حریم خصوصی زیر است.

مجوز شبکه محلی

具有 INTERNET 权限的任何应用都可以访问局域网上的设备。 这使得应用可以轻松连接到本地设备,但也存在隐私影响,例如形成用户指纹,以及成为位置信息的代理。

本地网络保护项目旨在通过在新的运行时权限后限制对本地网络的访问,来保护用户的隐私。

发布计划

这项变更将在 25Q2 和 26Q2 这两个版本之间部署。 开发者必须遵循 25Q2 的相关指南并分享反馈,因为这些保护措施将在后续 Android 版本中强制执行。此外,他们还需要按照以下指南更新依赖于隐式本地网络访问权限的场景,并为用户拒绝和撤消新权限做好准备。

影响

在当前阶段,LNP 是一项选择启用功能,这意味着只有选择启用的应用会受到影响。选择启用阶段的目标是让应用开发者了解应用的哪些部分依赖于隐式本地网络访问权限,以便他们为下一个版本做好权限保护准备。

如果应用使用以下方式访问用户的本地网络,则会受到影响:

  • 在本地网络地址(例如 mDNS 或 SSDP 服务发现协议)上直接或通过库使用原始套接字
  • 使用可访问本地网络的框架级类(例如 NsdManager)

本地网络地址发送流量和本地网络地址接收流量需要本地网络访问权限。下表列出了一些常见情况:

应用低级层网络操作 需要本地网络权限
建立出站 TCP 连接
接受传入的 TCP 连接
发送 UDP 单播、多播、广播
接收传入的 UDP 单播、多播、广播

这些限制是在网络堆栈深处实现的,因此适用于所有网络 API。这包括在原生代码或受管理代码中创建的套接字、Cronet 和 OkHttp 等网络库,以及基于这些库实现的任何 API。尝试解析本地网络上的服务(即带有 .local 后缀的服务)将需要本地网络权限。

上述规则的例外情况:

  • 如果设备的 DNS 服务器位于本地网络上,则进出该服务器(位于端口 53)的流量不需要本地网络访问权限。
  • 如果应用使用输出切换器作为其应用内选择器,则无需本地网络权限(更多指南将在 2025 年第 4 季度发布)。

开发者指南(选择启用)

如需选择启用本地网络限制,请执行以下操作:

  1. 将设备刷写到 25Q2 Beta 3 或更高版本的 build。
  2. 安装要测试的应用。
  3. 在 adb 中切换 Appcompat 标志:

    adb shell am compat enable RESTRICT_LOCAL_NETWORK <package_name>
    
  4. 重启设备

现在,您的应用对本地网络的访问受到限制,任何访问本地网络的尝试都会导致套接字错误。如果您使用的 API 在应用进程之外执行本地网络操作(例如:NsdManager),在选择启用阶段,这些 API 不会受到影响。

如需恢复访问权限,您必须向应用授予 NEARBY_WIFI_DEVICES 权限。

  1. 确保应用在其清单中声明了 NEARBY_WIFI_DEVICES 权限。
  2. 依次前往设置 > 应用 > [应用名称] > 权限 > 附近的设备 > 允许

现在,应用对本地网络的访问权限应该已恢复,并且所有场景都应像选择启用应用之前一样正常运行。

本地网络保护功能开始强制执行后,应用的网络流量将受到以下影响。

权限 出站 LAN 请求 出站/入站互联网请求 入站 LAN 请求
已授予 Works Works Works
未授予 最差排行榜 Works 最差排行榜

使用以下命令切换关闭应用兼容性标志

adb shell am compat disable RESTRICT_LOCAL_NETWORK <package_name>

错误

每当调用套接字调用 send 或 send 变体向本地网络地址发送数据时,系统都会向该套接字返回因这些限制而产生的错误。

错误示例:

sendto failed: EPERM (Operation not permitted)

sendto failed: ECONNABORTED (Operation not permitted)

本地网络定义

此项目中的本地网络是指使用支持广播的网络接口(例如 Wi-Fi 或以太网)的 IP 网络,但不包括移动网络 (WWAN) 或 VPN 连接。

以下网络被视为本地网络:

IPv4

  • 169.254.0.0/16 // 链路本地
  • 100.64.0.0/10 // CGNAT
  • 10.0.0.0/8 // RFC1918
  • 172.16.0.0/12 // RFC1918
  • 192.168.0.0/16 // RFC1918

IPv6

  • 链路本地
  • 直接连接的路线
  • Thread 等桩网络
  • 多个子网(待定)

此外,多播地址 (224.0.0.0/4、ff00::/8) 和 IPv4 广播地址 (255.255.255.255) 都归类为本地网络地址。

عکس‌های متعلق به برنامه

When prompted for photo and video permissions by an app targeting SDK 36 or higher on devices running Android 16 or higher, users who choose to limit access to selected media will see any photos owned by the app pre-selected in the photo picker. Users can deselect any of these pre-selected items, which will revoke the app's access to those photos and videos.