Resist SIM logical channel leaking when clients crash

When apps crashed with a logical channel opened, the channel
can not be reused by other apps, causing a leak.

With monitoring liveness of the cliets who open logical
channels. Telephony is able to close the channels proactively
when detecting clients die.

Bug: 197658986
Test: atest IccOpenLogicalChannelRequestTest CarrierApiTest
Change-Id: Ib511f2d05094f58661f32f652a87034df174d21d
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 0ce22c7..2eea80d 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -747,6 +747,12 @@
                         }
                         openChannelResp = new IccOpenLogicalChannelResponse(channelId,
                             IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
+
+                        uiccPort = getUiccPortFromRequest(request);
+                        IccLogicalChannelRequest channelRequest =
+                                (IccLogicalChannelRequest) request.argument;
+                        channelRequest.channel = channelId;
+                        uiccPort.onLogicalChannelOpened(channelRequest);
                     } else {
                         if (ar.result == null) {
                             loge("iccOpenLogicalChannel: Empty response");
@@ -789,6 +795,9 @@
                     request = (MainThreadRequest) ar.userObj;
                     if (ar.exception == null) {
                         request.result = true;
+                        uiccPort = getUiccPortFromRequest(request);
+                        final int channelId = (Integer) request.argument;
+                        uiccPort.onLogicalChannelClosed(channelId);
                     } else {
                         request.result = false;
                         if (ar.exception instanceof CommandException) {