Remove getCategoryKey() from DashboardFragment children.

Use the centralized registry to look up category key instead.

Bug: 32936784
Test: make RunSettingsRoboTests -j40
Change-Id: I0b8c72d70f93e4b5c58871ac90de41f69ad15653
This commit is contained in:
Fan Zhang
2017-01-24 14:02:17 -08:00
parent 88c0364ace
commit 7e6df837ee
32 changed files with 34 additions and 172 deletions

View File

@@ -55,11 +55,6 @@ public class DateTimeSettings extends DashboardFragment implements
return MetricsEvent.DATE_TIME;
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -67,11 +67,6 @@ public class DisplaySettings extends DashboardFragment {
mProgressiveDisclosureMixin.setTileLimit(4);
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_DISPLAY;
}
@Override
protected int getPreferenceScreenResId() {
if (mDashboardFeatureProvider.isEnabled()) {

View File

@@ -22,15 +22,14 @@ import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.accounts.AuthenticatorHelper;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.Tile;
import java.util.ArrayList;
@@ -62,8 +61,8 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
Bundle args = getArguments();
final Activity activity = getActivity();
UserHandle userHandle = Utils.getSecureTargetUser(activity.getActivityToken(),
(UserManager) getSystemService(Context.USER_SERVICE), args,
activity.getIntent().getExtras());
(UserManager) getSystemService(Context.USER_SERVICE), args,
activity.getIntent().getExtras());
if (args != null) {
if (args.containsKey(KEY_ACCOUNT)) {
mAccount = args.getParcelable(KEY_ACCOUNT);
@@ -93,11 +92,6 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
return MetricsEvent.ACCOUNT;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_ACCOUNT;
}
@Override
protected String getLogTag() {
return TAG;
@@ -142,6 +136,6 @@ public class AccountDetailDashboardFragment extends DashboardFragment {
}
final AuthenticatorHelper helper = new AuthenticatorHelper(context, userHandle, null);
headerPreference.setIcon(helper.getDrawableForType(context, mAccountType));
}
}
}

View File

@@ -25,7 +25,6 @@ import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.Tile;
import java.util.ArrayList;
@@ -44,11 +43,6 @@ public class UserAndAccountDashboardFragment extends DashboardFragment {
return MetricsEvent.ACCOUNT;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_ACCOUNT;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -31,7 +31,6 @@ import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
import java.util.Arrays;
@@ -41,11 +40,6 @@ public class AdvancedAppSettings extends DashboardFragment {
static final String TAG = "AdvancedAppSettings";
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_APPS_DEFAULT;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -25,7 +25,6 @@ import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.drawer.CategoryKey;
import java.util.Arrays;
import java.util.List;
@@ -39,11 +38,6 @@ public class AppAndNotificationDashboardFragment extends DashboardFragment {
return MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_APPS;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -30,7 +30,6 @@ import com.android.settings.nfc.NfcPreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
import java.util.Arrays;
@@ -47,11 +46,6 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
return MetricsProto.MetricsEvent.SETTINGS_CONNECTED_DEVICE_CATEGORY;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_DEVICE;
}
@Override
protected String getLogTag() {
return TAG;
@@ -73,8 +67,7 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
mUsbPrefController = new UsbModePreferenceController(context, new UsbBackend(context));
lifecycle.addObserver(mUsbPrefController);
controllers.add(mUsbPrefController);
mBluetoothPreferenceController =
new BluetoothMasterSwitchPreferenceController(
mBluetoothPreferenceController = new BluetoothMasterSwitchPreferenceController(
context, Utils.getLocalBtManager(context));
lifecycle.addObserver(mBluetoothPreferenceController);
controllers.add(mBluetoothPreferenceController);

View File

@@ -194,7 +194,10 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
/**
* Returns the CategoryKey for loading {@link DashboardCategory} for this fragment.
*/
protected abstract String getCategoryKey();
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
public String getCategoryKey() {
return DashboardFragmentRegistry.PARENT_TO_CATEGORY_KEY_MAP.get(getClass().getName());
}
/**
* Get the tag string for logging.
@@ -302,9 +305,9 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
final Context context = getContext();
mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey());
mSummaryLoader.setSummaryConsumer(this);
final TypedArray a = context.obtainStyledAttributes(new int[] {
mDashboardFeatureProvider.isEnabled() ? android.R.attr.colorControlNormal
: android.R.attr.colorAccent});
final TypedArray a = context.obtainStyledAttributes(new int[]{
mDashboardFeatureProvider.isEnabled() ? android.R.attr.colorControlNormal
: android.R.attr.colorAccent});
final int tintColor = a.getColor(0, context.getColor(android.R.color.white));
a.recycle();
final String pkgName = context.getPackageName();
@@ -319,7 +322,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
continue;
}
if (pkgName != null && tile.intent != null
&& !pkgName.equals(tile.intent.getComponent().getPackageName())) {
&& !pkgName.equals(tile.intent.getComponent().getPackageName())) {
// If this drawable is coming from outside Settings, tint it to match the color.
tile.icon.setTint(tintColor);
}

View File

@@ -21,13 +21,16 @@ import android.util.ArrayMap;
import com.android.settings.DevelopmentSettings;
import com.android.settings.DisplaySettings;
import com.android.settings.SecuritySettings;
import com.android.settings.accounts.AccountDetailDashboardFragment;
import com.android.settings.accounts.UserAndAccountDashboardFragment;
import com.android.settings.applications.AdvancedAppSettings;
import com.android.settings.applications.AppAndNotificationDashboardFragment;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.inputmethod.InputAndGestureSettings;
import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
import com.android.settings.language.LanguageAndRegionSettings;
import com.android.settings.network.NetworkDashboardFragment;
import com.android.settings.notification.SoundSettings;
import com.android.settings.system.SystemDashboardFragment;
@@ -37,7 +40,6 @@ import java.util.Map;
/**
* A registry to keep track of which page hosts which category.
* TODO: Remove DashboardFragment#getCategoryKey() and just use this registry instead.
*/
public class DashboardFragmentRegistry {
@@ -61,6 +63,8 @@ public class DashboardFragmentRegistry {
CategoryKey.CATEGORY_DEVICE);
PARENT_TO_CATEGORY_KEY_MAP.put(AppAndNotificationDashboardFragment.class.getName(),
CategoryKey.CATEGORY_APPS);
PARENT_TO_CATEGORY_KEY_MAP.put(PowerUsageSummary.class.getName(),
CategoryKey.CATEGORY_BATTERY);
PARENT_TO_CATEGORY_KEY_MAP.put(AdvancedAppSettings.class.getName(),
CategoryKey.CATEGORY_APPS_DEFAULT);
PARENT_TO_CATEGORY_KEY_MAP.put(DisplaySettings.class.getName(),
@@ -71,7 +75,7 @@ public class DashboardFragmentRegistry {
CategoryKey.CATEGORY_STORAGE);
PARENT_TO_CATEGORY_KEY_MAP.put(SecuritySettings.class.getName(),
CategoryKey.CATEGORY_SECURITY);
PARENT_TO_CATEGORY_KEY_MAP.put(UserAndAccountDashboardFragment.class.getName(),
PARENT_TO_CATEGORY_KEY_MAP.put(AccountDetailDashboardFragment.class.getName(),
CategoryKey.CATEGORY_ACCOUNT);
PARENT_TO_CATEGORY_KEY_MAP.put(UserAndAccountDashboardFragment.class.getName(),
CategoryKey.CATEGORY_ACCOUNT);
@@ -81,6 +85,8 @@ public class DashboardFragmentRegistry {
InputAndGestureSettings.class.getName(), CategoryKey.CATEGORY_SYSTEM_INPUT);
PARENT_TO_CATEGORY_KEY_MAP.put(InputMethodAndLanguageSettings.class.getName(),
CategoryKey.CATEGORY_SYSTEM_LANGUAGE);
PARENT_TO_CATEGORY_KEY_MAP.put(LanguageAndRegionSettings.class.getName(),
CategoryKey.CATEGORY_SYSTEM_LANGUAGE);
PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettings.class.getName(),
CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);

View File

@@ -100,11 +100,6 @@ public class StorageDashboardFragment extends DashboardFragment {
return TAG;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_STORAGE;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.storage_dashboard_fragment;

View File

@@ -24,7 +24,6 @@ import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable.SearchIndexProvider;
import java.util.ArrayList;
import java.util.Arrays;
@@ -39,11 +38,6 @@ public class EnterprisePrivacySettings extends DashboardFragment {
return MetricsEvent.ENTERPRISE_PRIVACY_SETTINGS;
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -387,11 +387,6 @@ public class PowerUsageDetail extends PowerUsageBase implements Button.OnClickLi
setupHeader();
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -37,6 +37,7 @@ import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatterySipper.DrainType;
@@ -52,7 +53,6 @@ import com.android.settings.display.TimeoutPreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.BatteryInfo;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
import java.util.Arrays;
@@ -138,11 +138,6 @@ public class PowerUsageSummary extends PowerUsageBase {
return super.onPreferenceTreeClick(preference);
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_BATTERY;
}
@Override
protected String getLogTag() {
return TAG;
@@ -414,8 +409,9 @@ public class PowerUsageSummary extends PowerUsageBase {
pref.setTitle(entry.getLabel());
pref.setOrder(i + 1);
pref.setPercent(percentOfMax, percentOfTotal);
if ((sipper.drainType != DrainType.APP || sipper.uidObj.getUid() == Process.ROOT_UID)
&& sipper.drainType != DrainType.USER) {
if ((sipper.drainType != DrainType.APP
|| sipper.uidObj.getUid() == Process.ROOT_UID)
&& sipper.drainType != DrainType.USER) {
pref.setTint(colorControl);
}
addedSome = true;
@@ -579,7 +575,7 @@ public class PowerUsageSummary extends PowerUsageBase {
= new SummaryLoader.SummaryProviderFactory() {
@Override
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
SummaryLoader summaryLoader) {
SummaryLoader summaryLoader) {
return new SummaryProvider(activity, summaryLoader);
}
};

View File

@@ -39,11 +39,6 @@ public class DoubleTapPowerSettings extends DashboardFragment {
return MetricsProto.MetricsEvent.SETTINGS_GESTURE_DOUBLE_TAP_POWER;
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -41,11 +41,6 @@ public class DoubleTapScreenSettings extends DashboardFragment {
return MetricsProto.MetricsEvent.SETTINGS_GESTURE_DOUBLE_TAP_SCREEN;
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -39,11 +39,6 @@ public class DoubleTwistGestureSettings extends DashboardFragment {
return MetricsProto.MetricsEvent.SETTINGS_GESTURE_DOUBLE_TWIST;
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -121,11 +121,6 @@ public class GestureSettings extends DashboardFragment {
}
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;
@@ -170,7 +165,7 @@ public class GestureSettings extends DashboardFragment {
List<PreferenceController> preferenceControllers =
getPreferenceControllers(context);
for(PreferenceController controller : preferenceControllers) {
for (PreferenceController controller : preferenceControllers) {
controller.updateNonIndexableKeys(result);
}
return result;

View File

@@ -41,11 +41,6 @@ public class PickupGestureSettings extends DashboardFragment {
return MetricsProto.MetricsEvent.SETTINGS_GESTURE_PICKUP;
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -39,11 +39,6 @@ public class SwipeToNotificationSettings extends DashboardFragment {
return MetricsProto.MetricsEvent.SETTINGS_GESTURE_SWIPE_TO_NOTIFICATION;
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -34,7 +34,6 @@ import com.android.settings.gestures.PickupGesturePreferenceController;
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
import java.util.Arrays;
@@ -51,11 +50,6 @@ public class InputAndGestureSettings extends DashboardFragment {
return MetricsProto.MetricsEvent.SETTINGS_INPUT_CATEGORY;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_SYSTEM_INPUT;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -38,7 +38,6 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settings.search.SearchIndexableRaw;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
import java.util.List;
@@ -60,11 +59,6 @@ public class InputMethodAndLanguageSettings extends DashboardFragment
return MetricsEvent.INPUTMETHOD_LANGUAGE;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_SYSTEM_LANGUAGE;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -24,7 +24,6 @@ import com.android.settings.R;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.inputmethod.SpellCheckerPreferenceController;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
import java.util.List;
@@ -38,11 +37,6 @@ public class LanguageAndRegionSettings extends DashboardFragment {
return MetricsProto.MetricsEvent.SETTINGS_LANGUAGE_CATEGORY;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_SYSTEM_LANGUAGE;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -27,7 +27,6 @@ import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
import java.util.Arrays;
@@ -46,11 +45,6 @@ public class NetworkDashboardFragment extends DashboardFragment implements
return MetricsProto.MetricsEvent.SETTINGS_NETWORK_CATEGORY;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_NETWORK;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -39,11 +39,6 @@ public class ConfigureNotificationSettings extends DashboardFragment {
return MetricsEvent.CONFIGURE_NOTIFICATION;
}
@Override
protected String getCategoryKey() {
return "";
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -46,11 +46,6 @@ public class OtherSoundSettings extends DashboardFragment {
return R.string.help_uri_other_sounds;
}
@Override
protected String getCategoryKey() {
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -20,7 +20,6 @@ import android.app.Activity;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -43,7 +42,7 @@ import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.drawer.CategoryKey;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -102,11 +101,6 @@ public class SoundSettings extends DashboardFragment {
return super.onPreferenceTreeClick(preference);
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_SOUND;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -30,7 +30,6 @@ import com.android.settings.localepicker.LocaleFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.drawer.CategoryKey;
import java.util.ArrayList;
import java.util.Arrays;
@@ -56,11 +55,6 @@ public class SystemDashboardFragment extends DashboardFragment {
return R.xml.system_dashboard_fragment;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_SYSTEM;
}
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
final List<PreferenceController> controllers = new ArrayList<>();

View File

@@ -15,8 +15,6 @@
*/
package com.android.settings.wifi;
import static android.content.Context.WIFI_SERVICE;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.provider.SearchIndexableResource;
@@ -32,6 +30,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static android.content.Context.WIFI_SERVICE;
public class ConfigureWifiSettings extends DashboardFragment {
private static final String TAG = "ConfigureWifiSettings";
@@ -43,12 +43,6 @@ public class ConfigureWifiSettings extends DashboardFragment {
return MetricsEvent.CONFIGURE_WIFI;
}
@Override
protected String getCategoryKey() {
// We don't want to inject any external settings into this screen.
return null;
}
@Override
protected String getLogTag() {
return TAG;

View File

@@ -305,7 +305,7 @@ public class WifiSettings extends RestrictedSettingsFragment
/**
* @return new WifiEnabler or null (as overridden by WifiSettingsForSetupWizard)
*/
/* package */ WifiEnabler createWifiEnabler() {
private WifiEnabler createWifiEnabler() {
final SettingsActivity activity = (SettingsActivity) getActivity();
return new WifiEnabler(activity, activity.getSwitchBar(), mMetricsFeatureProvider);
}

View File

@@ -82,7 +82,8 @@ public class AccountDetailDashboardFragmentTest {
@Test
public void testCategory_isAccount() {
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
assertThat(new AccountDetailDashboardFragment().getCategoryKey())
.isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
}
@Test

View File

@@ -26,7 +26,6 @@ import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.Tile;
@@ -199,11 +198,6 @@ public class DashboardFragmentTest {
return 0;
}
@Override
protected String getCategoryKey() {
return CategoryKey.CATEGORY_HOMEPAGE;
}
@Override
public PreferenceScreen getPreferenceScreen() {
return mScreen;

View File

@@ -21,6 +21,7 @@ import android.provider.SearchIndexableResource;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.accounts.UserAndAccountDashboardFragment;
import com.android.settings.dashboard.DashboardFragmentRegistry;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.CategoryKey;
import org.junit.Before;