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

Commit be3531a0 authored by Daniel Norman's avatar Daniel Norman
Browse files

Hides A11yMenu buttons that are restricted for the current user.

Bug: 347269196
Test: atest AccessibilityMenuServiceTest
Flag: com.android.systemui.accessibility.accessibilitymenu.hide_restricted_actions
Change-Id: I764c2a922bcd626b620fa9f45e5530d83ff3a069
parent ea96f6ba
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ android_app {
        "androidx.core_core",
        "androidx.preference_preference",
        "androidx.viewpager_viewpager",
        "com_android_systemui_flags_lib",
        "SettingsLibDisplayUtils",
        "SettingsLibSettingsTheme",
        "com_android_a11y_menu_flags_lib",
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
    package="com.android.systemui.accessibility.accessibilitymenu">

    <uses-permission android:name="android.permission.CONTROL_DISPLAY_BRIGHTNESS"/>
    <uses-permission android:name="android.permission.MANAGE_USERS"/>

    <application android:supportsRtl="true">
        <service
+10 −0
Original line number Diff line number Diff line
@@ -29,3 +29,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "hide_restricted_actions"
    namespace: "accessibility"
    description: "Hides shortcut buttons for possibly restricted actions like brightness/volume adjustment"
    bug: "347269196"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+40 −5
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.accessibility.accessibilitymenu.view;

import static android.os.UserManager.DISALLOW_ADJUST_VOLUME;
import static android.os.UserManager.DISALLOW_CONFIG_BRIGHTNESS;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.View.ACCESSIBILITY_LIVE_REGION_POLITE;
import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
@@ -24,6 +26,7 @@ import static java.lang.Math.max;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Insets;
@@ -32,6 +35,8 @@ import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.os.UserManager;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
@@ -48,6 +53,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;

import com.android.systemui.accessibility.accessibilitymenu.AccessibilityMenuService;
import com.android.systemui.accessibility.accessibilitymenu.Flags;
import com.android.systemui.accessibility.accessibilitymenu.R;
import com.android.systemui.accessibility.accessibilitymenu.activity.A11yMenuSettingsActivity.A11yMenuPreferenceFragment;
import com.android.systemui.accessibility.accessibilitymenu.model.A11yMenuShortcut;
@@ -94,8 +100,6 @@ public class A11yMenuOverlayLayout {
            A11yMenuShortcut.ShortcutId.ID_SCREENSHOT_VALUE.ordinal()
    };



    private final AccessibilityMenuService mService;
    private final WindowManager mWindowManager;
    private final DisplayManager mDisplayManager;
@@ -195,11 +199,43 @@ public class A11yMenuOverlayLayout {
        for (int shortcutId :
                (A11yMenuPreferenceFragment.isLargeButtonsEnabled(mService)
                        ? LARGE_SHORTCUT_LIST_DEFAULT : SHORTCUT_LIST_DEFAULT)) {
            if (!isShortcutRestricted(shortcutId)) {
                shortcutList.add(new A11yMenuShortcut(shortcutId));
            }
        }
        return shortcutList;
    }

    @SuppressLint("MissingPermission")
    private boolean isShortcutRestricted(int shortcutId) {
        if (!Flags.hideRestrictedActions()) {
            return false;
        }
        final UserManager userManager = mService.getSystemService(UserManager.class);
        if (userManager == null) {
            return false;
        }
        final int userId = mService.getUserId();
        final UserHandle userHandle = UserHandle.of(userId);
        if (shortcutId == A11yMenuShortcut.ShortcutId.ID_BRIGHTNESS_DOWN_VALUE.ordinal()
                || shortcutId == A11yMenuShortcut.ShortcutId.ID_BRIGHTNESS_UP_VALUE.ordinal()) {
            if (userManager.hasUserRestriction(DISALLOW_CONFIG_BRIGHTNESS)
                    || (com.android.systemui.Flags.enforceBrightnessBaseUserRestriction()
                    && userManager.hasBaseUserRestriction(
                            DISALLOW_CONFIG_BRIGHTNESS, userHandle))) {
                return true;
            }
        }
        if (shortcutId == A11yMenuShortcut.ShortcutId.ID_VOLUME_DOWN_VALUE.ordinal()
                || shortcutId == A11yMenuShortcut.ShortcutId.ID_VOLUME_UP_VALUE.ordinal()) {
            if (userManager.hasUserRestriction(DISALLOW_ADJUST_VOLUME)
                    || userManager.hasBaseUserRestriction(DISALLOW_ADJUST_VOLUME, userHandle)) {
                return true;
            }
        }
        return false;
    }

    /** Updates a11y menu layout position by configuring layout params. */
    private void updateLayoutPosition() {
        final Display display = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY);
@@ -326,8 +362,7 @@ public class A11yMenuOverlayLayout {
            return;
        }
        snackbar.setText(text);
        if (com.android.systemui.accessibility.accessibilitymenu
                .Flags.a11yMenuSnackbarLiveRegion()) {
        if (Flags.a11yMenuSnackbarLiveRegion()) {
            snackbar.setAccessibilityLiveRegion(ACCESSIBILITY_LIVE_REGION_POLITE);
        }

+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ android_test {
        "androidx.test.core",
        "androidx.test.runner",
        "androidx.test.ext.junit",
        "com_android_a11y_menu_flags_lib",
        "compatibility-device-util-axt",
        "platform-test-annotations",
        "truth",
Loading