پلتفرم اندروید ۱۷ شامل تغییرات رفتاری است که ممکن است بر برنامه شما تأثیر بگذارد. تغییرات رفتاری زیر برای همه برنامهها هنگام اجرا در اندروید ۱۷، صرف نظر از targetSdkVersion ، اعمال میشود. شما باید برنامه خود را آزمایش کنید و سپس در صورت لزوم، آن را برای پشتیبانی از این تغییرات، در صورت لزوم، اصلاح کنید.
حتماً فهرست تغییرات رفتاری که فقط بر برنامههای اندروید ۱۷ تأثیر میگذارند را نیز بررسی کنید.
عملکرد اصلی
اندروید ۱۷ (سطح API ۳۷) شامل تغییرات زیر است که قابلیتهای اصلی مختلف سیستم اندروید را اصلاح یا گسترش میدهد.
محدودیتهای حافظه برنامه
Android 17 introduces app memory limits based on the device's total RAM to create a more stable and deterministic environment for your apps and Android users. In Android 17, limits are set conservatively to establish system baselines, targeting extreme memory leaks and other outliers before they trigger system-wide instability resulting in UI stuttering, higher battery drain, and apps being killed. While we anticipate minimal impact on the vast majority of app sessions, we recommend the following memory best practices, including establishing a baseline for memory.
You can determine if your app session was impacted by calling
getDescription in ApplicationExitInfo; if your app was
affected, the exit reason will be REASON_OTHER and
the description will contain the string "MemoryLimiter:AnonSwap" along with
other information. You can also use trigger-based profiling with
TRIGGER_TYPE_ANOMALY to get heap dumps that are collected when the
memory limit is hit.
The Manage your app's memory documentation gives information to help you diagnose your app's memory issues and optimize its resource consumption.
Test your app's behavior under the memory constraints
You can use Android Debug Bridge (adb) to adjust or disable the
memory limits on any device that imposes them. The shell command am
provides three subcommands to adjust the memory limits. (These commands have
no effect on a device which does not impose memory limits.)
am memory-limiter ignore <uid>|none|allam memory-limiter manual <pid> <limit>|max|noneam memory-limiter status
ignoreInstructs the memory limiter to ignore some or all processes. Passing a UID (Android User ID) instructs the memory limiter to ignore enforcement on all processes associated with that UID. You can also pass
all(ignore all apps) ornone(do not ignore any apps). Passingnoneoverrides any previous calls toam memory-limiter ignore.If you instruct the memory limiter to ignore a UID, you can still apply a manual memory limit to a process within the app by calling
am memory-limiter manual.manualInstructs the system to impose a memory constraint on the process with the specified PID (Process ID). The memory constraint is specified as an integer number of MB; for example, passing
30specifies that the process is limited to 30 MB of memory. Passingmaxremoves all memory limits on that process. Passingnoneremoves any manual limits set on the process, restoring the system's default limit (if any).statusReports the current status of the memory limiter. The status includes the memory limits imposed on visible and non-visible processes.
حریم خصوصی
اندروید ۱۷ شامل تغییرات زیر برای بهبود حریم خصوصی کاربران است.
محافظت از طریق OTP در پیامک
Beginning with Android 17, Android is expanding its protection for SMS messages containing one-time passwords (OTP).
In previous versions of Android, this protection was primarily focused on the SMS Retriever format. Delivery of messages containing an SMS retriever hash was delayed for most apps for three hours. However, certain apps (like the default SMS handler) were exempt from the delay, and the app that owned the hash was also exempted.
Beginning with Android 17, the protection is also applied to WebOTP format messages. If an app has permission to read SMS messages but is not the intended recipient of a WebOTP message (as determined by domain verification), the message is not accessible to the app until three hours after the message's receipt. This change is intended to improve user security by ensuring that only apps associated with the domain mentioned in the message can programmatically read the verification code.
During this three hour delay, the SMS_RECEIVED_ACTION broadcast is
withheld and SMS provider database queries are filtered. The
SMS message is available to these apps after the delay. This change applies to
all apps, regardless of their target API level.
Certain apps such as the default SMS assistant app, connected device companion apps, etc., are exempted from this delay. All apps that rely on reading SMS messages for OTP extraction should transition to using SMS Retriever or SMS User Consent APIs to ensure continued functionality.
امنیت
اندروید ۱۷ شامل بهبودهای زیر در امنیت دستگاه و برنامهها است.
طرح منسوخشدهی usesClearTraffic
我们计划在未来的版本中弃用 usesCleartextTraffic 元素。需要建立未加密 (HTTP) 连接的应用应迁移为使用网络安全配置文件,该文件可让您指定应用需要与哪些网域建立明文连接。
请注意,网络安全配置文件仅在 API 级别 24 及更高版本中受支持。如果您的应用的最低 API 级别低于 24,您应执行以下两项操作:
- 将
usesCleartextTraffic属性设置为true - 使用网络配置文件
如果应用的最低 API 级别为 24 或更高,您可以使用网络配置文件,而无需设置 usesCleartextTraffic。
محدود کردن مجوزهای ضمنی URI
目前,如果应用启动的 intent 具有 URI,且该 URI 具有操作
ACTION_SEND、ACTION_SEND_MULTIPLE或
ACTION_IMAGE_CAPTURE,则系统会自动向目标应用授予读取和
写入 URI 权限。从 Android 18 开始,系统将
不再自动授予这些权限。因此,我们建议应用明确授予相关 URI 权限,而不是依赖系统授予这些权限。
如需检测应用中这些 intent 的使用情况,请将 StrictMode 与
detectImplicitUriPermissionGrant() 结合使用,以触发违规行为:
Kotlin
val policy = StrictMode.VmPolicy.Builder() .detectImplicitUriPermissionGrant() .penaltyLog() .build() StrictMode.setVmPolicy(policy)
Java
StrictMode.VmPolicy policy = new StrictMode.VmPolicy.Builder() .detectImplicitUriPermissionGrant() .penaltyLog() .build(); StrictMode.setVmPolicy(policy);
或者,您也可以监控包含消息 Please set the grant explicitly in the app 的已记录异常,该消息会在系统隐式设置授予时显示。您可以使用以下 adb 命令监控这些日志:
adb logcat | grep "Please set the grant explicitly in the app"
如需明确授予必要的权限,请将
FLAG_GRANT_READ_URI_PERMISSION标志添加到ACTION_SEND和
ACTION_SEND_MULTIPLEintent:
Kotlin
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
Java
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
对于
ACTION_IMAGE_CAPTURE intent,请同时添加FLAG_GRANT_READ_URI_PERMISSION 和
FLAG_GRANT_WRITE_URI_PERMISSION 标志:
Kotlin
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
Java
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
محدودیتهای فروشگاه کلید در هر برنامه
应用应避免在 Android 密钥库中创建过多的密钥,因为它是设备上所有应用的共享资源。从 Android 17 开始,系统会强制限制应用可拥有的密钥数量。对于以 Android 17(API 级别 37)或更高版本为目标平台的非系统应用,密钥数量上限为 50,000 个;对于所有其他应用,密钥数量上限为 200,000 个。无论系统应用以哪个 API 级别为目标,其密钥数量上限均为 20 万。
如果应用尝试创建超出限制的密钥,则创建会失败并显示 KeyStoreException。异常的消息字符串包含有关密钥限制的信息。如果应用针对异常调用 getNumericErrorCode(),则返回值取决于应用的目标 API 级别:
- 如果应用以 Android 17(API 级别 37)或更高版本为目标平台,
getNumericErrorCode()会返回新的ERROR_TOO_MANY_KEYS值。 - 所有其他应用:
getNumericErrorCode()返回ERROR_INCORRECT_USAGE。
مسدود کردن ترافیک loopback بین پروفایلی
从 Android 17 开始,默认情况下不再允许跨个人资料环回流量。同一个人资料内的环回流量不受影响。 此项变更适用于在 Android 17 或更高版本上运行的所有应用,无论应用以哪个 API 级别为目标平台。
تجربه کاربری و رابط کاربری سیستم
اندروید ۱۷ شامل تغییرات زیر است که برای ایجاد یک تجربه کاربری سازگارتر و شهودیتر در نظر گرفته شدهاند.
بازیابی قابلیت مشاهده پیشفرض IME پس از چرخش
从 Android 17 开始,当设备的配置发生变化(例如,通过旋转)且应用本身未处理此变化时,系统不会恢复之前的 IME 可见性。
如果应用经历了它无法处理的配置更改,并且应用需要在更改后显示键盘,您必须明确请求此行为。您可以通过以下方式之一提出此要求:
- 将
android:windowSoftInputMode属性设置为stateAlwaysVisible。 - 在 activity 的
onCreate()方法中以编程方式请求显示软键盘,或添加onConfigurationChanged()方法。
ورودی انسانی
اندروید ۱۷ شامل تغییرات زیر است که بر نحوه تعامل برنامهها با دستگاههای ورودی انسان مانند صفحهکلید و تاچپد تأثیر میگذارد.
تاچپدها به طور پیشفرض رویدادهای نسبی را هنگام گرفتن اشارهگر نمایش میدهند
از اندروید ۱۷ به بعد، اگر برنامهای با استفاده از View.requestPointerCapture() درخواست ضبط اشارهگر را داشته باشد و کاربر از تاچپد استفاده کند، سیستم حرکت اشارهگر و حرکات پیمایش را از لمسهای کاربر تشخیص میدهد و آنها را به همان روشی که حرکات اشارهگر و چرخ اسکرول از یک ماوس ضبط شده انجام میشود، به برنامه گزارش میدهد. در بیشتر موارد، این امر نیاز برنامههایی که از ماوسهای ضبط شده پشتیبانی میکنند را برای اضافه کردن منطق مدیریت ویژه برای تاچپدها برطرف میکند. برای جزئیات بیشتر، به مستندات View.POINTER_CAPTURE_MODE_RELATIVE مراجعه کنید.
پیش از این، سیستم تلاشی برای تشخیص حرکات از صفحه لمسی نمیکرد و در عوض، مکانهای خام و قطعی انگشت را با فرمتی مشابه لمسهای صفحه لمسی به برنامه تحویل میداد. اگر برنامهای هنوز به این دادههای قطعی نیاز دارد، باید به جای آن، متد جدید View.requestPointerCapture(int) را با View.POINTER_CAPTURE_MODE_ABSOLUTE فراخوانی کند.
رسانه
اندروید ۱۷ شامل تغییرات زیر در رفتار رسانهای است.
سخت شدن صدای پسزمینه
Beginning with Android 17, the audio framework enforces restrictions on background audio interactions including audio playback, audio focus requests, and volume change APIs to ensure that these changes are started intentionally by the user.
If the app tries to call audio APIs while the app is not in a valid lifecycle,
the audio playback and volume change APIs fail silently without throwing an
exception or providing a failure message. The audio focus API fails with the
result code AUDIOFOCUS_REQUEST_FAILED.
For more information, including mitigation strategies, see Background audio hardening.
اتصال
اندروید ۱۷ شامل تغییرات زیر برای بهبود اتصال دستگاه است.
جفتسازی مجدد خودکار برای از دست رفتن اتصال بلوتوث
اندروید ۱۷ قابلیت جفتسازی مجدد خودکار را معرفی میکند، یک بهبود در سطح سیستم که برای حل خودکار مشکل از دست دادن اتصال بلوتوث طراحی شده است.
پیش از این، اگر یک اتصال از بین میرفت، کاربران مجبور بودند به صورت دستی به تنظیمات بروند تا اتصال را قطع و سپس دوباره وصل کنند. این ویژگی بر اساس بهبود امنیتی اندروید ۱۶ ساخته شده است و به سیستم اجازه میدهد تا اتصالها را در پسزمینه دوباره برقرار کند، بدون اینکه کاربران مجبور باشند به صورت دستی به تنظیمات بروند تا اتصال را قطع و دوباره وصل کنند.
اگرچه اکثر برنامهها نیازی به تغییر کد ندارند، توسعهدهندگان باید از تغییرات رفتاری زیر در پشته بلوتوث آگاه باشند:
- زمینه جفتسازی جدید:
ACTION_PAIRING_REQUESTاکنون شاملEXTRA_PAIRING_CONTEXTاضافی است که به برنامهها اجازه میدهد بین یک درخواست جفتسازی استاندارد و یک تلاش جفتسازی مجدد خودکار توسط سیستم، تمایز قائل شوند. - بهروزرسانیهای مشروط کلید: کلیدهای امنیتی موجود تنها در صورتی جایگزین میشوند که جفتسازی مجدد موفقیتآمیز باشد و اتصال جدید سطح امنیتی پیوند قبلی را برآورده کند یا از آن فراتر رود.
- زمانبندی اینتنت اصلاحشده: اینتنت
ACTION_KEY_MISSINGاکنون فقط در صورتی پخش میشود که تلاش برای جفتسازی مجدد خودکار با شکست مواجه شود. این امر در صورتی که سیستم با موفقیت پیوند را در پسزمینه بازیابی کند، مدیریت خطاهای غیرضروری در برنامه را کاهش میدهد. - اعلان کاربر: سیستم، جفتسازی مجدد را از طریق اعلانها و پنجرههای محاورهای جدید رابط کاربری مدیریت میکند. از کاربران خواسته میشود تا تلاش برای جفتسازی مجدد را تأیید کنند تا از اتصال مجدد مطلع شوند.
تولیدکنندگان دستگاههای جانبی و توسعهدهندگان برنامههای همراه باید تأیید کنند که سختافزار و برنامه به خوبی از پس انتقال اتصال برمیآیند. برای آزمایش این رفتار، با استفاده از یکی از روشهای زیر، از دست دادن اتصال از راه دور را شبیهسازی کنید:
- اطلاعات مربوط به پیوند را به صورت دستی از دستگاه جانبی حذف کنید
- اتصال دستگاه را به صورت دستی از طریق تنظیمات > دستگاههای متصل قطع کنید