การเปลี่ยนแปลงลักษณะการทํางาน: แอปทั้งหมด

แพลตฟอร์ม Android 17 มีการเปลี่ยนแปลงลักษณะการทำงานที่อาจส่งผลต่อแอปของคุณ การเปลี่ยนแปลงลักษณะการทำงานต่อไปนี้จะมีผลกับ แอปทั้งหมด เมื่อทำงานบน Android 17 โดยไม่คำนึงถึง targetSdkVersion คุณควรทดสอบแอป แล้วแก้ไขตามความจำเป็นเพื่อรองรับการเปลี่ยนแปลงเหล่านี้ในกรณีที่เกี่ยวข้อง

โปรดตรวจสอบรายการการเปลี่ยนแปลงลักษณะการทำงานที่มีผลกับแอปที่กำหนดเป้าหมายเป็น Android 17 เท่านั้นด้วย

ฟังก์ชันหลัก

Android 17 (API ระดับ 37) มีการเปลี่ยนแปลงต่อไปนี้ซึ่งแก้ไขหรือขยายความสามารถหลักต่างๆ ของระบบ Android

ขีดจำกัดหน่วยความจำของแอป

Android 17 ขอแนะนำการจำกัดหน่วยความจำของแอปตาม RAM ทั้งหมดของอุปกรณ์เพื่อสร้างสภาพแวดล้อมที่เสถียรและกำหนดได้มากขึ้นสำหรับแอปพลิเคชันและผู้ใช้ Android ใน Android 17 เราได้ตั้งค่าขีดจำกัดอย่างระมัดระวังเพื่อกำหนดค่าพื้นฐานของระบบ โดยมุ่งเป้าไปที่หน่วยความจำรั่วไหลอย่างรุนแรงและข้อมูลผิดปกติทางสถิติอื่นๆ ก่อนที่จะทำให้ระบบไม่เสถียรทั่วทั้งระบบ ซึ่งส่งผลให้ UI เกิดการกระตุกแบบข้ามเฟรม แบตเตอรี่หมดเร็ว และแอปถูกปิด แม้ว่าเราจะคาดการณ์ว่าเซสชันของแอปส่วนใหญ่จะได้รับผลกระทบน้อยมาก แต่เราขอแนะนำแนวทางปฏิบัติแนะนำด้านหน่วยความจำต่อไปนี้ ซึ่งรวมถึงการกำหนดค่าพื้นฐานสำหรับหน่วยความจำ

คุณสามารถตรวจสอบว่าเซสชันของแอปได้รับผลกระทบหรือไม่โดยเรียกใช้ getDescription ใน ApplicationExitInfo หากแอปได้รับผลกระทบ เหตุผลที่ออกจะเป็น REASON_OTHER และ คำอธิบายจะมีสตริง "MemoryLimiter:AnonSwap" พร้อมกับ ข้อมูลอื่นๆ นอกจากนี้ คุณยังใช้การโปรไฟล์ตามทริกเกอร์กับ TRIGGER_TYPE_ANOMALYเพื่อรับฮีปดัมป์ที่รวบรวมไว้เมื่อถึง ขีดจำกัดหน่วยความจำได้ด้วย

งาน LeakCanary ในโปรไฟล์เลอร์ของ Android Studio

Android Studio Panda เพิ่มการผสานรวม LeakCanary ลงในโปรไฟล์เลอร์ของ Android Studio โดยตรงเป็นงานเฉพาะที่อยู่ใน IDE และผสานรวมกับซอร์สโค้ดของคุณอย่างสมบูรณ์ เพื่อช่วยคุณค้นหาการรั่วไหลของหน่วยความจำ

ความปลอดภัย

Android 17 มีการปรับปรุงความปลอดภัยของอุปกรณ์และแอปต่อไปนี้

แผนการเลิกใช้งาน 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 Send, SendMultiple, or ImageCapture, 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.

ประสบการณ์ของผู้ใช้และ UI ของระบบ

Android 17 มีการเปลี่ยนแปลงต่อไปนี้ซึ่งมีจุดประสงค์เพื่อสร้างประสบการณ์ของผู้ใช้ที่สอดคล้องและใช้งานง่ายมากขึ้น

การคืนค่าการแสดงผล IME เริ่มต้นหลังจากการหมุน

Beginning with Android 17, when the device's configuration changes (for example, through rotation), and this is not handled by the app itself, the previous IME visibility is not restored.

If your app undergoes a configuration change that it does not handle, and the app needs the keyboard to be visible after the change, you must explicitly request this. You can make this request in one of the following ways:

  • Set the android:windowSoftInputMode attribute to stateAlwaysVisible.
  • Programmatically request the soft keyboard in your activity's onCreate() method, or add the onConfigurationChanged() method.

อินพุตจากมนุษย์

Android 17 มีการเปลี่ยนแปลงต่อไปนี้ซึ่งส่งผลต่อวิธีที่แอปโต้ตอบกับอุปกรณ์อินพุตจากมนุษย์ เช่น แป้นพิมพ์และทัชแพด

ทัชแพดจะส่งเหตุการณ์สัมพัทธ์โดยค่าเริ่มต้นระหว่างการจับตัวชี้

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.

สื่อ

Android 17 มีการเปลี่ยนแปลงลักษณะการทำงานของสื่อต่อไปนี้

การปิดช่องโหว่ของเสียงในเบื้องหลัง

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.

การเชื่อมต่อ

Android 17 มีการเปลี่ยนแปลงต่อไปนี้เพื่อปรับปรุงการเชื่อมต่อของอุปกรณ์

การจับคู่ใหม่โดยอัตโนมัติเมื่อการเชื่อมต่อบลูทูธขาดหายไป

Android 17 ขอแนะนำการจับคู่ใหม่ด้วยตัวเอง ซึ่งเป็นการปรับปรุงระดับระบบที่ออกแบบมาเพื่อแก้ไขการสูญเสียการเชื่อมต่อ Bluetooth โดยอัตโนมัติ

ก่อนหน้านี้ หากการเชื่อมต่อขาดหายไป ผู้ใช้ต้องไปที่การตั้งค่าเพื่อยกเลิกการจับคู่และจับคู่กับอุปกรณ์ต่อพ่วงอีกครั้งด้วยตนเอง ฟีเจอร์นี้สร้างขึ้นจากการปรับปรุงความปลอดภัยของ Android 16 โดยอนุญาตให้ระบบสร้างการเชื่อมต่อใหม่ในเบื้องหลังโดยไม่กำหนดให้ผู้ใช้ไปที่การตั้งค่าเพื่อยกเลิกการจับคู่และจับคู่กับอุปกรณ์ต่อพ่วงอีกครั้งด้วยตนเอง

แม้ว่าแอปส่วนใหญ่จะไม่ต้องมีการเปลี่ยนแปลงโค้ด แต่นักพัฒนาแอปควรทราบถึงการเปลี่ยนแปลงลักษณะการทำงานต่อไปนี้ในสแต็ก Bluetooth

  • บริบทการจับคู่ใหม่: ตอนนี้ ACTION_PAIRING_REQUEST มีส่วนเพิ่มเติม EXTRA_PAIRING_CONTEXT ซึ่งช่วยให้แอปแยกแยะระหว่างคำขอการจับคู่มาตรฐานกับความพยายามในการจับคู่ใหม่ที่ระบบเริ่มต้นเองได้
  • การอัปเดตคีย์แบบมีเงื่อนไข: ระบบจะแทนที่คีย์ความปลอดภัยที่มีอยู่ก็ต่อเมื่อการจับคู่ใหม่สำเร็จและการเชื่อมต่อใหม่มีระดับความปลอดภัยเท่ากับหรือสูงกว่าการเชื่อมต่อก่อนหน้า
  • การกำหนดเวลา Intent ที่แก้ไข: ตอนนี้ระบบจะออกอากาศ Intent ACTION_KEY_MISSING ก็ต่อเมื่อความพยายามในการจับคู่ใหม่ด้วยตัวเองล้มเหลว ซึ่งจะช่วยลดการจัดการข้อผิดพลาดที่ไม่จำเป็นในแอปหากระบบกู้คืนการเชื่อมต่อในเบื้องหลังได้สำเร็จ
  • การแจ้งเตือนผู้ใช้: ระบบจะจัดการการจับคู่ใหม่ผ่านการแจ้งเตือนและกล่องโต้ตอบ UI ใหม่ ระบบจะแจ้งให้ผู้ใช้ยืนยันความพยายามในการจับคู่ใหม่เพื่อให้ผู้ใช้ทราบถึงการเชื่อมต่อใหม่

ผู้ผลิตอุปกรณ์ต่อพ่วงและนักพัฒนาแอปที่ใช้ร่วมกันควรตรวจสอบว่าฮาร์ดแวร์และแอปจัดการการเปลี่ยนการเชื่อมต่อได้อย่างราบรื่น หากต้องการทดสอบลักษณะการทำงานนี้ ให้จำลองการสูญเสียการเชื่อมต่อระยะไกลโดยใช้วิธีใดวิธีหนึ่งต่อไปนี้

  • นำข้อมูลการเชื่อมต่อออกจากอุปกรณ์ต่อพ่วงด้วยตนเอง
  • ยกเลิกการจับคู่อุปกรณ์ด้วยตนเองในส่วนการตั้งค่า > อุปกรณ์ที่เชื่อมต่อ