diff options
author | wangqi <wangqi@google.com> | 2017-08-21 14:44:00 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-08-30 11:21:26 -0700 |
commit | 4b2abce679a35d4ecc05c2dce1db1fc06df68153 (patch) | |
tree | ccb1160f545b2958670bcc827c2e45441550b2cb | |
parent | 4a7cd6b773053c707c7198cfb6a309c02ab32abb (diff) |
Fix crash on calling N api on M device for locale.
Bug: 64890396
Test: manual
PiperOrigin-RevId: 165977664
Change-Id: I99d88410292d6da9e85b09e7736750fa1bff207c
3 files changed, 25 insertions, 5 deletions
diff --git a/java/com/android/dialer/compat/CompatUtils.java b/java/com/android/dialer/compat/CompatUtils.java index 351c89ad7..584f20549 100644 --- a/java/com/android/dialer/compat/CompatUtils.java +++ b/java/com/android/dialer/compat/CompatUtils.java @@ -15,7 +15,12 @@ */ package com.android.dialer.compat; +import android.content.Context; import android.os.Build; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; +import android.os.LocaleList; +import java.util.Locale; public final class CompatUtils { @@ -64,4 +69,17 @@ public final class CompatUtils { public static boolean isCallSubjectCompatible() { return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP) >= Build.VERSION_CODES.M; } + + /** Returns locale of the device. */ + public static Locale getLocale(Context context) { + if (VERSION.SDK_INT >= VERSION_CODES.N) { + LocaleList localList = context.getResources().getConfiguration().getLocales(); + if (!localList.isEmpty()) { + return localList.get(0); + } + return Locale.getDefault(); + } else { + return context.getResources().getConfiguration().locale; + } + } } diff --git a/java/com/android/dialer/dialpadview/DialpadView.java b/java/com/android/dialer/dialpadview/DialpadView.java index 4a9b500b7..0c53273a4 100644 --- a/java/com/android/dialer/dialpadview/DialpadView.java +++ b/java/com/android/dialer/dialpadview/DialpadView.java @@ -29,7 +29,6 @@ import android.text.Spannable; import android.text.TextUtils; import android.text.style.TtsSpan; import android.util.AttributeSet; -import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -40,6 +39,8 @@ import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; import com.android.dialer.animation.AnimUtils; +import com.android.dialer.common.LogUtil; +import com.android.dialer.compat.CompatUtils; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Locale; @@ -153,7 +154,7 @@ public class DialpadView extends LinearLayout { // We translate dialpad numbers only for "fa" and not any other locale // ("ar" anybody ?). if ("fa".equals(currentLocale.getLanguage())) { - nf = DecimalFormat.getInstance(resources.getConfiguration().locale); + nf = DecimalFormat.getInstance(CompatUtils.getLocale(getContext())); } else { nf = DecimalFormat.getInstance(Locale.ENGLISH); } @@ -395,7 +396,7 @@ public class DialpadView extends LinearLayout { } } - Log.wtf(TAG, "Attempted to get animation delay for invalid key button id."); + LogUtil.e(TAG, "Attempted to get animation delay for invalid key button id."); return 0; } @@ -458,7 +459,7 @@ public class DialpadView extends LinearLayout { } } - Log.wtf(TAG, "Attempted to get animation duration for invalid key button id."); + LogUtil.e(TAG, "Attempted to get animation duration for invalid key button id."); return 0; } } diff --git a/java/com/android/dialer/phonenumbergeoutil/impl/PhoneNumberGeoUtilImpl.java b/java/com/android/dialer/phonenumbergeoutil/impl/PhoneNumberGeoUtilImpl.java index 86736b0a4..32f65927d 100644 --- a/java/com/android/dialer/phonenumbergeoutil/impl/PhoneNumberGeoUtilImpl.java +++ b/java/com/android/dialer/phonenumbergeoutil/impl/PhoneNumberGeoUtilImpl.java @@ -19,6 +19,7 @@ package com.android.dialer.phonenumbergeoutil.impl; import android.content.Context; import android.text.TextUtils; import com.android.dialer.common.LogUtil; +import com.android.dialer.compat.CompatUtils; import com.android.dialer.phonenumbergeoutil.PhoneNumberGeoUtil; import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.google.i18n.phonenumbers.NumberParseException; @@ -45,7 +46,7 @@ public class PhoneNumberGeoUtilImpl implements PhoneNumberGeoUtil { PhoneNumberUtil util = PhoneNumberUtil.getInstance(); PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance(); - Locale locale = context.getResources().getConfiguration().getLocales().get(0); + Locale locale = CompatUtils.getLocale(context); String countryIso = PhoneNumberHelper.getCurrentCountryIso(context, locale); Phonenumber.PhoneNumber pn = null; try { |