From bbb7f65a23937eeeabcc4caac5a3ea53ad836749 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 26 Feb 2018 11:04:18 -0500 Subject: ConfirmationDialog: Pass accessibility options and implement isSupported(). Bug: 63928580 Test: Manually tested. Change-Id: I6a06d10a4cb924c3e57c8e212ba4626cad00f4a1 --- core/java/android/security/ConfirmationDialog.java | 38 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'core/java/android/security/ConfirmationDialog.java') diff --git a/core/java/android/security/ConfirmationDialog.java b/core/java/android/security/ConfirmationDialog.java index e9df3705db6e..f6127e184139 100644 --- a/core/java/android/security/ConfirmationDialog.java +++ b/core/java/android/security/ConfirmationDialog.java @@ -17,7 +17,10 @@ package android.security; import android.annotation.NonNull; +import android.content.ContentResolver; import android.content.Context; +import android.provider.Settings; +import android.provider.Settings.SettingNotFoundException; import android.text.TextUtils; import android.util.Log; @@ -86,6 +89,7 @@ public class ConfirmationDialog { private byte[] mExtraData; private ConfirmationCallback mCallback; private Executor mExecutor; + private Context mContext; private final KeyStore mKeyStore = KeyStore.getInstance(); @@ -190,15 +194,39 @@ public class ConfirmationDialog { if (mExtraData == null) { throw new IllegalArgumentException("extraData must be set"); } - return new ConfirmationDialog(mPromptText, mExtraData); + return new ConfirmationDialog(context, mPromptText, mExtraData); } } - private ConfirmationDialog(CharSequence promptText, byte[] extraData) { + private ConfirmationDialog(Context context, CharSequence promptText, byte[] extraData) { + mContext = context; mPromptText = promptText; mExtraData = extraData; } + private static final int UI_OPTION_ACCESSIBILITY_INVERTED_FLAG = 1 << 0; + private static final int UI_OPTION_ACCESSIBILITY_MAGNIFIED_FLAG = 1 << 1; + + private int getUiOptionsAsFlags() { + int uiOptionsAsFlags = 0; + try { + ContentResolver contentResolver = mContext.getContentResolver(); + int inversionEnabled = Settings.Secure.getInt(contentResolver, + Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED); + if (inversionEnabled == 1) { + uiOptionsAsFlags |= UI_OPTION_ACCESSIBILITY_INVERTED_FLAG; + } + float fontScale = Settings.System.getFloat(contentResolver, + Settings.System.FONT_SCALE); + if (fontScale > 1.0) { + uiOptionsAsFlags |= UI_OPTION_ACCESSIBILITY_MAGNIFIED_FLAG; + } + } catch (SettingNotFoundException e) { + Log.w(TAG, "Unexpected SettingNotFoundException"); + } + return uiOptionsAsFlags; + } + /** * Requests a confirmation prompt to be presented to the user. * @@ -220,8 +248,7 @@ public class ConfirmationDialog { mCallback = callback; mExecutor = executor; - int uiOptionsAsFlags = 0; - // TODO: set AccessibilityInverted, AccessibilityMagnified in uiOptionsAsFlags as needed. + int uiOptionsAsFlags = getUiOptionsAsFlags(); String locale = Locale.getDefault().toLanguageTag(); int responseCode = mKeyStore.presentConfirmationPrompt( mCallbackBinder, mPromptText.toString(), mExtraData, locale, uiOptionsAsFlags); @@ -277,7 +304,6 @@ public class ConfirmationDialog { * @return true if confirmation prompts are supported by the device. */ public static boolean isSupported() { - // TODO: read and return system property. - return true; + return KeyStore.getInstance().isConfirmationPromptSupported(); } } -- cgit v1.2.3