diff options
author | Nancy Chen <nancychen@google.com> | 2014-10-30 10:25:00 -0700 |
---|---|---|
committer | Nancy Chen <nancychen@google.com> | 2014-11-03 10:58:01 -0800 |
commit | 18c52ffec7896bbbb7f161994b4453d91fcc79ef (patch) | |
tree | 91bdd1eff76e9409959d08e1ad3dfb5bdb24eb56 /src | |
parent | 272b84b3ef3d948ba1c9703b39525477d9d6f272 (diff) |
Adn queries for multi-SIM. (1/3)
Bring up a dialog if no default subscription account is set by the
user when handling ADN queries.
Bug: 17917937
Change-Id: Icd6a6dc2843463ba68d281a24e00fdba1880adf4
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/SpecialCharSequenceMgr.java | 86 | ||||
-rw-r--r-- | src/com/android/dialer/dialpad/DialpadFragment.java | 2 |
2 files changed, 64 insertions, 24 deletions
diff --git a/src/com/android/dialer/SpecialCharSequenceMgr.java b/src/com/android/dialer/SpecialCharSequenceMgr.java index 2bf1afcf9..45c22fd55 100644 --- a/src/com/android/dialer/SpecialCharSequenceMgr.java +++ b/src/com/android/dialer/SpecialCharSequenceMgr.java @@ -43,10 +43,8 @@ import com.android.contacts.common.database.NoNullCursorAsyncQueryHandler; import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener; import com.android.dialer.calllog.PhoneAccountUtils; -import com.android.incallui.InCallPresenter; import java.util.Arrays; -import java.util.List; import java.util.ArrayList; import java.util.List; @@ -151,7 +149,7 @@ public class SpecialCharSequenceMgr { * This code works alongside the Asynchronous query handler {@link QueryHandler} * and query cancel handler implemented in {@link SimContactQueryCookie}. */ - static boolean handleAdnEntry(Context context, String input, EditText textField) { + static boolean handleAdnEntry(final Context context, String input, EditText textField) { /* ADN entries are of the form "N(N)(N)#" */ TelephonyManager telephonyManager = @@ -175,7 +173,7 @@ public class SpecialCharSequenceMgr { if ((len > 1) && (len < 5) && (input.endsWith("#"))) { try { // get the ordinal number of the sim contact - int index = Integer.parseInt(input.substring(0, len-1)); + final int index = Integer.parseInt(input.substring(0, len-1)); // The original code that navigated to a SIM Contacts list view did not // highlight the requested contact correctly, a requirement for PTCRB @@ -185,10 +183,10 @@ public class SpecialCharSequenceMgr { // the dialer text field. // create the async query handler - QueryHandler handler = new QueryHandler (context.getContentResolver()); + final QueryHandler handler = new QueryHandler (context.getContentResolver()); // create the cookie object - SimContactQueryCookie sc = new SimContactQueryCookie(index - 1, handler, + final SimContactQueryCookie sc = new SimContactQueryCookie(index - 1, handler, ADN_QUERY_TOKEN); // setup the cookie fields @@ -205,18 +203,38 @@ public class SpecialCharSequenceMgr { sc.progressDialog.getWindow().addFlags( WindowManager.LayoutParams.FLAG_BLUR_BEHIND); - // display the progress dialog - sc.progressDialog.show(); - - // run the query. - handler.startQuery(ADN_QUERY_TOKEN, sc, Uri.parse("content://icc/adn"), - new String[]{ADN_PHONE_NUMBER_COLUMN_NAME}, null, null, null); - - if (sPreviousAdnQueryHandler != null) { - // It is harmless to call cancel() even after the handler's gone. - sPreviousAdnQueryHandler.cancel(); + final TelecomManager telecomManager = + (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); + List<PhoneAccountHandle> phoneAccountHandles = + PhoneAccountUtils.getSubscriptionPhoneAccounts(context); + + boolean hasUserSelectedDefault = hasDefaultSubscriptionAccount( + telecomManager.getUserSelectedOutgoingPhoneAccount(), phoneAccountHandles); + + if (phoneAccountHandles.size() == 1 || hasUserSelectedDefault) { + Uri uri = telecomManager.getAdnUriForPhoneAccount(null); + handleAdnQuery(handler, sc, uri); + } else if (phoneAccountHandles.size() > 1){ + SelectPhoneAccountListener listener = new SelectPhoneAccountListener() { + @Override + public void onPhoneAccountSelected(PhoneAccountHandle selectedAccountHandle, + boolean setDefault) { + Uri uri = + telecomManager.getAdnUriForPhoneAccount(selectedAccountHandle); + handleAdnQuery(handler, sc, uri); + //TODO: show error dialog if result isn't valid + } + @Override + public void onDialogDismissed() {} + }; + + SelectPhoneAccountDialogFragment.showAccountDialog( + ((Activity) context).getFragmentManager(), false, phoneAccountHandles, + listener); + } else { + return false; } - sPreviousAdnQueryHandler = handler; + return true; } catch (NumberFormatException ex) { // Ignore @@ -225,6 +243,27 @@ public class SpecialCharSequenceMgr { return false; } + private static void handleAdnQuery(QueryHandler handler, SimContactQueryCookie cookie, + Uri uri) { + if (handler == null || cookie == null || uri == null) { + Log.w(TAG, "queryAdn parameters incorrect"); + return; + } + + // display the progress dialog + cookie.progressDialog.show(); + + // run the query. + handler.startQuery(ADN_QUERY_TOKEN, cookie, uri, new String[]{ADN_PHONE_NUMBER_COLUMN_NAME}, + null, null, null); + + if (sPreviousAdnQueryHandler != null) { + // It is harmless to call cancel() even after the handler's gone. + sPreviousAdnQueryHandler.cancel(); + } + sPreviousAdnQueryHandler = handler; + } + static boolean handlePinEntry(Context context, final String input) { if ((input.startsWith("**04") || input.startsWith("**05")) && input.endsWith("#")) { final TelecomManager telecomManager = @@ -411,12 +450,13 @@ public class SpecialCharSequenceMgr { // get the EditText to update or see if the request was cancelled. EditText text = sc.getTextField(); - // if the textview is valid, and the cursor is valid and postionable - // on the Nth number, then we update the text field and display a - // toast indicating the caller name. + // if the TextView is valid, and the cursor is valid and positionable on the + // Nth number, then we update the text field and display a toast indicating the + // caller name. if ((c != null) && (text != null) && (c.moveToPosition(sc.contactNum))) { String name = c.getString(c.getColumnIndexOrThrow(ADN_NAME_COLUMN_NAME)); - String number = c.getString(c.getColumnIndexOrThrow(ADN_PHONE_NUMBER_COLUMN_NAME)); + String number = + c.getString(c.getColumnIndexOrThrow(ADN_PHONE_NUMBER_COLUMN_NAME)); // fill the text in. text.getText().replace(0, 0, number); @@ -434,8 +474,8 @@ public class SpecialCharSequenceMgr { public void cancel() { mCanceled = true; - // Ask AsyncQueryHandler to cancel the whole request. This will fails when the - // query already started. + // Ask AsyncQueryHandler to cancel the whole request. This will fail when the query is + // already started. cancelOperation(ADN_QUERY_TOKEN); } } diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java index c6bbe25b5..5695f1c48 100644 --- a/src/com/android/dialer/dialpad/DialpadFragment.java +++ b/src/com/android/dialer/dialpad/DialpadFragment.java @@ -284,7 +284,7 @@ public class DialpadFragment extends Fragment @Override public void afterTextChanged(Editable input) { - // When DTMF dialpad buttons are being pressed, we delay SpecialCharSequencMgr sequence, + // When DTMF dialpad buttons are being pressed, we delay SpecialCharSequenceMgr sequence, // since some of SpecialCharSequenceMgr's behavior is too abrupt for the "touch-down" // behavior. if (!mDigitsFilledByIntent && |