Merge "Allow OpenLogicalChannel with null aid for privilege apps" into rvc-dev am: da6daab1eb

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/SecureElement/+/11628925

Change-Id: I46507e9b4a76e26f9d257cb1a354b10ace89e45d
diff --git a/src/com/android/se/SecureElementService.java b/src/com/android/se/SecureElementService.java
index 5ca4646..e979fd9 100644
--- a/src/com/android/se/SecureElementService.java
+++ b/src/com/android/se/SecureElementService.java
@@ -303,9 +303,6 @@
                 throw new IllegalStateException("Session is closed");
             } else if (listener == null) {
                 throw new NullPointerException("listener must not be null");
-            } else if (((aid == null) || (aid.length == 0)) && mReader.getTerminal().getName()
-                    .startsWith(SecureElementService.UICC_TERMINAL)) {
-                return null;
             } else if ((p2 != 0x00) && (p2 != 0x04) && (p2 != 0x08)
                     && (p2 != (byte) 0x0C)) {
                 throw new UnsupportedOperationException("p2 not supported: "
diff --git a/src/com/android/se/Terminal.java b/src/com/android/se/Terminal.java
index 080f337..4638926 100644
--- a/src/com/android/se/Terminal.java
+++ b/src/com/android/se/Terminal.java
@@ -517,7 +517,7 @@
                     packageName);
             try {
                 channelAccess = setUpChannelAccess(aid, packageName, pid, false);
-            } catch (MissingResourceException e) {
+            } catch (MissingResourceException | UnsupportedOperationException e) {
                 return null;
             }
         }
@@ -761,6 +761,10 @@
             }
             if (isBasicChannel) {
                 throw new MissingResourceException("openBasicChannel is not allowed.", "", "");
+            } else if (aid == null) {
+                // openLogicalChannel with null aid is only allowed for privilege applications
+                throw new UnsupportedOperationException(
+                        "null aid is not accepted in UICC terminal.");
             }
         }