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

Commit 40dff7cd authored by PETER LIANG's avatar PETER LIANG Committed by Android (Google) Code Review
Browse files

Merge "Migrate AccessibilityButtonChooserActivity into dialog folder and renaming." into rvc-dev

parents 3002b11f 8b7c9dad
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 * 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.
@@ -13,7 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.internal.app;
package com.android.internal.accessibility.dialog;

import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_BUTTON;
import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY;
@@ -79,9 +79,10 @@ import java.util.List;
import java.util.Locale;

/**
 * Activity used to display and persist a service or feature target for the Accessibility button.
 * Activity used to display various targets related to accessibility service, accessibility
 * activity or white listing feature for volume key shortcut.
 */
public class AccessibilityButtonChooserActivity extends Activity {
public class AccessibilityShortcutChooserActivity extends Activity {
    @ShortcutType
    private static int sShortcutType;
    @UserShortcutType
@@ -355,17 +356,18 @@ public class AccessibilityButtonChooserActivity extends Activity {
            ViewHolder holder;
            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(
                        R.layout.accessibility_button_chooser_item, parent, /* attachToRoot= */
                        R.layout.accessibility_shortcut_chooser_item, parent, /* attachToRoot= */
                        false);
                holder = new ViewHolder();
                holder.mItemView = convertView;
                holder.mCheckBox = convertView.findViewById(
                        R.id.accessibility_button_target_checkbox);
                holder.mIconView = convertView.findViewById(R.id.accessibility_button_target_icon);
                        R.id.accessibility_shortcut_target_checkbox);
                holder.mIconView = convertView.findViewById(
                        R.id.accessibility_shortcut_target_icon);
                holder.mLabelView = convertView.findViewById(
                        R.id.accessibility_button_target_label);
                        R.id.accessibility_shortcut_target_label);
                holder.mSwitchItem = convertView.findViewById(
                        R.id.accessibility_button_target_switch_item);
                        R.id.accessibility_shortcut_target_switch_item);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.android.internal.accessibility.common.ShortcutConstants.Access
import static com.android.internal.accessibility.common.ShortcutConstants.SERVICES_SEPARATOR;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.NonNull;
import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
@@ -115,7 +116,7 @@ public final class AccessibilityUtils {
     * @return int from {@link AccessibilityFragmentType}.
     */
    public static @AccessibilityFragmentType int getAccessibilityServiceFragmentType(
            AccessibilityServiceInfo accessibilityServiceInfo) {
            @NonNull AccessibilityServiceInfo accessibilityServiceInfo) {
        final int targetSdk = accessibilityServiceInfo.getResolveInfo()
                .serviceInfo.applicationInfo.targetSdkVersion;
        final boolean requestA11yButton = (accessibilityServiceInfo.flags
+23 −20
Original line number Diff line number Diff line
@@ -39,21 +39,21 @@ public final class ShortcutUtils {
            new TextUtils.SimpleStringSplitter(SERVICES_SEPARATOR);

    /**
     * Opts in component name into colon-separated {@link UserShortcutType}
     * key's string in Settings.
     * Opts in component id into colon-separated {@link UserShortcutType}
     * key's string from Settings.
     *
     * @param context The current context.
     * @param shortcutType The preferred shortcut type user selected.
     * @param componentId The component id that need to be opted out from Settings.
     * @param componentId The component id that need to be opted in Settings.
     */
    public static void optInValueToSettings(Context context, @UserShortcutType int shortcutType,
            String componentId) {
            @NonNull String componentId) {
        final StringJoiner joiner = new StringJoiner(String.valueOf(SERVICES_SEPARATOR));
        final String targetKey = convertToKey(shortcutType);
        final String targetString = Settings.Secure.getString(context.getContentResolver(),
                targetKey);

        if (hasValueInSettings(context, shortcutType, componentId)) {
        if (isComponentIdExistingInSettings(context, shortcutType, componentId)) {
            return;
        }

@@ -66,14 +66,15 @@ public final class ShortcutUtils {
    }

    /**
     * Opts out component name into colon-separated {@code shortcutType} key's string in Settings.
     * Opts out of component id into colon-separated {@link UserShortcutType} key's string from
     * Settings.
     *
     * @param context The current context.
     * @param shortcutType The preferred shortcut type user selected.
     * @param componentId The component id that need to be opted out from Settings.
     * @param componentId The component id that need to be opted out of Settings.
     */
    public static void optOutValueFromSettings(
            Context context, @UserShortcutType int shortcutType, String componentId) {
            Context context, @UserShortcutType int shortcutType, @NonNull String componentId) {
        final StringJoiner joiner = new StringJoiner(String.valueOf(SERVICES_SEPARATOR));
        final String targetsKey = convertToKey(shortcutType);
        final String targetsValue = Settings.Secure.getString(context.getContentResolver(),
@@ -96,36 +97,38 @@ public final class ShortcutUtils {
    }

    /**
     * Returns if component name existed in one of {@code shortcutTypes} string in Settings.
     * Returns if component id existed in one of {@link UserShortcutType} string from Settings.
     *
     * @param context The current context.
     * @param shortcutTypes A combination of {@link UserShortcutType}.
     * @param componentId The component name that need to be checked existed in Settings.
     * @return {@code true} if componentName existed in Settings.
     * @param componentId The component id that need to be checked existed in Settings.
     * @return {@code true} if component id existed in Settings.
     */
    public static boolean hasValuesInSettings(Context context, int shortcutTypes,
    public static boolean hasValuesInSettings(Context context, @UserShortcutType int shortcutTypes,
            @NonNull String componentId) {
        boolean exist = false;
        if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
            exist = hasValueInSettings(context, UserShortcutType.SOFTWARE, componentId);
            exist = isComponentIdExistingInSettings(context, UserShortcutType.SOFTWARE,
                    componentId);
        }
        if (((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE)) {
            exist |= hasValueInSettings(context, UserShortcutType.HARDWARE, componentId);
            exist |= isComponentIdExistingInSettings(context, UserShortcutType.HARDWARE,
                    componentId);
        }
        return exist;
    }


    /**
     * Returns if component name existed in Settings.
     * Returns if component id existed in Settings.
     *
     * @param context The current context.
     * @param shortcutType The preferred shortcut type user selected.
     * @param componentId The component id that need to be checked existed in Settings.
     * @return {@code true} if componentName existed in Settings.
     * @return {@code true} if component id existed in Settings.
     */
    public static boolean hasValueInSettings(Context context, @UserShortcutType int shortcutType,
            @NonNull String componentId) {
    public static boolean isComponentIdExistingInSettings(Context context,
            @UserShortcutType int shortcutType, @NonNull String componentId) {
        final String targetKey = convertToKey(shortcutType);
        final String targetString = Settings.Secure.getString(context.getContentResolver(),
                targetKey);
@@ -146,7 +149,7 @@ public final class ShortcutUtils {
    }

    /**
     * Converts {@link UserShortcutType} to key in Settings.
     * Converts {@link UserShortcutType} to {@link Settings.Secure} key.
     *
     * @param type The shortcut type.
     * @return Mapping key in Settings.
@@ -169,7 +172,7 @@ public final class ShortcutUtils {
     * Converts {@link ShortcutType} to {@link UserShortcutType}.
     *
     * @param type The shortcut type.
     * @return {@link UserShortcutType}.
     * @return Mapping type from {@link UserShortcutType}.
     */
    public static @UserShortcutType int convertToUserType(@ShortcutType int type) {
        switch (type) {
+1 −1
Original line number Diff line number Diff line
@@ -5060,7 +5060,7 @@
                <category android:name="android.intent.category.VOICE" />
            </intent-filter>
        </activity>
        <activity android:name="com.android.internal.app.AccessibilityButtonChooserActivity"
        <activity android:name="com.android.internal.accessibility.dialog.AccessibilityShortcutChooserActivity"
                  android:exported="false"
                  android:theme="@style/Theme.DeviceDefault.Dialog.Alert.DayNight"
                  android:finishOnCloseSystemDialogs="true"
+4 −4
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
    android:padding="16dp">

    <CheckBox
        android:id="@+id/accessibility_button_target_checkbox"
        android:id="@+id/accessibility_shortcut_target_checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingStart="16dp"
@@ -34,13 +34,13 @@
        android:visibility="gone"/>

    <ImageView
        android:id="@+id/accessibility_button_target_icon"
        android:id="@+id/accessibility_shortcut_target_icon"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:scaleType="fitCenter"/>

    <TextView
        android:id="@+id/accessibility_button_target_label"
        android:id="@+id/accessibility_shortcut_target_label"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
@@ -50,7 +50,7 @@
        android:fontFamily="sans-serif-medium"/>

    <Switch
        android:id="@+id/accessibility_button_target_switch_item"
        android:id="@+id/accessibility_shortcut_target_switch_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
Loading