diff options
author | zachh <zachh@google.com> | 2017-07-28 14:49:00 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-07-28 16:14:16 -0700 |
commit | a69311f29586cd5f374fa98a5a217a45b97e306d (patch) | |
tree | 29ce160b0cc738ceb6feeb7d9efd71596163c0c1 /java/com/android/dialer/configprovider/SharedPrefConfigProvider.java | |
parent | a48f3c4bd2581c884e4668d3f4a47b7b374900ee (diff) |
Don't enable strict mode in non-bugfood builds.
There were some calls to StrictMode#enableDefaults in our codebase that were not guarded by bugfood checks. In testing, #enableDefaults causes warnings to be printed that otherwise would not.
This CL makes it so that we never call enableDefaults on non-bugfood builds, and cleans up and consolidates our usage of strict mode logic by introducing a new class called DialerStrictMode.
Test: none
PiperOrigin-RevId: 163521622
Change-Id: I841b4198a5dd6084ee104dc6907165e3379d0451
Diffstat (limited to 'java/com/android/dialer/configprovider/SharedPrefConfigProvider.java')
-rw-r--r-- | java/com/android/dialer/configprovider/SharedPrefConfigProvider.java | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/java/com/android/dialer/configprovider/SharedPrefConfigProvider.java b/java/com/android/dialer/configprovider/SharedPrefConfigProvider.java index fad25a409..6ee469572 100644 --- a/java/com/android/dialer/configprovider/SharedPrefConfigProvider.java +++ b/java/com/android/dialer/configprovider/SharedPrefConfigProvider.java @@ -20,11 +20,11 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; -import android.os.StrictMode; import android.support.annotation.Nullable; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.inject.ApplicationContext; +import com.android.dialer.strictmode.DialerStrictMode; import com.android.dialer.util.DialerUtils; import javax.inject.Inject; @@ -95,37 +95,26 @@ class SharedPrefConfigProvider implements ConfigProvider { @Override public String getString(String key, String defaultValue) { - return bypassStrictMode( + // Reading shared prefs on the main thread is generally safe since a single instance is cached. + return DialerStrictMode.bypass( () -> getSharedPrefs(appContext).getString(PREF_PREFIX + key, defaultValue)); } @Override public long getLong(String key, long defaultValue) { - return bypassStrictMode( + // Reading shared prefs on the main thread is generally safe since a single instance is cached. + return DialerStrictMode.bypass( () -> getSharedPrefs(appContext).getLong(PREF_PREFIX + key, defaultValue)); } @Override public boolean getBoolean(String key, boolean defaultValue) { - return bypassStrictMode( + // Reading shared prefs on the main thread is generally safe since a single instance is cached. + return DialerStrictMode.bypass( () -> getSharedPrefs(appContext).getBoolean(PREF_PREFIX + key, defaultValue)); } private static SharedPreferences getSharedPrefs(Context appContext) { return DialerUtils.getDefaultSharedPreferenceForDeviceProtectedStorageContext(appContext); } - - private interface Provider<T> { - T get(); - } - - // Reading shared prefs on the main thread is generally safe since a single instance is cached. - private static <T> T bypassStrictMode(Provider<T> provider) { - StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); - try { - return provider.get(); - } finally { - StrictMode.setThreadPolicy(oldPolicy); - } - } } |