am fc43ea86: Add user ID parameter for getSimCallMangaer

* commit 'fc43ea86697d3d052415cbb4feda7bd508563532':
  Add user ID parameter for getSimCallMangaer
diff --git a/src/com/android/server/telecom/PhoneAccountRegistrar.java b/src/com/android/server/telecom/PhoneAccountRegistrar.java
index e9fa52a..d500eda 100644
--- a/src/com/android/server/telecom/PhoneAccountRegistrar.java
+++ b/src/com/android/server/telecom/PhoneAccountRegistrar.java
@@ -16,6 +16,7 @@
 
 package com.android.server.telecom;
 
+import android.app.ActivityManager;
 import android.Manifest;
 import android.content.ComponentName;
 import android.content.Context;
@@ -275,8 +276,28 @@
      * 3. Otherwise, we return null.
      */
     public PhoneAccountHandle getSimCallManager() {
+        long token = Binder.clearCallingIdentity();
+        int user;
+        try {
+            user = ActivityManager.getCurrentUser();
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+        return getSimCallManager(user);
+    }
+
+    /**
+     * Returns the {@link PhoneAccountHandle} corresponding to the currently active SIM Call
+     * Manager. SIM Call Manager returned corresponds to the following priority order:
+     * 1. If a SIM Call Manager {@link PhoneAccount} is registered for the same package as the
+     * default dialer, then that one is returned.
+     * 2. If there is a SIM Call Manager {@link PhoneAccount} registered which matches the
+     * carrier configuration's default, then that one is returned.
+     * 3. Otherwise, we return null.
+     */
+    public PhoneAccountHandle getSimCallManager(int user) {
         // Get the default dialer in case it has a connection manager associated with it.
-        String dialerPackage = DefaultDialerManager.getDefaultDialerApplication(mContext);
+        String dialerPackage = DefaultDialerManager.getDefaultDialerApplication(mContext, user);
 
         // Check carrier config.
         String defaultSimCallManager = null;
diff --git a/src/com/android/server/telecom/TelecomServiceImpl.java b/src/com/android/server/telecom/TelecomServiceImpl.java
index e209097..ebe930b 100644
--- a/src/com/android/server/telecom/TelecomServiceImpl.java
+++ b/src/com/android/server/telecom/TelecomServiceImpl.java
@@ -256,13 +256,25 @@
 
         @Override
         public PhoneAccountHandle getSimCallManager() {
+            long token  = Binder.clearCallingIdentity();
+            int user;
+            try {
+                user = ActivityManager.getCurrentUser();
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+            return getSimCallManagerForUser(user);
+        }
+
+        @Override
+        public PhoneAccountHandle getSimCallManagerForUser(int user) {
             synchronized (mLock) {
                 try {
                     PhoneAccountHandle accountHandle = null;
 
                     long token = Binder.clearCallingIdentity();
                     try {
-                        accountHandle = mPhoneAccountRegistrar.getSimCallManager();
+                        accountHandle = mPhoneAccountRegistrar.getSimCallManager(user);
                     } finally {
                         // We restore early so that isVisibleToCaller invocation below uses the
                         // right user context.