From 73a74c3c709c87d4ad9860c1fbda585c139235e0 Mon Sep 17 00:00:00 2001 From: twyen Date: Wed, 7 Mar 2018 12:12:24 -0800 Subject: Handle preferred SIM for ACTION_CALL Previously preferred SIM is handled only by precall, which covers dialing with dialer or with the special receiver contacts uses. If a third party app uses ACTION_CALL or telecomManager.placeCall(), then the in call UI will be launched directly and the old account selection dialog will be used without preferred SIM support. In this CL logic from CallingAccountSelector is refactored out so InCallActivity can use it for the dialog. Bug: 73718976 Test: Unit tests, In call UI not covered. PiperOrigin-RevId: 188214007 Change-Id: Ifaacf982a3e98601dc362b649c3501d4ee96e63e --- .../android/contacts/common/res/values/strings.xml | 6 +- .../about/res/raw/third_party_license_metadata | 102 +- .../dialer/about/res/raw/third_party_licenses | 4133 +++++++++++++++++--- .../precall/impl/CallingAccountSelector.java | 386 +- .../dialer/precall/impl/res/values/strings.xml | 8 - .../preferredsim/PreferredAccountRecorder.java | 145 + .../preferredsim/PreferredAccountWorker.java | 273 ++ .../preferredsim/suggestion/AndroidManifest.xml | 19 + .../suggestion/SuggestionProvider.java | 37 + .../preferredsim/suggestion/res/values/strings.xml | 25 + java/com/android/incallui/InCallActivity.java | 92 +- java/com/android/incallui/call/DialerCall.java | 16 + 12 files changed, 4297 insertions(+), 945 deletions(-) create mode 100644 java/com/android/dialer/preferredsim/PreferredAccountRecorder.java create mode 100644 java/com/android/dialer/preferredsim/PreferredAccountWorker.java create mode 100644 java/com/android/dialer/preferredsim/suggestion/AndroidManifest.xml create mode 100644 java/com/android/dialer/preferredsim/suggestion/res/values/strings.xml (limited to 'java/com') diff --git a/java/com/android/contacts/common/res/values/strings.xml b/java/com/android/contacts/common/res/values/strings.xml index dbe97ea39..809439ee5 100644 --- a/java/com/android/contacts/common/res/values/strings.xml +++ b/java/com/android/contacts/common/res/values/strings.xml @@ -372,7 +372,11 @@ Always use this for calls - Call with + Choose SIM for this call + + + Remember this choice Remember this choice - - Uses same carrier - - - Recently used - \ No newline at end of file diff --git a/java/com/android/dialer/preferredsim/PreferredAccountRecorder.java b/java/com/android/dialer/preferredsim/PreferredAccountRecorder.java new file mode 100644 index 000000000..75f8ad71d --- /dev/null +++ b/java/com/android/dialer/preferredsim/PreferredAccountRecorder.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.preferredsim; + +import android.content.ContentValues; +import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.WorkerThread; +import android.telecom.PhoneAccountHandle; +import com.android.dialer.common.Assert; +import com.android.dialer.common.concurrent.DialerExecutor.Worker; +import com.android.dialer.common.concurrent.DialerExecutorComponent; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; +import com.android.dialer.preferredsim.PreferredSimFallbackContract.PreferredSim; +import com.android.dialer.preferredsim.suggestion.SimSuggestionComponent; +import com.android.dialer.preferredsim.suggestion.SuggestionProvider.Suggestion; + +/** Records selected preferred SIM and reports related metric to the suggestion provider */ +public class PreferredAccountRecorder { + + @Nullable private final String number; + @Nullable private final Suggestion suggestion; + @Nullable private final String dataId; + + public PreferredAccountRecorder( + @Nullable String number, @Nullable Suggestion suggestion, @Nullable String dataId) { + this.number = number; + this.suggestion = suggestion; + this.dataId = dataId; + } + + /** + * Record the result from {@link + * com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener#onPhoneAccountSelected} + */ + public void record( + Context context, PhoneAccountHandle selectedAccountHandle, boolean setDefault) { + + if (suggestion != null) { + if (suggestion.phoneAccountHandle.equals(selectedAccountHandle)) { + Logger.get(context) + .logImpression(DialerImpression.Type.DUAL_SIM_SELECTION_SUGGESTED_SIM_SELECTED); + } else { + Logger.get(context) + .logImpression(DialerImpression.Type.DUAL_SIM_SELECTION_NON_SUGGESTED_SIM_SELECTED); + } + } + + if (dataId != null && setDefault) { + Logger.get(context).logImpression(DialerImpression.Type.DUAL_SIM_SELECTION_PREFERRED_SET); + DialerExecutorComponent.get(context) + .dialerExecutorFactory() + .createNonUiTaskBuilder(new WritePreferredAccountWorker()) + .build() + .executeParallel( + new WritePreferredAccountWorkerInput(context, dataId, selectedAccountHandle)); + } + if (number != null) { + DialerExecutorComponent.get(context) + .dialerExecutorFactory() + .createNonUiTaskBuilder( + new UserSelectionReporter(selectedAccountHandle, number, setDefault)) + .build() + .executeParallel(context); + } + } + + private static class UserSelectionReporter implements Worker { + + private final String number; + private final PhoneAccountHandle phoneAccountHandle; + private final boolean remember; + + public UserSelectionReporter( + @NonNull PhoneAccountHandle phoneAccountHandle, @Nullable String number, boolean remember) { + this.phoneAccountHandle = Assert.isNotNull(phoneAccountHandle); + this.number = Assert.isNotNull(number); + this.remember = remember; + } + + @Nullable + @Override + public Void doInBackground(@NonNull Context context) throws Throwable { + SimSuggestionComponent.get(context) + .getSuggestionProvider() + .reportUserSelection(context, number, phoneAccountHandle, remember); + return null; + } + } + + private static class WritePreferredAccountWorkerInput { + private final Context context; + private final String dataId; + private final PhoneAccountHandle phoneAccountHandle; + + WritePreferredAccountWorkerInput( + @NonNull Context context, + @NonNull String dataId, + @NonNull PhoneAccountHandle phoneAccountHandle) { + this.context = Assert.isNotNull(context); + this.dataId = Assert.isNotNull(dataId); + this.phoneAccountHandle = Assert.isNotNull(phoneAccountHandle); + } + } + + private static class WritePreferredAccountWorker + implements Worker { + + @Nullable + @Override + @WorkerThread + public Void doInBackground(WritePreferredAccountWorkerInput input) throws Throwable { + ContentValues values = new ContentValues(); + values.put( + PreferredSim.PREFERRED_PHONE_ACCOUNT_COMPONENT_NAME, + input.phoneAccountHandle.getComponentName().flattenToString()); + values.put(PreferredSim.PREFERRED_PHONE_ACCOUNT_ID, input.phoneAccountHandle.getId()); + input + .context + .getContentResolver() + .update( + PreferredSimFallbackContract.CONTENT_URI, + values, + PreferredSim.DATA_ID + " = ?", + new String[] {String.valueOf(input.dataId)}); + return null; + } + } +} diff --git a/java/com/android/dialer/preferredsim/PreferredAccountWorker.java b/java/com/android/dialer/preferredsim/PreferredAccountWorker.java new file mode 100644 index 000000000..bfaaa7cde --- /dev/null +++ b/java/com/android/dialer/preferredsim/PreferredAccountWorker.java @@ -0,0 +1,273 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.preferredsim; + +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.database.Cursor; +import android.net.Uri; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; +import android.provider.ContactsContract.Contacts; +import android.provider.ContactsContract.Data; +import android.provider.ContactsContract.PhoneLookup; +import android.provider.ContactsContract.QuickContact; +import android.provider.ContactsContract.RawContacts; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.annotation.VisibleForTesting; +import android.support.annotation.WorkerThread; +import android.telecom.PhoneAccountHandle; +import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.DialerExecutor.Worker; +import com.android.dialer.configprovider.ConfigProviderBindings; +import com.android.dialer.preferredsim.PreferredAccountWorker.Result; +import com.android.dialer.preferredsim.PreferredSimFallbackContract.PreferredSim; +import com.android.dialer.preferredsim.suggestion.SimSuggestionComponent; +import com.android.dialer.preferredsim.suggestion.SuggestionProvider.Suggestion; +import com.android.dialer.util.PermissionsUtil; +import com.google.auto.value.AutoValue; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; + +/** Query a preferred SIM to make a call with. */ +public class PreferredAccountWorker implements Worker { + + /** The result of the worker. */ + @AutoValue + public abstract static class Result { + + /** The preferred phone account for the number. Absent if not set or invalid. */ + public abstract Optional getPhoneAccountHandle(); + + /** + * {@link android.provider.ContactsContract.Data#_ID} of the row matching the number. If the + * preferred account is to be set it should be stored in this row + */ + public abstract Optional getDataId(); + + public abstract Optional getSuggestion(); + + static Builder builder() { + return new AutoValue_PreferredAccountWorker_Result.Builder(); + } + + @AutoValue.Builder + abstract static class Builder { + + public abstract Builder setPhoneAccountHandle( + Optional phoneAccountHandle); + + public abstract Builder setDataId(Optional dataId); + + public abstract Builder setSuggestion(Optional suggestion); + + public abstract Result build(); + } + } + + @VisibleForTesting + public static final String METADATA_SUPPORTS_PREFERRED_SIM = + "supports_per_number_preferred_account"; + + private final String phoneNumber; + + public PreferredAccountWorker(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + @NonNull + @Override + @WorkerThread + public Result doInBackground(Context context) throws Throwable { + Result.Builder resultBuilder = Result.builder(); + if (!isPreferredSimEnabled(context)) { + return resultBuilder.build(); + } + if (!PermissionsUtil.hasContactsReadPermissions(context)) { + LogUtil.i("PreferredAccountWorker.doInBackground", "missing READ_CONTACTS permission"); + return resultBuilder.build(); + } + Optional dataId = getDataId(context, phoneNumber); + Optional phoneAccountHandle = Optional.absent(); + if (dataId.isPresent()) { + resultBuilder.setDataId(dataId); + phoneAccountHandle = getPreferredAccount(context, dataId.get()); + } + resultBuilder.setPhoneAccountHandle(phoneAccountHandle); + Optional suggestion = Optional.absent(); + if (!phoneAccountHandle.isPresent()) { + suggestion = + SimSuggestionComponent.get(context) + .getSuggestionProvider() + .getSuggestion(context, phoneNumber); + resultBuilder.setSuggestion(suggestion); + } + return resultBuilder.build(); + } + + @WorkerThread + @NonNull + private static Optional getDataId( + @NonNull Context context, @Nullable String phoneNumber) { + Assert.isWorkerThread(); + if (VERSION.SDK_INT < VERSION_CODES.N) { + return Optional.absent(); + } + try (Cursor cursor = + context + .getContentResolver() + .query( + Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber)), + new String[] {PhoneLookup.DATA_ID}, + null, + null, + null)) { + if (cursor == null) { + return Optional.absent(); + } + ImmutableSet validAccountTypes = PreferredAccountUtil.getValidAccountTypes(context); + String result = null; + while (cursor.moveToNext()) { + Optional accountType = + getAccountType(context.getContentResolver(), cursor.getLong(0)); + if (accountType.isPresent() && !validAccountTypes.contains(accountType.get())) { + // Empty accountType is treated as writable + LogUtil.i("CallingAccountSelector.getDataId", "ignoring non-writable " + accountType); + continue; + } + if (result != null && !result.equals(cursor.getString(0))) { + // TODO(twyen): if there are multiple entries attempt to grab from the contact that + // initiated the call. + LogUtil.i("CallingAccountSelector.getDataId", "lookup result not unique, ignoring"); + return Optional.absent(); + } + result = cursor.getString(0); + } + return Optional.fromNullable(result); + } + } + + @WorkerThread + private static Optional getAccountType(ContentResolver contentResolver, long dataId) { + Assert.isWorkerThread(); + Optional rawContactId = getRawContactId(contentResolver, dataId); + if (!rawContactId.isPresent()) { + return Optional.absent(); + } + try (Cursor cursor = + contentResolver.query( + ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId.get()), + new String[] {RawContacts.ACCOUNT_TYPE}, + null, + null, + null)) { + if (cursor == null || !cursor.moveToFirst()) { + return Optional.absent(); + } + return Optional.fromNullable(cursor.getString(0)); + } + } + + @WorkerThread + private static Optional getRawContactId(ContentResolver contentResolver, long dataId) { + Assert.isWorkerThread(); + try (Cursor cursor = + contentResolver.query( + ContentUris.withAppendedId(Data.CONTENT_URI, dataId), + new String[] {Data.RAW_CONTACT_ID}, + null, + null, + null)) { + if (cursor == null || !cursor.moveToFirst()) { + return Optional.absent(); + } + return Optional.of(cursor.getLong(0)); + } + } + + @WorkerThread + @NonNull + private static Optional getPreferredAccount( + @NonNull Context context, @NonNull String dataId) { + Assert.isWorkerThread(); + Assert.isNotNull(dataId); + try (Cursor cursor = + context + .getContentResolver() + .query( + PreferredSimFallbackContract.CONTENT_URI, + new String[] { + PreferredSim.PREFERRED_PHONE_ACCOUNT_COMPONENT_NAME, + PreferredSim.PREFERRED_PHONE_ACCOUNT_ID + }, + PreferredSim.DATA_ID + " = ?", + new String[] {dataId}, + null)) { + if (cursor == null) { + return Optional.absent(); + } + if (!cursor.moveToFirst()) { + return Optional.absent(); + } + return PreferredAccountUtil.getValidPhoneAccount( + context, cursor.getString(0), cursor.getString(1)); + } + } + + @WorkerThread + private static boolean isPreferredSimEnabled(Context context) { + Assert.isWorkerThread(); + if (!ConfigProviderBindings.get(context).getBoolean("preferred_sim_enabled", true)) { + return false; + } + + Intent quickContactIntent = getQuickContactIntent(); + ResolveInfo resolveInfo = + context + .getPackageManager() + .resolveActivity(quickContactIntent, PackageManager.GET_META_DATA); + if (resolveInfo == null + || resolveInfo.activityInfo == null + || resolveInfo.activityInfo.applicationInfo == null + || resolveInfo.activityInfo.applicationInfo.metaData == null) { + LogUtil.e("CallingAccountSelector.isPreferredSimEnabled", "cannot resolve quick contact app"); + return false; + } + if (!resolveInfo.activityInfo.applicationInfo.metaData.getBoolean( + METADATA_SUPPORTS_PREFERRED_SIM, false)) { + LogUtil.i( + "CallingAccountSelector.isPreferredSimEnabled", + "system contacts does not support preferred SIM"); + return false; + } + return true; + } + + @VisibleForTesting + public static Intent getQuickContactIntent() { + Intent intent = new Intent(QuickContact.ACTION_QUICK_CONTACT); + intent.addCategory(Intent.CATEGORY_DEFAULT); + intent.setData(Contacts.CONTENT_URI.buildUpon().appendPath("1").build()); + return intent; + } +} diff --git a/java/com/android/dialer/preferredsim/suggestion/AndroidManifest.xml b/java/com/android/dialer/preferredsim/suggestion/AndroidManifest.xml new file mode 100644 index 000000000..78f7c26d9 --- /dev/null +++ b/java/com/android/dialer/preferredsim/suggestion/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + diff --git a/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java b/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java index 0a91d1511..cfa37c883 100644 --- a/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java +++ b/java/com/android/dialer/preferredsim/suggestion/SuggestionProvider.java @@ -18,10 +18,14 @@ package com.android.dialer.preferredsim.suggestion; import android.content.Context; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.WorkerThread; import android.telecom.PhoneAccountHandle; import com.android.dialer.common.Assert; +import com.android.dialer.common.LogUtil; import com.google.common.base.Optional; +import java.util.ArrayList; +import java.util.List; /** Provides hints to the user when selecting a SIM to make a call. */ public interface SuggestionProvider { @@ -72,4 +76,37 @@ public interface SuggestionProvider { @WorkerThread void reportIncorrectSuggestion( @NonNull Context context, @NonNull String number, @NonNull PhoneAccountHandle newAccount); + + /** + * Return a list of suggestion strings matching the list position of the {@code + * phoneAccountHandles}. The list will contain {@code null} if the PhoneAccountHandle does not + * have suggestions. + */ + @Nullable + static List buildHint( + Context context, + List phoneAccountHandles, + @Nullable Suggestion suggestion) { + if (suggestion == null) { + return null; + } + List hints = new ArrayList<>(); + for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) { + if (!phoneAccountHandle.equals(suggestion.phoneAccountHandle)) { + hints.add(null); + continue; + } + switch (suggestion.reason) { + case INTRA_CARRIER: + hints.add(context.getString(R.string.pre_call_select_phone_account_hint_intra_carrier)); + break; + case FREQUENT: + hints.add(context.getString(R.string.pre_call_select_phone_account_hint_frequent)); + break; + default: + LogUtil.w("CallingAccountSelector.buildHint", "unhandled reason " + suggestion.reason); + } + } + return hints; + } } diff --git a/java/com/android/dialer/preferredsim/suggestion/res/values/strings.xml b/java/com/android/dialer/preferredsim/suggestion/res/values/strings.xml new file mode 100644 index 000000000..c4175313d --- /dev/null +++ b/java/com/android/dialer/preferredsim/suggestion/res/values/strings.xml @@ -0,0 +1,25 @@ + + + + +Uses same carrier + + +Recently used + \ No newline at end of file diff --git a/java/com/android/incallui/InCallActivity.java b/java/com/android/incallui/InCallActivity.java index f842aedf7..dee5e7eb1 100644 --- a/java/com/android/incallui/InCallActivity.java +++ b/java/com/android/incallui/InCallActivity.java @@ -39,6 +39,7 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.content.res.ResourcesCompat; import android.support.v4.graphics.ColorUtils; +import android.telecom.Call; import android.telecom.CallAudioState; import android.telecom.PhoneAccountHandle; import android.telephony.TelephonyManager; @@ -56,14 +57,19 @@ import com.android.dialer.animation.AnimUtils; import com.android.dialer.animation.AnimationListenerAdapter; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.DialerExecutorComponent; import com.android.dialer.common.concurrent.ThreadUtil; import com.android.dialer.compat.ActivityCompat; import com.android.dialer.compat.CompatUtils; import com.android.dialer.configprovider.ConfigProviderBindings; +import com.android.dialer.logging.DialerImpression.Type; import com.android.dialer.logging.Logger; import com.android.dialer.logging.ScreenEvent; import com.android.dialer.metrics.Metrics; import com.android.dialer.metrics.MetricsComponent; +import com.android.dialer.preferredsim.PreferredAccountRecorder; +import com.android.dialer.preferredsim.PreferredAccountWorker; +import com.android.dialer.preferredsim.suggestion.SuggestionProvider; import com.android.dialer.util.ViewUtil; import com.android.incallui.answer.bindings.AnswerBindings; import com.android.incallui.answer.protocol.AnswerScreen; @@ -124,8 +130,8 @@ public class InCallActivity extends TransactionSafeFragmentActivity private final InternationalCallOnWifiCallback internationalCallOnWifiCallback = new InternationalCallOnWifiCallback(); - private final SelectPhoneAccountListener selectPhoneAccountListener = - new SelectPhoneAccountListener(); + + private SelectPhoneAccountListener selectPhoneAccountListener; private Animation dialpadSlideInAnimation; private Animation dialpadSlideOutAnimation; @@ -179,6 +185,8 @@ public class InCallActivity extends TransactionSafeFragmentActivity Trace.beginSection("InCallActivity.onCreate"); super.onCreate(bundle); + selectPhoneAccountListener = new SelectPhoneAccountListener(getApplicationContext()); + if (bundle != null) { didShowAnswerScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN); didShowInCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN); @@ -358,22 +366,59 @@ public class InCallActivity extends TransactionSafeFragmentActivity return false; } - Bundle extras = waitingForAccountCall.getIntentExtras(); - List phoneAccountHandles = - extras == null - ? new ArrayList<>() - : extras.getParcelableArrayList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS); - - selectPhoneAccountDialogFragment = - SelectPhoneAccountDialogFragment.newInstance( - R.string.select_phone_account_for_calls, - true /* canSetDefault */, - 0 /* setDefaultResId */, - phoneAccountHandles, - selectPhoneAccountListener, - waitingForAccountCall.getId(), - null /* hints */); - selectPhoneAccountDialogFragment.show(getFragmentManager(), Tags.SELECT_ACCOUNT_FRAGMENT); + DialerExecutorComponent.get(this) + .dialerExecutorFactory() + .createNonUiTaskBuilder(new PreferredAccountWorker(waitingForAccountCall.getNumber())) + .onSuccess( + (result -> { + if (result.getPhoneAccountHandle().isPresent()) { + Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_PREFERRED_USED); + selectPhoneAccountListener.onPhoneAccountSelected( + result.getPhoneAccountHandle().get(), false, waitingForAccountCall.getId()); + return; + } + if (result.getSuggestion().isPresent()) { + LogUtil.i( + "CallingAccountSelector.processPreferredAccount", + "SIM suggested: " + result.getSuggestion().get().reason); + if (result.getSuggestion().get().shouldAutoSelect) { + Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_SUGGESTION_AUTO_SELECTED); + LogUtil.i( + "CallingAccountSelector.processPreferredAccount", "Auto selected suggestion"); + selectPhoneAccountListener.onPhoneAccountSelected( + result.getSuggestion().get().phoneAccountHandle, + false, + waitingForAccountCall.getId()); + return; + } + } + Bundle extras = waitingForAccountCall.getIntentExtras(); + List phoneAccountHandles = + extras == null + ? new ArrayList<>() + : extras.getParcelableArrayList(Call.AVAILABLE_PHONE_ACCOUNTS); + + waitingForAccountCall.setPreferredAccountRecorder( + new PreferredAccountRecorder( + waitingForAccountCall.getNumber(), + result.getSuggestion().orNull(), + result.getDataId().orNull())); + selectPhoneAccountDialogFragment = + SelectPhoneAccountDialogFragment.newInstance( + R.string.select_phone_account_for_calls, + result.getDataId().isPresent() /* canSetDefault */, + R.string.select_phone_account_for_calls_remember /* setDefaultResId */, + phoneAccountHandles, + selectPhoneAccountListener, + waitingForAccountCall.getId(), + SuggestionProvider.buildHint( + this, phoneAccountHandles, result.getSuggestion().orNull() /* hints */)); + selectPhoneAccountDialogFragment.show( + getFragmentManager(), Tags.SELECT_ACCOUNT_FRAGMENT); + })) + .build() + .executeParallel(this); + return true; } @@ -1650,6 +1695,12 @@ public class InCallActivity extends TransactionSafeFragmentActivity extends SelectPhoneAccountDialogFragment.SelectPhoneAccountListener { private static final String TAG = SelectPhoneAccountListener.class.getCanonicalName(); + private final Context appContext; + + SelectPhoneAccountListener(Context appContext) { + this.appContext = appContext; + } + @Override public void onPhoneAccountSelected( PhoneAccountHandle selectedAccountHandle, boolean setDefault, String callId) { @@ -1657,7 +1708,10 @@ public class InCallActivity extends TransactionSafeFragmentActivity LogUtil.i(TAG, "Phone account select with call:\n%s", call); if (call != null) { - call.phoneAccountSelected(selectedAccountHandle, setDefault); + call.phoneAccountSelected(selectedAccountHandle, false); + if (call.getPreferredAccountRecorder() != null) { + call.getPreferredAccountRecorder().record(appContext, selectedAccountHandle, setDefault); + } } } diff --git a/java/com/android/incallui/call/DialerCall.java b/java/com/android/incallui/call/DialerCall.java index 30d2bcb5e..5d2b1471d 100644 --- a/java/com/android/incallui/call/DialerCall.java +++ b/java/com/android/incallui/call/DialerCall.java @@ -71,6 +71,7 @@ import com.android.dialer.logging.ContactLookupResult; import com.android.dialer.logging.ContactLookupResult.Type; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; +import com.android.dialer.preferredsim.PreferredAccountRecorder; import com.android.dialer.telecom.TelecomCallUtil; import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.theme.R; @@ -181,6 +182,8 @@ public class DialerCall implements VideoTechListener, StateChangedListener, Capa private volatile boolean feedbackRequested = false; + @Nullable private PreferredAccountRecorder preferredAccountRecorder; + public static String getNumberFromHandle(Uri handle) { return handle == null ? "" : handle.getSchemeSpecificPart(); } @@ -1528,6 +1531,19 @@ public class DialerCall implements VideoTechListener, StateChangedListener, Capa return feedbackRequested; } + /** + * If the in call UI has shown the phone account selection dialog for the call, the {@link + * PreferredAccountRecorder} to record the result from the dialog. + */ + @Nullable + public PreferredAccountRecorder getPreferredAccountRecorder() { + return preferredAccountRecorder; + } + + public void setPreferredAccountRecorder(PreferredAccountRecorder preferredAccountRecorder) { + this.preferredAccountRecorder = preferredAccountRecorder; + } + /** * Specifies whether a number is in the call history or not. {@link #CALL_HISTORY_STATUS_UNKNOWN} * means there is no result. -- cgit v1.2.3