Make queryRemoteConnectionServices DSDS aware.

The method queryRemoteConnectionServices had the issue that it assumes
there is a single connection manager for the device.  This assumption does
not work on a multisim device.  Since the ConnectionManager is associated
with a particular carrier, this means that the connection mgr for one
carrier could try to impact calls destined for another carrier.

This change ensures that the calling package is passed into Telecom so
that we can determine which RemoteConnectionServices which are available to
the calling connection manager.

Test: Manual test on DSDS with a connection mgr carrier and another carrier.
Bug: 131856987
Change-Id: I46d80dc68adaab7fd4374f023d7ba4242804c253
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index 49b34b3..c66e92b 100644
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -1937,6 +1937,8 @@
             return;
         }
 
+        String callingPackage = getOpPackageName();
+
         mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() {
             @Override
             public void onResult(
@@ -1965,7 +1967,7 @@
                     }
                 }.prepare());
             }
-        });
+        }, callingPackage);
     }
 
     /**
diff --git a/telecomm/java/android/telecom/ConnectionServiceAdapter.java b/telecomm/java/android/telecom/ConnectionServiceAdapter.java
index 6c3f4f3..3acd83a 100644
--- a/telecomm/java/android/telecom/ConnectionServiceAdapter.java
+++ b/telecomm/java/android/telecom/ConnectionServiceAdapter.java
@@ -316,11 +316,11 @@
     /**
      * Retrieves a list of remote connection services usable to place calls.
      */
-    void queryRemoteConnectionServices(RemoteServiceCallback callback) {
+    void queryRemoteConnectionServices(RemoteServiceCallback callback, String callingPackage) {
         // Only supported when there is only one adapter.
         if (mAdapters.size() == 1) {
             try {
-                mAdapters.iterator().next().queryRemoteConnectionServices(callback,
+                mAdapters.iterator().next().queryRemoteConnectionServices(callback, callingPackage,
                         Log.getExternalSession());
             } catch (RemoteException e) {
                 Log.e(this, e, "Exception trying to query for remote CSs");
diff --git a/telecomm/java/android/telecom/ConnectionServiceAdapterServant.java b/telecomm/java/android/telecom/ConnectionServiceAdapterServant.java
index f99b218..b281589 100644
--- a/telecomm/java/android/telecom/ConnectionServiceAdapterServant.java
+++ b/telecomm/java/android/telecom/ConnectionServiceAdapterServant.java
@@ -186,8 +186,13 @@
                     break;
                 }
                 case MSG_QUERY_REMOTE_CALL_SERVICES:
-                    mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) msg.obj,
-                            null /*Session.Info*/);
+                    SomeArgs args2 = (SomeArgs) msg.obj;
+                    try {
+                        mDelegate.queryRemoteConnectionServices((RemoteServiceCallback) args2.arg1,
+                                (String) args2.arg2, null /*Session.Info*/);
+                    } finally {
+                        args2.recycle();
+                    }
                     break;
                 case MSG_SET_VIDEO_STATE:
                     mDelegate.setVideoState((String) msg.obj, msg.arg1, null /*Session.Info*/);
@@ -468,7 +473,10 @@
 
         @Override
         public void queryRemoteConnectionServices(RemoteServiceCallback callback,
-                Session.Info sessionInfo) {
+                String callingPackage, Session.Info sessionInfo) {
+            SomeArgs args = SomeArgs.obtain();
+            args.arg1 = callback;
+            args.arg2 = callingPackage;
             mHandler.obtainMessage(MSG_QUERY_REMOTE_CALL_SERVICES, callback).sendToTarget();
         }
 
diff --git a/telecomm/java/android/telecom/RemoteConnectionService.java b/telecomm/java/android/telecom/RemoteConnectionService.java
index 744544e..1e73bd6 100644
--- a/telecomm/java/android/telecom/RemoteConnectionService.java
+++ b/telecomm/java/android/telecom/RemoteConnectionService.java
@@ -288,7 +288,7 @@
 
         @Override
         public void queryRemoteConnectionServices(RemoteServiceCallback callback,
-                Session.Info sessionInfo) {
+                String callingPackage, Session.Info sessionInfo) {
             // Not supported from remote connection service.
         }
 
diff --git a/telecomm/java/com/android/internal/telecom/IConnectionServiceAdapter.aidl b/telecomm/java/com/android/internal/telecom/IConnectionServiceAdapter.aidl
index 76ac88e..9cf098c 100644
--- a/telecomm/java/com/android/internal/telecom/IConnectionServiceAdapter.aidl
+++ b/telecomm/java/com/android/internal/telecom/IConnectionServiceAdapter.aidl
@@ -78,7 +78,8 @@
 
     void onPostDialChar(String callId, char nextChar, in Session.Info sessionInfo);
 
-    void queryRemoteConnectionServices(RemoteServiceCallback callback, in Session.Info sessionInfo);
+    void queryRemoteConnectionServices(RemoteServiceCallback callback, String callingPackage,
+    in Session.Info sessionInfo);
 
     void setVideoProvider(String callId, IVideoProvider videoProvider, in Session.Info sessionInfo);