From 4fb013772611c0bf59ac27a6f68135c14caa1f1f Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Wed, 18 Mar 2020 18:29:30 +0900 Subject: [PATCH] Remove NETWORK_STACK_SERVICE constant Instead, have a dedicated method in android.net.NetworkStack allowing to fetch the stable AIDL token for the service. This avoids returning IBinder from getSystemService, as getSystemService should generally return manager classes. Test: atest FrameworksNetTests NetworkStackTests Fixes: 151243982 Merged-In: I58a6e1f27aff052050197d1901f43a98d7aa1167 (clean cherry-pick from internal branch) Change-Id: I75aba269595f3e315dd5e0693c878b2026e8e299 --- api/system-current.txt | 2 +- api/test-current.txt | 2 +- .../java/android/app/SystemServiceRegistry.java | 8 -------- core/java/android/content/Context.java | 2 -- core/java/android/net/NetworkStack.java | 17 +++++++++++++++-- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 67c6a2a927f6b..332baa394d6f0 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -1612,7 +1612,6 @@ package android.content { field public static final String NETD_SERVICE = "netd"; field public static final String NETWORK_POLICY_SERVICE = "netpolicy"; field public static final String NETWORK_SCORE_SERVICE = "network_score"; - field public static final String NETWORK_STACK_SERVICE = "network_stack"; field public static final String OEM_LOCK_SERVICE = "oem_lock"; field public static final String PERMISSION_SERVICE = "permission"; field public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block"; @@ -4740,6 +4739,7 @@ package android.net { } public class NetworkStack { + method @Nullable public static android.os.IBinder getService(); field public static final String PERMISSION_MAINLINE_NETWORK_STACK = "android.permission.MAINLINE_NETWORK_STACK"; } diff --git a/api/test-current.txt b/api/test-current.txt index d46f36885c56d..c776e6f3f31be 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -658,7 +658,6 @@ package android.content { field public static final String BUGREPORT_SERVICE = "bugreport"; field public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture"; field public static final String ETHERNET_SERVICE = "ethernet"; - field public static final String NETWORK_STACK_SERVICE = "network_stack"; field public static final String PERMISSION_SERVICE = "permission"; field public static final String ROLLBACK_SERVICE = "rollback"; field public static final String STATUS_BAR_SERVICE = "statusbar"; @@ -1518,6 +1517,7 @@ package android.net { } public class NetworkStack { + method @Nullable public static android.os.IBinder getService(); field public static final String PERMISSION_MAINLINE_NETWORK_STACK = "android.permission.MAINLINE_NETWORK_STACK"; } diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java index 7a736d69bbb55..4d972b13dcd3a 100644 --- a/core/java/android/app/SystemServiceRegistry.java +++ b/core/java/android/app/SystemServiceRegistry.java @@ -347,14 +347,6 @@ final class SystemServiceRegistry { } }); - registerService(Context.NETWORK_STACK_SERVICE, IBinder.class, - new StaticServiceFetcher() { - @Override - public IBinder createService() { - return ServiceManager.getService(Context.NETWORK_STACK_SERVICE); - } - }); - registerService(Context.TETHERING_SERVICE, TetheringManager.class, new CachedServiceFetcher() { @Override diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index c19c2848a0ae5..f9793a909dba5 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -3864,8 +3864,6 @@ public abstract class Context { * @hide * @see NetworkStackClient */ - @SystemApi - @TestApi public static final String NETWORK_STACK_SERVICE = "network_stack"; /** diff --git a/core/java/android/net/NetworkStack.java b/core/java/android/net/NetworkStack.java index a46c410bd55ef..a6d52d133ce90 100644 --- a/core/java/android/net/NetworkStack.java +++ b/core/java/android/net/NetworkStack.java @@ -19,15 +19,17 @@ import static android.Manifest.permission.NETWORK_STACK; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.SystemApi; import android.annotation.TestApi; import android.content.Context; +import android.os.IBinder; +import android.os.ServiceManager; import java.util.ArrayList; import java.util.Arrays; /** - * - * Constants for client code communicating with the network stack service. + * Constants and utilities for client code communicating with the network stack service. * @hide */ @SystemApi @@ -43,6 +45,17 @@ public class NetworkStack { public static final String PERMISSION_MAINLINE_NETWORK_STACK = "android.permission.MAINLINE_NETWORK_STACK"; + /** + * Get an {@link IBinder} representing the NetworkStack stable AIDL Interface, if registered. + * @hide + */ + @Nullable + @SystemApi + @TestApi + public static IBinder getService() { + return ServiceManager.getService(Context.NETWORK_STACK_SERVICE); + } + private NetworkStack() {} /**