ConfirmationDialog: Pass accessibility options and implement isSupported().

Bug: 63928580
Test: Manually tested.
Change-Id: I6a06d10a4cb924c3e57c8e212ba4626cad00f4a1
This commit is contained in:
David Zeuthen
2018-02-26 11:04:18 -05:00
parent c5f5ad103f
commit bbb7f65a23
2 changed files with 46 additions and 6 deletions

View File

@@ -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();
}
}

View File

@@ -783,6 +783,20 @@ public class KeyStore {
}
}
/**
* Requests keystore to check if the confirmationui HAL is available.
*
* @return whether the confirmationUI HAL is available.
*/
public boolean isConfirmationPromptSupported() {
try {
return mBinder.isConfirmationPromptSupported();
} catch (RemoteException e) {
Log.w(TAG, "Cannot connect to keystore", e);
return false;
}
}
/**
* Returns a {@link KeyStoreException} corresponding to the provided keystore/keymaster error
* code.