diff --git a/res/xml/dream_fragment_overview.xml b/res/xml/dream_fragment_overview.xml
index 42b0334385b..59da68817bf 100644
--- a/res/xml/dream_fragment_overview.xml
+++ b/res/xml/dream_fragment_overview.xml
@@ -19,23 +19,15 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/screensaver_settings_title">
-
+
-
-
-
-
+ android:fragment="com.android.settings.dream.WhenToDreamPicker"/>
diff --git a/src/com/android/settings/accessibility/RingVibrationIntensityPreferenceController.java b/src/com/android/settings/accessibility/RingVibrationIntensityPreferenceController.java
index 894d8180517..e79ad8b2f02 100644
--- a/src/com/android/settings/accessibility/RingVibrationIntensityPreferenceController.java
+++ b/src/com/android/settings/accessibility/RingVibrationIntensityPreferenceController.java
@@ -16,57 +16,12 @@
package com.android.settings.accessibility;
-import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
-import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
-
import android.content.Context;
-import android.media.AudioManager;
-import android.os.VibrationAttributes;
-import android.os.Vibrator;
-import android.provider.Settings;
/** Preference controller for ringtone vibration intensity */
public class RingVibrationIntensityPreferenceController
extends VibrationIntensityPreferenceController {
- /** General configuration for ringtone vibration intensity settings. */
- public static final class RingVibrationPreferenceConfig extends VibrationPreferenceConfig {
- private final AudioManager mAudioManager;
-
- public RingVibrationPreferenceConfig(Context context) {
- super(context, Settings.System.RING_VIBRATION_INTENSITY,
- VibrationAttributes.USAGE_RINGTONE);
- mAudioManager = context.getSystemService(AudioManager.class);
- }
-
- @Override
- public int readIntensity() {
- final int vibrateWhenRinging = Settings.System.getInt(mContentResolver,
- Settings.System.VIBRATE_WHEN_RINGING, ON);
-
- if ((vibrateWhenRinging == OFF)
- && !mAudioManager.isRampingRingerEnabled()) {
- // VIBRATE_WHEN_RINGING is deprecated but should still be applied if the user has
- // turned it off and has not enabled the ramping ringer (old three-state setting).
- return Vibrator.VIBRATION_INTENSITY_OFF;
- }
-
- return super.readIntensity();
- }
-
- @Override
- public boolean updateIntensity(int intensity) {
- final boolean success = super.updateIntensity(intensity);
-
- // VIBRATE_WHEN_RINGING is deprecated but should still reflect the intensity setting.
- // Ramping ringer is independent of the ring intensity and should not be affected.
- Settings.System.putInt(mContentResolver, Settings.System.VIBRATE_WHEN_RINGING,
- (intensity == Vibrator.VIBRATION_INTENSITY_OFF) ? OFF : ON);
-
- return success;
- }
- }
-
public RingVibrationIntensityPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey, new RingVibrationPreferenceConfig(context));
}
diff --git a/src/com/android/settings/accessibility/RingVibrationPreferenceConfig.java b/src/com/android/settings/accessibility/RingVibrationPreferenceConfig.java
new file mode 100644
index 00000000000..da446d77ac8
--- /dev/null
+++ b/src/com/android/settings/accessibility/RingVibrationPreferenceConfig.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2022 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.accessibility;
+
+import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
+import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
+
+import android.content.Context;
+import android.media.AudioManager;
+import android.os.VibrationAttributes;
+import android.os.Vibrator;
+import android.provider.Settings;
+
+/** General configuration for ringtone vibration intensity settings. */
+public class RingVibrationPreferenceConfig extends VibrationPreferenceConfig {
+ private final AudioManager mAudioManager;
+
+ public RingVibrationPreferenceConfig(Context context) {
+ super(context, Settings.System.RING_VIBRATION_INTENSITY,
+ VibrationAttributes.USAGE_RINGTONE);
+ mAudioManager = context.getSystemService(AudioManager.class);
+ }
+
+ @Override
+ public int readIntensity() {
+ final int vibrateWhenRinging = Settings.System.getInt(mContentResolver,
+ Settings.System.VIBRATE_WHEN_RINGING, ON);
+
+ if ((vibrateWhenRinging == OFF)
+ && !mAudioManager.isRampingRingerEnabled()) {
+ // VIBRATE_WHEN_RINGING is deprecated but should still be applied if the user has
+ // turned it off and has not enabled the ramping ringer (old three-state setting).
+ return Vibrator.VIBRATION_INTENSITY_OFF;
+ }
+
+ return super.readIntensity();
+ }
+
+ @Override
+ public boolean updateIntensity(int intensity) {
+ final boolean success = super.updateIntensity(intensity);
+
+ // VIBRATE_WHEN_RINGING is deprecated but should still reflect the intensity setting.
+ // Ramping ringer is independent of the ring intensity and should not be affected.
+ Settings.System.putInt(mContentResolver, Settings.System.VIBRATE_WHEN_RINGING,
+ (intensity == Vibrator.VIBRATION_INTENSITY_OFF) ? OFF : ON);
+
+ return success;
+ }
+}
diff --git a/src/com/android/settings/accessibility/RingVibrationTogglePreferenceController.java b/src/com/android/settings/accessibility/RingVibrationTogglePreferenceController.java
index e68b6cead7b..efad94625eb 100644
--- a/src/com/android/settings/accessibility/RingVibrationTogglePreferenceController.java
+++ b/src/com/android/settings/accessibility/RingVibrationTogglePreferenceController.java
@@ -18,8 +18,6 @@ package com.android.settings.accessibility;
import android.content.Context;
-import com.android.settings.accessibility.RingVibrationIntensityPreferenceController.RingVibrationPreferenceConfig;
-
/** Preference controller for ringtone vibration with only a toggle for on/off states. */
public class RingVibrationTogglePreferenceController extends VibrationTogglePreferenceController {
diff --git a/src/com/android/settings/accessibility/TextReadingPreviewPreference.java b/src/com/android/settings/accessibility/TextReadingPreviewPreference.java
new file mode 100644
index 00000000000..1b9cc4b5171
--- /dev/null
+++ b/src/com/android/settings/accessibility/TextReadingPreviewPreference.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2022 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.accessibility;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceViewHolder;
+import androidx.viewpager.widget.ViewPager;
+
+import com.android.internal.util.Preconditions;
+import com.android.settings.R;
+import com.android.settings.display.PreviewPagerAdapter;
+import com.android.settings.widget.DotsPageIndicator;
+
+/**
+ * A {@link Preference} that could show the preview related to the text and reading options.
+ */
+final class TextReadingPreviewPreference extends Preference {
+ private int mCurrentItem;
+ private PreviewPagerAdapter mPreviewAdapter;
+
+ TextReadingPreviewPreference(Context context) {
+ super(context);
+ init();
+ }
+
+ TextReadingPreviewPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init();
+ }
+
+ TextReadingPreviewPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init();
+ }
+
+ TextReadingPreviewPreference(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ init();
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+
+ final ViewPager viewPager = (ViewPager) holder.findViewById(R.id.preview_pager);
+ final DotsPageIndicator pageIndicator =
+ (DotsPageIndicator) holder.findViewById(R.id.page_indicator);
+ updateAdapterIfNeeded(viewPager, pageIndicator, mPreviewAdapter);
+ updatePagerAndIndicator(viewPager, pageIndicator);
+ }
+
+ void setPreviewAdapter(PreviewPagerAdapter previewAdapter) {
+ if (previewAdapter != mPreviewAdapter) {
+ mPreviewAdapter = previewAdapter;
+ notifyChanged();
+ }
+ }
+
+ void setCurrentItem(int currentItem) {
+ Preconditions.checkNotNull(mPreviewAdapter,
+ "Preview adapter is null, you should init the preview adapter first");
+
+ if (currentItem != mCurrentItem) {
+ mCurrentItem = currentItem;
+ notifyChanged();
+ }
+ }
+
+ int getCurrentItem() {
+ return mCurrentItem;
+ }
+
+ private void updateAdapterIfNeeded(ViewPager viewPager, DotsPageIndicator pageIndicator,
+ PreviewPagerAdapter previewAdapter) {
+ if (viewPager.getAdapter() == previewAdapter) {
+ return;
+ }
+
+ viewPager.setAdapter(previewAdapter);
+
+ if (previewAdapter != null) {
+ pageIndicator.setViewPager(viewPager);
+ } else {
+ mCurrentItem = 0;
+ }
+ }
+
+ private void updatePagerAndIndicator(ViewPager viewPager, DotsPageIndicator pageIndicator) {
+ if (viewPager.getAdapter() == null) {
+ return;
+ }
+
+ if (viewPager.getCurrentItem() != mCurrentItem) {
+ viewPager.setCurrentItem(mCurrentItem);
+ }
+
+ pageIndicator.setVisibility(
+ viewPager.getAdapter().getCount() > 1 ? View.VISIBLE : View.GONE);
+ }
+
+ private void init() {
+ setLayoutResource(R.layout.accessibility_text_reading_preview);
+ }
+}
diff --git a/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java b/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
index ef15f06dbc9..b3e8168af87 100644
--- a/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
+++ b/src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java
@@ -19,6 +19,7 @@ package com.android.settings.accessibility;
import android.content.Context;
import android.os.Vibrator;
+import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
@@ -70,13 +71,22 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe
super.displayPreference(screen);
final SeekBarPreference preference = screen.findPreference(getPreferenceKey());
mSettingsContentObserver.onDisplayPreference(this, preference);
- // TODO: remove this and replace with a different way to play the haptic preview without
- // relying on the setting being propagated to the service.
+ preference.setEnabled(mPreferenceConfig.isPreferenceEnabled());
+ // TODO: remove setContinuousUpdates and replace with a different way to play the haptic
+ // preview without relying on the setting being propagated to the service.
preference.setContinuousUpdates(true);
preference.setMin(getMin());
preference.setMax(getMax());
}
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ if (preference != null) {
+ preference.setEnabled(mPreferenceConfig.isPreferenceEnabled());
+ }
+ }
+
@Override
public int getMin() {
return Vibrator.VIBRATION_INTENSITY_OFF;
@@ -89,12 +99,19 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe
@Override
public int getSliderPosition() {
+ if (!mPreferenceConfig.isPreferenceEnabled()) {
+ return getMin();
+ }
final int position = mPreferenceConfig.readIntensity();
return Math.min(position, getMax());
}
@Override
public boolean setSliderPosition(int position) {
+ if (!mPreferenceConfig.isPreferenceEnabled()) {
+ // Ignore slider updates when the preference is disabled.
+ return false;
+ }
final int intensity = calculateVibrationIntensity(position);
final boolean success = mPreferenceConfig.updateIntensity(intensity);
diff --git a/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java b/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java
new file mode 100644
index 00000000000..726bbc1f054
--- /dev/null
+++ b/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceController.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2022 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.accessibility;
+
+import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
+import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
+
+import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+import android.provider.Settings;
+
+import com.android.settings.R;
+import com.android.settings.widget.SettingsMainSwitchPreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
+/**
+ * Preference controller for the main switch setting for vibration and haptics screen.
+ *
+ * This preference is controlled by the setting key{@link Settings.System#VIBRATE_ON}, and it
+ * will disable the entire settings screen once the settings is turned OFF. All device haptics will
+ * be disabled by this setting, except the flagged alerts and accessibility touch feedback.
+ */
+public class VibrationMainSwitchPreferenceController extends SettingsMainSwitchPreferenceController
+ implements LifecycleObserver, OnStart, OnStop {
+
+ private final ContentObserver mSettingObserver;
+
+ public VibrationMainSwitchPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mSettingObserver = new ContentObserver(new Handler(/* async= */ true)) {
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ updateState(mSwitchPreference);
+ }
+ };
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public void onStart() {
+ mContext.getContentResolver().registerContentObserver(
+ Settings.System.getUriFor(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY),
+ /* notifyForDescendants= */ false,
+ mSettingObserver);
+ }
+
+ @Override
+ public void onStop() {
+ mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return VibrationPreferenceConfig.isMainVibrationSwitchEnabled(
+ mContext.getContentResolver());
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ return Settings.System.putInt(mContext.getContentResolver(),
+ VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY,
+ isChecked ? ON : OFF);
+ }
+
+ @Override
+ public int getSliceHighlightMenuRes() {
+ return R.string.menu_key_accessibility;
+ }
+}
diff --git a/src/com/android/settings/accessibility/VibrationPreferenceConfig.java b/src/com/android/settings/accessibility/VibrationPreferenceConfig.java
index aa59554b64a..1b0b1635456 100644
--- a/src/com/android/settings/accessibility/VibrationPreferenceConfig.java
+++ b/src/com/android/settings/accessibility/VibrationPreferenceConfig.java
@@ -16,6 +16,8 @@
package com.android.settings.accessibility;
+import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
+
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -36,12 +38,23 @@ import com.android.settingslib.core.AbstractPreferenceController;
*/
public abstract class VibrationPreferenceConfig {
+ /**
+ * SettingsProvider key for the main "Vibration & haptics" toggle preference, that can disable
+ * all device vibrations.
+ */
+ public static final String MAIN_SWITCH_SETTING_KEY = Settings.System.VIBRATE_ON;
+
protected final ContentResolver mContentResolver;
private final Vibrator mVibrator;
private final String mSettingKey;
private final int mDefaultIntensity;
private final VibrationAttributes mVibrationAttributes;
+ /** Returns true if the user setting for enabling device vibrations is enabled. */
+ public static boolean isMainVibrationSwitchEnabled(ContentResolver contentResolver) {
+ return Settings.System.getInt(contentResolver, MAIN_SWITCH_SETTING_KEY, ON) == ON;
+ }
+
public VibrationPreferenceConfig(Context context, String settingKey, int vibrationUsage) {
mContentResolver = context.getContentResolver();
mVibrator = context.getSystemService(Vibrator.class);
@@ -52,11 +65,16 @@ public abstract class VibrationPreferenceConfig {
.build();
}
- /** Return the setting key for this setting preference. */
+ /** Returns the setting key for this setting preference. */
public String getSettingKey() {
return mSettingKey;
}
+ /** Returns true if this setting preference is enabled for user update. */
+ public boolean isPreferenceEnabled() {
+ return isMainVibrationSwitchEnabled(mContentResolver);
+ }
+
/** Returns the default intensity to be displayed when the setting value is not set. */
public int getDefaultIntensity() {
return mDefaultIntensity;
@@ -80,6 +98,9 @@ public abstract class VibrationPreferenceConfig {
/** {@link ContentObserver} for a setting described by a {@link VibrationPreferenceConfig}. */
public static final class SettingObserver extends ContentObserver {
+ private static final Uri MAIN_SWITCH_SETTING_URI =
+ Settings.System.getUriFor(MAIN_SWITCH_SETTING_KEY);
+
private final Uri mUri;
private AbstractPreferenceController mPreferenceController;
private Preference mPreference;
@@ -92,7 +113,11 @@ public abstract class VibrationPreferenceConfig {
@Override
public void onChange(boolean selfChange, Uri uri) {
- if (mUri.equals(uri) && mPreferenceController != null && mPreference != null) {
+ if (mPreferenceController == null || mPreference == null) {
+ // onDisplayPreference not triggered yet, nothing to update.
+ return;
+ }
+ if (mUri.equals(uri) || MAIN_SWITCH_SETTING_URI.equals(uri)) {
mPreferenceController.updateState(mPreference);
}
}
@@ -103,6 +128,8 @@ public abstract class VibrationPreferenceConfig {
*/
public void register(ContentResolver contentResolver) {
contentResolver.registerContentObserver(mUri, /* notifyForDescendants= */ false, this);
+ contentResolver.registerContentObserver(MAIN_SWITCH_SETTING_URI,
+ /* notifyForDescendants= */ false, this);
}
/**
diff --git a/src/com/android/settings/accessibility/VibrationRampingRingerTogglePreferenceController.java b/src/com/android/settings/accessibility/VibrationRampingRingerTogglePreferenceController.java
index 21a5e36d25f..37a0257cb20 100644
--- a/src/com/android/settings/accessibility/VibrationRampingRingerTogglePreferenceController.java
+++ b/src/com/android/settings/accessibility/VibrationRampingRingerTogglePreferenceController.java
@@ -21,7 +21,6 @@ import android.database.ContentObserver;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Handler;
-import android.os.VibrationAttributes;
import android.os.Vibrator;
import android.provider.DeviceConfig;
import android.provider.Settings;
@@ -57,8 +56,9 @@ public class VibrationRampingRingerTogglePreferenceController
private final DeviceConfigProvider mDeviceConfigProvider;
private final ContentObserver mSettingObserver;
- private final Vibrator mVibrator;
private final AudioManager mAudioManager;
+ private final VibrationPreferenceConfig mRingVibrationPreferenceConfig;
+ private final VibrationPreferenceConfig.SettingObserver mRingSettingObserver;
private Preference mPreference;
@@ -70,8 +70,10 @@ public class VibrationRampingRingerTogglePreferenceController
String preferenceKey, DeviceConfigProvider deviceConfigProvider) {
super(context, preferenceKey);
mDeviceConfigProvider = deviceConfigProvider;
- mVibrator = context.getSystemService(Vibrator.class);
mAudioManager = context.getSystemService(AudioManager.class);
+ mRingVibrationPreferenceConfig = new RingVibrationPreferenceConfig(context);
+ mRingSettingObserver = new VibrationPreferenceConfig.SettingObserver(
+ mRingVibrationPreferenceConfig);
mSettingObserver = new ContentObserver(new Handler(/* async= */ true)) {
@Override
public void onChange(boolean selfChange, Uri uri) {
@@ -91,18 +93,16 @@ public class VibrationRampingRingerTogglePreferenceController
@Override
public void onStart() {
+ mRingSettingObserver.register(mContext.getContentResolver());
mContext.getContentResolver().registerContentObserver(
Settings.System.getUriFor(Settings.System.APPLY_RAMPING_RINGER),
/* notifyForDescendants= */ false,
mSettingObserver);
- mContext.getContentResolver().registerContentObserver(
- Settings.System.getUriFor(Settings.System.RING_VIBRATION_INTENSITY),
- /* notifyForDescendants= */ false,
- mSettingObserver);
}
@Override
public void onStop() {
+ mRingSettingObserver.unregister(mContext.getContentResolver());
mContext.getContentResolver().unregisterContentObserver(mSettingObserver);
}
@@ -110,6 +110,7 @@ public class VibrationRampingRingerTogglePreferenceController
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
+ mRingSettingObserver.onDisplayPreference(this, mPreference);
mPreference.setEnabled(isRingVibrationEnabled());
}
@@ -141,9 +142,8 @@ public class VibrationRampingRingerTogglePreferenceController
}
private boolean isRingVibrationEnabled() {
- final int ringIntensity = Settings.System.getInt(mContext.getContentResolver(),
- Settings.System.RING_VIBRATION_INTENSITY,
- mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_RINGTONE));
- return ringIntensity != Vibrator.VIBRATION_INTENSITY_OFF;
+ return mRingVibrationPreferenceConfig.isPreferenceEnabled()
+ && (mRingVibrationPreferenceConfig.readIntensity()
+ != Vibrator.VIBRATION_INTENSITY_OFF);
}
}
diff --git a/src/com/android/settings/accessibility/VibrationTogglePreferenceController.java b/src/com/android/settings/accessibility/VibrationTogglePreferenceController.java
index 5278b662b36..8f158cc04b5 100644
--- a/src/com/android/settings/accessibility/VibrationTogglePreferenceController.java
+++ b/src/com/android/settings/accessibility/VibrationTogglePreferenceController.java
@@ -58,16 +58,29 @@ public abstract class VibrationTogglePreferenceController extends TogglePreferen
super.displayPreference(screen);
final Preference preference = screen.findPreference(getPreferenceKey());
mSettingsContentObserver.onDisplayPreference(this, preference);
+ preference.setEnabled(mPreferenceConfig.isPreferenceEnabled());
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ if (preference != null) {
+ preference.setEnabled(mPreferenceConfig.isPreferenceEnabled());
+ }
}
@Override
public boolean isChecked() {
- final int position = mPreferenceConfig.readIntensity();
- return position != Vibrator.VIBRATION_INTENSITY_OFF;
+ return mPreferenceConfig.isPreferenceEnabled()
+ && (mPreferenceConfig.readIntensity() != Vibrator.VIBRATION_INTENSITY_OFF);
}
@Override
public boolean setChecked(boolean isChecked) {
+ if (!mPreferenceConfig.isPreferenceEnabled()) {
+ // Ignore toggle updates when the preference is disabled.
+ return false;
+ }
final int newIntensity = isChecked
? mPreferenceConfig.getDefaultIntensity()
: Vibrator.VIBRATION_INTENSITY_OFF;
diff --git a/src/com/android/settings/biometrics/BiometricUtils.java b/src/com/android/settings/biometrics/BiometricUtils.java
index 5ee788095b4..febe3c6a93e 100644
--- a/src/com/android/settings/biometrics/BiometricUtils.java
+++ b/src/com/android/settings/biometrics/BiometricUtils.java
@@ -289,4 +289,14 @@ public class BiometricUtils {
}
return false;
}
+
+ /**
+ * Returns {@code true} if the screen is going into a landscape mode and the angle is equal to
+ * 90.
+ * @param context Context that we use to get the display this context is associated with
+ * @return True if the angle of the rotation is equal to 90.
+ */
+ public static boolean isLandscape(@NonNull Context context) {
+ return context.getDisplay().getRotation() == Surface.ROTATION_90;
+ }
}
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
index c2bcee33428..d42e8f1c3aa 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
@@ -19,11 +19,13 @@ package com.android.settings.biometrics.fingerprint;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.annotation.IntDef;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.res.Configuration;
import android.graphics.drawable.Animatable2;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
@@ -54,7 +56,9 @@ import com.android.settings.biometrics.BiometricEnrollSidecar;
import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.biometrics.BiometricsEnrollEnrolling;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settingslib.display.DisplayDensityUtils;
+import com.airbnb.lottie.LottieAnimationView;
import com.google.android.setupcompat.template.FooterBarMixin;
import com.google.android.setupcompat.template.FooterButton;
import com.google.android.setupcompat.util.WizardManagerHelper;
@@ -126,6 +130,10 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
private boolean mIsSetupWizard;
private AccessibilityManager mAccessibilityManager;
private boolean mIsAccessibilityEnabled;
+ private LottieAnimationView mIllustrationLottie;
+ private boolean mHaveShownUdfpsTipLottie;
+ private boolean mHaveShownUdfpsSideLottie;
+ private boolean mShouldShowLottie;
private OrientationEventListener mOrientationEventListener;
private int mPreviousRotation = 0;
@@ -163,6 +171,20 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
setHeaderText(R.string.security_settings_fingerprint_enroll_repeat_title);
}
+ DisplayDensityUtils displayDensity =
+ new DisplayDensityUtils(getApplicationContext());
+ int currentDensityIndex = displayDensity.getCurrentIndex();
+ final int currentDensity = displayDensity.getValues()[currentDensityIndex];
+ final int defaultDensity = displayDensity.getDefaultDensity();
+ mShouldShowLottie = defaultDensity == currentDensity;
+ // Only show the lottie if the current display density is the default density.
+ // Otherwise, the lottie will overlap with the settings header text.
+ boolean isLandscape = BiometricUtils.isReverseLandscape(getApplicationContext())
+ || BiometricUtils.isLandscape(getApplicationContext());
+
+ updateOrientation((isLandscape
+ ? Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT));
+
mErrorText = findViewById(R.id.error_text);
mProgressBar = findViewById(R.id.fingerprint_progress_bar);
mVibrator = getSystemService(Vibrator.class);
@@ -339,20 +361,34 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
case STAGE_FINGERTIP:
setHeaderText(R.string.security_settings_udfps_enroll_fingertip_title);
- if (isStageHalfCompleted()) {
- setDescriptionText(R.string.security_settings_fingerprint_enroll_repeat_title);
- } else {
+ if (!mHaveShownUdfpsTipLottie && mIllustrationLottie != null) {
+ mHaveShownUdfpsTipLottie = true;
setDescriptionText("");
+ mIllustrationLottie.setAnimation(R.raw.udfps_tip_hint_lottie);
+ mIllustrationLottie.setVisibility(View.VISIBLE);
+ mIllustrationLottie.playAnimation();
+ mIllustrationLottie.setContentDescription(
+ getString(R.string.security_settings_udfps_tip_fingerprint_help));
}
break;
case STAGE_EDGES:
setHeaderText(R.string.security_settings_udfps_enroll_edge_title);
- if (isStageHalfCompleted()) {
- setDescriptionText(
- R.string.security_settings_fingerprint_enroll_repeat_message);
- } else {
- setDescriptionText(R.string.security_settings_udfps_enroll_edge_message);
+ if (!mHaveShownUdfpsSideLottie && mIllustrationLottie != null) {
+ mHaveShownUdfpsSideLottie = true;
+ setDescriptionText("");
+ mIllustrationLottie.setAnimation(R.raw.udfps_edge_hint_lottie);
+ mIllustrationLottie.setVisibility(View.VISIBLE);
+ mIllustrationLottie.playAnimation();
+ mIllustrationLottie.setContentDescription(
+ getString(R.string.security_settings_udfps_side_fingerprint_help));
+ } else if (mIllustrationLottie == null) {
+ if (isStageHalfCompleted()) {
+ setDescriptionText(
+ R.string.security_settings_fingerprint_enroll_repeat_message);
+ } else {
+ setDescriptionText(R.string.security_settings_udfps_enroll_edge_message);
+ }
}
break;
@@ -634,6 +670,41 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling {
return SettingsEnums.FINGERPRINT_ENROLLING;
}
+ private void updateOrientation(int orientation) {
+ switch(orientation) {
+ case Configuration.ORIENTATION_LANDSCAPE: {
+ mIllustrationLottie = null;
+ break;
+ }
+ case Configuration.ORIENTATION_PORTRAIT: {
+ if (mShouldShowLottie) {
+ mIllustrationLottie = findViewById(R.id.illustration_lottie);
+ }
+ break;
+ }
+ default:
+ Log.e(TAG, "Error unhandled configuration change");
+ break;
+ }
+ }
+
+ @Override
+ public void onConfigurationChanged(@NonNull Configuration newConfig) {
+ switch(newConfig.orientation) {
+ case Configuration.ORIENTATION_LANDSCAPE: {
+ updateOrientation(Configuration.ORIENTATION_LANDSCAPE);
+ break;
+ }
+ case Configuration.ORIENTATION_PORTRAIT: {
+ updateOrientation(Configuration.ORIENTATION_PORTRAIT);
+ break;
+ }
+ default:
+ Log.e(TAG, "Error unhandled configuration change");
+ break;
+ }
+ }
+
public static class IconTouchDialog extends InstrumentedDialogFragment {
@Override
diff --git a/src/com/android/settings/dream/CurrentDreamPicker.java b/src/com/android/settings/dream/CurrentDreamPicker.java
deleted file mode 100644
index 3134e79ffdb..00000000000
--- a/src/com/android/settings/dream/CurrentDreamPicker.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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.dream;
-
-import android.app.settings.SettingsEnums;
-import android.content.ComponentName;
-import android.content.Context;
-import android.graphics.drawable.Drawable;
-
-import com.android.settings.R;
-import com.android.settings.widget.RadioButtonPickerFragment;
-import com.android.settingslib.dream.DreamBackend;
-import com.android.settingslib.dream.DreamBackend.DreamInfo;
-import com.android.settingslib.widget.CandidateInfo;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-public final class CurrentDreamPicker extends RadioButtonPickerFragment {
-
- private DreamBackend mBackend;
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
-
- mBackend = DreamBackend.getInstance(context);
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.current_dream_settings;
- }
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.DREAM;
- }
-
- @Override
- protected boolean setDefaultKey(String key) {
- Map componentNameMap = getDreamComponentsMap();
- if (componentNameMap.get(key) != null) {
- mBackend.setActiveDream(componentNameMap.get(key));
- return true;
- }
- return false;
- }
-
- @Override
- protected String getDefaultKey() {
- return mBackend.getActiveDream().flattenToString();
- }
-
- @Override
- protected List extends CandidateInfo> getCandidates() {
- final List candidates;
- candidates = mBackend.getDreamInfos().stream()
- .map(DreamCandidateInfo::new)
- .collect(Collectors.toList());
-
- return candidates;
- }
-
- @Override
- protected void onSelectionPerformed(boolean success) {
- super.onSelectionPerformed(success);
-
- getActivity().finish();
- }
-
- private Map getDreamComponentsMap() {
- Map comps = new HashMap<>();
- mBackend.getDreamInfos()
- .forEach((info) ->
- comps.put(info.componentName.flattenToString(), info.componentName));
-
- return comps;
- }
-
- private static final class DreamCandidateInfo extends CandidateInfo {
- private final CharSequence name;
- private final Drawable icon;
- private final String key;
-
- DreamCandidateInfo(DreamInfo info) {
- super(true);
-
- name = info.caption;
- icon = info.icon;
- key = info.componentName.flattenToString();
- }
-
- @Override
- public CharSequence loadLabel() {
- return name;
- }
-
- @Override
- public Drawable loadIcon() {
- return icon;
- }
-
- @Override
- public String getKey() {
- return key;
- }
- }
-}
diff --git a/src/com/android/settings/dream/CurrentDreamPreferenceController.java b/src/com/android/settings/dream/CurrentDreamPreferenceController.java
deleted file mode 100644
index c267921fd2a..00000000000
--- a/src/com/android/settings/dream/CurrentDreamPreferenceController.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.dream;
-
-import android.content.Context;
-
-import androidx.preference.Preference;
-
-import com.android.settings.Utils;
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.widget.GearPreference;
-import com.android.settingslib.RestrictedPreference;
-import com.android.settingslib.dream.DreamBackend;
-import com.android.settingslib.dream.DreamBackend.DreamInfo;
-
-import java.util.Optional;
-
-public class CurrentDreamPreferenceController extends BasePreferenceController {
-
- private final DreamBackend mBackend;
-
- public CurrentDreamPreferenceController(Context context, String key) {
- super(context, key);
- mBackend = DreamBackend.getInstance(context);
- }
-
- @Override
- public int getAvailabilityStatus() {
- return mBackend.getDreamInfos().size() > 0 ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- setGearClickListenerForPreference(preference);
- setActiveDreamIcon(preference);
- }
-
- @Override
- public CharSequence getSummary() {
- return mBackend.getActiveDreamName();
- }
-
- private void setGearClickListenerForPreference(Preference preference) {
- if (!(preference instanceof GearPreference)) {
- return;
- }
-
- final GearPreference gearPreference = (GearPreference) preference;
- final Optional info = getActiveDreamInfo();
- if (!info.isPresent() || info.get().settingsComponentName == null) {
- gearPreference.setOnGearClickListener(null);
- return;
- }
- gearPreference.setOnGearClickListener(gearPref -> launchScreenSaverSettings());
- }
-
- private void launchScreenSaverSettings() {
- final Optional info = getActiveDreamInfo();
- if (!info.isPresent()) return;
- mBackend.launchSettings(mContext, info.get());
- }
-
- private Optional getActiveDreamInfo() {
- return mBackend.getDreamInfos()
- .stream()
- .filter((info) -> info.isActive)
- .findFirst();
- }
-
- private void setActiveDreamIcon(Preference preference) {
- if (!(preference instanceof GearPreference)) {
- return;
- }
- final GearPreference gearPref = (GearPreference) preference;
- gearPref.setIconSize(RestrictedPreference.ICON_SIZE_SMALL);
- gearPref.setIcon(Utils.getSafeIcon(mBackend.getActiveIcon()));
- }
-}
diff --git a/src/com/android/settings/dream/DreamPickerAdapter.java b/src/com/android/settings/dream/DreamPickerAdapter.java
new file mode 100644
index 00000000000..50aaee216e3
--- /dev/null
+++ b/src/com/android/settings/dream/DreamPickerAdapter.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2022 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.dream;
+
+
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.android.settings.R;
+import com.android.settingslib.dream.DreamBackend.DreamInfo;
+
+import java.util.List;
+
+/**
+ * RecyclerView adapter which displays list of available dreams for the user to select.
+ */
+class DreamPickerAdapter extends RecyclerView.Adapter {
+ private final List mDreamInfoList;
+ private final OnItemClickListener mItemClickListener;
+ private final OnItemClickListener mOnDreamSelected = new OnItemClickListener() {
+ @Override
+ public void onItemClicked(DreamInfo dreamInfo) {
+ if (mItemClickListener != null) {
+ mItemClickListener.onItemClicked(dreamInfo);
+ }
+ mDreamInfoList.forEach(dream -> {
+ if (dream != null) {
+ dream.isActive = false;
+ }
+ });
+ dreamInfo.isActive = true;
+ notifyDataSetChanged();
+ }
+ };
+ private final OnItemClickListener mOnCustomizeListener;
+
+ interface OnItemClickListener {
+ void onItemClicked(DreamInfo dreamInfo);
+ }
+
+ /**
+ * View holder for each Dream service.
+ */
+ private static class DreamViewHolder extends RecyclerView.ViewHolder {
+ private final ImageView mIconView;
+ private final TextView mTitleView;
+ private final TextView mSummaryView;
+ private final ImageView mPreviewView;
+ private final Button mCustomizeButton;
+
+ DreamViewHolder(View view) {
+ super(view);
+ mPreviewView = view.findViewById(R.id.preview);
+ mIconView = view.findViewById(R.id.icon);
+ mTitleView = view.findViewById(R.id.title_text);
+ mSummaryView = view.findViewById(R.id.summary_text);
+ mCustomizeButton = view.findViewById(R.id.customize_button);
+ }
+
+ /**
+ * Bind the dream service view at the given position. Add details on the
+ * dream's icon, name and description.
+ */
+ public void bindView(DreamInfo dreamInfo, OnItemClickListener clickListener,
+ OnItemClickListener customizeListener) {
+ mIconView.setImageDrawable(dreamInfo.icon);
+ mTitleView.setText(dreamInfo.caption);
+ mPreviewView.setImageDrawable(dreamInfo.previewImage);
+ mSummaryView.setText(dreamInfo.description);
+ itemView.setActivated(dreamInfo.isActive);
+ if (dreamInfo.isActive && dreamInfo.settingsComponentName != null) {
+ mCustomizeButton.setVisibility(View.VISIBLE);
+ mCustomizeButton.setOnClickListener(
+ v -> customizeListener.onItemClicked(dreamInfo));
+ } else {
+ mCustomizeButton.setVisibility(View.GONE);
+ }
+
+ itemView.setOnClickListener(v -> clickListener.onItemClicked(dreamInfo));
+ }
+ }
+
+ DreamPickerAdapter(List dreamInfos, OnItemClickListener clickListener,
+ OnItemClickListener onCustomizeListener) {
+ mDreamInfoList = dreamInfos;
+ mItemClickListener = clickListener;
+ mOnCustomizeListener = onCustomizeListener;
+ }
+
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
+ View view = LayoutInflater.from(viewGroup.getContext())
+ .inflate(R.layout.dream_preference_layout, viewGroup, false);
+ return new DreamViewHolder(view);
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
+ ((DreamViewHolder) viewHolder).bindView(mDreamInfoList.get(i), mOnDreamSelected,
+ mOnCustomizeListener);
+ }
+
+ @Override
+ public int getItemCount() {
+ return mDreamInfoList.size();
+ }
+}
diff --git a/src/com/android/settings/dream/DreamPickerController.java b/src/com/android/settings/dream/DreamPickerController.java
new file mode 100644
index 00000000000..15cd75c8f6f
--- /dev/null
+++ b/src/com/android/settings/dream/DreamPickerController.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2022 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.dream;
+
+import android.content.Context;
+import android.widget.Button;
+
+import androidx.annotation.Nullable;
+import androidx.preference.Preference;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.dream.DreamPickerAdapter.OnItemClickListener;
+import com.android.settingslib.dream.DreamBackend;
+import com.android.settingslib.widget.LayoutPreference;
+
+import java.util.List;
+
+/**
+ * Controller for the dream picker where the user can select a screensaver.
+ */
+public class DreamPickerController extends BasePreferenceController {
+ public static final String KEY = "dream_picker";
+
+ private final DreamBackend mBackend;
+ private final List mDreamInfos;
+ private Button mPreviewButton;
+ @Nullable
+ private DreamBackend.DreamInfo mActiveDream;
+
+ private final OnItemClickListener mItemClickListener =
+ new OnItemClickListener() {
+ @Override
+ public void onItemClicked(DreamBackend.DreamInfo dreamInfo) {
+ mActiveDream = dreamInfo;
+ mBackend.setActiveDream(
+ mActiveDream == null ? null : mActiveDream.componentName);
+ updatePreviewButtonState();
+ }
+ };
+
+ private final OnItemClickListener mCustomizeListener = new OnItemClickListener() {
+ @Override
+ public void onItemClicked(DreamBackend.DreamInfo dreamInfo) {
+ mBackend.launchSettings(mContext, dreamInfo);
+ }
+ };
+
+ public DreamPickerController(Context context, String preferenceKey) {
+ this(context, preferenceKey, DreamBackend.getInstance(context));
+ }
+
+ public DreamPickerController(Context context, String preferenceKey, DreamBackend backend) {
+ super(context, preferenceKey);
+ mBackend = backend;
+ mDreamInfos = mBackend.getDreamInfos();
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mDreamInfos.size() > 0 ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+
+ mActiveDream = getActiveDreamInfo();
+
+ final DreamPickerAdapter adapter =
+ new DreamPickerAdapter(mDreamInfos, mItemClickListener, mCustomizeListener);
+
+ final RecyclerView recyclerView =
+ ((LayoutPreference) preference).findViewById(R.id.dream_list);
+ recyclerView.setLayoutManager(new AutoFitGridLayoutManager(mContext));
+ recyclerView.setAdapter(adapter);
+
+ mPreviewButton = ((LayoutPreference) preference).findViewById(R.id.preview_button);
+ mPreviewButton.setOnClickListener(v -> mBackend.preview(mActiveDream));
+ updatePreviewButtonState();
+ }
+
+ private void updatePreviewButtonState() {
+ final boolean hasDream = mActiveDream != null;
+ mPreviewButton.setClickable(hasDream);
+ mPreviewButton.setEnabled(hasDream);
+ }
+
+ @Nullable
+ private DreamBackend.DreamInfo getActiveDreamInfo() {
+ return mDreamInfos
+ .stream()
+ .filter(d -> d.isActive)
+ .findFirst()
+ .orElse(null);
+ }
+
+ /** Grid layout manager that calculates the number of columns for the screen size. */
+ private static final class AutoFitGridLayoutManager extends GridLayoutManager {
+ private final float mColumnWidth;
+
+ AutoFitGridLayoutManager(Context context) {
+ super(context, /* spanCount= */ 1);
+ this.mColumnWidth = context
+ .getResources()
+ .getDimensionPixelSize(R.dimen.dream_item_min_column_width);
+ }
+
+ @Override
+ public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
+ final int totalSpace = getWidth() - getPaddingRight() - getPaddingLeft();
+ final int spanCount = Math.max(1, (int) (totalSpace / mColumnWidth));
+ setSpanCount(spanCount);
+ super.onLayoutChildren(recycler, state);
+ }
+ }
+}
diff --git a/src/com/android/settings/dream/StartNowPreferenceController.java b/src/com/android/settings/dream/StartNowPreferenceController.java
deleted file mode 100644
index f270496d00f..00000000000
--- a/src/com/android/settings/dream/StartNowPreferenceController.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.dream;
-
-import android.content.Context;
-import android.widget.Button;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.overlay.FeatureFactory;
-import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
-import com.android.settingslib.dream.DreamBackend;
-import com.android.settingslib.widget.LayoutPreference;
-
-/**
- * Controller that used to enable screen saver
- */
-public class StartNowPreferenceController extends BasePreferenceController {
-
- private final DreamBackend mBackend;
- private final MetricsFeatureProvider mMetricsFeatureProvider;
-
- public StartNowPreferenceController(Context context, String preferenceKey) {
- super(context, preferenceKey);
- mBackend = DreamBackend.getInstance(context);
- mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
- }
-
- @Override
- public int getAvailabilityStatus() {
- return AVAILABLE;
- }
-
- @Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
-
- final LayoutPreference pref = screen.findPreference(getPreferenceKey());
- final Button startButton = pref.findViewById(R.id.dream_start_now_button);
- startButton.setOnClickListener(v -> {
- mMetricsFeatureProvider.logClickedPreference(pref,
- pref.getExtras().getInt(DashboardFragment.CATEGORY));
- mBackend.startDreaming();
- });
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
- final Button startButton = ((LayoutPreference) preference)
- .findViewById(R.id.dream_start_now_button);
- startButton.setEnabled(mBackend.getWhenToDreamSetting() != DreamBackend.NEVER);
- }
-}
diff --git a/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java b/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java
index 0d7d531814b..bcc55e3a2db 100644
--- a/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java
+++ b/src/com/android/settings/localepicker/LocalePickerWithRegionActivity.java
@@ -17,7 +17,6 @@
package com.android.settings.localepicker;
import android.app.FragmentTransaction;
-import android.app.ListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
@@ -48,14 +47,6 @@ public class LocalePickerWithRegionActivity extends SettingsBaseActivity
.commit();
}
- @Override
- protected void onStart() {
- super.onStart();
- final ListFragment listFragment =
- (ListFragment) getFragmentManager().findFragmentById(R.id.content_frame);
- listFragment.getListView().setNestedScrollingEnabled(true);
- }
-
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
diff --git a/src/com/android/settings/network/VpnPreferenceController.java b/src/com/android/settings/network/VpnPreferenceController.java
index a1e72b0eaad..be0780948df 100644
--- a/src/com/android/settings/network/VpnPreferenceController.java
+++ b/src/com/android/settings/network/VpnPreferenceController.java
@@ -30,7 +30,6 @@ import android.provider.SettingsSlicesContract;
import android.security.Credentials;
import android.security.LegacyVpnProfileStore;
import android.util.Log;
-import android.util.SparseArray;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -140,6 +139,7 @@ public class VpnPreferenceController extends AbstractPreferenceController
}
VpnConfig vpn = vpnManager.getVpnConfig(uid);
if ((vpn != null) && vpn.legacy) {
+ // Copied from SystemUI::SecurityControllerImpl
// Legacy VPNs should do nothing if the network is disconnected. Third-party
// VPN warnings need to continue as traffic can still go to the app.
final LegacyVpnInfo legacyVpn = vpnManager.getLegacyVpnInfo(uid);
@@ -158,34 +158,19 @@ public class VpnPreferenceController extends AbstractPreferenceController
}
protected int getNumberOfNonLegacyVpn(UserManager userManager, VpnManager vpnManager) {
- // Copied from SystemUI::SecurityControllerImpl
- SparseArray vpns = new SparseArray<>();
- final List users = userManager.getUsers();
- int connectedLegacyVpnCount = 0;
- for (UserInfo user : users) {
- VpnConfig cfg = vpnManager.getVpnConfig(user.id);
- if (cfg == null) {
- continue;
- } else if (cfg.legacy) {
- // Legacy VPNs should do nothing if the network is disconnected. Third-party
- // VPN warnings need to continue as traffic can still go to the app.
- final LegacyVpnInfo legacyVpn = vpnManager.getLegacyVpnInfo(user.id);
- if (legacyVpn == null || legacyVpn.state != LegacyVpnInfo.STATE_CONNECTED) {
- continue;
- } else {
- connectedLegacyVpnCount++;
- }
- }
- vpns.put(user.id, cfg);
- }
- return vpns.size() - connectedLegacyVpnCount;
+ // Converted from SystemUI::SecurityControllerImpl
+ return (int) userManager.getUsers().stream()
+ .map(user -> vpnManager.getVpnConfig(user.id))
+ .filter(cfg -> (cfg != null) && (!cfg.legacy))
+ .count();
}
protected String getInsecureVpnSummaryOverride(UserManager userManager,
VpnManager vpnManager) {
// Optionally add warning icon if an insecure VPN is present.
if (mPreference instanceof VpnInfoPreference) {
- final int insecureVpnCount = getInsecureVpnCount();
+ String [] legacyVpnProfileKeys = LegacyVpnProfileStore.list(Credentials.VPN);
+ final int insecureVpnCount = getInsecureVpnCount(legacyVpnProfileKeys);
boolean isInsecureVPN = insecureVpnCount > 0;
((VpnInfoPreference) mPreference).setInsecureVpn(isInsecureVPN);
@@ -193,11 +178,14 @@ public class VpnPreferenceController extends AbstractPreferenceController
if (isInsecureVPN) {
// Add the users and the number of legacy vpns to determine if there is more than
// one vpn, since there can be more than one VPN per user.
- final int vpnCount = getNumberOfNonLegacyVpn(userManager, vpnManager)
- + LegacyVpnProfileStore.list(Credentials.VPN).length;
- if (vpnCount == 1) {
- return mContext.getString(R.string.vpn_settings_insecure_single);
- } else if (insecureVpnCount == 1) {
+ int vpnCount = legacyVpnProfileKeys.length;
+ if (vpnCount <= 1) {
+ vpnCount += getNumberOfNonLegacyVpn(userManager, vpnManager);
+ if (vpnCount == 1) {
+ return mContext.getString(R.string.vpn_settings_insecure_single);
+ }
+ }
+ if (insecureVpnCount == 1) {
return mContext.getString(
R.string.vpn_settings_single_insecure_multiple_total,
insecureVpnCount);
@@ -229,10 +217,10 @@ public class VpnPreferenceController extends AbstractPreferenceController
}
@VisibleForTesting
- protected int getInsecureVpnCount() {
+ protected int getInsecureVpnCount(String [] legacyVpnProfileKeys) {
final Function keyToProfile = key ->
VpnProfile.decode(key, LegacyVpnProfileStore.get(Credentials.VPN + key));
- return (int) Arrays.stream(LegacyVpnProfileStore.list(Credentials.VPN))
+ return (int) Arrays.stream(legacyVpnProfileKeys)
.map(keyToProfile)
// Return whether any profile is an insecure type.
.filter(profile -> VpnProfile.isLegacyType(profile.type))
diff --git a/src/com/android/settings/password/ChooseLockPattern.java b/src/com/android/settings/password/ChooseLockPattern.java
index 3e7622c6b66..60b8c6cd37d 100644
--- a/src/com/android/settings/password/ChooseLockPattern.java
+++ b/src/com/android/settings/password/ChooseLockPattern.java
@@ -541,8 +541,6 @@ public class ChooseLockPattern extends SettingsActivity {
mDefaultHeaderColorList = mHeaderText.getTextColors();
mLockPatternView = (LockPatternView) view.findViewById(R.id.lockPattern);
mLockPatternView.setOnPatternListener(mChooseNewLockPatternListener);
- mLockPatternView.setTactileFeedbackEnabled(
- mLockPatternUtils.isTactileFeedbackEnabled());
mLockPatternView.setFadePattern(false);
mFooterText = (TextView) view.findViewById(R.id.footerText);
diff --git a/src/com/android/settings/password/ConfirmLockPattern.java b/src/com/android/settings/password/ConfirmLockPattern.java
index ec5efcfbc4e..6b9140acef3 100644
--- a/src/com/android/settings/password/ConfirmLockPattern.java
+++ b/src/com/android/settings/password/ConfirmLockPattern.java
@@ -144,8 +144,6 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
mHeaderText = mDevicePolicyManager.getOrganizationNameForUser(mUserId);
}
- mLockPatternView.setTactileFeedbackEnabled(
- mLockPatternUtils.isTactileFeedbackEnabled());
mLockPatternView.setInStealthMode(!mLockPatternUtils.isVisiblePatternEnabled(
mEffectiveUserId));
mLockPatternView.setOnPatternListener(mConfirmExistingLockPatternListener);
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index 255b85fe0bf..dc4bca35b1c 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -814,8 +814,8 @@ public class UserSettings extends SettingsPreferenceFragment
}
try {
getContext().getSystemService(UserManager.class)
- .removeUserOrSetEphemeral(UserHandle.myUserId(),
- /* evenWhenDisallowed= */ false);
+ .removeUserWhenPossible(UserHandle.of(UserHandle.myUserId()),
+ /* overrideDevicePolicy= */ false);
ActivityManager.getService().switchUser(UserHandle.USER_SYSTEM);
} catch (RemoteException re) {
Log.e(TAG, "Unable to remove self user");
diff --git a/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java b/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
index 7dc4613c449..aec31fc7790 100644
--- a/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/AllInOneTetherSettingsTest.java
@@ -35,6 +35,7 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.TetheringManager;
import android.net.wifi.SoftApConfiguration;
+import android.net.wifi.WifiManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.FeatureFlagUtils;
@@ -43,27 +44,23 @@ import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.FeatureFlags;
-import com.android.settings.testutils.shadow.ShadowWifiManager;
import com.android.settings.wifi.tether.WifiTetherAutoOffPreferenceController;
import com.android.settings.wifi.tether.WifiTetherSecurityPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowWifiManager.class})
public class AllInOneTetherSettingsTest {
private static final String[] WIFI_REGEXS = {"wifi_regexs"};
private static final String[] USB_REGEXS = {"usb_regexs"};
@@ -73,6 +70,8 @@ public class AllInOneTetherSettingsTest {
private Context mContext;
private AllInOneTetherSettings mAllInOneTetherSettings;
+ @Mock
+ private WifiManager mWifiManager;
@Mock
private ConnectivityManager mConnectivityManager;
@Mock
@@ -91,6 +90,7 @@ public class AllInOneTetherSettingsTest {
mContext = spy(RuntimeEnvironment.application);
MockitoAnnotations.initMocks(this);
+ doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
doReturn(mConnectivityManager)
.when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
doReturn(mTetheringManager)
@@ -178,7 +178,6 @@ public class AllInOneTetherSettingsTest {
}
@Test
- @Ignore
public void createPreferenceControllers_hasAutoOffPreference() {
assertThat(mAllInOneTetherSettings.createPreferenceControllers(mContext)
.stream()
diff --git a/tests/robotests/src/com/android/settings/MainClearTest.java b/tests/robotests/src/com/android/settings/MainClearTest.java
index e2a7ca904e8..ec33fadfd02 100644
--- a/tests/robotests/src/com/android/settings/MainClearTest.java
+++ b/tests/robotests/src/com/android/settings/MainClearTest.java
@@ -55,7 +55,6 @@ import com.android.settingslib.development.DevelopmentSettingsEnabler;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -209,7 +208,6 @@ public class MainClearTest {
}
@Test
- @Ignore
public void testShowWipeEuicc_euiccEnabled_unprovisioned() {
prepareEuiccState(
true /* isEuiccEnabled */,
@@ -228,7 +226,6 @@ public class MainClearTest {
}
@Test
- @Ignore
public void testShowWipeEuicc_developerMode_unprovisioned() {
prepareEuiccState(
true /* isEuiccEnabled */,
diff --git a/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java
new file mode 100644
index 00000000000..6b9395a335c
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/TextReadingPreviewPreferenceTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2022 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.accessibility;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+
+import androidx.preference.PreferenceViewHolder;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.viewpager.widget.ViewPager;
+
+import com.android.settings.R;
+import com.android.settings.display.PreviewPagerAdapter;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+/**
+ * Tests for {@link TextReadingPreferenceFragment}.
+ */
+@RunWith(RobolectricTestRunner.class)
+public class TextReadingPreviewPreferenceTest {
+
+ private TextReadingPreviewPreference mTextReadingPreviewPreference;
+ private PreferenceViewHolder mHolder;
+ private ViewPager mViewPager;
+ private PreviewPagerAdapter mPreviewPagerAdapter;
+
+ @Before
+ public void setUp() {
+ final Context context = ApplicationProvider.getApplicationContext();
+ final int[] sampleResIds = new int[]{1, 2, 3, 4, 5, 6};
+ final Configuration[] configurations = createConfigurations(6);
+ mTextReadingPreviewPreference = new TextReadingPreviewPreference(context);
+ mPreviewPagerAdapter =
+ new PreviewPagerAdapter(context, /* isLayoutRtl= */ false, sampleResIds,
+ configurations);
+ final LayoutInflater inflater = LayoutInflater.from(context);
+ final View view =
+ inflater.inflate(mTextReadingPreviewPreference.getLayoutResource(),
+ new LinearLayout(context), false);
+ mHolder = PreferenceViewHolder.createInstanceForTests(view);
+ mViewPager = view.findViewById(R.id.preview_pager);
+ }
+
+ @Test
+ public void setPreviewerAdapter_success() {
+ mTextReadingPreviewPreference.setPreviewAdapter(mPreviewPagerAdapter);
+ mTextReadingPreviewPreference.onBindViewHolder(mHolder);
+
+ assertThat(mViewPager.getAdapter()).isEqualTo(mPreviewPagerAdapter);
+ }
+
+ @Test
+ public void setPreviewAdapterWithNull_resetCurrentItem() {
+ final int currentItem = 2;
+ mTextReadingPreviewPreference.setPreviewAdapter(mPreviewPagerAdapter);
+ mTextReadingPreviewPreference.setCurrentItem(currentItem);
+ mTextReadingPreviewPreference.onBindViewHolder(mHolder);
+
+ mTextReadingPreviewPreference.setPreviewAdapter(null);
+ mTextReadingPreviewPreference.onBindViewHolder(mHolder);
+
+ assertThat(mTextReadingPreviewPreference.getCurrentItem()).isEqualTo(0);
+ }
+
+ @Test
+ public void setCurrentItem_success() {
+ final int currentItem = 3;
+ mTextReadingPreviewPreference.setPreviewAdapter(mPreviewPagerAdapter);
+ mTextReadingPreviewPreference.onBindViewHolder(mHolder);
+
+ mTextReadingPreviewPreference.setCurrentItem(currentItem);
+ mTextReadingPreviewPreference.onBindViewHolder(mHolder);
+
+ assertThat(mViewPager.getCurrentItem()).isEqualTo(currentItem);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void setCurrentItemBeforeSetPreviewAdapter_throwNPE() {
+ final int currentItem = 5;
+
+ mTextReadingPreviewPreference.setCurrentItem(currentItem);
+ }
+
+ private static Configuration[] createConfigurations(int count) {
+ final Configuration[] configurations = new Configuration[count];
+ for (int i = 0; i < count; i++) {
+ configurations[i] = new Configuration();
+ }
+
+ return configurations;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/VibrationIntensityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/VibrationIntensityPreferenceControllerTest.java
index ba48f66e899..048bce4c37a 100644
--- a/tests/robotests/src/com/android/settings/accessibility/VibrationIntensityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/VibrationIntensityPreferenceControllerTest.java
@@ -38,11 +38,14 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
+/** Tests for {@link VibrationIntensityPreferenceController}. */
@RunWith(RobolectricTestRunner.class)
public class VibrationIntensityPreferenceControllerTest {
private static final String SETTING_KEY = Settings.System.NOTIFICATION_VIBRATION_INTENSITY;
private static final int VIBRATION_USAGE = VibrationAttributes.USAGE_NOTIFICATION;
+ private static final int OFF = 0;
+ private static final int ON = 1;
/** Basic implementation of preference controller to test generic behavior. */
private static class TestPreferenceController extends VibrationIntensityPreferenceController {
@@ -77,12 +80,33 @@ public class VibrationIntensityPreferenceControllerTest {
@Test
public void missingSetting_shouldReturnDefault() {
VibrationIntensityPreferenceController controller = createPreferenceController(3);
- Settings.System.putString(mContext.getContentResolver(), SETTING_KEY, null);
+ Settings.System.putString(mContext.getContentResolver(), SETTING_KEY, /* value= */ null);
controller.updateState(mPreference);
assertThat(mPreference.getProgress())
.isEqualTo(mVibrator.getDefaultVibrationIntensity(VIBRATION_USAGE));
}
+ @Test
+ public void updateState_mainSwitchUpdates_shouldPreserveSettingBetweenUpdates() {
+ VibrationIntensityPreferenceController controller = createPreferenceController(3);
+ updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
+
+ updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, ON);
+ controller.updateState(mPreference);
+ assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
+ assertThat(mPreference.isEnabled()).isTrue();
+
+ updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, OFF);
+ controller.updateState(mPreference);
+ assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
+ assertThat(mPreference.isEnabled()).isFalse();
+
+ updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, ON);
+ controller.updateState(mPreference);
+ assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
+ assertThat(mPreference.isEnabled()).isTrue();
+ }
+
@Test
public void updateState_allLevelsSupported_shouldDisplayIntensityInSliderPosition() {
VibrationIntensityPreferenceController controller = createPreferenceController(3);
@@ -146,6 +170,22 @@ public class VibrationIntensityPreferenceControllerTest {
assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
}
+ @Test
+ public void setProgress_mainSwitchDisabled_ignoresUpdates() throws Exception {
+ VibrationIntensityPreferenceController controller = createPreferenceController(3);
+ updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
+ controller.updateState(mPreference);
+ assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
+
+ updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, OFF);
+ controller.updateState(mPreference);
+ assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
+ assertThat(mPreference.isEnabled()).isFalse();
+
+ assertThat(controller.setSliderPosition(Vibrator.VIBRATION_INTENSITY_HIGH)).isFalse();
+ assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
+ assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
+ }
@Test
public void setProgress_allSupportedPositions_updatesIntensitySetting() throws Exception {
VibrationIntensityPreferenceController controller = createPreferenceController(3);
diff --git a/tests/robotests/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceControllerTest.java
new file mode 100644
index 00000000000..6f5700347a7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/VibrationMainSwitchPreferenceControllerTest.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2022 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.accessibility;
+
+import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
+import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.widget.MainSwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+/** Tests for {@link VibrationMainSwitchPreferenceController}. */
+@RunWith(RobolectricTestRunner.class)
+public class VibrationMainSwitchPreferenceControllerTest {
+
+ private static final String PREFERENCE_KEY = "preference_key";
+
+ @Mock private PreferenceScreen mScreen;
+
+ private Lifecycle mLifecycle;
+ private Context mContext;
+ private VibrationMainSwitchPreferenceController mController;
+ private MainSwitchPreference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mLifecycle = new Lifecycle(() -> mLifecycle);
+ mContext = ApplicationProvider.getApplicationContext();
+ mController = new VibrationMainSwitchPreferenceController(mContext, PREFERENCE_KEY);
+ mLifecycle.addObserver(mController);
+ mPreference = new MainSwitchPreference(mContext);
+ mPreference.setTitle("Test title");
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ }
+
+ @Test
+ public void verifyConstants() {
+ assertThat(mController.getPreferenceKey()).isEqualTo(PREFERENCE_KEY);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void updateState_shouldReturnTheSettingState() {
+ updateSetting(Settings.System.VIBRATE_ON, ON);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isTrue();
+
+ updateSetting(Settings.System.VIBRATE_ON, OFF);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isFalse();
+ }
+
+ @Test
+ public void setChecked_updatesSetting() throws Settings.SettingNotFoundException {
+ updateSetting(Settings.System.VIBRATE_ON, OFF);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isFalse();
+
+ mController.setChecked(true);
+ assertThat(readSetting(Settings.System.VIBRATE_ON)).isEqualTo(ON);
+
+ mController.setChecked(false);
+ assertThat(readSetting(Settings.System.VIBRATE_ON)).isEqualTo(OFF);
+ }
+
+ private void updateSetting(String key, int value) {
+ Settings.System.putInt(mContext.getContentResolver(), key, value);
+ }
+
+ private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
+ return Settings.System.getInt(mContext.getContentResolver(), settingKey);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/VibrationTogglePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/VibrationTogglePreferenceControllerTest.java
new file mode 100644
index 00000000000..cb4a07e865f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/VibrationTogglePreferenceControllerTest.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2022 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.accessibility;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.VibrationAttributes;
+import android.os.Vibrator;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+
+/** Tests for {@link VibrationTogglePreferenceController}. */
+@RunWith(RobolectricTestRunner.class)
+public class VibrationTogglePreferenceControllerTest {
+
+ private static final String SETTING_KEY = Settings.System.NOTIFICATION_VIBRATION_INTENSITY;
+ private static final int VIBRATION_USAGE = VibrationAttributes.USAGE_NOTIFICATION;
+ private static final int OFF = 0;
+ private static final int ON = 1;
+
+ /** Basic implementation of preference controller to test generic behavior. */
+ private static class TestPreferenceController extends VibrationTogglePreferenceController {
+
+ TestPreferenceController(Context context) {
+ super(context, "preference_key",
+ new VibrationPreferenceConfig(context, SETTING_KEY, VIBRATION_USAGE) {});
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+ }
+
+ @Mock private PreferenceScreen mScreen;
+
+ private Lifecycle mLifecycle;
+ private Context mContext;
+ private Vibrator mVibrator;
+ private SwitchPreference mPreference;
+ private VibrationTogglePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mLifecycle = new Lifecycle(() -> mLifecycle);
+ mContext = ApplicationProvider.getApplicationContext();
+ mVibrator = mContext.getSystemService(Vibrator.class);
+ mController = new TestPreferenceController(mContext);
+ mLifecycle.addObserver(mController);
+ mPreference = new SwitchPreference(mContext);
+ mPreference.setTitle("Test title");
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ }
+
+ @Test
+ public void missingSetting_shouldBeCheckedByDefault() {
+ Settings.System.putString(mContext.getContentResolver(), SETTING_KEY, /* value= */ null);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isTrue();
+ }
+
+ @Test
+ public void updateState_mainSwitchUpdates_shouldPreserveSettingBetweenUpdates() {
+ updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
+
+ updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, ON);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isTrue();
+ assertThat(mPreference.isEnabled()).isTrue();
+
+ updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, OFF);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isFalse();
+ assertThat(mPreference.isEnabled()).isFalse();
+
+ updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, ON);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isTrue();
+ assertThat(mPreference.isEnabled()).isTrue();
+ }
+
+ @Test
+ public void updateState_shouldUpdateToggleState() {
+ updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_HIGH);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isTrue();
+
+ updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isFalse();
+
+ updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_MEDIUM);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isTrue();
+
+ updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_OFF);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isFalse();
+
+ updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isTrue();
+ }
+
+ @Test
+ public void setProgress_mainSwitchDisabled_ignoresUpdates() throws Exception {
+ updateSetting(SETTING_KEY, Vibrator.VIBRATION_INTENSITY_LOW);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isTrue();
+
+ updateSetting(VibrationPreferenceConfig.MAIN_SWITCH_SETTING_KEY, OFF);
+ mController.updateState(mPreference);
+ assertThat(mPreference.isChecked()).isFalse();
+
+ mController.setChecked(true);
+ assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW);
+ assertThat(mPreference.isChecked()).isFalse();
+ assertThat(mPreference.isEnabled()).isFalse();
+
+ }
+ @Test
+ public void setProgress_updatesCheckedState() throws Exception {
+ mController.setChecked(false);
+ assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
+
+ mController.setChecked(true);
+ assertThat(readSetting(SETTING_KEY))
+ .isEqualTo(mVibrator.getDefaultVibrationIntensity(VIBRATION_USAGE));
+
+ mController.setChecked(false);
+ assertThat(readSetting(SETTING_KEY)).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF);
+ }
+
+ private void updateSetting(String key, int value) {
+ Settings.System.putInt(mContext.getContentResolver(), key, value);
+ }
+
+ private int readSetting(String settingKey) throws Settings.SettingNotFoundException {
+ return Settings.System.getInt(mContext.getContentResolver(), settingKey);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
index dcb1a50595c..17283cfaf38 100644
--- a/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deletionhelper/AutomaticStorageManagerSwitchBarControllerTest.java
@@ -38,7 +38,6 @@ import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -138,13 +137,13 @@ public class AutomaticStorageManagerSwitchBarControllerTest {
}
@Test
- @Ignore
public void initializingSwitchDoesNotTriggerView() {
Settings.Secure.putInt(
mContext.getContentResolver(),
Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED,
1);
+ mSwitchBar = new SettingsMainSwitchBar(mContext);
mController =
new AutomaticStorageManagerSwitchBarController(
mContext,
diff --git a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java
index 4e52fed4234..2266ed9765c 100644
--- a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverAppPreferenceControllerTest.java
@@ -43,7 +43,6 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -54,7 +53,6 @@ import org.robolectric.RuntimeEnvironment;
import java.util.Arrays;
@RunWith(RobolectricTestRunner.class)
-@Ignore
public class GraphicsDriverAppPreferenceControllerTest {
private static final int DEFAULT = 0;
diff --git a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableForAllAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableForAllAppsPreferenceControllerTest.java
index a0fb577754b..e24b9e565ca 100644
--- a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableForAllAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableForAllAppsPreferenceControllerTest.java
@@ -40,7 +40,6 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -49,7 +48,6 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
-@Ignore
public class GraphicsDriverEnableForAllAppsPreferenceControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverGlobalSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverGlobalSwitchBarControllerTest.java
index 2c8ce06e8e7..838703d3381 100644
--- a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverGlobalSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverGlobalSwitchBarControllerTest.java
@@ -32,7 +32,6 @@ import com.android.settings.widget.SwitchBarController;
import com.android.settings.widget.SwitchWidgetController;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -41,7 +40,6 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
-@Ignore
public class GraphicsDriverGlobalSwitchBarControllerTest {
@Mock
diff --git a/tests/robotests/src/com/android/settings/development/qstile/DevelopmentTilesTest.java b/tests/robotests/src/com/android/settings/development/qstile/DevelopmentTilesTest.java
index 7720a713052..9ab67c2719c 100644
--- a/tests/robotests/src/com/android/settings/development/qstile/DevelopmentTilesTest.java
+++ b/tests/robotests/src/com/android/settings/development/qstile/DevelopmentTilesTest.java
@@ -30,7 +30,6 @@ import android.service.quicksettings.Tile;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -62,7 +61,6 @@ public class DevelopmentTilesTest {
}
@Test
- @Ignore
public void refresh_devOptionIsDisabled_shouldResetTileValue() {
final ComponentName cn = new ComponentName(
mService.getPackageName(), mService.getClass().getName());
diff --git a/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java b/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java
deleted file mode 100644
index 88d0ff1846e..00000000000
--- a/tests/robotests/src/com/android/settings/dream/CurrentDreamPickerTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.dream;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.app.Activity;
-import android.content.ComponentName;
-import android.content.Context;
-import android.os.UserManager;
-
-import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settingslib.dream.DreamBackend;
-import com.android.settingslib.dream.DreamBackend.DreamInfo;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.util.ReflectionHelpers;
-
-import java.util.Collections;
-
-@RunWith(RobolectricTestRunner.class)
-public class CurrentDreamPickerTest {
-
- private static String COMPONENT_KEY = "mocked_component_name_string";
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private DreamBackend mBackend;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private Activity mActivity;
- @Mock
- private UserManager mUserManager;
- private CurrentDreamPicker mPicker;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
- FakeFeatureFactory.setupForTest();
-
- mPicker = new CurrentDreamPicker();
- mPicker.onAttach(mActivity);
-
- ReflectionHelpers.setField(mPicker, "mBackend", mBackend);
- }
-
- @Test
- public void getDefaultShouldReturnActiveDream() {
- ComponentName mockComponentName = mock(ComponentName.class);
- when(mockComponentName.flattenToString()).thenReturn(COMPONENT_KEY);
- when(mBackend.getActiveDream()).thenReturn(mockComponentName);
-
- assertThat(mPicker.getDefaultKey()).isEqualTo(COMPONENT_KEY);
- }
-
- @Test
- public void setDefaultShouldUpdateActiveDream() {
- DreamInfo mockInfo = mock(DreamInfo.class);
- ComponentName mockName = mock(ComponentName.class);
-
- mockInfo.componentName = mockName;
- when(mockName.flattenToString()).thenReturn(COMPONENT_KEY);
- when(mBackend.getDreamInfos()).thenReturn(Collections.singletonList(mockInfo));
-
- mPicker.setDefaultKey(COMPONENT_KEY);
-
- verify(mBackend).setActiveDream(mockName);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/dream/CurrentDreamPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/dream/DreamPickerControllerTest.java
similarity index 51%
rename from tests/robotests/src/com/android/settings/dream/CurrentDreamPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/dream/DreamPickerControllerTest.java
index 8a5ee20c4f1..1048970cd46 100644
--- a/tests/robotests/src/com/android/settings/dream/CurrentDreamPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/dream/DreamPickerControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2022 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.
@@ -18,94 +18,92 @@ package com.android.settings.dream;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
+import android.widget.Button;
-import com.android.settings.widget.GearPreference;
+import androidx.preference.PreferenceScreen;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.settings.R;
import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.dream.DreamBackend.DreamInfo;
+import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
-import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.Collections;
@RunWith(RobolectricTestRunner.class)
-public class CurrentDreamPreferenceControllerTest {
-
- private CurrentDreamPreferenceController mController;
+public class DreamPickerControllerTest {
+ private DreamPickerController mController;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private DreamBackend mBackend;
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock
- private DreamInfo mDreamInfo;
+ private PreferenceScreen mScreen;
+ private LayoutPreference mPreference;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
+ mContext = ApplicationProvider.getApplicationContext();
- mController = new CurrentDreamPreferenceController(mContext, "test");
- ReflectionHelpers.setField(mController, "mBackend", mBackend);
+ mPreference = new LayoutPreference(mContext, R.layout.dream_picker_layout);
+ when(mScreen.findPreference(anyString())).thenReturn(mPreference);
+
+ mController = new DreamPickerController(
+ mContext,
+ /* preferenceKey= */ "test",
+ mBackend);
+
+ mController.displayPreference(mScreen);
}
@Test
public void isDisabledIfNoDreamsAvailable() {
when(mBackend.getDreamInfos()).thenReturn(new ArrayList<>(0));
-
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isEnabledIfDreamsAvailable() {
- when(mBackend.getDreamInfos()).thenReturn(Collections.singletonList(mDreamInfo));
-
+ when(mBackend.getDreamInfos()).thenReturn(Collections.singletonList(new DreamInfo()));
assertThat(mController.isAvailable()).isTrue();
}
@Test
- public void gearShowsIfActiveDreamInfoHasOptions() {
- mDreamInfo.settingsComponentName = mock(ComponentName.class);
- mDreamInfo.isActive = true;
+ public void testDreamDisplayedInList() {
+ when(mBackend.getDreamInfos()).thenReturn(Collections.singletonList(new DreamInfo()));
+ mController.updateState(mPreference);
- when(mBackend.getDreamInfos()).thenReturn(Collections.singletonList(mDreamInfo));
-
- GearPreference mockPref = mock(GearPreference.class);
- ArgumentCaptor captor =
- ArgumentCaptor.forClass(GearPreference.OnGearClickListener.class);
-
- // verify that updateState sets a non-null gear click listener
- mController.updateState(mockPref);
- verify(mockPref).setOnGearClickListener(captor.capture());
- captor.getAllValues().forEach(listener -> assertThat(listener).isNotNull());
+ RecyclerView view = mPreference.findViewById(R.id.dream_list);
+ assertThat(view.getAdapter().getItemCount()).isEqualTo(1);
}
@Test
- public void gearHidesIfActiveDreamInfoHasNoOptions() {
- mDreamInfo.settingsComponentName = null;
- mDreamInfo.isActive = true;
+ public void testPreviewButton() {
+ final DreamInfo mockDreamInfo = new DreamInfo();
+ mockDreamInfo.componentName = new ComponentName("package", "class");
+ mockDreamInfo.isActive = true;
- when(mBackend.getDreamInfos()).thenReturn(Collections.singletonList(mDreamInfo));
+ when(mBackend.getDreamInfos()).thenReturn(Collections.singletonList(mockDreamInfo));
+ mController.updateState(mPreference);
- GearPreference mockPref = mock(GearPreference.class);
- ArgumentCaptor captor =
- ArgumentCaptor.forClass(GearPreference.OnGearClickListener.class);
-
- // setting a null onGearClickListener removes the gear from view
- mController.updateState(mockPref);
- verify(mockPref).setOnGearClickListener(captor.capture());
- captor.getAllValues().forEach(listener -> assertThat(listener).isNull());
+ Button view = mPreference.findViewById(R.id.preview_button);
+ view.performClick();
+ verify(mBackend).preview(mockDreamInfo);
}
}
diff --git a/tests/robotests/src/com/android/settings/dream/StartNowPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/dream/StartNowPreferenceControllerTest.java
deleted file mode 100644
index 98ba1ce2b31..00000000000
--- a/tests/robotests/src/com/android/settings/dream/StartNowPreferenceControllerTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.dream;
-
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.widget.Button;
-
-import androidx.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settingslib.dream.DreamBackend;
-import com.android.settingslib.widget.LayoutPreference;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.util.ReflectionHelpers;
-
-@RunWith(RobolectricTestRunner.class)
-public class StartNowPreferenceControllerTest {
-
- private StartNowPreferenceController mController;
- private Context mContext;
-
- @Mock
- private PreferenceScreen mScreen;
- @Mock
- private LayoutPreference mLayoutPref;
- @Mock
- private Button mButton;
- @Mock
- private DreamBackend mBackend;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
-
- mContext = spy(RuntimeEnvironment.application);
- mController = new StartNowPreferenceController(mContext, "key");
- when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mLayoutPref);
- when(mLayoutPref.findViewById(R.id.dream_start_now_button)).thenReturn(mButton);
-
- ReflectionHelpers.setField(mController, "mBackend", mBackend);
- }
-
- @Test
- public void updateState_neverDreaming_buttonShouldDidabled() {
- when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.NEVER);
- mController.displayPreference(mScreen);
-
- mController.updateState(mLayoutPref);
-
- verify(mButton).setEnabled(false);
- }
-
- @Test
- public void updateState_dreamIsAvailable_buttonShouldEnabled() {
- when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.EITHER);
- mController.displayPreference(mScreen);
-
- mController.updateState(mLayoutPref);
-
- verify(mButton).setEnabled(true);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
index b0f14de9b46..f9b1543f9a7 100644
--- a/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
+++ b/tests/robotests/src/com/android/settings/localepicker/LocaleListEditorTest.java
@@ -34,7 +34,6 @@ import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -82,7 +81,6 @@ public class LocaleListEditorTest {
}
@Test
- @Ignore
public void testDisallowConfigLocale_unrestrict() {
ReflectionHelpers.setField(mLocaleListEditor, "mIsUiRestricted", true);
mLocaleListEditor.onAttach(mContext);
@@ -91,7 +89,6 @@ public class LocaleListEditorTest {
}
@Test
- @Ignore
public void testDisallowConfigLocale_restrict() {
ReflectionHelpers.setField(mLocaleListEditor, "mIsUiRestricted", false);
mLocaleListEditor.onAttach(mContext);
diff --git a/tests/robotests/src/com/android/settings/location/LocationSettingsFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/LocationSettingsFooterPreferenceControllerTest.java
index a64132469d3..333929dc10e 100644
--- a/tests/robotests/src/com/android/settings/location/LocationSettingsFooterPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/LocationSettingsFooterPreferenceControllerTest.java
@@ -46,7 +46,6 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.FooterPreference;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -168,7 +167,6 @@ public class LocationSettingsFooterPreferenceControllerTest {
}
@Test
- @Ignore
public void onLocationModeChanged_on_setTitle() {
final List testResolveInfos = new ArrayList<>();
testResolveInfos.add(
diff --git a/tests/robotests/src/com/android/settings/network/WifiConnectionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/WifiConnectionPreferenceControllerTest.java
index 038a292cbec..925b000e652 100644
--- a/tests/robotests/src/com/android/settings/network/WifiConnectionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/WifiConnectionPreferenceControllerTest.java
@@ -40,6 +40,7 @@ import com.android.wifitrackerlib.WifiEntry;
import com.android.wifitrackerlib.WifiPickerTracker;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -49,6 +50,7 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
+@Ignore
public class WifiConnectionPreferenceControllerTest {
private static final String KEY = "wifi_connection";
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java
index 4df3bc9665c..9204d4326f5 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiPrimarySwitchPreferenceControllerTest.java
@@ -19,6 +19,9 @@ package com.android.settings.wifi;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -26,6 +29,7 @@ import static org.mockito.Mockito.when;
import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkRequest;
@@ -42,7 +46,6 @@ import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -55,6 +58,8 @@ import org.robolectric.annotation.Config;
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
public class WifiPrimarySwitchPreferenceControllerTest {
+ @Mock
+ private Intent mIntentReceiver;
@Mock
private WifiManager mWifiManager;
@Mock
@@ -75,6 +80,9 @@ public class WifiPrimarySwitchPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mMetricsFeatureProvider = FakeFeatureFactory.setupForTest().getMetricsFeatureProvider();
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+ doReturn(mIntentReceiver).when(mContext)
+ .registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class), anyInt());
+ doNothing().when(mContext).unregisterReceiver(any(BroadcastReceiver.class));
when(mContext.getSystemService(ConnectivityManager.class)).thenReturn(mConnectivityManager);
when(mContext.getSystemService(NetworkScoreManager.class)).thenReturn(mNetworkScoreManager);
mController = new WifiPrimarySwitchPreferenceController(mContext, mMetricsFeatureProvider);
@@ -95,11 +103,11 @@ public class WifiPrimarySwitchPreferenceControllerTest {
}
@Test
- @Ignore
public void onResume_shouldRegisterCallback() {
mController.onResume();
- verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
+ verify(mContext).registerReceiver(
+ any(BroadcastReceiver.class), any(IntentFilter.class), anyInt());
verify(mConnectivityManager).registerNetworkCallback(
any(NetworkRequest.class),
any(ConnectivityManager.NetworkCallback.class),
@@ -107,7 +115,6 @@ public class WifiPrimarySwitchPreferenceControllerTest {
}
@Test
- @Ignore
public void onPause_shouldUnregisterCallback() {
mController.onResume();
mController.onPause();
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
index e5d39dd7336..e0cd780950d 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -31,6 +31,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.TetheringManager;
+import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
@@ -43,10 +44,8 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.core.FeatureFlags;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowFragment;
-import com.android.settings.testutils.shadow.ShadowWifiManager;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -60,13 +59,14 @@ import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowWifiManager.class})
public class WifiTetherSettingsTest {
private static final String[] WIFI_REGEXS = {"wifi_regexs"};
private Context mContext;
private WifiTetherSettings mWifiTetherSettings;
+ @Mock
+ private WifiManager mWifiManager;
@Mock
private ConnectivityManager mConnectivityManager;
@Mock
@@ -79,6 +79,7 @@ public class WifiTetherSettingsTest {
mContext = spy(RuntimeEnvironment.application);
MockitoAnnotations.initMocks(this);
+ doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
doReturn(mConnectivityManager)
.when(mContext).getSystemService(Context.CONNECTIVITY_SERVICE);
doReturn(mTetheringManager).when(mContext).getSystemService(Context.TETHERING_SERVICE);
@@ -89,7 +90,6 @@ public class WifiTetherSettingsTest {
}
@Test
- @Ignore
public void wifiTetherNonIndexableKeys_tetherAvailable_keysNotReturned() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.TETHER_ALL_IN_ONE, false);
// To let TetherUtil.isTetherAvailable return true, select one of the combinations
@@ -119,7 +119,6 @@ public class WifiTetherSettingsTest {
}
@Test
- @Ignore
public void createPreferenceControllers_notEmpty() {
assertThat(WifiTetherSettings.SEARCH_INDEX_DATA_PROVIDER.getPreferenceControllers(mContext))
.isNotEmpty();
@@ -152,7 +151,6 @@ public class WifiTetherSettingsTest {
}
@Test
- @Ignore
public void createPreferenceControllers_hasAutoOffPreference() {
assertThat(mWifiTetherSettings.createPreferenceControllers(mContext)
.stream()