Merge "Add tests for ServiceManager Java Binder API" into main am: a7d789633f am: f97e1bd890

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3099917

Change-Id: I0d29cdfb21c89b7a9f1af530e799ddb5e834413a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/core/tests/coretests/src/android/os/BinderTest.java b/core/tests/coretests/src/android/os/BinderTest.java
index 6c8b69f..9767d67 100644
--- a/core/tests/coretests/src/android/os/BinderTest.java
+++ b/core/tests/coretests/src/android/os/BinderTest.java
@@ -20,6 +20,8 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyInt;
 import static org.testng.Assert.assertThrows;
 
 import android.platform.test.annotations.IgnoreUnderRavenwood;
@@ -27,6 +29,9 @@
 
 import androidx.test.filters.SmallTest;
 
+import com.android.internal.os.BinderInternal;
+
+
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -81,4 +86,27 @@
         binder.setExtension(null);
         assertNull(binder.getExtension());
     }
+
+    @SmallTest
+    @Test(expected = java.lang.SecurityException.class)
+    public void testServiceManagerNativeSecurityException() throws RemoteException {
+        // Find the service manager
+        IServiceManager sServiceManager = ServiceManagerNative
+                .asInterface(Binder.allowBlocking(BinderInternal.getContextObject()));
+
+        Binder binder = new Binder();
+        sServiceManager.addService("ValidName",  binder,
+                anyBoolean(), anyInt());
+    }
+
+    @SmallTest
+    @Test(expected = java.lang.NullPointerException.class)
+    public void testServiceManagerNativeNullptrException() throws RemoteException {
+        // Find the service manager
+        IServiceManager sServiceManager = ServiceManagerNative
+                .asInterface(Binder.allowBlocking(BinderInternal.getContextObject()));
+
+        sServiceManager.addService("ValidName",  null,
+                anyBoolean(), anyInt());
+    }
 }