Allow SimDialogActivity to be started for result
In Telephony, we sometimes need to be able to launch
the SIM pick dialog activity for SMS without setting
a new default (i.e. user chose "ask every time") for
default SMS subscription.
Adds the ability for the SimDialogActivity to be
called using startActivityForResult and not set the
user's choice as the default.
Bug: 130853716
Bug: 130567323
Test: run Telephony SmsManagerTestApp
Merged-In: Ib448a6901581294050fc988ed9c16f7e93066860
Change-Id: If9f9ebbfe9b7b6718ed759937abbcfa6d22c6295
diff --git a/src/com/android/settings/sim/SimDialogActivity.java b/src/com/android/settings/sim/SimDialogActivity.java
index 853f80d..5a45fb4 100644
--- a/src/com/android/settings/sim/SimDialogActivity.java
+++ b/src/com/android/settings/sim/SimDialogActivity.java
@@ -22,6 +22,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
+import android.content.Intent;
import android.os.Bundle;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
@@ -50,11 +51,15 @@
public static String PREFERRED_SIM = "preferred_sim";
public static String DIALOG_TYPE_KEY = "dialog_type";
+ // sub ID returned from startActivityForResult
+ public static String RESULT_SUB_ID = "result_sub_id";
public static final int INVALID_PICK = -1;
public static final int DATA_PICK = 0;
public static final int CALLS_PICK = 1;
public static final int SMS_PICK = 2;
public static final int PREFERRED_PICK = 3;
+ // Show the "select SMS subscription" dialog, but don't save as default, just return a result
+ public static final int SMS_PICK_FOR_MESSAGE = 4;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -65,6 +70,7 @@
case DATA_PICK:
case CALLS_PICK:
case SMS_PICK:
+ case SMS_PICK_FOR_MESSAGE:
createDialog(this, dialogType).show();
break;
case PREFERRED_PICK:
@@ -179,6 +185,14 @@
sir = subInfoList.get(value);
setDefaultSmsSubId(context, sir.getSubscriptionId());
break;
+ case SMS_PICK_FOR_MESSAGE:
+ sir = subInfoList.get(value);
+ // Don't set a default here.
+ // The caller has created this dialog waiting for a result.
+ Intent intent = new Intent();
+ intent.putExtra(RESULT_SUB_ID, sir.getSubscriptionId());
+ setResult(Activity.RESULT_OK, intent);
+ break;
default:
throw new IllegalArgumentException("Invalid dialog type "
+ id + " in SIM dialog.");
@@ -250,8 +264,11 @@
builder.setTitle(R.string.select_sim_for_calls);
break;
case SMS_PICK:
+ // intentional fallthrough
+ case SMS_PICK_FOR_MESSAGE:
builder.setTitle(R.string.sim_card_select_title);
break;
+
default:
throw new IllegalArgumentException("Invalid dialog type "
+ id + " in SIM dialog.");