Merge "Add a test API for testing NetworkStack.getService" into rvc-dev

This commit is contained in:
Remi NGUYEN VAN
2020-03-19 14:53:35 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 0 deletions

View File

@@ -1832,6 +1832,7 @@ package android.net {
public class NetworkStack {
method @Nullable public static android.os.IBinder getService();
method public static void setServiceForTest(@Nullable android.os.IBinder);
field public static final String PERMISSION_MAINLINE_NETWORK_STACK = "android.permission.MAINLINE_NETWORK_STACK";
}

View File

@@ -45,6 +45,9 @@ public class NetworkStack {
public static final String PERMISSION_MAINLINE_NETWORK_STACK =
"android.permission.MAINLINE_NETWORK_STACK";
@Nullable
private static volatile IBinder sMockService;
/**
* Get an {@link IBinder} representing the NetworkStack stable AIDL Interface, if registered.
* @hide
@@ -53,9 +56,23 @@ public class NetworkStack {
@SystemApi
@TestApi
public static IBinder getService() {
final IBinder mockService = sMockService;
if (mockService != null) return mockService;
return ServiceManager.getService(Context.NETWORK_STACK_SERVICE);
}
/**
* Set a mock service for testing, to be returned by future calls to {@link #getService()}.
*
* <p>Passing a {@code null} {@code mockService} resets {@link #getService()} to normal
* behavior.
* @hide
*/
@TestApi
public static void setServiceForTest(@Nullable IBinder mockService) {
sMockService = mockService;
}
private NetworkStack() {}
/**