From a92080f4432c048f28e703dc2ede885d081f1285 Mon Sep 17 00:00:00 2001 From: Handa Wang Date: Mon, 1 Apr 2024 07:28:04 +0000 Subject: [PATCH] [Thread] add NetworkCapability.NOT_METERED for Thread network Thread is an unmetered network so we should add this capability. Bug: 332219983 Test: `bw_costly_thread-wpan` won't show up after this CL. Change-Id: I0818700e5e7aad04ae15b0d0fd4490ab3f12839e --- .../ThreadNetworkControllerService.java | 1 + .../cts/ThreadNetworkControllerTest.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java index d80dcfb18d..63cd574066 100644 --- a/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java +++ b/thread/service/java/com/android/server/thread/ThreadNetworkControllerService.java @@ -699,6 +699,7 @@ final class ThreadNetworkControllerService extends IThreadNetworkController.Stub new NetworkCapabilities.Builder() .addTransportType(NetworkCapabilities.TRANSPORT_THREAD) .addCapability(NetworkCapabilities.NET_CAPABILITY_LOCAL_NETWORK) + .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED) .build(); final NetworkScore score = diff --git a/thread/tests/cts/src/android/net/thread/cts/ThreadNetworkControllerTest.java b/thread/tests/cts/src/android/net/thread/cts/ThreadNetworkControllerTest.java index 9a81388c7f..ba7392cdb3 100644 --- a/thread/tests/cts/src/android/net/thread/cts/ThreadNetworkControllerTest.java +++ b/thread/tests/cts/src/android/net/thread/cts/ThreadNetworkControllerTest.java @@ -17,6 +17,12 @@ package android.net.thread.cts; import static android.Manifest.permission.ACCESS_NETWORK_STATE; +import static android.net.NetworkCapabilities.NET_CAPABILITY_LOCAL_NETWORK; +import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED; +import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED; +import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VCN_MANAGED; +import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN; +import static android.net.NetworkCapabilities.NET_CAPABILITY_TRUSTED; import static android.net.thread.ThreadNetworkController.DEVICE_ROLE_CHILD; import static android.net.thread.ThreadNetworkController.DEVICE_ROLE_LEADER; import static android.net.thread.ThreadNetworkController.DEVICE_ROLE_ROUTER; @@ -805,6 +811,20 @@ public class ThreadNetworkControllerTest { assertThat(isAttached(mController)).isTrue(); assertThat(networkFuture.get(NETWORK_CALLBACK_TIMEOUT_MILLIS, MILLISECONDS)).isNotNull(); + NetworkCapabilities caps = + runAsShell( + ACCESS_NETWORK_STATE, () -> cm.getNetworkCapabilities(networkFuture.get())); + assertThat(caps).isNotNull(); + assertThat(caps.hasTransport(NetworkCapabilities.TRANSPORT_THREAD)).isTrue(); + assertThat(caps.getCapabilities()) + .asList() + .containsAtLeast( + NET_CAPABILITY_LOCAL_NETWORK, + NET_CAPABILITY_NOT_METERED, + NET_CAPABILITY_NOT_RESTRICTED, + NET_CAPABILITY_NOT_VCN_MANAGED, + NET_CAPABILITY_NOT_VPN, + NET_CAPABILITY_TRUSTED); } private void grantPermissions(String... permissions) {