Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0e32a58 authored by Rhed Jao's avatar Rhed Jao Committed by Android (Google) Code Review
Browse files

Merge "Accessibility shortcut improvement (7/n)"

parents 3eb1980f f211ff6a
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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 android.provider.settings.validators;

import static android.provider.settings.validators.SettingsValidators.COMPONENT_NAME_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.PACKAGE_NAME_VALIDATOR;

import android.text.TextUtils;

/**
 * Ensure a restored value is a string in the format the accessibility shortcut system handles
 *
 * @hide
 */
public final class AccessibilityShortcutTargetListValidator extends ListValidator {
    public AccessibilityShortcutTargetListValidator() {
        super(":");
    }

    @Override
    protected boolean isEntryValid(String entry) {
        return !TextUtils.isEmpty(entry);
    }

    @Override
    protected boolean isItemValid(String item) {
        if (TextUtils.isEmpty(item)) {
            return false;
        }
        return (COMPONENT_NAME_VALIDATOR.validate(item) || PACKAGE_NAME_VALIDATOR.validate(item));
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ abstract class ListValidator implements Validator {
        if (!isEntryValid(value)) {
            return false;
        }
        String[] items = value.split(",");
        String[] items = value.split(mListSplitRegex);
        for (String item : items) {
            if (!isItemValid(item)) {
                return false;
+6 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.provider.settings.validators;

import static android.provider.settings.validators.SettingsValidators.ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.ANY_INTEGER_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.BOOLEAN_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.COLON_SEPARATED_COMPONENT_LIST_VALIDATOR;
@@ -71,10 +72,13 @@ public class SecureSettingsValidators {
        VALIDATORS.put(Secure.TOUCH_EXPLORATION_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(
                Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, NULLABLE_COMPONENT_NAME_VALIDATOR);
                Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
                ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR);
        // technically either ComponentName or class name, but there's proper value
        // validation at callsites, so allow any non-null string
        VALIDATORS.put(Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT, value -> value != null);
        VALIDATORS.put(
                Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT,
                ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_SHORTCUT_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, BOOLEAN_VALIDATOR);
+3 −0
Original line number Diff line number Diff line
@@ -204,4 +204,7 @@ public class SettingsValidators {
            new InclusiveIntegerRangeValidator(0, 100);

    static final Validator VIBRATION_INTENSITY_VALIDATOR = new InclusiveIntegerRangeValidator(0, 3);

    static final Validator ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR =
            new AccessibilityShortcutTargetListValidator();
}
+12 −0
Original line number Diff line number Diff line
@@ -296,6 +296,18 @@ public class SettingsValidatorsTest {
        assertFalse(SettingsValidators.TILE_LIST_VALIDATOR.validate(null));
    }

    @Test
    public void testAccessibilityShortcutTargetValidator() {
        assertTrue(SettingsValidators.ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR.validate(
                "com.google.android/.AccessibilityShortcutTarget"));
        assertTrue(SettingsValidators.ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR.validate(
                "com.google.android"));
        assertTrue(SettingsValidators.ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR.validate(
                "com.google.android/.AccessibilityShortcutTarget:com.google.android"));
        assertFalse(SettingsValidators.ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR.validate(
                "com.google.android/.AccessibilityShortcutTarget:com.google.@android"));
    }

    @Test
    public void ensureAllBackedUpGlobalSettingsHaveValidators() {
        String offenders = getOffenders(concat(GlobalSettings.SETTINGS_TO_BACKUP,