تغییرات رفتار: همه برنامه ها

پلتفرم اندروید ۱۷ شامل تغییرات رفتاری است که ممکن است بر برنامه شما تأثیر بگذارد. تغییرات رفتاری زیر برای همه برنامه‌ها هنگام اجرا در اندروید ۱۷، صرف نظر از 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 applications 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|all
  • am memory-limiter manual <pid> <limit>|max|none
  • am memory-limiter status
ignore

Instructs the memory limiter to ignore some or all processes. Passing a UID instructs the memory limiter to ignore all processes associated with that UID. You can also pass all (ignore all processes) or none (do not ignore any processes). Passing none overrides any previous calls to am memory-limiter ignore.

If you instruct the memory limiter to ignore a process, you can still apply a manual memory limit to the process by calling am memory-limiter manual.

manual

Instructs the system to impose a memory constraint on the process with the specified PID. The memory constraint is specified as an integer number of MB; for example, passing 30 specifies that the process is limited to 30 MB of memory. Passing max removes all memory limits on that process. Passing none removes any manual limits set on the process, restoring the system's default limit (if any).

status

Reports 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 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

In a future release, we plan to deprecate the usesCleartextTraffic element. Apps that need to make unencrypted (HTTP) connections should migrate to using a network security configuration file, which lets you specify which domains your app needs to make cleartext connections to.

Be aware that network security configuration files are only supported on API levels 24 and higher. If your app has a minimum API level lower than 24, you should do both of the following:

  • Set the usesCleartextTraffic attribute to true
  • Use a network configuration file

If your app's minimum API level is 24 or higher, you can use a network configuration file and you don't need to set usesCleartextTraffic.

محدود کردن مجوزهای ضمنی URI

Currently, if an app launches an intent with a URI that has the action ACTION_SEND, SEND_MULTIPLE, or ACTION_IMAGE_CAPTURE, the system automatically grants the read and write URI permissions to the target app. We plan to change this behavior in Android 18. For this reason, we recommend that apps explicitly grant the relevant URI permissions instead of relying on the system to grant them.

محدودیت‌های فروشگاه کلید در هر برنامه

Apps should avoid creating excessive numbers of keys in Android Keystore, because it is a shared resource for all apps on the device. Beginning with Android 17, the system enforces a limit on the number of keys an app can own. The limit is 50,000 keys for non-system apps targeting Android 17 (API level 37) or higher, and 200,000 keys for all other apps. System apps have a limit of 200,000 keys, regardless of which API level they target.

If an app attempts to create keys beyond the limit, the creation fails with a KeyStoreException. The exception's message string contains information about the key limit. If the app calls getNumericErrorCode() on the exception, the return value depends on what API level the app targets:

  • Apps targeting Android 17 (API level 37) or higher: getNumericErrorCode() returns the new ERROR_TOO_MANY_KEYS value.
  • All other apps: getNumericErrorCode() returns ERROR_INCORRECT_USAGE.

مسدود کردن ترافیک loopback بین پروفایلی

از اندروید ۱۷ به بعد، ترافیک loopback بین پروفایل‌ها دیگر به طور پیش‌فرض مجاز نیست. ترافیک loopback در همان پروفایل تحت تأثیر قرار نمی‌گیرد. این تغییر برای همه برنامه‌هایی که روی اندروید ۱۷ یا بالاتر اجرا می‌شوند، صرف نظر از اینکه برنامه چه سطح API را هدف قرار می‌دهد، اعمال می‌شود.

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

اندروید ۱۷ شامل تغییرات زیر است که برای ایجاد یک تجربه کاربری سازگارتر و شهودی‌تر در نظر گرفته شده‌اند.

بازیابی قابلیت مشاهده پیش‌فرض IME پس از چرخش

از اندروید ۱۷ به بعد، وقتی پیکربندی دستگاه تغییر می‌کند (مثلاً از طریق چرخش) و این تغییر توسط خود برنامه مدیریت نمی‌شود، قابلیت مشاهده IME قبلی بازیابی نمی‌شود.

اگر برنامه شما دچار تغییر پیکربندی شود که قادر به مدیریت آن نباشد و برنامه نیاز داشته باشد که صفحه‌کلید پس از تغییر قابل مشاهده باشد، باید صریحاً این درخواست را ارائه دهید. می‌توانید این درخواست را به یکی از روش‌های زیر انجام دهید:

  • ویژگی android:windowSoftInputMode را روی stateAlwaysVisible تنظیم کنید.
  • به صورت برنامه‌نویسی، صفحه‌کلید نرم‌افزاری را در متد onCreate() مربوط به activity خود درخواست کنید، یا متد onConfigurationChanged() را اضافه کنید.

ورودی انسانی

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

تاچ‌پدها به طور پیش‌فرض رویدادهای نسبی را هنگام گرفتن اشاره‌گر نمایش می‌دهند

Beginning with Android 17, if an app requests pointer capture using View.requestPointerCapture() and the user uses a touchpad, the system recognizes pointer movement and scrolling gestures from the user's touches and reports them to the app in the same way as pointer and scroll wheel movements from a captured mouse. In most cases, this removes the need for apps that support captured mice to add special handling logic for touchpads. For more details, see the documentation for View.POINTER_CAPTURE_MODE_RELATIVE.

Previously, the system did not attempt to recognize gestures from the touchpad, and instead delivered the raw, absolute finger locations to the app in a similar format to touchscreen touches. If an app still requires this absolute data, it should call the new View.requestPointerCapture(int) method with View.POINTER_CAPTURE_MODE_ABSOLUTE instead.

رسانه

اندروید ۱۷ شامل تغییرات زیر در رفتار رسانه‌ای است.

سخت شدن صدای پس‌زمینه

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 اکنون فقط در صورتی پخش می‌شود که تلاش برای جفت‌سازی مجدد خودکار با شکست مواجه شود. این امر در صورتی که سیستم با موفقیت پیوند را در پس‌زمینه بازیابی کند، مدیریت خطاهای غیرضروری در برنامه را کاهش می‌دهد.
  • اعلان کاربر: سیستم، جفت‌سازی مجدد را از طریق اعلان‌ها و پنجره‌های محاوره‌ای جدید رابط کاربری مدیریت می‌کند. از کاربران خواسته می‌شود تا تلاش برای جفت‌سازی مجدد را تأیید کنند تا از اتصال مجدد مطلع شوند.

تولیدکنندگان دستگاه‌های جانبی و توسعه‌دهندگان برنامه‌های همراه باید تأیید کنند که سخت‌افزار و برنامه به خوبی از پس انتقال اتصال برمی‌آیند. برای آزمایش این رفتار، با استفاده از یکی از روش‌های زیر، از دست دادن اتصال از راه دور را شبیه‌سازی کنید:

  • اطلاعات مربوط به پیوند را به صورت دستی از دستگاه جانبی حذف کنید
  • اتصال دستگاه را به صورت دستی از طریق تنظیمات > دستگاه‌های متصل قطع کنید