diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-01-26 00:11:47 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-01-26 00:11:47 +0000 |
commit | b9596e65467d9ad33efdfebb5ebc098207fda991 (patch) | |
tree | 22437ddadb9b8016f14c74333364f96f5cea6998 /java/com/android/dialer | |
parent | a0cfd3965218696493c5ed06c2ef69e2b61368e8 (diff) | |
parent | 334c0e1b40e4967e254d9e6ccd0bef447767867a (diff) |
Merge changes I607c6af4,I452b3f2b
* changes:
Explicitly disable strict mode during the assisted dialing action.
Set avatar as background instead of src.
Diffstat (limited to 'java/com/android/dialer')
3 files changed, 43 insertions, 24 deletions
diff --git a/java/com/android/dialer/assisteddialing/ConcreteCreator.java b/java/com/android/dialer/assisteddialing/ConcreteCreator.java index c1ffbd396..2561e28cd 100644 --- a/java/com/android/dialer/assisteddialing/ConcreteCreator.java +++ b/java/com/android/dialer/assisteddialing/ConcreteCreator.java @@ -29,6 +29,7 @@ import android.telephony.TelephonyManager; import com.android.dialer.common.LogUtil; import com.android.dialer.configprovider.ConfigProvider; import com.android.dialer.configprovider.ConfigProviderBindings; +import com.android.dialer.strictmode.StrictModeUtils; /** * A Creator for AssistedDialingMediators. @@ -90,8 +91,11 @@ public final class ConcreteCreator { return new AssistedDialingMediatorImpl( new LocationDetector( telephonyManager, - PreferenceManager.getDefaultSharedPreferences(context) - .getString(context.getString(R.string.assisted_dialing_setting_cc_key), null)), + StrictModeUtils.bypass( + () -> + PreferenceManager.getDefaultSharedPreferences(context) + .getString( + context.getString(R.string.assisted_dialing_setting_cc_key), null))), new NumberTransformer(constraints)); } diff --git a/java/com/android/dialer/assisteddialing/Constraints.java b/java/com/android/dialer/assisteddialing/Constraints.java index f95312a21..788b875ff 100644 --- a/java/com/android/dialer/assisteddialing/Constraints.java +++ b/java/com/android/dialer/assisteddialing/Constraints.java @@ -25,6 +25,7 @@ import android.text.TextUtils; import com.android.dialer.common.LogUtil; import com.android.dialer.logging.DialerImpression; import com.android.dialer.logging.Logger; +import com.android.dialer.strictmode.StrictModeUtils; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; @@ -36,7 +37,7 @@ import java.util.Optional; @TargetApi(VERSION_CODES.N) @SuppressWarnings("AndroidApiChecker") // Use of optional final class Constraints { - private final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance(); + private final PhoneNumberUtil phoneNumberUtil; private final Context context; private final CountryCodeProvider countryCodeProvider; @@ -56,10 +57,8 @@ final class Constraints { throw new NullPointerException("Provided configProviderCountryCodes cannot be null"); } - // We allow dynamic country support only in Dialer; this should be removed in the framework - // implementation. - // TODO(erfanian): Remove in the framework implementation. this.countryCodeProvider = countryCodeProvider; + this.phoneNumberUtil = StrictModeUtils.bypass(() -> PhoneNumberUtil.getInstance()); } /** @@ -148,16 +147,18 @@ final class Constraints { */ private Optional<PhoneNumber> parsePhoneNumber( @NonNull String numberToParse, @NonNull String userHomeCountryCode) { - try { - // TODO(erfanian): confirm behavior of blocking the foreground thread when moving to the - // framework - return Optional.of(phoneNumberUtil.parseAndKeepRawInput(numberToParse, userHomeCountryCode)); - } catch (NumberParseException e) { - Logger.get(context) - .logImpression(DialerImpression.Type.ASSISTED_DIALING_CONSTRAINT_PARSING_FAILURE); - LogUtil.i("Constraints.parsePhoneNumber", "could not parse the number"); - return Optional.empty(); - } + return StrictModeUtils.bypass( + () -> { + try { + return Optional.of( + phoneNumberUtil.parseAndKeepRawInput(numberToParse, userHomeCountryCode)); + } catch (NumberParseException e) { + Logger.get(context) + .logImpression(DialerImpression.Type.ASSISTED_DIALING_CONSTRAINT_PARSING_FAILURE); + LogUtil.i("Constraints.parsePhoneNumber", "could not parse the number"); + return Optional.empty(); + } + }); } /** Returns a boolean indicating if the provided number is already internationally formatted. */ @@ -195,7 +196,8 @@ final class Constraints { /** Returns a boolean indicating if the provided number is considered to be a valid number. */ private boolean isValidNumber(@NonNull Optional<PhoneNumber> parsedPhoneNumber) { - boolean result = PhoneNumberUtil.getInstance().isValidNumber(parsedPhoneNumber.get()); + boolean result = + StrictModeUtils.bypass(() -> phoneNumberUtil.isValidNumber(parsedPhoneNumber.get())); LogUtil.i("Constraints.isValidNumber", String.valueOf(result)); return result; diff --git a/java/com/android/dialer/assisteddialing/NumberTransformer.java b/java/com/android/dialer/assisteddialing/NumberTransformer.java index 0156f2ec2..8bbad329d 100644 --- a/java/com/android/dialer/assisteddialing/NumberTransformer.java +++ b/java/com/android/dialer/assisteddialing/NumberTransformer.java @@ -21,6 +21,7 @@ import android.os.Build.VERSION_CODES; import android.support.annotation.NonNull; import android.text.TextUtils; import com.android.dialer.common.LogUtil; +import com.android.dialer.strictmode.StrictModeUtils; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; @@ -29,11 +30,12 @@ import java.util.Optional; /** Responsible for transforming numbers to make them dialable and valid when roaming. */ final class NumberTransformer { - private final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance(); + private final PhoneNumberUtil phoneNumberUtil; private final Constraints constraints; public NumberTransformer(Constraints constraints) { this.constraints = constraints; + this.phoneNumberUtil = StrictModeUtils.bypass(() -> PhoneNumberUtil.getInstance()); } /** @@ -68,16 +70,27 @@ final class NumberTransformer { return Optional.empty(); } - PhoneNumber phoneNumber; - try { - phoneNumber = phoneNumberUtil.parse(numbertoTransform, userHomeCountryCode); - } catch (NumberParseException e) { - LogUtil.i("NumberTransformer.doAssistedDialingTransformation", "number failed to parse"); + PhoneNumber phoneNumber = + StrictModeUtils.bypass( + () -> { + try { + return phoneNumberUtil.parse(numbertoTransform, userHomeCountryCode); + } catch (NumberParseException e) { + LogUtil.i( + "NumberTransformer.doAssistedDialingTransformation", "number failed to parse"); + return null; + } + }); + + if (phoneNumber == null) { return Optional.empty(); } String transformedNumber = - phoneNumberUtil.formatNumberForMobileDialing(phoneNumber, userRoamingCountryCode, true); + StrictModeUtils.bypass( + () -> + phoneNumberUtil.formatNumberForMobileDialing( + phoneNumber, userRoamingCountryCode, true)); // formatNumberForMobileDialing may return an empty String. if (TextUtils.isEmpty(transformedNumber)) { |