Add a test for bindIsolatedService with unusual characters in instanceName.

Test: atest CtsAppTestCases:android.app.cts.ServiceTest
Bug: 130164289
Change-Id: I1abb1eb02f5c2502388156c607c7825d76709c25
diff --git a/tests/app/src/android/app/cts/ServiceTest.java b/tests/app/src/android/app/cts/ServiceTest.java
index 6bea944..0809d38 100644
--- a/tests/app/src/android/app/cts/ServiceTest.java
+++ b/tests/app/src/android/app/cts/ServiceTest.java
@@ -1160,6 +1160,31 @@
     }
 
     /**
+     * Verify that certain characters are prohibited in instanceName.
+     */
+    public void testFailBindIsoaltedServiceWithInvalidInstanceName() throws Exception {
+        String[] badNames = {
+            "t\rest",
+            "test\n",
+            "test-three",
+            "test four",
+            "escape\u00a9seq",
+            "\u0164est",
+        };
+        for (String instanceName : badNames) {
+            EmptyConnection conn = new EmptyConnection();
+            try {
+                mContext.bindIsolatedService(mIsolatedService, Context.BIND_AUTO_CREATE,
+                        instanceName, mContextMainExecutor, conn);
+                mContext.unbindService(conn);
+                fail("Didn't get IllegalArgumentException: " + instanceName);
+            } catch (IllegalArgumentException e) {
+                // This is expected.
+            }
+        }
+    }
+
+    /**
      * Verify that bindIsolatedService() correctly makes different instances when given
      * different instance names.
      */