Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7a9a48a authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by Automerger Merge Worker
Browse files

Merge "Add a test API for testing NetworkStack.getService" am: d4373f3a

Change-Id: I359470501a3a4b0ded7c806e6a661867c2d1a294
parents 88e1e454 d4373f3a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1519,6 +1519,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";
  }

+17 −0
Original line number Diff line number Diff line
@@ -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() {}

    /**