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

Commit 240bbb0b authored by Daniel Norman's avatar Daniel Norman
Browse files

Removes type SYSTEM_ALERT_DIALOG from the A11yService warning dialog.

This type is unnecessary and causes unpleasant UX when the user attempts
to go home or open recent apps while the dialog is showing.

This does not affect the touch-consuming property of the dialog, so it
should still prevent interaction while another window is drawing over
it (FLAG_WINDOW_IS_OBSCURED/FLAG_WINDOW_IS_PARTIALLY_OBSCURED).

Bug: 336719951
Flag: android.view.accessibility.warning_use_default_dialog_type
Test: atest AccessibilityServiceWarningTest
Test: Observe that the dialog still works as expected, both when
      triggered by the Settings app and when triggered by the bespoke
      volume key shortcut editor.
Test: Observe that the dialog minimizes with the app window while
      switching apps.
Change-Id: Iaefd299b94df9cefd7fb5fbb4239c174d7bf7a63
parent 562064be
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -210,3 +210,13 @@ flag {
    description: "Feature flag for declaring system pinch zoom opt-out apis"
    bug: "315089687"
}

flag {
    name: "warning_use_default_dialog_type"
    namespace: "accessibility"
    description: "Uses the default type for the A11yService warning dialog, instead of SYSTEM_ALERT_DIALOG"
    bug: "336719951"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.accessibility.Flags;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
@@ -64,7 +65,9 @@ public class AccessibilityServiceWarning {
        Window window = ad.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.privateFlags |= SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
        if (!Flags.warningUseDefaultDialogType()) {
            params.type = WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
        }
        window.setAttributes(params);
        return ad;
    }
+21 −2
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.AlertDialog;
import android.content.Context;
import android.os.RemoteException;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.testing.AndroidTestingRunner;
@@ -33,6 +35,7 @@ import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.accessibility.Flags;
import android.widget.TextView;

import androidx.test.platform.app.InstrumentationRegistry;
@@ -89,7 +92,19 @@ public class AccessibilityServiceWarningTest {
    }

    @Test
    public void createAccessibilityServiceWarningDialog_hasExpectedWindowParams() {
    @RequiresFlagsDisabled(Flags.FLAG_WARNING_USE_DEFAULT_DIALOG_TYPE)
    public void createAccessibilityServiceWarningDialog_hasExpectedWindowParams_isSystemDialog() {
        createAccessibilityServiceWarningDialog_hasExpectedWindowParams(true);
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_WARNING_USE_DEFAULT_DIALOG_TYPE)
    public void createAccessibilityServiceWarningDialog_hasExpectedWindowParams_notSystemDialog() {
        createAccessibilityServiceWarningDialog_hasExpectedWindowParams(false);
    }

    private void createAccessibilityServiceWarningDialog_hasExpectedWindowParams(
            boolean expectSystemDialog) {
        final AlertDialog dialog =
                AccessibilityServiceWarning.createAccessibilityServiceWarningDialog(
                        mContext,
@@ -101,7 +116,11 @@ public class AccessibilityServiceWarningTest {
        expect.that(dialogWindow.getAttributes().privateFlags
                & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS).isEqualTo(
                SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
        if (expectSystemDialog) {
            expect.that(dialogWindow.getAttributes().type).isEqualTo(TYPE_SYSTEM_DIALOG);
        } else {
            expect.that(dialogWindow.getAttributes().type).isNotEqualTo(TYPE_SYSTEM_DIALOG);
        }
    }

    @Test