Remove the redundant constructor of SuggestionFeatureProviderImpl

Fix: 175167313
Test: robotest
Change-Id: I7ebbaf92398a8300971d592e2ee7a6e0d82c1d2f
This commit is contained in:
Chaohui Wang
2022-03-29 11:49:34 +08:00
parent ae9d768549
commit 80a11a251e
21 changed files with 36 additions and 59 deletions

View File

@@ -30,21 +30,15 @@ import com.android.settings.biometrics.fingerprint.FingerprintSuggestionActivity
import com.android.settings.display.NightDisplayPreferenceController; import com.android.settings.display.NightDisplayPreferenceController;
import com.android.settings.notification.zen.ZenOnboardingActivity; import com.android.settings.notification.zen.ZenOnboardingActivity;
import com.android.settings.notification.zen.ZenSuggestionActivity; import com.android.settings.notification.zen.ZenSuggestionActivity;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.password.ScreenLockSuggestionActivity; import com.android.settings.password.ScreenLockSuggestionActivity;
import com.android.settings.wallpaper.StyleSuggestionActivity; import com.android.settings.wallpaper.StyleSuggestionActivity;
import com.android.settings.wallpaper.WallpaperSuggestionActivity; import com.android.settings.wallpaper.WallpaperSuggestionActivity;
import com.android.settings.wifi.calling.WifiCallingSuggestionActivity; import com.android.settings.wifi.calling.WifiCallingSuggestionActivity;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider { public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider {
private static final String TAG = "SuggestionFeature";
private static final String SHARED_PREF_FILENAME = "suggestions"; private static final String SHARED_PREF_FILENAME = "suggestions";
private final MetricsFeatureProvider mMetricsFeatureProvider;
@Override @Override
public boolean isSuggestionEnabled(Context context) { public boolean isSuggestionEnabled(Context context) {
final ActivityManager am = final ActivityManager am =
@@ -91,10 +85,4 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
public Class<? extends Fragment> getContextualSuggestionFragment() { public Class<? extends Fragment> getContextualSuggestionFragment() {
return null; return null;
} }
public SuggestionFeatureProviderImpl(Context context) {
final Context appContext = context.getApplicationContext();
mMetricsFeatureProvider = FeatureFactory.getFactory(appContext)
.getMetricsFeatureProvider();
}
} }

View File

@@ -84,7 +84,7 @@ public class SuggestionStateProvider extends ContentProvider {
} else { } else {
final Context context = getContext(); final Context context = getContext();
isComplete = FeatureFactory.getFactory(context) isComplete = FeatureFactory.getFactory(context)
.getSuggestionFeatureProvider(context) .getSuggestionFeatureProvider()
.isSuggestionComplete(context, cn); .isSuggestionComplete(context, cn);
} }
Log.d(TAG, "Suggestion " + id + " complete: " + isComplete); Log.d(TAG, "Suggestion " + id + " complete: " + isComplete);

View File

@@ -19,7 +19,6 @@ package com.android.settings.gestures;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.provider.SearchIndexableResource;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
@@ -28,9 +27,6 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import java.util.Arrays;
import java.util.List;
@SearchIndexable @SearchIndexable
public class DoubleTapPowerSettings extends DashboardFragment { public class DoubleTapPowerSettings extends DashboardFragment {
@@ -42,8 +38,8 @@ public class DoubleTapPowerSettings extends DashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) SuggestionFeatureProvider suggestionFeatureProvider =
.getSuggestionFeatureProvider(context); FeatureFactory.getFactory(context).getSuggestionFeatureProvider();
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
} }

View File

@@ -20,7 +20,6 @@ import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.hardware.display.AmbientDisplayConfiguration; import android.hardware.display.AmbientDisplayConfiguration;
import android.provider.SearchIndexableResource;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
@@ -29,9 +28,6 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import java.util.Arrays;
import java.util.List;
@SearchIndexable @SearchIndexable
public class DoubleTapScreenSettings extends DashboardFragment { public class DoubleTapScreenSettings extends DashboardFragment {
@@ -43,8 +39,8 @@ public class DoubleTapScreenSettings extends DashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) SuggestionFeatureProvider suggestionFeatureProvider =
.getSuggestionFeatureProvider(context); FeatureFactory.getFactory(context).getSuggestionFeatureProvider();
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();

View File

@@ -42,8 +42,8 @@ public class DoubleTwistGestureSettings extends DashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) SuggestionFeatureProvider suggestionFeatureProvider =
.getSuggestionFeatureProvider(context); FeatureFactory.getFactory(context).getSuggestionFeatureProvider();
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
} }

View File

@@ -39,8 +39,8 @@ public class PickupGestureSettings extends DashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) SuggestionFeatureProvider suggestionFeatureProvider =
.getSuggestionFeatureProvider(context); FeatureFactory.getFactory(context).getSuggestionFeatureProvider();
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();

View File

@@ -38,8 +38,8 @@ public class SwipeToNotificationSettings extends DashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) SuggestionFeatureProvider suggestionFeatureProvider =
.getSuggestionFeatureProvider(context); FeatureFactory.getFactory(context).getSuggestionFeatureProvider();
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();
} }

View File

@@ -103,8 +103,8 @@ public class SystemNavigationGestureSettings extends RadioButtonPickerFragment i
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) SuggestionFeatureProvider suggestionFeatureProvider =
.getSuggestionFeatureProvider(context); FeatureFactory.getFactory(context).getSuggestionFeatureProvider();
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();

View File

@@ -19,7 +19,6 @@ package com.android.settings.gestures;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.hardware.display.AmbientDisplayConfiguration; import android.hardware.display.AmbientDisplayConfiguration;
import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto; import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R; import com.android.settings.R;
@@ -27,12 +26,8 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider; import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.Indexable;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import java.util.Arrays;
import java.util.List;
@SearchIndexable @SearchIndexable
public class TapScreenGestureSettings extends DashboardFragment { public class TapScreenGestureSettings extends DashboardFragment {
private static final String TAG = "TapScreenGestureSettings"; private static final String TAG = "TapScreenGestureSettings";
@@ -43,8 +38,8 @@ public class TapScreenGestureSettings extends DashboardFragment {
@Override @Override
public void onAttach(Context context) { public void onAttach(Context context) {
super.onAttach(context); super.onAttach(context);
SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) SuggestionFeatureProvider suggestionFeatureProvider =
.getSuggestionFeatureProvider(context); FeatureFactory.getFactory(context).getSuggestionFeatureProvider();
SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context);
prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply();

View File

@@ -351,7 +351,7 @@ public class SettingsHomepageActivity extends FragmentActivity implements
private void showSuggestionFragment(boolean scrollNeeded) { private void showSuggestionFragment(boolean scrollNeeded) {
final Class<? extends Fragment> fragmentClass = FeatureFactory.getFactory(this) final Class<? extends Fragment> fragmentClass = FeatureFactory.getFactory(this)
.getSuggestionFeatureProvider(this).getContextualSuggestionFragment(); .getSuggestionFeatureProvider().getContextualSuggestionFragment();
if (fragmentClass == null) { if (fragmentClass == null) {
return; return;
} }

View File

@@ -64,7 +64,7 @@ public class LegacySuggestionContextualCardController implements ContextualCardC
return; return;
} }
final ComponentName suggestionServiceComponent = final ComponentName suggestionServiceComponent =
FeatureFactory.getFactory(mContext).getSuggestionFeatureProvider(mContext) FeatureFactory.getFactory(mContext).getSuggestionFeatureProvider()
.getSuggestionServiceComponent(); .getSuggestionServiceComponent();
mSuggestionController = new SuggestionController( mSuggestionController = new SuggestionController(
mContext, suggestionServiceComponent, this /* listener */); mContext, suggestionServiceComponent, this /* listener */);
@@ -93,7 +93,7 @@ public class LegacySuggestionContextualCardController implements ContextualCardC
@Override @Override
public void onDismissed(ContextualCard card) { public void onDismissed(ContextualCard card) {
mSuggestionController mSuggestionController
.dismissSuggestions(((LegacySuggestionContextualCard)card).getSuggestion()); .dismissSuggestions(((LegacySuggestionContextualCard) card).getSuggestion());
mSuggestions.remove(card); mSuggestions.remove(card);
updateAdapter(); updateAdapter();
} }

View File

@@ -179,8 +179,8 @@ public class ZenOnboardingActivity extends Activity {
} }
private static boolean withinShowTimeThreshold(Context context) { private static boolean withinShowTimeThreshold(Context context) {
final SuggestionFeatureProvider featureProvider = FeatureFactory.getFactory(context) final SuggestionFeatureProvider featureProvider =
.getSuggestionFeatureProvider(context); FeatureFactory.getFactory(context).getSuggestionFeatureProvider();
final SharedPreferences prefs = featureProvider.getSharedPrefs(context); final SharedPreferences prefs = featureProvider.getSharedPrefs(context);
final long currentTimeMs = System.currentTimeMillis(); final long currentTimeMs = System.currentTimeMillis();
final long firstDisplayTimeMs; final long firstDisplayTimeMs;

View File

@@ -102,7 +102,10 @@ public abstract class FeatureFactory {
public abstract AssistGestureFeatureProvider getAssistGestureFeatureProvider(); public abstract AssistGestureFeatureProvider getAssistGestureFeatureProvider();
public abstract SuggestionFeatureProvider getSuggestionFeatureProvider(Context context); /**
* Gets implementation for the Suggestion Feature provider.
*/
public abstract SuggestionFeatureProvider getSuggestionFeatureProvider();
public abstract SupportFeatureProvider getSupportFeatureProvider(Context context); public abstract SupportFeatureProvider getSupportFeatureProvider(Context context);

View File

@@ -225,10 +225,9 @@ public class FeatureFactoryImpl extends FeatureFactory {
} }
@Override @Override
public SuggestionFeatureProvider getSuggestionFeatureProvider(Context context) { public SuggestionFeatureProvider getSuggestionFeatureProvider() {
if (mSuggestionFeatureProvider == null) { if (mSuggestionFeatureProvider == null) {
mSuggestionFeatureProvider = new SuggestionFeatureProviderImpl( mSuggestionFeatureProvider = new SuggestionFeatureProviderImpl();
context.getApplicationContext());
} }
return mSuggestionFeatureProvider; return mSuggestionFeatureProvider;
} }

View File

@@ -73,7 +73,7 @@ public class SuggestionFeatureProviderImplTest {
when(mContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(mActivityManager); when(mContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(mActivityManager);
when(mActivityManager.isLowRamDevice()).thenReturn(false); when(mActivityManager.isLowRamDevice()).thenReturn(false);
mProvider = new SuggestionFeatureProviderImpl(mContext); mProvider = new SuggestionFeatureProviderImpl();
} }
@Test @Test

View File

@@ -111,7 +111,7 @@ public class DoubleTapPowerPreferenceControllerTest {
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true); com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet. // No stored value in shared preferences if not visited yet.
final SharedPreferences prefs = final SharedPreferences prefs =
new SuggestionFeatureProviderImpl(mContext).getSharedPrefs(mContext); new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
assertThat(isSuggestionComplete(mContext, prefs)).isFalse(); assertThat(isSuggestionComplete(mContext, prefs)).isFalse();
} }
@@ -121,7 +121,7 @@ public class DoubleTapPowerPreferenceControllerTest {
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true); com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet. // No stored value in shared preferences if not visited yet.
final SharedPreferences prefs = final SharedPreferences prefs =
new SuggestionFeatureProviderImpl(mContext).getSharedPrefs(mContext); new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
prefs.edit().putBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit(); prefs.edit().putBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();
assertThat(isSuggestionComplete(mContext, prefs)).isTrue(); assertThat(isSuggestionComplete(mContext, prefs)).isTrue();

View File

@@ -83,7 +83,7 @@ public class DoubleTapScreenPreferenceControllerTest {
// No stored value in shared preferences if not visited yet. // No stored value in shared preferences if not visited yet.
final Context context = RuntimeEnvironment.application; final Context context = RuntimeEnvironment.application;
final SharedPreferences prefs = final SharedPreferences prefs =
new SuggestionFeatureProviderImpl(context).getSharedPrefs(context); new SuggestionFeatureProviderImpl().getSharedPrefs(context);
assertThat(DoubleTapScreenPreferenceController assertThat(DoubleTapScreenPreferenceController
.isSuggestionComplete(mAmbientDisplayConfiguration, prefs)).isFalse(); .isSuggestionComplete(mAmbientDisplayConfiguration, prefs)).isFalse();
@@ -94,7 +94,7 @@ public class DoubleTapScreenPreferenceControllerTest {
when(mAmbientDisplayConfiguration.doubleTapSensorAvailable()).thenReturn(false); when(mAmbientDisplayConfiguration.doubleTapSensorAvailable()).thenReturn(false);
final Context context = RuntimeEnvironment.application; final Context context = RuntimeEnvironment.application;
final SharedPreferences prefs = final SharedPreferences prefs =
new SuggestionFeatureProviderImpl(context).getSharedPrefs(context); new SuggestionFeatureProviderImpl().getSharedPrefs(context);
prefs.edit().putBoolean( prefs.edit().putBoolean(
DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit(); DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();

View File

@@ -85,7 +85,7 @@ public class PickupGesturePreferenceControllerTest {
when(mContext.getResources().getString(anyInt())).thenReturn("foo"); when(mContext.getResources().getString(anyInt())).thenReturn("foo");
final Context context = RuntimeEnvironment.application; final Context context = RuntimeEnvironment.application;
final SharedPreferences prefs = final SharedPreferences prefs =
new SuggestionFeatureProviderImpl(context).getSharedPrefs(context); new SuggestionFeatureProviderImpl().getSharedPrefs(context);
prefs.edit().putBoolean(PickupGestureSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit(); prefs.edit().putBoolean(PickupGestureSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();
assertThat(PickupGesturePreferenceController.isSuggestionComplete(mContext, prefs)) assertThat(PickupGesturePreferenceController.isSuggestionComplete(mContext, prefs))

View File

@@ -145,7 +145,7 @@ public class SwipeToNotificationPreferenceControllerTest {
.thenReturn(true); .thenReturn(true);
// No stored value in shared preferences if not visited yet. // No stored value in shared preferences if not visited yet.
final Context context = RuntimeEnvironment.application; final Context context = RuntimeEnvironment.application;
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context) final SharedPreferences prefs = new SuggestionFeatureProviderImpl()
.getSharedPrefs(context); .getSharedPrefs(context);
assertThat(SwipeToNotificationPreferenceController.isSuggestionComplete(mContext, prefs)) assertThat(SwipeToNotificationPreferenceController.isSuggestionComplete(mContext, prefs))
@@ -161,7 +161,7 @@ public class SwipeToNotificationPreferenceControllerTest {
.thenReturn(true); .thenReturn(true);
// No stored value in shared preferences if not visited yet. // No stored value in shared preferences if not visited yet.
final Context context = RuntimeEnvironment.application; final Context context = RuntimeEnvironment.application;
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context) final SharedPreferences prefs = new SuggestionFeatureProviderImpl()
.getSharedPrefs(context); .getSharedPrefs(context);
prefs.edit() prefs.edit()
.putBoolean(SwipeToNotificationSettings.PREF_KEY_SUGGESTION_COMPLETE, true) .putBoolean(SwipeToNotificationSettings.PREF_KEY_SUGGESTION_COMPLETE, true)

View File

@@ -142,7 +142,7 @@ public class FakeFeatureFactory extends FeatureFactory {
} }
@Override @Override
public SuggestionFeatureProvider getSuggestionFeatureProvider(Context context) { public SuggestionFeatureProvider getSuggestionFeatureProvider() {
return suggestionsFeatureProvider; return suggestionsFeatureProvider;
} }

View File

@@ -128,7 +128,7 @@ public class FakeFeatureFactory extends FeatureFactory {
} }
@Override @Override
public SuggestionFeatureProvider getSuggestionFeatureProvider(Context context) { public SuggestionFeatureProvider getSuggestionFeatureProvider() {
return suggestionsFeatureProvider; return suggestionsFeatureProvider;
} }