From 04306a75588b58208758f43821e1898c6f125baf Mon Sep 17 00:00:00 2001 From: twyen Date: Thu, 25 Jan 2018 16:14:15 -0800 Subject: Update preferred SIM SuggestionProvider "remember this SIM" checkbox state is reported to the provider. The other SIM is reported to the provider when "change SIM" is used Bug: 70503524 Test: Unit tests PiperOrigin-RevId: 183308581 Change-Id: I3d097d14a503c759f130044c9a9c48c420eee19d --- .../precall/impl/CallingAccountSelector.java | 10 +- .../dialer/precall/impl/PreferredAccountUtil.java | 116 --------------------- 2 files changed, 7 insertions(+), 119 deletions(-) delete mode 100644 java/com/android/dialer/precall/impl/PreferredAccountUtil.java (limited to 'java/com/android/dialer/precall') diff --git a/java/com/android/dialer/precall/impl/CallingAccountSelector.java b/java/com/android/dialer/precall/impl/CallingAccountSelector.java index 9397d1848..d5ee0f278 100644 --- a/java/com/android/dialer/precall/impl/CallingAccountSelector.java +++ b/java/com/android/dialer/precall/impl/CallingAccountSelector.java @@ -56,6 +56,7 @@ import com.android.dialer.logging.Logger; import com.android.dialer.precall.PreCallAction; import com.android.dialer.precall.PreCallCoordinator; import com.android.dialer.precall.PreCallCoordinator.PendingAction; +import com.android.dialer.preferredsim.PreferredAccountUtil; import com.android.dialer.preferredsim.PreferredSimFallbackContract; import com.android.dialer.preferredsim.PreferredSimFallbackContract.PreferredSim; import com.android.dialer.preferredsim.suggestion.SimSuggestionComponent; @@ -483,7 +484,8 @@ public class CallingAccountSelector implements PreCallAction { if (number != null) { DialerExecutorComponent.get(coordinator.getActivity()) .dialerExecutorFactory() - .createNonUiTaskBuilder(new UserSelectionReporter(selectedAccountHandle, number)) + .createNonUiTaskBuilder( + new UserSelectionReporter(selectedAccountHandle, number, setDefault)) .build() .executeParallel(coordinator.getActivity()); } @@ -505,11 +507,13 @@ public class CallingAccountSelector implements PreCallAction { private final String number; private final PhoneAccountHandle phoneAccountHandle; + private final boolean remember; public UserSelectionReporter( - @NonNull PhoneAccountHandle phoneAccountHandle, @Nullable String number) { + @NonNull PhoneAccountHandle phoneAccountHandle, @Nullable String number, boolean remember) { this.phoneAccountHandle = Assert.isNotNull(phoneAccountHandle); this.number = Assert.isNotNull(number); + this.remember = remember; } @Nullable @@ -517,7 +521,7 @@ public class CallingAccountSelector implements PreCallAction { public Void doInBackground(@NonNull Context context) throws Throwable { SimSuggestionComponent.get(context) .getSuggestionProvider() - .reportUserSelection(context, number, phoneAccountHandle); + .reportUserSelection(context, number, phoneAccountHandle, remember); return null; } } diff --git a/java/com/android/dialer/precall/impl/PreferredAccountUtil.java b/java/com/android/dialer/precall/impl/PreferredAccountUtil.java deleted file mode 100644 index 650588829..000000000 --- a/java/com/android/dialer/precall/impl/PreferredAccountUtil.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2017 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.precall.impl; - -import android.content.ComponentName; -import android.content.Context; -import android.os.Build.VERSION; -import android.os.Build.VERSION_CODES; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.telecom.PhoneAccount; -import android.telecom.PhoneAccountHandle; -import android.telecom.TelecomManager; -import android.telephony.SubscriptionInfo; -import android.telephony.SubscriptionManager; -import android.telephony.TelephonyManager; -import android.text.TextUtils; -import com.android.dialer.common.LogUtil; -import com.android.dialer.configprovider.ConfigProviderComponent; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableSet; - -/** - * Utilities for looking up and validating preferred {@link PhoneAccountHandle}. Contacts should - * follow the same logic. - */ -public class PreferredAccountUtil { - - /** - * Validates {@code componentNameString} and {@code idString} maps to SIM that is present on the - * device. - */ - @NonNull - public static Optional getValidPhoneAccount( - @NonNull Context context, @Nullable String componentNameString, @Nullable String idString) { - if (TextUtils.isEmpty(componentNameString) || TextUtils.isEmpty(idString)) { - LogUtil.i("PreferredAccountUtil.getValidPhoneAccount", "empty componentName or id"); - return Optional.absent(); - } - ComponentName componentName = ComponentName.unflattenFromString(componentNameString); - if (componentName == null) { - LogUtil.e("PreferredAccountUtil.getValidPhoneAccount", "cannot parse component name"); - return Optional.absent(); - } - PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(componentName, idString); - - if (isPhoneAccountValid(context, phoneAccountHandle)) { - return Optional.of(phoneAccountHandle); - } - return Optional.absent(); - } - - private static boolean isPhoneAccountValid( - Context context, PhoneAccountHandle phoneAccountHandle) { - if (VERSION.SDK_INT >= VERSION_CODES.O) { - return context - .getSystemService(TelephonyManager.class) - .createForPhoneAccountHandle(phoneAccountHandle) - != null; - } - - PhoneAccount phoneAccount = - context.getSystemService(TelecomManager.class).getPhoneAccount(phoneAccountHandle); - if (phoneAccount == null) { - LogUtil.e("PreferredAccountUtil.isPhoneAccountValid", "invalid phone account"); - return false; - } - - if (!phoneAccount.isEnabled()) { - LogUtil.e("PreferredAccountUtil.isPhoneAccountValid", "disabled phone account"); - return false; - } - for (SubscriptionInfo info : - SubscriptionManager.from(context).getActiveSubscriptionInfoList()) { - if (phoneAccountHandle.getId().startsWith(info.getIccId())) { - LogUtil.i("PreferredAccountUtil.isPhoneAccountValid", "sim found"); - return true; - } - } - return false; - } - - /** - * Return a set of {@link android.accounts.Account#type} that is known to have writable contacts. - * This is a light weight implementation of {@link - * com.android.contacts.common.model.AccountTypeManager#getAccountTypes(boolean)}. External - * accounts are not supported. - */ - public static ImmutableSet getValidAccountTypes(Context context) { - return ImmutableSet.copyOf( - ConfigProviderComponent.get(context) - .getConfigProvider() - .getString( - "preferred_sim_valid_account_types", - "com.google;" - + "com.osp.app.signin;" - + "com.android.exchange;" - + "com.google.android.exchange;" - + "com.google.android.gm.exchange") - .split(";")); - } -} -- cgit v1.2.3