From 73ae7522a6d9faca76f24b94e3bb3e2088e5f74f Mon Sep 17 00:00:00 2001 From: twyen Date: Fri, 16 Mar 2018 12:40:07 -0700 Subject: Use current county ISO for PhoneLookupHistoryRecorder Previously it is unclear what the "county ISO" should be so the originating county of the SIM is used. When telecom writes to the call log the county the user is in is used. This caused the DialerPhoneNumber key in in call UI and call log to differ and info to be lost. In this CL, the current country is used in PhoneLookupHistoryRecorder to make it consistent with the call log. PhoneLookupHistoryRecorder is currently the only consumer for telecom call util.getCountryCode(). Additionally, dialer/location no longer depends on dialer/util. dialer/util has too many unnecessary dependencies that will cause cycles. Bug: 73752730 Test: Unit tests PiperOrigin-RevId: 189378542 Change-Id: I59773f7745c835a6523efda951c475e2fde9aaf9 --- java/com/android/dialer/location/CountryDetector.java | 13 ++++++++++--- java/com/android/dialer/location/GeoUtil.java | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'java/com/android/dialer/location') diff --git a/java/com/android/dialer/location/CountryDetector.java b/java/com/android/dialer/location/CountryDetector.java index 5c5ed9c84..664bb50d5 100644 --- a/java/com/android/dialer/location/CountryDetector.java +++ b/java/com/android/dialer/location/CountryDetector.java @@ -16,10 +16,12 @@ package com.android.dialer.location; +import android.Manifest.permission; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.location.Address; import android.location.Geocoder; import android.location.Location; @@ -35,7 +37,6 @@ import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; import com.android.dialer.common.concurrent.DialerExecutorComponent; -import com.android.dialer.util.PermissionsUtil; import java.util.List; import java.util.Locale; @@ -98,8 +99,9 @@ public class CountryDetector { } } + @SuppressWarnings("missingPermission") private static void registerForLocationUpdates(Context context, LocationManager locationManager) { - if (!PermissionsUtil.hasLocationPermissions(context)) { + if (!hasLocationPermissions(context)) { LogUtil.w( "CountryDetector.registerForLocationUpdates", "no location permissions, not registering for location updates"); @@ -163,7 +165,7 @@ public class CountryDetector { @Nullable private String getLocationBasedCountryIso() { if (!Geocoder.isPresent() - || !PermissionsUtil.hasLocationPermissions(appContext) + || !hasLocationPermissions(appContext) || !UserManagerCompat.isUserUnlocked(appContext)) { return null; } @@ -265,4 +267,9 @@ public class CountryDetector { return null; } } + + private static boolean hasLocationPermissions(Context context) { + return context.checkSelfPermission(permission.ACCESS_FINE_LOCATION) + == PackageManager.PERMISSION_GRANTED; + } } diff --git a/java/com/android/dialer/location/GeoUtil.java b/java/com/android/dialer/location/GeoUtil.java index 27fbf2315..8a875e842 100644 --- a/java/com/android/dialer/location/GeoUtil.java +++ b/java/com/android/dialer/location/GeoUtil.java @@ -22,7 +22,12 @@ import android.os.Trace; /** Static methods related to Geo. */ public class GeoUtil { - /** @return the ISO 3166-1 two letters country code of the country the user is in. */ + /** + * Return the ISO 3166-1 two letters country code of the country the user is in. + * + *

WARNING: {@link CountryDetector} caches TelephonyManager and other system services in a + * static. {@link CountryDetector#instance} must be reset in tests. + */ public static String getCurrentCountryIso(Context context) { // The {@link CountryDetector} should never return null so this is safe to return as-is. Trace.beginSection("GeoUtil.getCurrentCountryIso"); -- cgit v1.2.3