chore(magnification): remove onResume overrides for controllers in ToggleScreenMagnificationPreferenceFragment
As b/186731461, so far MagnificationModePreferenceController and other magnification preference controllers are only used in ToggleScreenMagnificationPreferenceFragment, which is DashboardFragment. Since DashboardFragment already updates preference state in its onResume, so we can remove the onResume overrides in those controllers. Besides, we can also remove the LifeCycle dependency for the controllers since it's not used anymore. Bug: 186731461 Flag: NA Test: manually atest ToggleScreenMagnificationPreferenceFragmentTest atest MagnificationAlwaysOnPreferenceControllerTest atest MagnificationFollowTypingPreferenceControllerTest atest MagnificationJoystickPreferenceControllerTest atest MagnificationModePreferenceControllerTest Change-Id: I379a6a3a985c9d8b7a37bbb878b84cee1bd6adfb
This commit is contained in:
@@ -22,12 +22,6 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
@@ -36,15 +30,12 @@ import com.android.settings.core.TogglePreferenceController;
|
||||
* feature, where the magnifier will not deactivate on Activity transitions; it will only zoom out
|
||||
* to 100%.
|
||||
*/
|
||||
public class MagnificationAlwaysOnPreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver {
|
||||
public class MagnificationAlwaysOnPreferenceController extends TogglePreferenceController {
|
||||
|
||||
private static final String TAG =
|
||||
MagnificationAlwaysOnPreferenceController.class.getSimpleName();
|
||||
static final String PREF_KEY = Settings.Secure.ACCESSIBILITY_MAGNIFICATION_ALWAYS_ON_ENABLED;
|
||||
|
||||
private TwoStatePreference mSwitchPreference;
|
||||
|
||||
public MagnificationAlwaysOnPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
@@ -71,24 +62,4 @@ public class MagnificationAlwaysOnPreferenceController extends TogglePreferenceC
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_accessibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mSwitchPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
// TODO(b/186731461): Remove it when this controller is used in DashBoardFragment only.
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
void onResume() {
|
||||
updateState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the state of preference components which has been displayed by
|
||||
* {@link MagnificationAlwaysOnPreferenceController#displayPreference}.
|
||||
*/
|
||||
void updateState() {
|
||||
updateState(mSwitchPreference);
|
||||
}
|
||||
}
|
||||
|
@@ -22,25 +22,16 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/** Controller that accesses and switches the preference status of following typing feature */
|
||||
public class MagnificationFollowTypingPreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver {
|
||||
public class MagnificationFollowTypingPreferenceController extends TogglePreferenceController {
|
||||
|
||||
private static final String TAG =
|
||||
MagnificationFollowTypingPreferenceController.class.getSimpleName();
|
||||
static final String PREF_KEY = "magnification_follow_typing";
|
||||
|
||||
private TwoStatePreference mFollowTypingPreference;
|
||||
|
||||
public MagnificationFollowTypingPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
@@ -67,24 +58,4 @@ public class MagnificationFollowTypingPreferenceController extends TogglePrefere
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_accessibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mFollowTypingPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
// TODO(b/186731461): Remove it when this controller is used in DashBoardFragment only.
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
void onResume() {
|
||||
updateState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the state of preference components which has been displayed by
|
||||
* {@link MagnificationFollowTypingPreferenceController#displayPreference}.
|
||||
*/
|
||||
void updateState() {
|
||||
updateState(mFollowTypingPreference);
|
||||
}
|
||||
}
|
||||
|
@@ -22,27 +22,18 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* Controller that accesses and switches the preference status of the magnification joystick feature
|
||||
*/
|
||||
public class MagnificationJoystickPreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver {
|
||||
public class MagnificationJoystickPreferenceController extends TogglePreferenceController {
|
||||
|
||||
private static final String TAG =
|
||||
MagnificationJoystickPreferenceController.class.getSimpleName();
|
||||
static final String PREF_KEY = Settings.Secure.ACCESSIBILITY_MAGNIFICATION_JOYSTICK_ENABLED;
|
||||
|
||||
private TwoStatePreference mSwitchPreference;
|
||||
|
||||
public MagnificationJoystickPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
@@ -69,24 +60,4 @@ public class MagnificationJoystickPreferenceController extends TogglePreferenceC
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_accessibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mSwitchPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
// TODO(b/186731461): Remove it when this controller is used in DashBoardFragment only.
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
void onResume() {
|
||||
updateState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the state of preference components which has been displayed by
|
||||
* {@link MagnificationJoystickPreferenceController#displayPreference}.
|
||||
*/
|
||||
void updateState() {
|
||||
updateState(mSwitchPreference);
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,6 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.utils.AnnotationSpan;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnCreate;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -55,7 +54,7 @@ import java.util.List;
|
||||
|
||||
/** Controller that shows the magnification area mode summary and the preference click behavior. */
|
||||
public class MagnificationModePreferenceController extends BasePreferenceController implements
|
||||
DialogCreatable, LifecycleObserver, OnCreate, OnResume, OnSaveInstanceState {
|
||||
DialogCreatable, LifecycleObserver, OnCreate, OnSaveInstanceState {
|
||||
|
||||
static final String PREF_KEY = "screen_magnification_mode";
|
||||
private static final int DIALOG_ID_BASE = 10;
|
||||
@@ -297,12 +296,6 @@ public class MagnificationModePreferenceController extends BasePreferenceControl
|
||||
updateCapabilitiesAndSummary(mModeCache);
|
||||
}
|
||||
|
||||
// TODO(b/186731461): Remove it when this controller is used in DashBoardFragment only.
|
||||
@Override
|
||||
public void onResume() {
|
||||
updateState(mModePreference);
|
||||
}
|
||||
|
||||
/**
|
||||
* An interface to help the delegate to show the dialog. It will be injected to the delegate.
|
||||
*/
|
||||
|
@@ -206,22 +206,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
magnificationModePreferenceController.setDialogHelper(this);
|
||||
getSettingsLifecycle().addObserver(magnificationModePreferenceController);
|
||||
magnificationModePreferenceController.displayPreference(getPreferenceScreen());
|
||||
addPreferenceController(magnificationModePreferenceController);
|
||||
|
||||
mFollowingTypingSwitchPreference = new SwitchPreferenceCompat(getPrefContext());
|
||||
mFollowingTypingSwitchPreference.setTitle(
|
||||
R.string.accessibility_screen_magnification_follow_typing_title);
|
||||
mFollowingTypingSwitchPreference.setSummary(
|
||||
R.string.accessibility_screen_magnification_follow_typing_summary);
|
||||
mFollowingTypingSwitchPreference.setKey(
|
||||
MagnificationFollowTypingPreferenceController.PREF_KEY);
|
||||
generalCategory.addPreference(mFollowingTypingSwitchPreference);
|
||||
|
||||
mFollowTypingPreferenceController = new MagnificationFollowTypingPreferenceController(
|
||||
getContext(), MagnificationFollowTypingPreferenceController.PREF_KEY);
|
||||
getSettingsLifecycle().addObserver(mFollowTypingPreferenceController);
|
||||
mFollowTypingPreferenceController.displayPreference(getPreferenceScreen());
|
||||
addPreferenceController(mFollowTypingPreferenceController);
|
||||
|
||||
addFollowTypingSetting(generalCategory);
|
||||
addAlwaysOnSetting(generalCategory);
|
||||
addJoystickSetting(generalCategory);
|
||||
}
|
||||
@@ -250,6 +237,22 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
super.onProcessArguments(arguments);
|
||||
}
|
||||
|
||||
private void addFollowTypingSetting(PreferenceCategory generalCategory) {
|
||||
var followTypingSwitchPreference = new SwitchPreferenceCompat(getPrefContext());
|
||||
followTypingSwitchPreference.setTitle(
|
||||
R.string.accessibility_screen_magnification_follow_typing_title);
|
||||
followTypingSwitchPreference.setSummary(
|
||||
R.string.accessibility_screen_magnification_follow_typing_summary);
|
||||
followTypingSwitchPreference.setKey(
|
||||
MagnificationFollowTypingPreferenceController.PREF_KEY);
|
||||
generalCategory.addPreference(followTypingSwitchPreference);
|
||||
|
||||
var followTypingPreferenceController = new MagnificationFollowTypingPreferenceController(
|
||||
getContext(), MagnificationFollowTypingPreferenceController.PREF_KEY);
|
||||
followTypingPreferenceController.displayPreference(getPreferenceScreen());
|
||||
addPreferenceController(followTypingPreferenceController);
|
||||
}
|
||||
|
||||
private boolean isAlwaysOnSettingEnabled() {
|
||||
final boolean defaultValue = getContext().getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_magnification_always_on_enabled);
|
||||
@@ -276,7 +279,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
|
||||
var alwaysOnPreferenceController = new MagnificationAlwaysOnPreferenceController(
|
||||
getContext(), MagnificationAlwaysOnPreferenceController.PREF_KEY);
|
||||
getSettingsLifecycle().addObserver(alwaysOnPreferenceController);
|
||||
alwaysOnPreferenceController.displayPreference(getPreferenceScreen());
|
||||
addPreferenceController(alwaysOnPreferenceController);
|
||||
}
|
||||
@@ -304,7 +306,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
getContext(),
|
||||
MagnificationJoystickPreferenceController.PREF_KEY
|
||||
);
|
||||
getSettingsLifecycle().addObserver(joystickPreferenceController);
|
||||
joystickPreferenceController.displayPreference(getPreferenceScreen());
|
||||
addPreferenceController(joystickPreferenceController);
|
||||
}
|
||||
|
@@ -17,10 +17,10 @@
|
||||
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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -56,38 +56,13 @@ public class MagnificationAlwaysOnPreferenceControllerTest {
|
||||
mSwitchPreference.setKey(MagnificationAlwaysOnPreferenceController.PREF_KEY);
|
||||
screen.addPreference(mSwitchPreference);
|
||||
mController.displayPreference(screen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_defaultStateForAlwaysOn_onResumeShouldReturnTrue() {
|
||||
mController.onResume();
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_enableAlwaysOn_onResumeShouldReturnTrue() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ALWAYS_ON, ON);
|
||||
mController.onResume();
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_disableAlwaysOn_onResumeShouldReturnFalse() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ALWAYS_ON, OFF);
|
||||
mController.onResume();
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
||||
mController.updateState(mSwitchPreference);
|
||||
reset(mSwitchPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performClick_switchDefaultStateForAlwaysOn_shouldReturnFalse() {
|
||||
mController.onResume();
|
||||
|
||||
mSwitchPreference.performClick();
|
||||
|
||||
verify(mSwitchPreference).setChecked(false);
|
||||
@@ -99,7 +74,7 @@ public class MagnificationAlwaysOnPreferenceControllerTest {
|
||||
public void updateState_disableAlwaysOn_shouldReturnFalse() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ALWAYS_ON, OFF);
|
||||
|
||||
mController.updateState();
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
verify(mSwitchPreference).setChecked(false);
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
|
@@ -17,10 +17,10 @@
|
||||
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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -56,38 +56,13 @@ public class MagnificationFollowTypingPreferenceControllerTest {
|
||||
mSwitchPreference.setKey(MagnificationFollowTypingPreferenceController.PREF_KEY);
|
||||
screen.addPreference(mSwitchPreference);
|
||||
mController.displayPreference(screen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_defaultStateForFollowTyping_onResumeShouldReturnTrue() {
|
||||
mController.onResume();
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_enableFollowTyping_onResumeShouldReturnTrue() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_FOLLOW_TYPING, ON);
|
||||
mController.onResume();
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_disableFollowTyping_onResumeShouldReturnFalse() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_FOLLOW_TYPING, OFF);
|
||||
mController.onResume();
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
||||
mController.updateState(mSwitchPreference);
|
||||
reset(mSwitchPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performClick_switchDefaultStateForFollowTyping_shouldReturnFalse() {
|
||||
mController.onResume();
|
||||
|
||||
mSwitchPreference.performClick();
|
||||
|
||||
verify(mSwitchPreference).setChecked(false);
|
||||
@@ -99,7 +74,7 @@ public class MagnificationFollowTypingPreferenceControllerTest {
|
||||
public void updateState_disableFollowTyping_shouldReturnFalse() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_FOLLOW_TYPING, OFF);
|
||||
|
||||
mController.updateState();
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
verify(mSwitchPreference).setChecked(false);
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
|
@@ -17,10 +17,10 @@
|
||||
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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -56,38 +56,13 @@ public class MagnificationJoystickPreferenceControllerTest {
|
||||
mSwitchPreference.setKey(MagnificationJoystickPreferenceController.PREF_KEY);
|
||||
screen.addPreference(mSwitchPreference);
|
||||
mController.displayPreference(screen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_defaultStateForJoystick_onResumeShouldReturnFalse() {
|
||||
mController.onResume();
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_enableJoystick_onResumeShouldReturnTrue() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_JOYSTICK, ON);
|
||||
mController.onResume();
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
assertThat(mSwitchPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_disableJoystick_onResumeShouldReturnFalse() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_JOYSTICK, OFF);
|
||||
mController.onResume();
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
assertThat(mSwitchPreference.isChecked()).isFalse();
|
||||
mController.updateState(mSwitchPreference);
|
||||
reset(mSwitchPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void performClick_switchDefaultStateForJoystick_shouldReturnTrue() {
|
||||
mController.onResume();
|
||||
|
||||
mSwitchPreference.performClick();
|
||||
|
||||
verify(mSwitchPreference).setChecked(true);
|
||||
@@ -99,7 +74,7 @@ public class MagnificationJoystickPreferenceControllerTest {
|
||||
public void updateState_disableJoystick_shouldReturnFalse() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_JOYSTICK, OFF);
|
||||
|
||||
mController.updateState();
|
||||
mController.updateState(mSwitchPreference);
|
||||
|
||||
verify(mSwitchPreference).setChecked(false);
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
|
@@ -90,7 +90,6 @@ public class MagnificationModePreferenceControllerTest {
|
||||
mModePreference.getOnPreferenceClickListener().onPreferenceClick(mModePreference);
|
||||
|
||||
assertThat(getCheckedModeFromDialog()).isEqualTo(MAGNIFICATION_MODE_DEFAULT);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -19,6 +19,7 @@ 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.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
import static com.android.settings.accessibility.MagnificationCapabilities.MagnificationMode;
|
||||
import static com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_SAVED_USER_SHORTCUT_TYPE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -43,9 +44,11 @@ import android.os.Bundle;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
@@ -54,12 +57,14 @@ import com.android.settings.DialogCreatable;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.accessibility.AccessibilityDialogUtils.DialogType;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
import com.android.settings.testutils.shadow.ShadowStorageManager;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
|
||||
import com.google.common.truth.Correspondence;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -82,6 +87,7 @@ import java.util.List;
|
||||
ShadowUserManager.class,
|
||||
ShadowStorageManager.class,
|
||||
ShadowSettings.ShadowSecure.class,
|
||||
ShadowDeviceConfig.class,
|
||||
})
|
||||
public class ToggleScreenMagnificationPreferenceFragmentTest {
|
||||
|
||||
@@ -109,6 +115,11 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
||||
|
||||
private static final String KEY_FOLLOW_TYPING =
|
||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_FOLLOW_TYPING_ENABLED;
|
||||
private static final String KEY_ALWAYS_ON =
|
||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_ALWAYS_ON_ENABLED;
|
||||
private static final String KEY_JOYSTICK =
|
||||
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_JOYSTICK_ENABLED;
|
||||
|
||||
private FragmentController<ToggleScreenMagnificationPreferenceFragment> mFragController;
|
||||
private Context mContext;
|
||||
private Resources mSpyResources;
|
||||
@@ -137,15 +148,48 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
||||
mFragController = FragmentController.of(fragment, SettingsActivity.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowDeviceConfig.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_defaultStateForMagnificationMode_preferenceShouldReturnFullScreen() {
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
// Default is MagnificationMode.FULLSCREEN
|
||||
final String expected =
|
||||
MagnificationCapabilities.getSummary(mContext, MagnificationMode.FULLSCREEN);
|
||||
|
||||
final Preference preference = mFragController.get().findPreference(
|
||||
MagnificationModePreferenceController.PREF_KEY);
|
||||
assertThat(preference).isNotNull();
|
||||
assertThat(preference.getSummary()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_setMagnificationModeToAll_preferenceShouldReturnAll() {
|
||||
setKeyMagnificationMode(MagnificationMode.ALL);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final String expected =
|
||||
MagnificationCapabilities.getSummary(mContext, MagnificationMode.ALL);
|
||||
|
||||
final Preference preference = mFragController.get().findPreference(
|
||||
MagnificationModePreferenceController.PREF_KEY);
|
||||
assertThat(preference).isNotNull();
|
||||
assertThat(preference.getSummary()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_defaultStateForFollowingTyping_switchPreferenceShouldReturnTrue() {
|
||||
setKeyFollowTypingEnabled(true);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference =
|
||||
mFragController.get().findPreference(
|
||||
MagnificationFollowTypingPreferenceController.PREF_KEY);
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationFollowTypingPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNotNull();
|
||||
assertThat(switchPreference.isChecked()).isTrue();
|
||||
}
|
||||
@@ -156,9 +200,84 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference =
|
||||
mFragController.get().findPreference(
|
||||
MagnificationFollowTypingPreferenceController.PREF_KEY);
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationFollowTypingPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNotNull();
|
||||
assertThat(switchPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_defaultStateForAlwaysOn_switchPreferenceShouldReturnTrue() {
|
||||
setAlwaysOnSupported(true);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationAlwaysOnPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNotNull();
|
||||
assertThat(switchPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_enableAlwaysOn_switchPreferenceShouldReturnTrue() {
|
||||
setAlwaysOnSupported(true);
|
||||
setKeyAlwaysOnEnabled(true);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationAlwaysOnPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNotNull();
|
||||
assertThat(switchPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_disableAlwaysOn_switchPreferenceShouldReturnFalse() {
|
||||
setAlwaysOnSupported(true);
|
||||
setKeyAlwaysOnEnabled(false);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationAlwaysOnPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNotNull();
|
||||
assertThat(switchPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_defaultStateForJoystick_switchPreferenceShouldReturnFalse() {
|
||||
setJoystickSupported(true);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationJoystickPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNotNull();
|
||||
assertThat(switchPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_enableJoystick_switchPreferenceShouldReturnTrue() {
|
||||
setJoystickSupported(true);
|
||||
setKeyJoystickEnabled(true);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationJoystickPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNotNull();
|
||||
assertThat(switchPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_disableJoystick_switchPreferenceShouldReturnFalse() {
|
||||
setJoystickSupported(true);
|
||||
setKeyJoystickEnabled(false);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationJoystickPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNotNull();
|
||||
assertThat(switchPreference.isChecked()).isFalse();
|
||||
}
|
||||
@@ -556,6 +675,28 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
||||
assertThat(mFragController.get().mSettingsPreference).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateView_alwaysOnNotSupported_settingsPreferenceIsNull() {
|
||||
setAlwaysOnSupported(false);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationAlwaysOnPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateView_joystickNotSupported_settingsPreferenceIsNull() {
|
||||
setJoystickSupported(false);
|
||||
|
||||
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
|
||||
|
||||
final TwoStatePreference switchPreference = mFragController.get().findPreference(
|
||||
MagnificationJoystickPreferenceController.PREF_KEY);
|
||||
assertThat(switchPreference).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateView_setDialogDelegateAndAddTheControllerToLifeCycleObserver() {
|
||||
Correspondence instanceOf = Correspondence.transforming(
|
||||
@@ -690,11 +831,41 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
|
||||
enabled ? ON : OFF);
|
||||
}
|
||||
|
||||
private void setKeyMagnificationMode(@MagnificationMode int mode) {
|
||||
MagnificationCapabilities.setCapabilities(mContext, mode);
|
||||
}
|
||||
|
||||
private void setKeyFollowTypingEnabled(boolean enabled) {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_FOLLOW_TYPING,
|
||||
enabled ? ON : OFF);
|
||||
}
|
||||
|
||||
private void setAlwaysOnSupported(boolean supported) {
|
||||
ShadowDeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
||||
"AlwaysOnMagnifier__enable_always_on_magnifier",
|
||||
supported ? "true" : "false",
|
||||
/* makeDefault= */ false);
|
||||
}
|
||||
|
||||
private void setKeyAlwaysOnEnabled(boolean enabled) {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_ALWAYS_ON,
|
||||
enabled ? ON : OFF);
|
||||
}
|
||||
|
||||
private void setJoystickSupported(boolean supported) {
|
||||
ShadowDeviceConfig.setProperty(
|
||||
DeviceConfig.NAMESPACE_WINDOW_MANAGER,
|
||||
"MagnificationJoystick__enable_magnification_joystick",
|
||||
supported ? "true" : "false",
|
||||
/* makeDefault= */ false);
|
||||
}
|
||||
|
||||
private void setKeyJoystickEnabled(boolean enabled) {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), KEY_JOYSTICK,
|
||||
enabled ? ON : OFF);
|
||||
}
|
||||
|
||||
private String getStringFromSettings(String key) {
|
||||
return Settings.Secure.getString(mContext.getContentResolver(), key);
|
||||
}
|
||||
|
Reference in New Issue
Block a user