am bf329143: Merge "Make OTASP an explicit option for carriers." into lmp-dev

* commit 'bf329143cabb50afad4d4be1b0ad1eedc816513d':
  Make OTASP an explicit option for carriers.
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 382d39f..498b632 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -275,6 +275,8 @@
     <style name="SimImportTheme" parent="@android:style/Theme.Material.Light">
         <item name="android:actionBarStyle">@style/TelephonyActionBarStyle</item>
         <item name="android:colorPrimaryDark">@color/dialer_theme_color_dark</item>
+        <item name="android:homeAsUpIndicator">@drawable/ic_back_arrow</item>
+        <item name="android:actionOverflowButtonStyle">@style/DialtactsActionBarOverflow</item>
     </style>
 
     <style name="OutgoingCallBroadcasterTheme" parent="@android:style/Theme.Holo.NoActionBar">
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 26e31b0..e609eaf 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -37,6 +37,7 @@
 import android.os.Process;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
@@ -45,6 +46,7 @@
 import android.telephony.NeighboringCellInfo;
 import android.telephony.ServiceState;
 import android.telephony.SubscriptionManager;
+import android.telephony.SubInfoRecord;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Log;
@@ -61,6 +63,7 @@
 import com.android.internal.telephony.CallManager;
 import com.android.internal.telephony.CommandException;
 import com.android.internal.telephony.PhoneConstants;
+import com.android.internal.telephony.TelephonyIntents;
 import com.android.internal.telephony.dataconnection.DctController;
 import com.android.internal.telephony.uicc.AdnRecord;
 import com.android.internal.telephony.uicc.IccIoResult;
@@ -237,17 +240,20 @@
                     break;
 
                 case CMD_ANSWER_RINGING_CALL:
-                    answerRingingCallInternal();
+                    request = (MainThreadRequest) msg.obj;
+                    long answer_subId = ((Long)request.argument).longValue();
+                    answerRingingCallInternal(answer_subId);
                     break;
 
                 case CMD_END_CALL:
                     request = (MainThreadRequest) msg.obj;
-                    boolean hungUp;
-                    int phoneType = mPhone.getPhoneType();
+                    long end_subId = ((Long)request.argument).longValue();
+                    final boolean hungUp;
+                    int phoneType = getPhone(end_subId).getPhoneType();
                     if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
                         // CDMA: If the user presses the Power button we treat it as
                         // ending the complete call session
-                        hungUp = PhoneUtils.hangupRingingAndActive(mPhone);
+                        hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
                     } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
                         // GSM: End the call as per the Phone state
                         hungUp = PhoneUtils.hangup(mCM);
@@ -706,11 +712,8 @@
     }
 
     // returns phone associated with the subId.
-    // getPhone(0) returns default phone in single SIM mode.
     private Phone getPhone(long subId) {
-        // FIXME: hack for the moment
-        return mPhone;
-        // return PhoneUtils.getPhoneForSubscriber(subId);
+        return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
     }
     //
     // Implementation of the ITelephony interface.
@@ -736,7 +739,6 @@
         if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
             Intent  intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            intent.putExtra(SUBSCRIPTION_KEY, subId);
             mApp.startActivity(intent);
         }
     }
@@ -763,6 +765,18 @@
             return;
         }
 
+        boolean isValid = false;
+        List<SubInfoRecord> slist = SubscriptionManager.getActiveSubInfoList();
+        for (SubInfoRecord subInfoRecord : slist) {
+            if (subInfoRecord.subId == subId) {
+                isValid = true;
+                break;
+            }
+        }
+        if (isValid == false) {
+            return;
+        }
+
         Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
         intent.putExtra(SUBSCRIPTION_KEY, subId);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -783,7 +797,7 @@
      */
     public boolean endCallForSubscriber(long subId) {
         enforceCallPermission();
-        return (Boolean) sendRequest(CMD_END_CALL, subId, null);
+        return (Boolean) sendRequest(CMD_END_CALL, new Long(subId), null);
     }
 
     public void answerRingingCall() {
@@ -796,7 +810,7 @@
         // but that can probably wait till the big TelephonyManager API overhaul.
         // For now, protect this call with the MODIFY_PHONE_STATE permission.
         enforceModifyPermission();
-        sendRequestAsync(CMD_ANSWER_RINGING_CALL);
+        sendRequest(CMD_ANSWER_RINGING_CALL, new Long(subId), null);
     }
 
     /**
@@ -812,11 +826,11 @@
      * than sendRequestAsync(), and right now we don't actually *need* that
      * return value, so let's just return void for now.
      */
-    private void answerRingingCallInternal() {
-        final boolean hasRingingCall = !mPhone.getRingingCall().isIdle();
+    private void answerRingingCallInternal(long subId) {
+        final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
         if (hasRingingCall) {
-            final boolean hasActiveCall = !mPhone.getForegroundCall().isIdle();
-            final boolean hasHoldingCall = !mPhone.getBackgroundCall().isIdle();
+            final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
+            final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
             if (hasActiveCall && hasHoldingCall) {
                 // Both lines are in use!
                 // TODO: provide a flag to let the caller specify what
@@ -1805,7 +1819,7 @@
     @Override
     public int getCalculatedPreferredNetworkType() {
         enforceReadPermission();
-        return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext());
+        return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get PhoneId from somewhere.
     }
 
     /**
diff --git a/src/com/android/phone/SimContacts.java b/src/com/android/phone/SimContacts.java
index a069e41..8192795 100644
--- a/src/com/android/phone/SimContacts.java
+++ b/src/com/android/phone/SimContacts.java
@@ -39,6 +39,7 @@
 import android.provider.ContactsContract.Data;
 import android.provider.ContactsContract.RawContacts;
 import android.telecom.PhoneAccount;
+import android.telephony.SubscriptionManager;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.ContextMenu;
@@ -242,8 +243,13 @@
 
     @Override
     protected Uri resolveIntent() {
-        Intent intent = getIntent();
-        intent.setData(Uri.parse("content://icc/adn"));
+        final Intent intent = getIntent();
+        if (intent.hasExtra("subscription_id")) {
+            final long subId = intent.getLongExtra("subscription_id", -1);
+            intent.setData(Uri.parse("content://icc/adn/subId/" + subId));
+        } else {
+            intent.setData(Uri.parse("content://icc/adn"));
+        }
         if (Intent.ACTION_PICK.equals(intent.getAction())) {
             // "index" is 1-based
             mInitialSelection = intent.getIntExtra("index", 0) - 1;