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

Commit 23c4fc41 authored by Jason Hsu's avatar Jason Hsu Committed by Android (Google) Code Review
Browse files

Merge changes from topic "accessibility_floating_menu_controller" into sc-dev

* changes:
  Set to accessibility floating menu mode when navigation mode is gestural
  Add the string for the accessibility floating menu tooltip
  Set default value of accessibility button mode
  Handle the phone get booted case to show accessibility floating menu
  Handle the basic logic to show or hide accessibility floating menu
  Observer for the accessibility button mode and notify its listeners for the changes
parents 8212a70a 37efae84
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -252,4 +252,8 @@

    <!-- Default for Settings.Global.DEVELOPMENT_ENABLE_NON_RESIZABLE_MULTI_WINDOW -->
    <bool name="def_enable_non_resizable_multi_window">true</bool>

    <!-- Default for Settings.Secure.ACCESSIBILITY_BUTTON_MODE -->
    <integer name="def_accessibility_button_mode">1</integer>

</resources>
+41 −1
Original line number Diff line number Diff line
@@ -3399,7 +3399,7 @@ public class SettingsProvider extends ContentProvider {
        }

        private final class UpgradeController {
            private static final int SETTINGS_VERSION = 198;
            private static final int SETTINGS_VERSION = 199;

            private final int mUserId;

@@ -4897,6 +4897,36 @@ public class SettingsProvider extends ContentProvider {
                    currentVersion = 198;
                }

                if (currentVersion == 198) {
                    // Version 198: Set the default value for accessibility button. If the user
                    // uses accessibility button in the navigation bar to trigger their
                    // accessibility features (check if ACCESSIBILITY_BUTTON_TARGETS has value)
                    // then leave accessibility button mode in the navigation bar, otherwise, set it
                    // to the floating menu.
                    final SettingsState secureSettings = getSecureSettingsLocked(userId);
                    final Setting accessibilityButtonMode = secureSettings.getSettingLocked(
                            Secure.ACCESSIBILITY_BUTTON_MODE);
                    if (accessibilityButtonMode.isNull()) {
                        if (isAccessibilityButtonInNavigationBarOn(secureSettings)) {
                            secureSettings.insertSettingLocked(Secure.ACCESSIBILITY_BUTTON_MODE,
                                    String.valueOf(
                                            Secure.ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR),
                                    /*tag= */ null, /* makeDefault= */ false,
                                    SettingsState.SYSTEM_PACKAGE_NAME);
                        } else {
                            final int defAccessibilityButtonMode =
                                    getContext().getResources().getInteger(
                                            R.integer.def_accessibility_button_mode);
                            secureSettings.insertSettingLocked(Secure.ACCESSIBILITY_BUTTON_MODE,
                                    String.valueOf(defAccessibilityButtonMode), /* tag= */
                                    null, /* makeDefault= */ true,
                                    SettingsState.SYSTEM_PACKAGE_NAME);
                        }
                    }

                    currentVersion = 199;
                }

                // vXXX: Add new settings above this point.

                if (currentVersion != newVersion) {
@@ -5075,5 +5105,15 @@ public class SettingsProvider extends ContentProvider {
            }
            return items;
        }

        private boolean isAccessibilityButtonInNavigationBarOn(SettingsState secureSettings) {
            final boolean hasValueInA11yBtnTargets = !TextUtils.isEmpty(
                    secureSettings.getSettingLocked(
                            Secure.ACCESSIBILITY_BUTTON_TARGETS).getValue());
            final int navigationMode = getContext().getResources().getInteger(
                    com.android.internal.R.integer.config_navBarInteractionMode);

            return hasValueInA11yBtnTargets && (navigationMode != NAV_BAR_MODE_GESTURAL);
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -2673,6 +2673,12 @@
    <!-- Click action label for magnification switch. [CHAR LIMIT=NONE] -->
    <string name="magnification_mode_switch_click_label">Switch</string>

    <!-- Accessibility floating menu strings -->
    <!-- Message for the accessibility floating button migration tooltip. It shows when the user use gestural navigation then upgrade their system. It will tell the user the accessibility gesture had been replaced by accessibility floating button. [CHAR LIMIT=100] -->
    <string name="accessibility_floating_button_migration_tooltip">Accessibility button replaced the accessibility gesture\n\n<annotation id="link">View settings</annotation></string>
    <!-- Message for the accessibility floating button docking tooltip. It shows when the user first time drag the button. It will tell the user about docking behavior. [CHAR LIMIT=70] -->
    <string name="accessibility_floating_button_docking_tooltip">Move button to the edge to hide it temporarily</string>

    <!-- Device Controls strings -->
    <!-- Device Controls empty state, title [CHAR LIMIT=30] -->
    <string name="quick_controls_title">Device controls</string>
+14 −0
Original line number Diff line number Diff line
@@ -34,6 +34,9 @@ import com.android.keyguard.KeyguardSecurityModel;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.keyguard.clock.ClockManager;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.systemui.accessibility.AccessibilityButtonModeObserver;
import com.android.systemui.accessibility.AccessibilityButtonTargetsObserver;
import com.android.systemui.accessibility.floatingmenu.AccessibilityFloatingMenuController;
import com.android.systemui.appops.AppOpsController;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.broadcast.BroadcastDispatcher;
@@ -284,6 +287,8 @@ public class Dependency {
    @Inject Lazy<IWindowManager> mIWindowManager;
    @Inject Lazy<OverviewProxyService> mOverviewProxyService;
    @Inject Lazy<NavigationModeController> mNavBarModeController;
    @Inject Lazy<AccessibilityButtonModeObserver> mAccessibilityButtonModeObserver;
    @Inject Lazy<AccessibilityButtonTargetsObserver> mAccessibilityButtonListController;
    @Inject Lazy<EnhancedEstimates> mEnhancedEstimates;
    @Inject Lazy<VibratorHelper> mVibratorHelper;
    @Inject Lazy<IStatusBarService> mIStatusBarService;
@@ -294,6 +299,7 @@ public class Dependency {
    @Inject Lazy<NotificationRemoteInputManager.Callback> mNotificationRemoteInputManagerCallback;
    @Inject Lazy<AppOpsController> mAppOpsController;
    @Inject Lazy<NavigationBarController> mNavigationBarController;
    @Inject Lazy<AccessibilityFloatingMenuController> mAccessibilityFloatingMenuController;
    @Inject Lazy<StatusBarStateController> mStatusBarStateController;
    @Inject Lazy<NotificationLockscreenUserManager> mNotificationLockscreenUserManager;
    @Inject Lazy<NotificationGroupAlertTransferHelper> mNotificationGroupAlertTransferHelper;
@@ -470,6 +476,11 @@ public class Dependency {

        mProviders.put(NavigationModeController.class, mNavBarModeController::get);

        mProviders.put(AccessibilityButtonModeObserver.class,
                mAccessibilityButtonModeObserver::get);
        mProviders.put(AccessibilityButtonTargetsObserver.class,
                mAccessibilityButtonListController::get);

        mProviders.put(EnhancedEstimates.class, mEnhancedEstimates::get);

        mProviders.put(VibratorHelper.class, mVibratorHelper::get);
@@ -489,6 +500,9 @@ public class Dependency {

        mProviders.put(NavigationBarController.class, mNavigationBarController::get);

        mProviders.put(AccessibilityFloatingMenuController.class,
                mAccessibilityFloatingMenuController::get);

        mProviders.put(StatusBarStateController.class, mStatusBarStateController::get);
        mProviders.put(NotificationLockscreenUserManager.class,
                mNotificationLockscreenUserManager::get);
+101 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.systemui.accessibility;

import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR;

import android.annotation.IntDef;
import android.annotation.MainThread;
import android.content.Context;
import android.provider.Settings;
import android.util.Log;

import com.android.systemui.dagger.SysUISingleton;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

import javax.inject.Inject;

/**
 * Observes changes of the accessibility button mode
 * {@link Settings.Secure#ACCESSIBILITY_BUTTON_MODE} and notify its listeners.
 */
@MainThread
@SysUISingleton
public class AccessibilityButtonModeObserver extends
        SecureSettingsContentObserver<AccessibilityButtonModeObserver.ModeChangedListener> {

    private static final String TAG = "A11yButtonModeObserver";

    private static final int ACCESSIBILITY_BUTTON_MODE_DEFAULT =
            ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
            ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR,
            ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU
    })
    public @interface AccessibilityButtonMode {}

    /** Listener for accessibility button mode changes. */
    public interface ModeChangedListener {

        /**
         * Called when accessibility button mode changes.
         *
         * @param mode Current accessibility button mode
         */
        void onAccessibilityButtonModeChanged(@AccessibilityButtonMode int mode);
    }

    @Inject
    public AccessibilityButtonModeObserver(Context context) {
        super(context, Settings.Secure.ACCESSIBILITY_BUTTON_MODE);
    }

    @Override
    void onValueChanged(ModeChangedListener listener, String value) {
        final int mode = parseAccessibilityButtonMode(value);
        listener.onAccessibilityButtonModeChanged(mode);
    }

    /**
     * Gets the current accessibility button mode from the current user's settings.
     *
     * See {@link Settings.Secure#ACCESSIBILITY_BUTTON_MODE}.
     */
    public int getCurrentAccessibilityButtonMode() {
        final String value = getSettingsValue();

        return parseAccessibilityButtonMode(value);
    }

    private int parseAccessibilityButtonMode(String value) {
        int mode;

        try {
            mode = Integer.parseInt(value);
        } catch (NumberFormatException e) {
            Log.e(TAG, "Invalid string for  " + e);
            mode = ACCESSIBILITY_BUTTON_MODE_DEFAULT;
        }

        return mode;
    }
}
Loading