From 7658f34ae01715d496573bf7e29e748cb5459f69 Mon Sep 17 00:00:00 2001 From: erfanian Date: Mon, 4 Dec 2017 15:50:59 -0800 Subject: Add filtration logic to Assisted Dialing Settings. The filtration logic will only show countries in the country picker if the feature is enabled for those countries. This will not cover the regressive case where a user has already selected a default option, but then the option is later removed. This behavior is currently undefined. Bug: 69274259 Test: unit tests PiperOrigin-RevId: 177881199 Change-Id: I113f6d25249c42c1bd98383fd6ee0bc6a8c0e615 --- .../dialer/assisteddialing/AndroidManifest.xml | 22 +++++++ .../dialer/assisteddialing/ConcreteCreator.java | 1 - .../assisteddialing/CountryCodeProvider.java | 2 +- .../dialer/assisteddialing/res/values/strings.xml | 22 +++++++ .../dialer/assisteddialing/ui/AndroidManifest.xml | 2 +- .../ui/AssistedDialingSettingFragment.java | 76 ++++++++++++++++++++++ .../assisteddialing/ui/res/values/strings.xml | 6 -- packages.mk | 1 + 8 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 java/com/android/dialer/assisteddialing/AndroidManifest.xml create mode 100644 java/com/android/dialer/assisteddialing/res/values/strings.xml diff --git a/java/com/android/dialer/assisteddialing/AndroidManifest.xml b/java/com/android/dialer/assisteddialing/AndroidManifest.xml new file mode 100644 index 000000000..6625dff07 --- /dev/null +++ b/java/com/android/dialer/assisteddialing/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/java/com/android/dialer/assisteddialing/ConcreteCreator.java b/java/com/android/dialer/assisteddialing/ConcreteCreator.java index 8a5661e03..73817d7fc 100644 --- a/java/com/android/dialer/assisteddialing/ConcreteCreator.java +++ b/java/com/android/dialer/assisteddialing/ConcreteCreator.java @@ -25,7 +25,6 @@ import android.support.annotation.NonNull; import android.support.annotation.VisibleForTesting; import android.support.v4.os.UserManagerCompat; import android.telephony.TelephonyManager; -import com.android.dialer.assisteddialing.ui.R; import com.android.dialer.common.LogUtil; import com.android.dialer.configprovider.ConfigProvider; import com.android.dialer.configprovider.ConfigProviderBindings; diff --git a/java/com/android/dialer/assisteddialing/CountryCodeProvider.java b/java/com/android/dialer/assisteddialing/CountryCodeProvider.java index b12b3ddc0..118696e9b 100644 --- a/java/com/android/dialer/assisteddialing/CountryCodeProvider.java +++ b/java/com/android/dialer/assisteddialing/CountryCodeProvider.java @@ -34,7 +34,7 @@ import java.util.stream.Collectors; /** A class to provide the appropriate country codes related to assisted dialing. */ @TargetApi(VERSION_CODES.N) @SuppressWarnings("AndroidApiChecker") // Java 8 APIs -final class CountryCodeProvider { +public final class CountryCodeProvider { // TODO(erfanian): Ensure the below standard is consistent between libphonenumber and the // platform. diff --git a/java/com/android/dialer/assisteddialing/res/values/strings.xml b/java/com/android/dialer/assisteddialing/res/values/strings.xml new file mode 100644 index 000000000..f9cb123e0 --- /dev/null +++ b/java/com/android/dialer/assisteddialing/res/values/strings.xml @@ -0,0 +1,22 @@ + + + + + assisted_dialing_setting_toggle_key + + + assisted_dialing_setting_cc_key + \ No newline at end of file diff --git a/java/com/android/dialer/assisteddialing/ui/AndroidManifest.xml b/java/com/android/dialer/assisteddialing/ui/AndroidManifest.xml index 6625dff07..724874750 100644 --- a/java/com/android/dialer/assisteddialing/ui/AndroidManifest.xml +++ b/java/com/android/dialer/assisteddialing/ui/AndroidManifest.xml @@ -13,7 +13,7 @@ limitations under the License. --> + package="com.android.dialer.assisteddialing.ui"> defaultCountryChoices = + buildDefaultCountryChooserKeysAndValues(countryChooserPref); + + // Always include the default preference. + List newKeys = new ArrayList<>(); + List newValues = new ArrayList<>(); + newKeys.add(countryChooserPref.getEntries()[0]); + newValues.add(countryChooserPref.getEntryValues()[0]); + + for (DisplayNameAndCountryCodeTuple tuple : defaultCountryChoices) { + if (countryCodeProvider.isSupportedCountryCode(tuple.countryCode().toString())) { + newKeys.add(tuple.countryDisplayname()); + newValues.add(tuple.countryCode()); + } + } + + countryChooserPref.setEntries(newKeys.toArray(new CharSequence[newKeys.size()])); + countryChooserPref.setEntryValues(newValues.toArray(new CharSequence[newValues.size()])); + } + + private List buildDefaultCountryChooserKeysAndValues( + ListPreference countryChooserPref) { + CharSequence[] keys = countryChooserPref.getEntries(); + CharSequence[] values = countryChooserPref.getEntryValues(); + + if (keys.length != values.length) { + throw new IllegalStateException("Unexpected mismatch in country chooser key/value size"); + } + + List displayNamesandCountryCodes = new ArrayList<>(); + for (int i = 0; i < keys.length; i++) { + displayNamesandCountryCodes.add(DisplayNameAndCountryCodeTuple.create(keys[i], values[i])); + } + + return displayNamesandCountryCodes; + } + boolean updateListSummary(Preference pref, Object newValue) { ListPreference listPref = (ListPreference) pref; CharSequence[] entries = listPref.getEntries(); diff --git a/java/com/android/dialer/assisteddialing/ui/res/values/strings.xml b/java/com/android/dialer/assisteddialing/ui/res/values/strings.xml index 1dc778f59..3a81780a9 100644 --- a/java/com/android/dialer/assisteddialing/ui/res/values/strings.xml +++ b/java/com/android/dialer/assisteddialing/ui/res/values/strings.xml @@ -22,12 +22,6 @@ Predict and add a country code when you call while traveling abroad - - assisted_dialing_setting_toggle_key - - - assisted_dialing_setting_cc_key - Automatically detected diff --git a/packages.mk b/packages.mk index c86e276ef..ce425a90f 100644 --- a/packages.mk +++ b/packages.mk @@ -8,6 +8,7 @@ LOCAL_AAPT_FLAGS := \ com.android.dialer.app \ com.android.dialer.app.manifests.activities \ com.android.dialer.app.voicemail.error \ + com.android.dialer.assisteddialing \ com.android.dialer.assisteddialing.ui \ com.android.dialer.backup \ com.android.dialer.binary.aosp.testing \ -- cgit v1.2.3