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

Commit f3f0683e authored by David Zeuthen's avatar David Zeuthen Committed by android-build-merger
Browse files

Merge "ConfirmationDialog: Fail if accessibility services are running." into pi-dev

am: b5736556

Change-Id: I5cc4ac36d980a4a0b6c202ddcba4ffb5433cd149
parents ff617929 b5736556
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -227,12 +227,32 @@ public class ConfirmationDialog {
        return uiOptionsAsFlags;
    }

    private boolean isAccessibilityServiceRunning() {
        boolean serviceRunning = false;
        try {
            ContentResolver contentResolver = mContext.getContentResolver();
            int a11yEnabled = Settings.Secure.getInt(contentResolver,
                    Settings.Secure.ACCESSIBILITY_ENABLED);
            if (a11yEnabled == 1) {
                serviceRunning = true;
            }
        } catch (SettingNotFoundException e) {
            Log.w(TAG, "Unexpected SettingNotFoundException");
            e.printStackTrace();
        }
        return serviceRunning;
    }

    /**
     * Requests a confirmation prompt to be presented to the user.
     *
     * When the prompt is no longer being presented, one of the methods in
     * {@link ConfirmationCallback} is called on the supplied callback object.
     *
     * Confirmation dialogs may not be available when accessibility services are running so this
     * may fail with a {@link ConfirmationNotAvailableException} exception even if
     * {@link #isSupported} returns {@code true}.
     *
     * @param executor the executor identifying the thread that will receive the callback.
     * @param callback the callback to use when the dialog is done showing.
     * @throws IllegalArgumentException if the prompt text is too long or malfomed.
@@ -245,6 +265,9 @@ public class ConfirmationDialog {
        if (mCallback != null) {
            throw new ConfirmationAlreadyPresentingException();
        }
        if (isAccessibilityServiceRunning()) {
            throw new ConfirmationNotAvailableException();
        }
        mCallback = callback;
        mExecutor = executor;