From e3aad1c076cd5ac1b1c5496597bfce3619dd50ff Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 12 Mar 2018 16:47:03 -0400 Subject: [PATCH] ConfirmationDialog: Fail if accessibility services are running. As the confirmation dialog only has limited accessibility support it may not be usable by users requiring accessibility services. Therefore, if the user has enabled accessibility services, fail with ConfirmationNotAvailableException so the application can handle this case. Also document this behavior. Bug: 74545109 Test: Manually tested. Change-Id: Ibfb80d217f5cbdc9ec2f4e0432dfdd88add69703 --- .../android/security/ConfirmationDialog.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/java/android/security/ConfirmationDialog.java b/core/java/android/security/ConfirmationDialog.java index f6127e1841397..1697106c37822 100644 --- a/core/java/android/security/ConfirmationDialog.java +++ b/core/java/android/security/ConfirmationDialog.java @@ -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;