package com.android.settings;
import android.app.Activity;
+import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
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;
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;
private static final String LOG_TAG = "DeviceInfoSettings";
- private BuildNumberPreferenceController mBuildNumberPreferenceController;
-
@Override
public int getMetricsCategory() {
return MetricsEvent.DEVICEINFO;
@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);
@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 {
}
};
+ 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.
*/
}
@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 */);
}
};
}
@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));
return controllers;
}
- @Override
- protected int getHelpResource() {
- return R.string.help_uri_display;
- }
-
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
}
@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);
}
};
}
@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
.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
}
@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 */);
}
};
}
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;
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
}
@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;
}
+
};
}
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 {
}
@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 =
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;
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;
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() {
mBluetoothPan = null;
mConnectivityManager = null;
mBluetoothAdapter = null;
- mUserManager = null;
}
public TetherPreferenceController(Context context) {
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,
}
@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;
}
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 {
return true;
}
- @Override
- public void updateNonIndexableKeys(List<String> keys) {
- if (!Utils.isVoiceCapable(mContext)) {
- keys.add(KEY_WIFI_DISPLAY);
- }
- }
-
}
@VisibleForTesting
NotificationVolumePreferenceController(Context context,
- VolumeSeekBarPreference.Callback callback, Lifecycle lifecycle, AudioHelper helper) {
+ Callback callback, Lifecycle lifecycle, AudioHelper helper) {
super(context, callback, lifecycle);
mHelper = helper;
}
}
@Override
- public void updateNonIndexableKeys(List<String> keys) {
- if (!mPreference.isApplicable(mContext)) {
- keys.add(mPreference.getKey());
- }
- }
-
- @Override
public void updateState(Preference preference) {
mPreference.update(mContext);
}
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;
private final VolumePreferenceCallback mVolumeCallback = new VolumePreferenceCallback();
private final H mHandler = new H();
- private WorkSoundPreferenceController mWorkSoundController;
private RingtonePreference mRequestPreference;
@Override
@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
}
}
+ 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 =
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();
}
}
}
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;
*/
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() {
}
@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
@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));
}
@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);
}
};
}
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;
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;
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;
@Mock
private UserManager mUserManager;
+ private Lifecycle mLifecycle;
private FakeFeatureFactory mFactory;
private Preference mPreference;
private BuildNumberPreferenceController mController;
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());
@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(
@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(
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,
@Mock
private BluetoothAdapter mBluetoothAdapter;
@Mock
- private UserManager mUserManager;
- @Mock
private Preference mPreference;
private TetherPreferenceController mController;
ReflectionHelpers.setField(mController, "mContext", mContext);
ReflectionHelpers.setField(mController, "mConnectivityManager", mConnectivityManager);
ReflectionHelpers.setField(mController, "mBluetoothAdapter", mBluetoothAdapter);
- ReflectionHelpers.setField(mController, "mUserManager", mUserManager);
}
@Test
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;
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)
}
@Test
- public void updateNonIndexableKeys_voiceCapable_shouldNotUpdate() {
- when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
+ public void updateNonIndexableKeys_shouldNotUpdate() {
final List<String> keys = new ArrayList<>();
mController.updateNonIndexableKeys(keys);
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();
- }
-
}
--- /dev/null
+/*
+ * 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);
+ }
+}