Accessibility shortcut secondary action - correct magnification shortcut logic
- correct magnification shortcut logic - add magnification tests Bug: 142530063 Test: make RunSettingsRoboTests -j52 ROBOTEST_FILTER=ToggleScreenMagnificationPreferenceFragmentTest Change-Id: I15f8bccde63570e93e28399bc1730fb1afdb1242
This commit is contained in:
@@ -46,6 +46,7 @@ import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
|
||||
@@ -509,7 +510,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
int EDIT_SHORTCUT = 3;
|
||||
}
|
||||
|
||||
private static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) {
|
||||
@VisibleForTesting
|
||||
static void optInAllMagnificationValuesToSettings(Context context, int shortcutTypes) {
|
||||
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||
optInMagnificationValueToSettings(context, UserShortcutType.SOFTWARE);
|
||||
}
|
||||
@@ -532,7 +534,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
}
|
||||
|
||||
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
|
||||
if (TextUtils.isEmpty(targetString)) {
|
||||
if (!TextUtils.isEmpty(targetString)) {
|
||||
joiner.add(targetString);
|
||||
}
|
||||
joiner.add(MAGNIFICATION_CONTROLLER_NAME);
|
||||
@@ -540,7 +542,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
|
||||
}
|
||||
|
||||
private static void optOutAllMagnificationValuesFromSettings(Context context,
|
||||
@VisibleForTesting
|
||||
static void optOutAllMagnificationValuesFromSettings(Context context,
|
||||
int shortcutTypes) {
|
||||
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||
optOutMagnificationValueFromSettings(context, UserShortcutType.SOFTWARE);
|
||||
@@ -576,7 +579,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
|
||||
}
|
||||
|
||||
private static boolean hasMagnificationValuesInSettings(Context context, int shortcutTypes) {
|
||||
@VisibleForTesting
|
||||
static boolean hasMagnificationValuesInSettings(Context context, int shortcutTypes) {
|
||||
boolean exist = false;
|
||||
|
||||
if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
|
||||
|
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.UserShortcutType;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ToggleScreenMagnificationPreferenceFragmentTest {
|
||||
|
||||
private static final String DUMMY_PACKAGE_NAME = "com.dummy.example";
|
||||
private static final String DUMMY_CLASS_NAME = DUMMY_PACKAGE_NAME + ".dummy_a11y_service";
|
||||
private static final ComponentName DUMMY_COMPONENT_NAME = new ComponentName(DUMMY_PACKAGE_NAME,
|
||||
DUMMY_CLASS_NAME);
|
||||
private static final String SOFTWARE_SHORTCUT_KEY =
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
|
||||
private static final String HARDWARE_SHORTCUT_KEY =
|
||||
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
|
||||
private static final String TRIPLETAP_SHORTCUT_KEY =
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED;
|
||||
private static final String MAGNIFICATION_CONTROLLER_NAME =
|
||||
"com.android.server.accessibility.MagnificationController";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasValueInSettings_putValue_hasValue() {
|
||||
putStringIntoSettings(TRIPLETAP_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
||||
|
||||
assertThat(ToggleScreenMagnificationPreferenceFragment.hasMagnificationValuesInSettings(
|
||||
mContext, UserShortcutType.TRIPLETAP)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optInAllValuesToSettings_optInValue_haveMatchString() {
|
||||
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.TRIPLETAP;
|
||||
|
||||
ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext,
|
||||
shortcutTypes);
|
||||
|
||||
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
|
||||
MAGNIFICATION_CONTROLLER_NAME);
|
||||
assertThat(getStringFromSettings(TRIPLETAP_SHORTCUT_KEY)).isEqualTo(
|
||||
MAGNIFICATION_CONTROLLER_NAME);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optInAllValuesToSettings_existOtherValue_optInValue_haveMatchString() {
|
||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, DUMMY_COMPONENT_NAME.flattenToString());
|
||||
|
||||
ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext,
|
||||
UserShortcutType.SOFTWARE);
|
||||
|
||||
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
|
||||
DUMMY_COMPONENT_NAME.flattenToString() + ":" + MAGNIFICATION_CONTROLLER_NAME);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optOutAllValuesToSettings_optOutValue_emptyString() {
|
||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
||||
putStringIntoSettings(HARDWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
||||
putStringIntoSettings(TRIPLETAP_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
|
||||
int shortcutTypes =
|
||||
UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE | UserShortcutType.TRIPLETAP;
|
||||
|
||||
ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings(
|
||||
mContext, shortcutTypes);
|
||||
|
||||
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEmpty();
|
||||
assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEmpty();
|
||||
assertThat(getStringFromSettings(TRIPLETAP_SHORTCUT_KEY)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optOutValueFromSettings_existOtherValue_optOutValue_haveMatchString() {
|
||||
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY,
|
||||
DUMMY_COMPONENT_NAME.flattenToString() + ":" + MAGNIFICATION_CONTROLLER_NAME);
|
||||
putStringIntoSettings(HARDWARE_SHORTCUT_KEY,
|
||||
DUMMY_COMPONENT_NAME.flattenToString() + ":" + MAGNIFICATION_CONTROLLER_NAME);
|
||||
int shortcutTypes = UserShortcutType.SOFTWARE | UserShortcutType.HARDWARE;
|
||||
|
||||
ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings(
|
||||
mContext, shortcutTypes);
|
||||
|
||||
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
|
||||
DUMMY_COMPONENT_NAME.flattenToString());
|
||||
assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEqualTo(
|
||||
DUMMY_COMPONENT_NAME.flattenToString());
|
||||
}
|
||||
|
||||
private void putStringIntoSettings(String key, String componentName) {
|
||||
Settings.Secure.putString(mContext.getContentResolver(), key, componentName);
|
||||
}
|
||||
|
||||
private String getStringFromSettings(String key) {
|
||||
return Settings.Secure.getString(mContext.getContentResolver(), key);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user