From f838726676381241f578f7d21d660d28410469e7 Mon Sep 17 00:00:00 2001 From: zachh Date: Tue, 26 Sep 2017 12:18:18 -0700 Subject: Bypassed some strict mode violations. These are old code and considered to be grandfathered in. Cleaned up some warnings in GoogleLocationSettingHelper. Bug: 66498656 Test: none PiperOrigin-RevId: 170090310 Change-Id: I2c43564af751eb5f431a395d75afa5ce126b5d18 --- .../dialer/app/settings/DialerSettingsActivity.java | 2 +- .../calllocation/impl/GoogleLocationSettingHelper.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/java/com/android/dialer/app/settings/DialerSettingsActivity.java b/java/com/android/dialer/app/settings/DialerSettingsActivity.java index 6286bfc88..10ef9ed60 100644 --- a/java/com/android/dialer/app/settings/DialerSettingsActivity.java +++ b/java/com/android/dialer/app/settings/DialerSettingsActivity.java @@ -52,7 +52,7 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mPreferences = PreferenceManager.getDefaultSharedPreferences(this); + mPreferences = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); } @Override diff --git a/java/com/android/incallui/calllocation/impl/GoogleLocationSettingHelper.java b/java/com/android/incallui/calllocation/impl/GoogleLocationSettingHelper.java index 18a80b8ce..ed2e84368 100644 --- a/java/com/android/incallui/calllocation/impl/GoogleLocationSettingHelper.java +++ b/java/com/android/incallui/calllocation/impl/GoogleLocationSettingHelper.java @@ -26,6 +26,7 @@ import android.net.Uri; import android.provider.Settings.Secure; import android.provider.Settings.SettingNotFoundException; import com.android.dialer.common.LogUtil; +import com.android.dialer.strictmode.DialerStrictMode; /** * Helper class to check if Google Location Services is enabled. This class is based on @@ -48,7 +49,7 @@ public class GoogleLocationSettingHelper { private static final String USE_LOCATION_FOR_SERVICES = "use_location_for_services"; /** Determine if Google apps need to conform to the USE_LOCATION_FOR_SERVICES setting. */ - public static boolean isEnforceable(Context context) { + private static boolean isEnforceable(Context context) { final ResolveInfo ri = context .getPackageManager() @@ -102,7 +103,7 @@ public class GoogleLocationSettingHelper { } /** Whether or not the system location setting is enable */ - public static boolean isSystemLocationSettingEnabled(Context context) { + static boolean isSystemLocationSettingEnabled(Context context) { try { return Secure.getInt(context.getContentResolver(), Secure.LOCATION_MODE) != Secure.LOCATION_MODE_OFF; @@ -116,8 +117,11 @@ public class GoogleLocationSettingHelper { } /** Convenience method that returns true is GLS is ON or if it's not enforceable. */ - public static boolean isGoogleLocationServicesEnabled(Context context) { - return !isEnforceable(context) - || getUseLocationForServices(context) == USE_LOCATION_FOR_SERVICES_ON; + static boolean isGoogleLocationServicesEnabled(Context context) { + if (!isEnforceable(context)) { + return true; + } + int locationServiceStatus = DialerStrictMode.bypass(() -> getUseLocationForServices(context)); + return locationServiceStatus == USE_LOCATION_FOR_SERVICES_ON; } } -- cgit v1.2.3