Allow non-primary users to configure calling accounts

PhoneAccountSettingsFragment is now open to non-primary user.
Hardcoding component of pstn conecntion service to avoid accessing
PhoneGlobal in non-primary user.

Change-Id: I05632fdf61fa6a579ca260e04a74ae370b4de51f
diff --git a/src/com/android/phone/PhoneUtils.java b/src/com/android/phone/PhoneUtils.java
index 1fa886c..a3b4cfb 100644
--- a/src/com/android/phone/PhoneUtils.java
+++ b/src/com/android/phone/PhoneUtils.java
@@ -145,6 +145,10 @@
     private static AlertDialog sUssdDialog = null;
     private static StringBuilder sUssdMsg = new StringBuilder();
 
+    private static final ComponentName PSTN_CONNECTION_SERVICE_COMPONENT =
+            new ComponentName("com.android.phone",
+                    "com.android.services.telephony.TelephonyConnectionService");
+
     /**
      * Handler that tracks the connections and updates the value of the
      * Mute settings for each connection as needed.
@@ -2511,7 +2515,7 @@
     }
 
     private static ComponentName getPstnConnectionServiceName() {
-        return new ComponentName(PhoneGlobals.getInstance(), TelephonyConnectionService.class);
+        return PSTN_CONNECTION_SERVICE_COMPONENT;
     }
 
     private static Phone getPhoneFromIccId(String iccId) {
diff --git a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
index c08b32a..27de57c 100644
--- a/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
+++ b/src/com/android/phone/settings/PhoneAccountSettingsFragment.java
@@ -7,6 +7,7 @@
 import android.graphics.drawable.Icon;
 import android.net.sip.SipManager;
 import android.os.Bundle;
+import android.os.UserManager;
 import android.preference.CheckBoxPreference;
 import android.preference.ListPreference;
 import android.preference.Preference;
@@ -150,7 +151,7 @@
             getPreferenceScreen().removePreference(mAccountList);
         }
 
-        if (SipUtil.isVoipSupported(getActivity())) {
+        if (isPrimaryUser() && SipUtil.isVoipSupported(getActivity())) {
             mSipSharedPreferences = new SipSharedPreferences(getActivity());
 
             mUseSipCalling = (ListPreference)
@@ -450,4 +451,13 @@
 
         return intent;
     }
+
+    /**
+     * @return Whether the current user is the primary user.
+     */
+    private boolean isPrimaryUser() {
+        final UserManager userManager = (UserManager) getActivity()
+                .getSystemService(Context.USER_SERVICE);
+        return userManager.isPrimaryUser();
+    }
 }