From bb4c1be2923ea7bfc9152e3cef9d0c12cb6664bd Mon Sep 17 00:00:00 2001 From: zachh Date: Tue, 27 Mar 2018 17:04:15 -0700 Subject: Use CallLogConfig for enabling new peer. ConfigProvider should not be used directly for reading NUI flags as CallLogConfig needs to perform work when they change. Bug: 74821995 Test: existing PiperOrigin-RevId: 190698415 Change-Id: Ic084d9032d2a6f35ffba9f395eaaff9053cfa262 --- .../configprovider/SharedPrefConfigProvider.java | 22 +++++++++++++--------- .../SharedPrefConfigProviderModule.java | 5 ++++- .../com/android/dialer/main/impl/MainActivity.java | 6 +++--- 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/configprovider/SharedPrefConfigProvider.java b/java/com/android/dialer/configprovider/SharedPrefConfigProvider.java index d700fb676..ce95c5700 100644 --- a/java/com/android/dialer/configprovider/SharedPrefConfigProvider.java +++ b/java/com/android/dialer/configprovider/SharedPrefConfigProvider.java @@ -23,8 +23,8 @@ import android.content.SharedPreferences.Editor; 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.storage.StorageComponent; +import com.android.dialer.storage.Unencrypted; import com.android.dialer.strictmode.StrictModeUtils; import javax.inject.Inject; @@ -49,14 +49,14 @@ import javax.inject.Inject; * /data/user_de/0/com.android.dialer/shared_prefs/com.android.dialer_preferences.xml * */ -class SharedPrefConfigProvider implements ConfigProvider { +public class SharedPrefConfigProvider implements ConfigProvider { private static final String PREF_PREFIX = "config_provider_prefs_"; - private final Context appContext; + private final SharedPreferences sharedPreferences; @Inject - SharedPrefConfigProvider(@ApplicationContext Context appContext) { - this.appContext = appContext; + SharedPrefConfigProvider(@Unencrypted SharedPreferences sharedPreferences) { + this.sharedPreferences = sharedPreferences; } /** Service to write values into {@link SharedPrefConfigProvider} using adb. */ @@ -93,25 +93,29 @@ class SharedPrefConfigProvider implements ConfigProvider { } } + /** Set a boolean config value. */ + public void putBoolean(String key, boolean value) { + sharedPreferences.edit().putBoolean(PREF_PREFIX + key, value).apply(); + } + @Override public String getString(String key, String defaultValue) { // Reading shared prefs on the main thread is generally safe since a single instance is cached. return StrictModeUtils.bypass( - () -> getSharedPrefs(appContext).getString(PREF_PREFIX + key, defaultValue)); + () -> sharedPreferences.getString(PREF_PREFIX + key, defaultValue)); } @Override public long getLong(String key, long defaultValue) { // Reading shared prefs on the main thread is generally safe since a single instance is cached. - return StrictModeUtils.bypass( - () -> getSharedPrefs(appContext).getLong(PREF_PREFIX + key, defaultValue)); + return StrictModeUtils.bypass(() -> sharedPreferences.getLong(PREF_PREFIX + key, defaultValue)); } @Override public boolean getBoolean(String key, boolean defaultValue) { // Reading shared prefs on the main thread is generally safe since a single instance is cached. return StrictModeUtils.bypass( - () -> getSharedPrefs(appContext).getBoolean(PREF_PREFIX + key, defaultValue)); + () -> sharedPreferences.getBoolean(PREF_PREFIX + key, defaultValue)); } private static SharedPreferences getSharedPrefs(Context appContext) { diff --git a/java/com/android/dialer/configprovider/SharedPrefConfigProviderModule.java b/java/com/android/dialer/configprovider/SharedPrefConfigProviderModule.java index fe1c90816..4af8bfe17 100644 --- a/java/com/android/dialer/configprovider/SharedPrefConfigProviderModule.java +++ b/java/com/android/dialer/configprovider/SharedPrefConfigProviderModule.java @@ -16,14 +16,17 @@ package com.android.dialer.configprovider; +import com.android.dialer.storage.StorageModule; import dagger.Binds; import dagger.Module; import javax.inject.Singleton; /** Dagger module providing {@link ConfigProvider} based on shared preferences. */ -@Module +@Module(includes = StorageModule.class) public abstract class SharedPrefConfigProviderModule { + private SharedPrefConfigProviderModule() {} + @Binds @Singleton abstract ConfigProvider to(SharedPrefConfigProvider impl); diff --git a/java/com/android/dialer/main/impl/MainActivity.java b/java/com/android/dialer/main/impl/MainActivity.java index 1d705f06c..2046b048f 100644 --- a/java/com/android/dialer/main/impl/MainActivity.java +++ b/java/com/android/dialer/main/impl/MainActivity.java @@ -21,9 +21,9 @@ import android.content.Intent; import android.os.Bundle; import android.support.v4.content.LocalBroadcastManager; import com.android.dialer.blockreportspam.ShowBlockReportSpamDialogReceiver; +import com.android.dialer.calllog.config.CallLogConfigComponent; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; -import com.android.dialer.configprovider.ConfigProviderBindings; import com.android.dialer.interactions.PhoneNumberInteraction.DisambigDialogDismissedListener; import com.android.dialer.interactions.PhoneNumberInteraction.InteractionErrorCode; import com.android.dialer.interactions.PhoneNumberInteraction.InteractionErrorListener; @@ -53,7 +53,7 @@ public class MainActivity extends TransactionSafeActivity /** Returns intent that will open MainActivity to the specified tab. */ public static Intent getShowTabIntent(Context context, @TabIndex int tabIndex) { - if (ConfigProviderBindings.get(context).getBoolean("nui_peer_enabled", false)) { + if (CallLogConfigComponent.get(context).callLogConfig().isNewPeerEnabled()) { // TODO(calderwoodra): implement this in NewMainActivityPeer return null; } @@ -82,7 +82,7 @@ public class MainActivity extends TransactionSafeActivity } protected MainActivityPeer getNewPeer() { - if (ConfigProviderBindings.get(this).getBoolean("nui_peer_enabled", false)) { + if (CallLogConfigComponent.get(this).callLogConfig().isNewPeerEnabled()) { return new NewMainActivityPeer(this); } else { return new OldMainActivityPeer(this); -- cgit v1.2.3