Let fragment and indexProvider share prefControllers
Bug: 35812240
Test: make RunSettingsRoboTests
Change-Id: Ifd96f935836a52e0a56f170f3cdf9b9ddf7c499a
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index 47cb9829..89ba999 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -17,6 +17,7 @@
package com.android.settings;
import android.app.Activity;
+import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
@@ -24,6 +25,7 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceController;
+import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
@@ -38,7 +40,6 @@
import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
import com.android.settings.deviceinfo.SELinuxStatusPreferenceController;
import com.android.settings.deviceinfo.SafetyInfoPreferenceController;
-import com.android.settings.deviceinfo.SafetyLegalPreferenceController;
import com.android.settings.deviceinfo.SecurityPatchPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -51,8 +52,6 @@
private static final String LOG_TAG = "DeviceInfoSettings";
- private BuildNumberPreferenceController mBuildNumberPreferenceController;
-
@Override
public int getMetricsCategory() {
return MetricsEvent.DEVICEINFO;
@@ -65,7 +64,9 @@
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (mBuildNumberPreferenceController.onActivityResult(requestCode, resultCode, data)) {
+ final BuildNumberPreferenceController buildNumberPreferenceController =
+ getPreferenceController(BuildNumberPreferenceController.class);
+ if (buildNumberPreferenceController.onActivityResult(requestCode, resultCode, data)) {
return;
}
super.onActivityResult(requestCode, resultCode, data);
@@ -83,24 +84,8 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
- final List<PreferenceController> controllers = new ArrayList<>();
- mBuildNumberPreferenceController =
- new BuildNumberPreferenceController(context, getActivity(), this /* fragment */);
- getLifecycle().addObserver(mBuildNumberPreferenceController);
- controllers.add(mBuildNumberPreferenceController);
- controllers.add(new AdditionalSystemUpdatePreferenceController(context));
- controllers.add(new ManualPreferenceController(context));
- controllers.add(new FeedbackPreferenceController(this, context));
- controllers.add(new KernelVersionPreferenceController(context));
- controllers.add(new BasebandVersionPreferenceController(context));
- controllers.add(new FirmwareVersionPreferenceController(context, getLifecycle()));
- controllers.add(new RegulatoryInfoPreferenceController(context));
- controllers.add(new DeviceModelPreferenceController(context));
- controllers.add(new SecurityPatchPreferenceController(context));
- controllers.add(new FccEquipmentIdPreferenceController(context));
- controllers.add(new SELinuxStatusPreferenceController(context));
- controllers.add(new SafetyInfoPreferenceController(context));
- return controllers;
+ return buildPreferenceControllers(context, getActivity(), this /* fragment */,
+ getLifecycle());
}
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
@@ -131,6 +116,26 @@
}
};
+ private static List<PreferenceController> buildPreferenceControllers(Context context,
+ Activity activity, Fragment fragment, Lifecycle lifecycle) {
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(
+ new BuildNumberPreferenceController(context, activity, fragment, lifecycle));
+ controllers.add(new AdditionalSystemUpdatePreferenceController(context));
+ controllers.add(new ManualPreferenceController(context));
+ controllers.add(new FeedbackPreferenceController(fragment, context));
+ controllers.add(new KernelVersionPreferenceController(context));
+ controllers.add(new BasebandVersionPreferenceController(context));
+ controllers.add(new FirmwareVersionPreferenceController(context, lifecycle));
+ controllers.add(new RegulatoryInfoPreferenceController(context));
+ controllers.add(new DeviceModelPreferenceController(context));
+ controllers.add(new SecurityPatchPreferenceController(context));
+ controllers.add(new FccEquipmentIdPreferenceController(context));
+ controllers.add(new SELinuxStatusPreferenceController(context));
+ controllers.add(new SafetyInfoPreferenceController(context));
+ return controllers;
+ }
+
/**
* For Search.
*/
@@ -146,19 +151,9 @@
}
@Override
- public List<String> getNonIndexableKeys(Context context) {
- final List<String> keys = new ArrayList<>();
- new SafetyLegalPreferenceController(context).updateNonIndexableKeys(keys);
- new BasebandVersionPreferenceController(context).updateNonIndexableKeys(keys);
- new FeedbackPreferenceController(null, context).updateNonIndexableKeys(keys);
- new AdditionalSystemUpdatePreferenceController(context)
- .updateNonIndexableKeys(keys);
- new RegulatoryInfoPreferenceController(context).updateNonIndexableKeys(keys);
- new SecurityPatchPreferenceController(context).updateNonIndexableKeys(keys);
- new FccEquipmentIdPreferenceController(context).updateNonIndexableKeys(keys);
- new SELinuxStatusPreferenceController(context).updateNonIndexableKeys(keys);
- new SafetyInfoPreferenceController(context).updateNonIndexableKeys(keys);
- return keys;
+ public List<PreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context, null /*activity */,
+ null /* fragment */, null /* lifecycle */);
}
};
}
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index 1e0547b..6fbffe8 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -69,6 +69,15 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
+
+ @Override
+ protected int getHelpResource() {
+ return R.string.help_uri_display;
+ }
+
+ private static List<PreferenceController> buildPreferenceControllers(Context context) {
final List<PreferenceController> controllers = new ArrayList<>();
controllers.add(new AutoBrightnessPreferenceController(context));
controllers.add(new AutoRotatePreferenceController(context));
@@ -87,11 +96,6 @@
return controllers;
}
- @Override
- protected int getHelpResource() {
- return R.string.help_uri_display;
- }
-
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -106,32 +110,8 @@
}
@Override
- public List<String> getNonIndexableKeys(Context context) {
- ArrayList<String> result = new ArrayList<>();
-
- new AutoBrightnessPreferenceController(context).updateNonIndexableKeys(result);
- new AutoRotatePreferenceController(context).updateNonIndexableKeys(result);
- new CameraGesturePreferenceController(context).updateNonIndexableKeys(result);
- new DozePreferenceController(context).updateNonIndexableKeys(result);
- new FontSizePreferenceController(context).updateNonIndexableKeys(result);
- new LiftToWakePreferenceController(context).updateNonIndexableKeys(result);
- new NightDisplayPreferenceController(context).updateNonIndexableKeys(result);
- new NightModePreferenceController(context).updateNonIndexableKeys(result);
- new ScreenSaverPreferenceController(context).updateNonIndexableKeys(result);
- new TapToWakePreferenceController(context).updateNonIndexableKeys(result);
- new TimeoutPreferenceController(context).updateNonIndexableKeys(result);
- new VrDisplayPreferenceController(context).updateNonIndexableKeys(result);
- new WallpaperPreferenceController(context).updateNonIndexableKeys(result);
- new ThemePreferenceController(context).updateNonIndexableKeys(result);
-
- return result;
- }
-
- @Override
public List<PreferenceController> getPreferenceControllers(Context context) {
- final List<PreferenceController> controllers = new ArrayList<>();
- controllers.add(new AutoBrightnessPreferenceController(context));
- return controllers;
+ return buildPreferenceControllers(context);
}
};
}
diff --git a/src/com/android/settings/applications/assist/ManageAssist.java b/src/com/android/settings/applications/assist/ManageAssist.java
index b1ca5c6..a54f0ff 100644
--- a/src/com/android/settings/applications/assist/ManageAssist.java
+++ b/src/com/android/settings/applications/assist/ManageAssist.java
@@ -50,15 +50,7 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
- final Lifecycle lifecycle = getLifecycle();
- final List<PreferenceController> controllers = new ArrayList<>();
- controllers.add(new DefaultAssistPreferenceController(context));
- controllers.add(new GestureAssistPreferenceController(context));
- controllers.add(new AssistContextPreferenceController(context, lifecycle));
- controllers.add(new AssistScreenshotPreferenceController(context, lifecycle));
- controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle));
- controllers.add(new DefaultVoiceInputPreferenceController(context, lifecycle));
- return controllers;
+ return buildPreferenceControllers(context, getLifecycle());
}
@Override
@@ -74,6 +66,19 @@
.setTitle(R.string.assist_footer);
}
+ private static List<PreferenceController> buildPreferenceControllers(Context context,
+ Lifecycle lifecycle) {
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new DefaultAssistPreferenceController(context));
+ controllers.add(new GestureAssistPreferenceController(context));
+ controllers.add(new AssistContextPreferenceController(context, lifecycle));
+ controllers.add(new AssistScreenshotPreferenceController(context, lifecycle));
+ controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle));
+ controllers.add(new DefaultVoiceInputPreferenceController(context, lifecycle));
+ return controllers;
+ }
+
+
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
@@ -85,19 +90,8 @@
}
@Override
- public List<String> getNonIndexableKeys(Context context) {
- List<String> result = new ArrayList<>();
- new DefaultAssistPreferenceController(context).updateNonIndexableKeys(result);
- new GestureAssistPreferenceController(context).updateNonIndexableKeys(result);
- new AssistContextPreferenceController(context, null)
- .updateNonIndexableKeys(result);
- new AssistScreenshotPreferenceController(context, null)
- .updateNonIndexableKeys(result);
- new AssistFlashScreenPreferenceController(context, null)
- .updateNonIndexableKeys(result);
- new DefaultVoiceInputPreferenceController(context, null)
- .updateNonIndexableKeys(result);
- return result;
+ public List<PreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context, null /* lifecycle */);
}
};
}
diff --git a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
index a9fd21b..6c492cc 100644
--- a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
@@ -36,6 +36,7 @@
import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.core.lifecycle.LifecycleObserver;
import com.android.settings.core.lifecycle.events.OnResume;
import com.android.settings.overlay.FeatureFactory;
@@ -61,12 +62,16 @@
private int mDevHitCountdown;
private boolean mProcessingLastDevHit;
- public BuildNumberPreferenceController(Context context, Activity activity, Fragment fragment) {
+ public BuildNumberPreferenceController(Context context, Activity activity, Fragment fragment,
+ Lifecycle lifecycle) {
super(context);
mActivity = activity;
mFragment = fragment;
- mUm = UserManager.get(activity);
+ mUm = UserManager.get(context);
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
}
@Override
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index 72e1493..298a7ad 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -184,16 +184,19 @@
}
@Override
- public List<String> getNonIndexableKeys(Context context) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
- final ManageStoragePreferenceController controller =
- new ManageStoragePreferenceController(context);
- final List<String> keys = new ArrayList<>();
- controller.updateNonIndexableKeys(keys);
- return keys;
+ public List<PreferenceController> getPreferenceControllers(Context context) {
+ final StorageManager sm = context.getSystemService(StorageManager.class);
+ final UserManagerWrapper userManager =
+ new UserManagerWrapperImpl(context.getSystemService(UserManager.class));
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new StorageSummaryDonutPreferenceController(context));
+ controllers.add(new StorageItemPreferenceController(context, null /* host */,
+ null /* volume */, new StorageManagerVolumeProvider(sm)));
+ controllers.addAll(SecondaryUserController.getSecondaryUserControllers(
+ context, userManager));
+ controllers.add(new ManageStoragePreferenceController(context));
+ return controllers;
}
+
};
}
diff --git a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
index 0bf43e2..4fcacd8 100644
--- a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
@@ -28,8 +28,6 @@
import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
-import java.util.List;
-
import static android.content.Context.CARRIER_CONFIG_SERVICE;
public class SystemUpdatePreferenceController extends PreferenceController {
@@ -67,14 +65,6 @@
}
@Override
- public void updateNonIndexableKeys(List<String> keys) {
- // TODO: system update needs to be fixed for non-owner user b/22760654
- if (!isAvailable()) {
- keys.add(KEY_SYSTEM_UPDATE_SETTINGS);
- }
- }
-
- @Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (KEY_SYSTEM_UPDATE_SETTINGS.equals(preference.getKey())) {
CarrierConfigManager configManager =
diff --git a/src/com/android/settings/network/TetherPreferenceController.java b/src/com/android/settings/network/TetherPreferenceController.java
index 236fa96..5b8d55e 100644
--- a/src/com/android/settings/network/TetherPreferenceController.java
+++ b/src/com/android/settings/network/TetherPreferenceController.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.UserHandle;
-import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
@@ -30,7 +29,6 @@
import com.android.settings.TetherSettings;
import com.android.settings.core.PreferenceController;
-import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import static android.os.UserManager.DISALLOW_CONFIG_TETHERING;
@@ -45,7 +43,6 @@
private final AtomicReference<BluetoothPan> mBluetoothPan;
private final ConnectivityManager mConnectivityManager;
private final BluetoothAdapter mBluetoothAdapter;
- private final UserManager mUserManager;
private final BluetoothProfile.ServiceListener mBtProfileServiceListener =
new android.bluetooth.BluetoothProfile.ServiceListener() {
@@ -68,7 +65,6 @@
mBluetoothPan = null;
mConnectivityManager = null;
mBluetoothAdapter = null;
- mUserManager = null;
}
public TetherPreferenceController(Context context) {
@@ -78,7 +74,6 @@
context, DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
mConnectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter != null) {
mBluetoothAdapter.getProfileProxy(context, mBtProfileServiceListener,
@@ -114,13 +109,6 @@
}
@Override
- public void updateNonIndexableKeys(List<String> keys) {
- if (!mUserManager.isAdminUser() || !mConnectivityManager.isTetheringSupported()) {
- keys.add(KEY_TETHER_SETTINGS);
- }
- }
-
- @Override
public String getPreferenceKey() {
return KEY_TETHER_SETTINGS;
}
diff --git a/src/com/android/settings/notification/CastPreferenceController.java b/src/com/android/settings/notification/CastPreferenceController.java
index 7de5c48..0156dfd 100644
--- a/src/com/android/settings/notification/CastPreferenceController.java
+++ b/src/com/android/settings/notification/CastPreferenceController.java
@@ -17,11 +17,8 @@
package com.android.settings.notification;
import android.content.Context;
-import android.support.v7.preference.Preference;
-import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
-import java.util.List;
public class CastPreferenceController extends PreferenceController {
@@ -41,11 +38,4 @@
return true;
}
- @Override
- public void updateNonIndexableKeys(List<String> keys) {
- if (!Utils.isVoiceCapable(mContext)) {
- keys.add(KEY_WIFI_DISPLAY);
- }
- }
-
}
diff --git a/src/com/android/settings/notification/NotificationVolumePreferenceController.java b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
index e4759d7..40448a4 100644
--- a/src/com/android/settings/notification/NotificationVolumePreferenceController.java
+++ b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
@@ -37,7 +37,7 @@
@VisibleForTesting
NotificationVolumePreferenceController(Context context,
- VolumeSeekBarPreference.Callback callback, Lifecycle lifecycle, AudioHelper helper) {
+ Callback callback, Lifecycle lifecycle, AudioHelper helper) {
super(context, callback, lifecycle);
mHelper = helper;
}
diff --git a/src/com/android/settings/notification/SettingPrefController.java b/src/com/android/settings/notification/SettingPrefController.java
index d126fc4..64d65bb 100644
--- a/src/com/android/settings/notification/SettingPrefController.java
+++ b/src/com/android/settings/notification/SettingPrefController.java
@@ -71,13 +71,6 @@
}
@Override
- public void updateNonIndexableKeys(List<String> keys) {
- if (!mPreference.isApplicable(mContext)) {
- keys.add(mPreference.getKey());
- }
- }
-
- @Override
public void updateState(Preference preference) {
mPreference.update(mContext);
}
diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java
index a5a1bfd..df60573 100644
--- a/src/com/android/settings/notification/SoundSettings.java
+++ b/src/com/android/settings/notification/SoundSettings.java
@@ -33,7 +33,6 @@
import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import java.util.ArrayList;
@@ -51,7 +50,6 @@
private final VolumePreferenceCallback mVolumeCallback = new VolumePreferenceCallback();
private final H mHandler = new H();
- private WorkSoundPreferenceController mWorkSoundController;
private RingtonePreference mRequestPreference;
@Override
@@ -105,40 +103,7 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
- final List<PreferenceController> controllers = new ArrayList<>();
- Lifecycle lifecycle = getLifecycle();
- controllers.add(new ZenModePreferenceController(context));
- controllers.add(new EmergencyBroadcastPreferenceController(context));
- controllers.add(new VibrateWhenRingPreferenceController(context));
-
- // === Volumes ===
- controllers.add(new AlarmVolumePreferenceController(context, mVolumeCallback, lifecycle));
- controllers.add(new MediaVolumePreferenceController(context, mVolumeCallback, lifecycle));
- controllers.add(
- new NotificationVolumePreferenceController(context, mVolumeCallback, lifecycle));
- controllers.add(new RingVolumePreferenceController(context, mVolumeCallback, lifecycle));
-
- // === Phone & notification ringtone ===
- controllers.add(new PhoneRingtonePreferenceController(context));
- controllers.add(new AlarmRingtonePreferenceController(context));
- controllers.add(new NotificationRingtonePreferenceController(context));
-
- // === Work Sound Settings ===
- mWorkSoundController = new WorkSoundPreferenceController(context, this, getLifecycle());
- controllers.add(mWorkSoundController);
-
- // === Other Sound Settings ===
- controllers.add(new DialPadTonePreferenceController(context, this, lifecycle));
- controllers.add(new ScreenLockSoundPreferenceController(context, this, lifecycle));
- controllers.add(new ChargingSoundPreferenceController(context, this, lifecycle));
- controllers.add(new DockingSoundPreferenceController(context, this, lifecycle));
- controllers.add(new TouchSoundPreferenceController(context, this, lifecycle));
- controllers.add(new VibrateOnTouchPreferenceController(context, this, lifecycle));
- controllers.add(new DockAudioMediaPreferenceController(context, this, lifecycle));
- controllers.add(new BootSoundPreferenceController(context));
- controllers.add(new EmergencyTonePreferenceController(context, this, lifecycle));
-
- return controllers;
+ return buildPreferenceControllers(context, this, mVolumeCallback, getLifecycle());
}
@Override
@@ -206,6 +171,43 @@
}
}
+ private static List<PreferenceController> buildPreferenceControllers(Context context,
+ SoundSettings fragment, VolumeSeekBarPreference.Callback callback,
+ Lifecycle lifecycle) {
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new ZenModePreferenceController(context));
+ controllers.add(new EmergencyBroadcastPreferenceController(context));
+ controllers.add(new VibrateWhenRingPreferenceController(context));
+
+ // === Volumes ===
+ controllers.add(new AlarmVolumePreferenceController(context, callback, lifecycle));
+ controllers.add(new MediaVolumePreferenceController(context, callback, lifecycle));
+ controllers.add(
+ new NotificationVolumePreferenceController(context, callback, lifecycle));
+ controllers.add(new RingVolumePreferenceController(context, callback, lifecycle));
+
+ // === Phone & notification ringtone ===
+ controllers.add(new PhoneRingtonePreferenceController(context));
+ controllers.add(new AlarmRingtonePreferenceController(context));
+ controllers.add(new NotificationRingtonePreferenceController(context));
+
+ // === Work Sound Settings ===
+ controllers.add(new WorkSoundPreferenceController(context, fragment, lifecycle));
+
+ // === Other Sound Settings ===
+ controllers.add(new DialPadTonePreferenceController(context, fragment, lifecycle));
+ controllers.add(new ScreenLockSoundPreferenceController(context, fragment, lifecycle));
+ controllers.add(new ChargingSoundPreferenceController(context, fragment, lifecycle));
+ controllers.add(new DockingSoundPreferenceController(context, fragment, lifecycle));
+ controllers.add(new TouchSoundPreferenceController(context, fragment, lifecycle));
+ controllers.add(new VibrateOnTouchPreferenceController(context, fragment, lifecycle));
+ controllers.add(new DockAudioMediaPreferenceController(context, fragment, lifecycle));
+ controllers.add(new BootSoundPreferenceController(context));
+ controllers.add(new EmergencyTonePreferenceController(context, fragment, lifecycle));
+
+ return controllers;
+ }
+
// === Indexing ===
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
@@ -218,52 +220,20 @@
return Arrays.asList(sir);
}
- public List<String> getNonIndexableKeys(Context context) {
- final ArrayList<String> rt = new ArrayList<String>();
- new NotificationVolumePreferenceController(
- context, null /* Callback */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
- new RingVolumePreferenceController(
- context, null /* Callback */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
- new PhoneRingtonePreferenceController(context).updateNonIndexableKeys(rt);
- new VibrateWhenRingPreferenceController(context).updateNonIndexableKeys(rt);
- new EmergencyBroadcastPreferenceController(context).updateNonIndexableKeys(rt);
- new DialPadTonePreferenceController(context,
- null /* SettingsPreferenceFragment */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
- new ScreenLockSoundPreferenceController(context,
- null /* SettingsPreferenceFragment */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
- new ChargingSoundPreferenceController(context,
- null /* SettingsPreferenceFragment */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
- new DockingSoundPreferenceController(context,
- null /* SettingsPreferenceFragment */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
- new TouchSoundPreferenceController(context, null /*
- SettingsPreferenceFragment */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
- new VibrateOnTouchPreferenceController(context,
- null /* SettingsPreferenceFragment */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
- new DockAudioMediaPreferenceController(context,
- null /* SettingsPreferenceFragment */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
- new BootSoundPreferenceController(context).updateNonIndexableKeys(rt);
- new EmergencyTonePreferenceController(context,
- null /* SettingsPreferenceFragment */,
- null /* Lifecycle */).updateNonIndexableKeys(rt);
-
- return rt;
+ @Override
+ public List<PreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context, null /* fragment */,
+ null /* callback */, null /* lifecycle */);
}
};
// === Work Sound Settings ===
void enableWorkSync() {
- if (mWorkSoundController != null) {
- mWorkSoundController.enableWorkSync();
+ final WorkSoundPreferenceController workSoundController =
+ getPreferenceController(WorkSoundPreferenceController.class);
+ if (workSoundController != null) {
+ workSoundController.enableWorkSync();
}
}
}
diff --git a/src/com/android/settings/search/BaseSearchIndexProvider.java b/src/com/android/settings/search/BaseSearchIndexProvider.java
index bb518ba..38c8d40 100644
--- a/src/com/android/settings/search/BaseSearchIndexProvider.java
+++ b/src/com/android/settings/search/BaseSearchIndexProvider.java
@@ -18,8 +18,10 @@
import android.content.Context;
import android.provider.SearchIndexableResource;
+
import com.android.settings.core.PreferenceController;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -28,7 +30,7 @@
*/
public class BaseSearchIndexProvider implements Indexable.SearchIndexProvider {
- private static final List<String> EMPTY_LIST = Collections.<String>emptyList();
+ private static final List<String> EMPTY_LIST = Collections.emptyList();
public BaseSearchIndexProvider() {
}
@@ -45,7 +47,16 @@
@Override
public List<String> getNonIndexableKeys(Context context) {
- return EMPTY_LIST;
+ final List<PreferenceController> controllers = getPreferenceControllers(context);
+ if (controllers != null && !controllers.isEmpty()) {
+ final List<String> nonIndexableKeys = new ArrayList<>();
+ for (PreferenceController controller : controllers) {
+ controller.updateNonIndexableKeys(nonIndexableKeys);
+ }
+ return nonIndexableKeys;
+ } else {
+ return EMPTY_LIST;
+ }
}
@Override
diff --git a/src/com/android/settings/system/SystemDashboardFragment.java b/src/com/android/settings/system/SystemDashboardFragment.java
index 2898ce2..c4bf0da 100644
--- a/src/com/android/settings/system/SystemDashboardFragment.java
+++ b/src/com/android/settings/system/SystemDashboardFragment.java
@@ -55,6 +55,10 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
+
+ private static List<PreferenceController> buildPreferenceControllers(Context context) {
final List<PreferenceController> controllers = new ArrayList<>();
controllers.add(new SystemUpdatePreferenceController(context, UserManager.get(context)));
controllers.add(new AdditionalSystemUpdatePreferenceController(context));
@@ -79,17 +83,8 @@
}
@Override
- public List<String> getNonIndexableKeys(Context context) {
- if (!FeatureFactory.getFactory(context).getDashboardFeatureProvider(context)
- .isEnabled()) {
- return null;
- }
- final List<String> keys = new ArrayList<>();
- new SystemUpdatePreferenceController(context, UserManager.get(context))
- .updateNonIndexableKeys(keys);
- new AdditionalSystemUpdatePreferenceController(context)
- .updateNonIndexableKeys(keys);
- return keys;
+ public List<PreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
}
};
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
index 017c5a8..0a74cc4 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/BuildNumberPreferenceControllerTest.java
@@ -29,6 +29,7 @@
import com.android.settings.DevelopmentSettings;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -40,6 +41,7 @@
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
@@ -47,6 +49,7 @@
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -65,6 +68,7 @@
@Mock
private UserManager mUserManager;
+ private Lifecycle mLifecycle;
private FakeFeatureFactory mFactory;
private Preference mPreference;
private BuildNumberPreferenceController mController;
@@ -74,8 +78,10 @@
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
- when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- mController = new BuildNumberPreferenceController(mContext, mActivity, mFragment);
+ mLifecycle = new Lifecycle();
+ when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+ mController = new BuildNumberPreferenceController(
+ mContext, mActivity, mFragment, mLifecycle);
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
@@ -104,11 +110,13 @@
@Test
public void handlePrefTreeClick_deviceNotProvisioned_doNothing() {
when(mUserManager.isAdminUser()).thenReturn(true);
- final Context context = ShadowApplication.getInstance().getApplicationContext();
+ final Context context = RuntimeEnvironment.application;
Settings.Global.putInt(context.getContentResolver(),
Settings.Global.DEVICE_PROVISIONED, 0);
- mController = new BuildNumberPreferenceController(context, mActivity, mFragment);
+ mController = new BuildNumberPreferenceController(
+ context, mActivity, mFragment, mLifecycle);
+ ReflectionHelpers.setField(mController, "mContext", context);
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
verify(mFactory.metricsFeatureProvider).action(
@@ -118,14 +126,17 @@
@Test
public void handlePrefTreeClick_userHasRestriction_doNothing() {
- when(mUserManager.isAdminUser()).thenReturn(true);
- final Context context = ShadowApplication.getInstance().getApplicationContext();
+ final Context context = spy(RuntimeEnvironment.application);
Settings.Global.putInt(context.getContentResolver(),
Settings.Global.DEVICE_PROVISIONED, 1);
+
+ when(mUserManager.isAdminUser()).thenReturn(true);
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES))
.thenReturn(true);
- mController = new BuildNumberPreferenceController(context, mActivity, mFragment);
+ mController = new BuildNumberPreferenceController(
+ mContext, mActivity, mFragment, mLifecycle);
+ ReflectionHelpers.setField(mController, "mContext", context);
assertThat(mController.handlePreferenceTreeClick(mPreference)).isFalse();
verify(mFactory.metricsFeatureProvider).action(
@@ -161,7 +172,8 @@
public void onActivityResult_confirmPasswordRequestCompleted_enableDevPref() {
final Context context = ShadowApplication.getInstance().getApplicationContext();
- mController = new BuildNumberPreferenceController(context, mActivity, mFragment);
+ mController = new BuildNumberPreferenceController(
+ context, mActivity, mFragment, mLifecycle);
final boolean activityResultHandled = mController.onActivityResult(
BuildNumberPreferenceController.REQUEST_CONFIRM_PASSWORD_FOR_DEV_PREF,
diff --git a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
index 3d6a233..a856e8c 100644
--- a/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/TetherPreferenceControllerTest.java
@@ -51,8 +51,6 @@
@Mock
private BluetoothAdapter mBluetoothAdapter;
@Mock
- private UserManager mUserManager;
- @Mock
private Preference mPreference;
private TetherPreferenceController mController;
@@ -64,7 +62,6 @@
ReflectionHelpers.setField(mController, "mContext", mContext);
ReflectionHelpers.setField(mController, "mConnectivityManager", mConnectivityManager);
ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
- ReflectionHelpers.setField(mController, "mUserManager", mUserManager);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/CastPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/CastPreferenceControllerTest.java
index 5fe4c42..fc9867e 100644
--- a/tests/robotests/src/com/android/settings/notification/CastPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/CastPreferenceControllerTest.java
@@ -22,9 +22,6 @@
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import java.util.ArrayList;
-import java.util.List;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,8 +30,10 @@
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
+import java.util.ArrayList;
+import java.util.List;
+
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@@ -61,8 +60,7 @@
}
@Test
- public void updateNonIndexableKeys_voiceCapable_shouldNotUpdate() {
- when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
+ public void updateNonIndexableKeys_shouldNotUpdate() {
final List<String> keys = new ArrayList<>();
mController.updateNonIndexableKeys(keys);
@@ -70,14 +68,4 @@
assertThat(keys).isEmpty();
}
- @Test
- public void updateNonIndexableKeys_voiceIncapable_shouldUpdate() {
- when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
- final List<String> keys = new ArrayList<>();
-
- mController.updateNonIndexableKeys(keys);
-
- assertThat(keys).isNotEmpty();
- }
-
}
diff --git a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
new file mode 100644
index 0000000..818f8a2
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.search;
+
+
+import android.content.Context;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.core.PreferenceController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class BaseSearchIndexProviderTest {
+
+ private static final String TEST_PREF_KEY = "test_pref_key";
+
+ @Mock
+ private Context mContext;
+ private BaseSearchIndexProvider mIndexProvider;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mIndexProvider = spy(BaseSearchIndexProvider.class);
+ }
+
+ @Test
+ public void getNonIndexableKeys_noPreferenceController_shouldReturnEmptyList() {
+ assertThat(mIndexProvider.getNonIndexableKeys(mContext)).isEqualTo(Collections.EMPTY_LIST);
+ }
+
+ @Test
+ public void getNonIndexableKeys_preferenceIsAvailable_shouldReturnEmptyList() {
+ List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new PreferenceController(mContext) {
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return TEST_PREF_KEY;
+ }
+ });
+ doReturn(controllers).when(mIndexProvider).getPreferenceControllers(mContext);
+
+ assertThat(mIndexProvider.getNonIndexableKeys(mContext)).isEqualTo(Collections.EMPTY_LIST);
+ }
+
+ @Test
+ public void getNonIndexableKeys_preferenceIsNotAvailable_shouldReturnKey() {
+ List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new PreferenceController(mContext) {
+ @Override
+ public boolean isAvailable() {
+ return false;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return TEST_PREF_KEY;
+ }
+ });
+ doReturn(controllers).when(mIndexProvider).getPreferenceControllers(mContext);
+
+ assertThat(mIndexProvider.getNonIndexableKeys(mContext)).contains(TEST_PREF_KEY);
+ }
+}