Thay đổi về hành vi: Ứng dụng nhắm đến Android 16 trở lên

Giống như các bản phát hành trước, Android 16 có các thay đổi về hành vi có thể ảnh hưởng đến ứng dụng của bạn. Những thay đổi về hành vi sau đây chỉ áp dụng cho các ứng dụng nhắm đến Android 16 trở lên. Nếu ứng dụng của bạn nhắm đến Android 16 trở lên, bạn nên điều chỉnh ứng dụng để hỗ trợ những hành vi này (nếu cần).

Ngoài ra, hãy nhớ tham khảo danh sách các thay đổi về hành vi ảnh hưởng đến tất cả ứng dụng chạy trên Android 16 bất kể targetSdkVersion của ứng dụng.

Trải nghiệm người dùng và giao diện người dùng hệ thống

Android 16 (cấp độ API 36) có những thay đổi sau đây nhằm tạo ra trải nghiệm người dùng nhất quán và trực quan hơn.

Lựa chọn không sử dụng chế độ tràn viền sẽ không còn nữa

Android 15 thực thi chế độ hiển thị tràn viền cho các ứng dụng nhắm đến Android 15 (API cấp 35), nhưng ứng dụng của bạn có thể chọn không sử dụng bằng cách đặt R.attr#windowOptOutEdgeToEdgeEnforcement thành true. Đối với các ứng dụng nhắm đến Android 16 (cấp độ API 36), R.attr#windowOptOutEdgeToEdgeEnforcement sẽ không được dùng nữa và bị vô hiệu hoá, đồng thời ứng dụng của bạn không thể chọn không hiển thị tràn viền.

  • Nếu ứng dụng của bạn nhắm đến Android 16 (API cấp 36) và đang chạy trên một thiết bị Android 15, thì R.attr#windowOptOutEdgeToEdgeEnforcement vẫn hoạt động.
  • Nếu ứng dụng của bạn nhắm đến Android 16 (cấp độ API 36) và đang chạy trên một thiết bị Android 16, thì R.attr#windowOptOutEdgeToEdgeEnforcement sẽ bị tắt.

Để kiểm thử trong Android 16, hãy đảm bảo ứng dụng của bạn hỗ trợ chế độ hiển thị tràn viền và xoá mọi cách sử dụng R.attr#windowOptOutEdgeToEdgeEnforcement để ứng dụng của bạn cũng hỗ trợ chế độ hiển thị tràn viền trên thiết bị Android 15. Để hỗ trợ chế độ hiển thị tràn viền, hãy xem hướng dẫn về ComposeKhung hiển thị.

Bạn phải di chuyển hoặc chọn không sử dụng tính năng xem trước thao tác quay lại

Đối với các ứng dụng nhắm đến Android 16 (cấp độ API 36) trở lên và chạy trên thiết bị Android 16 trở lên, theo mặc định, ảnh động hệ thống xem trước thao tác quay lại (quay lại trang chủ, giữa các tác vụ và giữa các hoạt động) sẽ được bật. Ngoài ra, onBackPressed không được gọi và KeyEvent.KEYCODE_BACK không còn được gửi đi nữa.

Nếu ứng dụng của bạn chặn sự kiện quay lại và bạn chưa di chuyển sang tính năng xem trước thao tác quay lại, hãy cập nhật ứng dụng để sử dụng các API điều hướng quay lại được hỗ trợ hoặc tạm thời chọn không sử dụng bằng cách đặt thuộc tính android:enableOnBackInvokedCallback thành false trong thẻ <application> hoặc <activity> của tệp AndroidManifest.xml của ứng dụng.

Ảnh động xem trước thao tác quay lại màn hình chính.
Ảnh động xem trước trên nhiều hoạt động.
Ảnh động dự đoán cho nhiều nhiệm vụ.

Các API phông chữ Elegant không được dùng nữa và bị vô hiệu hoá

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.

Chức năng cốt lõi

Android 16 (cấp độ API 36) có những thay đổi sau đây nhằm sửa đổi hoặc mở rộng nhiều chức năng cốt lõi của hệ thống Android.

Tối ưu hoá lịch làm việc theo mức giá cố định

Prior to targeting Android 16, when scheduleAtFixedRate missed a task execution due to being outside a valid process lifecycle, all missed executions immediately execute when the app returns to a valid lifecycle.

When targeting Android 16, at most one missed execution of scheduleAtFixedRate is immediately executed when the app returns to a valid lifecycle. This behavior change is expected to improve app performance. Test this behavior in your app to check if your app is impacted. You can also test by using the app compatibility framework and enabling the STPE_SKIP_MULTIPLE_MISSED_PERIODIC_TASKS compat flag.

Kiểu dáng thiết bị

Android 16 (cấp độ API 36) có những thay đổi sau đây đối với các ứng dụng khi hiển thị trên thiết bị có màn hình lớn.

Bố cục thích ứng (Adaptive Layouts)

With Android apps now running on a variety of devices (such as phones, tablets, foldables, desktops, cars, and TVs) and windowing modes on large screens (such as split screen and desktop windowing), developers should build Android apps that adapt to any screen and window size, regardless of device orientation. Paradigms like restricting orientation and resizability are too restrictive in today's multidevice world.

Ignore orientation, resizability, and aspect ratio restrictions

For apps targeting Android 16 (API level 36), orientation, resizability, and aspect ratio restrictions no longer apply on displays with smallest width >= 600dp. Apps fill the entire display window, regardless of aspect ratio or a user's preferred orientation, and pillarboxing isn't used.

This change introduces a new standard platform behavior. Android is moving toward a model where apps are expected to adapt to various orientations, display sizes, and aspect ratios. Restrictions like fixed orientation or limited resizability hinder app adaptability. Make your app adaptive to deliver the best possible user experience.

You can also test this behavior by using the app compatibility framework and enabling the UNIVERSAL_RESIZABLE_BY_DEFAULT compat flag.

Common breaking changes

Ignoring orientation, resizability, and aspect ratio restrictions might impact your app's UI on some devices, especially elements that were designed for small layouts locked in portrait orientation: for example, issues like stretched layouts and off-screen animations and components. Any assumptions about aspect ratio or orientation can cause visual issues with your app. Learn more about how to avoid them and improve your app's adaptive behaviour.

Allowing device rotation results in more activity re-creation, which can result in losing user state if not properly preserved. Learn how to correctly save UI state in Save UI states.

Implementation details

The following manifest attributes and runtime APIs are ignored across large screen devices in full-screen and multi-window modes:

The following values for screenOrientation, setRequestedOrientation(), and getRequestedOrientation() are ignored:

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

Regarding display resizability, android:resizeableActivity="false", android:minAspectRatio, and android:maxAspectRatio have no effect.

For apps targeting Android 16 (API level 36), app orientation, resizability, and aspect ratio constraints are ignored on large screens by default, but every app that isn't fully ready can temporarily override this behavior by opting out (which results in the previous behavior of being placed in compatibility mode).

Exceptions

The Android 16 orientation, resizability, and aspect ratio restrictions don't apply in the following situations:

  • Games (based on the android:appCategory flag)
  • Users explicitly opting in to the app's default behavior in aspect ratio settings of the device
  • Screens that are smaller than sw600dp

Opt out temporarily

To opt out a specific activity, declare the PROPERTY_COMPAT_ALLOW_RESTRICTED_RESIZABILITY manifest property:

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

If too many parts of your app aren't ready for Android 16, you can opt out completely by applying the same property at the application level:

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

Sức khoẻ và thể chất

Android 16 (cấp độ API 36) có những thay đổi sau đây liên quan đến dữ liệu về sức khoẻ và thể chất.

Quyền đối với dữ liệu về sức khoẻ và thể dục

Đối với các ứng dụng nhắm đến Android 16 (API cấp 36) trở lên, BODY_SENSORS quyền sử dụng các quyền chi tiết hơn trong android.permissions.health. Health Connect cũng sử dụng các quyền này. Kể từ Android 16, mọi API trước đây yêu cầu quyền BODY_SENSORS hoặc BODY_SENSORS_BACKGROUND đều yêu cầu quyền tương ứng android.permissions.health. Điều này ảnh hưởng đến các loại dữ liệu, API và loại dịch vụ trên nền trước sau đây:

Nếu sử dụng các API này, ứng dụng của bạn nên yêu cầu các quyền chi tiết tương ứng:

Các quyền này giống như những quyền bảo vệ quyền truy cập để đọc dữ liệu từ Health Connect, kho lưu trữ dữ liệu Android cho dữ liệu về sức khoẻ, thể dục và thể chất.

Ứng dụng trên điện thoại di động

Các ứng dụng trên điện thoại di động di chuyển để sử dụng READ_HEART_RATE và các quyền chi tiết khác cũng phải khai báo một hoạt động để hiển thị chính sách quyền riêng tư của ứng dụng. Đây là yêu cầu giống như Health Connect.

Khả năng kết nối

Android 16 (cấp độ API 36) bao gồm các thay đổi sau trong ngăn xếp Bluetooth để cải thiện khả năng kết nối với các thiết bị ngoại vi.

Các ý định mới để xử lý tình trạng mất liên kết và thay đổi chế độ mã hoá

Trong phần Cải thiện khả năng xử lý việc mất liên kết, Android 16 cũng giới thiệu 2 ý định mới để giúp ứng dụng nhận biết rõ hơn về việc mất liên kết và các thay đổi về mã hoá.

Ứng dụng nhắm đến Android 16 hiện có thể:

  • Nhận ý định ACTION_KEY_MISSING khi phát hiện mất liên kết từ xa, cho phép họ cung cấp ý kiến phản hồi chi tiết hơn cho người dùng và thực hiện các hành động thích hợp.
  • Nhận ý định ACTION_ENCRYPTION_CHANGE bất cứ khi nào trạng thái mã hoá của đường liên kết thay đổi. Điều này bao gồm thay đổi trạng thái mã hoá, thay đổi thuật toán mã hoá và thay đổi kích thước khoá mã hoá. Các ứng dụng phải xem xét việc khôi phục liên kết nếu đường liên kết được mã hoá thành công sau khi nhận được ý định ACTION_ENCRYPTION_CHANGE.

Điều chỉnh cho phù hợp với nhiều cách triển khai của nhà sản xuất thiết bị gốc (OEM)

Mặc dù Android 16 giới thiệu các ý định mới này, nhưng cách triển khai và truyền tin của các ý định này có thể khác nhau tuỳ theo nhà sản xuất thiết bị gốc (OEM). Để đảm bảo ứng dụng của bạn mang lại trải nghiệm nhất quán và đáng tin cậy trên tất cả thiết bị, nhà phát triển nên thiết kế cách xử lý việc mất liên kết để thích ứng linh hoạt với những biến thể tiềm ẩn này.

Bạn nên áp dụng các hành vi sau đây cho ứng dụng:

  • Nếu ý định ACTION_KEY_MISSING được truyền tin:

    Hệ thống sẽ ngắt kết nối liên kết ACL (Không có kết nối không đồng bộ), nhưng thông tin liên kết cho thiết bị sẽ được giữ lại (như mô tả tại đây).

    Ứng dụng của bạn nên sử dụng ý định này làm tín hiệu chính để phát hiện mất liên kết và hướng dẫn người dùng xác nhận thiết bị từ xa nằm trong phạm vi trước khi bắt đầu quên thiết bị hoặc ghép nối lại.

    Nếu một thiết bị ngắt kết nối sau khi nhận được ACTION_KEY_MISSING, thì ứng dụng của bạn nên thận trọng khi kết nối lại, vì thiết bị có thể không còn liên kết với hệ thống nữa.

  • Nếu ý định ACTION_KEY_MISSING KHÔNG được truyền tin:

    Đường liên kết ACL sẽ vẫn được kết nối và hệ thống sẽ xoá thông tin liên kết cho thiết bị, tương tự như hành vi trong Android 15.

    Trong trường hợp này, ứng dụng của bạn sẽ tiếp tục các cơ chế xử lý mất liên kết hiện có như trong các bản phát hành Android trước, để phát hiện và quản lý các sự kiện mất liên kết.

Cách mới để xoá mối liên kết Bluetooth

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.

Bảo mật

Android 16 (cấp độ API 36) có những thay đổi sau đây về bảo mật.

Khoá phiên bản MediaStore

For apps targeting Android 16 or higher, MediaStore#getVersion() will now be unique to each app. This eliminates identifying properties from the version string to prevent abuse and usage for fingerprinting techniques. Apps shouldn't make any assumptions around the format of this version. Apps should already handle version changes when using this API and in most cases shouldn't need to change their current behavior, unless the developer has attempted to infer additional information that is beyond the intended scope of this API.

Ý định an toàn hơn

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:")

Lọc lệnh gọi hệ thống 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.

Quyền riêng tư

Android 16 (cấp độ API 36) bao gồm những thay đổi sau đây về quyền riêng tư.

Quyền truy cập mạng cục bộ

Mọi ứng dụng có quyền INTERNET đều có thể truy cập vào các thiết bị trên mạng LAN. Điều này giúp các ứng dụng dễ dàng kết nối với các thiết bị cục bộ nhưng cũng có những tác động đến quyền riêng tư, chẳng hạn như tạo dấu vân tay của người dùng và là một proxy cho vị trí.

Dự án Bảo vệ mạng cục bộ nhằm mục đích bảo vệ quyền riêng tư của người dùng bằng cách hạn chế quyền truy cập vào mạng cục bộ thông qua một quyền khi bắt đầu chạy mới.

Kế hoạch phát hành

Thay đổi này sẽ được triển khai trong khoảng thời gian giữa hai bản phát hành, lần lượt là 25Q2 và 26Q2. Nhà phát triển bắt buộc phải tuân theo hướng dẫn này cho 25Q2 và chia sẻ ý kiến phản hồi vì những biện pháp bảo vệ này sẽ được thực thi trong một bản phát hành Android sau này. Ngoài ra, họ sẽ cần cập nhật các trường hợp phụ thuộc vào quyền truy cập ngầm vào mạng cục bộ bằng cách làm theo hướng dẫn sau đây và chuẩn bị cho trường hợp người dùng từ chối và thu hồi quyền mới.

Tác động

Ở giai đoạn hiện tại, LNP là một tính năng chọn sử dụng, tức là chỉ những ứng dụng chọn sử dụng mới bị ảnh hưởng. Mục tiêu của giai đoạn chọn tham gia là giúp nhà phát triển ứng dụng hiểu rõ những phần nào trong ứng dụng của họ phụ thuộc vào quyền truy cập ngầm vào mạng cục bộ để họ có thể chuẩn bị bảo vệ những phần đó bằng quyền cho bản phát hành tiếp theo.

Các ứng dụng sẽ bị ảnh hưởng nếu truy cập vào mạng cục bộ của người dùng bằng cách sử dụng:

  • Sử dụng trực tiếp hoặc sử dụng thư viện của các socket thô trên địa chỉ mạng cục bộ (ví dụ: giao thức khám phá dịch vụ mDNS hoặc SSDP)
  • Sử dụng các lớp cấp khung truy cập vào mạng cục bộ (ví dụ: NsdManager)

Lưu lượng truy cập đếntừ một địa chỉ mạng cục bộ cần có quyền truy cập vào mạng cục bộ. Bảng sau đây liệt kê một số trường hợp phổ biến:

Thao tác mạng cấp thấp của ứng dụng Cần có quyền truy cập vào mạng cục bộ
Tạo kết nối TCP đi
Chấp nhận các kết nối TCP đến
Gửi một gói đơn điểm, đa điểm, truyền tin quảng bá UDP
Nhận một gói đơn phương, đa phương, quảng bá UDP đến

Những hạn chế này được triển khai sâu trong ngăn xếp mạng, do đó, chúng áp dụng cho tất cả các API mạng. Điều này bao gồm các ổ cắm được tạo trong mã gốc hoặc mã được quản lý, các thư viện mạng như Cronet và OkHttp, cũng như mọi API được triển khai trên các thư viện đó. Việc cố gắng phân giải các dịch vụ trên mạng cục bộ (tức là những dịch vụ có hậu tố .local) sẽ yêu cầu có quyền truy cập mạng cục bộ.

Các trường hợp ngoại lệ đối với các quy tắc nêu trên:

  • Nếu máy chủ DNS của một thiết bị nằm trên mạng cục bộ, thì lưu lượng truy cập đến hoặc đi từ máy chủ đó (ở cổng 53) không yêu cầu quyền truy cập vào mạng cục bộ.
  • Những ứng dụng sử dụng Output Switcher làm bộ chọn trong ứng dụng sẽ không cần quyền truy cập vào mạng cục bộ (sẽ có thêm hướng dẫn vào quý 4 năm 2025).

Hướng dẫn cho nhà phát triển (chọn sử dụng)

Để chọn áp dụng các quy định hạn chế về mạng cục bộ, hãy làm như sau:

  1. Cài đặt ROM cho thiết bị sang bản dựng 25Q2 Beta 3 trở lên.
  2. Cài đặt ứng dụng cần kiểm thử.
  3. Bật/tắt cờ Appcompat trong adb:

    adb shell am compat enable RESTRICT_LOCAL_NETWORK <package_name>
    
  4. Khởi động lại thiết bị

Giờ đây, quyền truy cập của ứng dụng vào mạng cục bộ sẽ bị hạn chế và mọi nỗ lực truy cập vào mạng cục bộ sẽ dẫn đến lỗi socket. Nếu bạn đang sử dụng các API thực hiện hoạt động mạng cục bộ bên ngoài quy trình ứng dụng của bạn (ví dụ: NsdManager), thì các API này sẽ không bị ảnh hưởng trong giai đoạn chọn tham gia.

Để khôi phục quyền truy cập, bạn phải cấp cho ứng dụng của mình quyền NEARBY_WIFI_DEVICES.

  1. Đảm bảo ứng dụng khai báo quyền NEARBY_WIFI_DEVICES trong tệp kê khai.
  2. Chuyển đến phần Cài đặt > Ứng dụng > [Tên ứng dụng] > Quyền > Thiết bị ở gần > Cho phép.

Giờ đây, quyền truy cập của ứng dụng vào mạng cục bộ sẽ được khôi phục và tất cả các trường hợp của bạn sẽ hoạt động như trước khi chọn sử dụng ứng dụng.

Sau khi bắt đầu thực thi tính năng bảo vệ mạng cục bộ, lưu lượng truy cập mạng của ứng dụng sẽ bị ảnh hưởng như sau.

Quyền Yêu cầu LAN đi Yêu cầu Internet đi/đến Yêu cầu LAN đến
Đã cấp Works Works Works
Không được cấp Thất bại Works Thất bại

Sử dụng lệnh sau để tắt cờ App-Compat

adb shell am compat disable RESTRICT_LOCAL_NETWORK <package_name>

Lỗi

Lỗi phát sinh từ những hạn chế này sẽ được trả về ổ cắm gọi bất cứ khi nào ổ cắm này gọi send hoặc một biến thể send đến một địa chỉ mạng cục bộ.

Ví dụ về lỗi:

sendto failed: EPERM (Operation not permitted)

sendto failed: ECONNABORTED (Operation not permitted)

Định nghĩa về mạng cục bộ

Mạng cục bộ trong dự án này đề cập đến một mạng IP sử dụng giao diện mạng có khả năng truyền tin, chẳng hạn như Wi-Fi hoặc Ethernet, nhưng không bao gồm các kết nối di động (WWAN) hoặc VPN.

Sau đây được coi là mạng lưới địa phương:

IPv4:

  • 169.254.0.0/16 // Link Local
  • 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:

  • Liên kết cục bộ
  • Tuyến đường có kết nối trực tiếp
  • Các mạng stub như Thread
  • Nhiều mạng con (TBD)

Ngoài ra, cả địa chỉ truyền tin đa hướng (224.0.0.0/4, ff00::/8) và địa chỉ truyền tin IPv4 (255.255.255.255) đều được phân loại là địa chỉ mạng cục bộ.

Ảnh thuộc về ứng dụng

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.