Disable non-permitted accessibility services and IMEs

Bug: 14469005
Change-Id: I4986f035318854c27ecb92bbe2f0c977d53b6361
This commit is contained in:
Kenny Guy
2014-08-21 13:20:21 +01:00
parent 10673f1a1e
commit 333f2bc71a
4 changed files with 47 additions and 6 deletions

View File

@@ -68,6 +68,7 @@ class InputMethodPreference extends SwitchPreference implements OnPreferenceClic
private final boolean mHasPriorityInSorting;
private final OnSavePreferenceListener mOnSaveListener;
private final InputMethodSettingValuesWrapper mInputMethodSettingValues;
private final boolean mIsAllowedByOrganization;
private AlertDialog mDialog = null;
@@ -78,14 +79,18 @@ class InputMethodPreference extends SwitchPreference implements OnPreferenceClic
* @param imi The {@link InputMethodInfo} of this preference.
* @param isImeEnabler true if this preference is the IME enabler that has enable/disable
* switches for all available IMEs, not the list of enabled IMEs.
* @param isAllowedByOrganization false if the IME has been disabled by a device or profile
owner.
* @param onSaveListener The listener called when this preference has been changed and needs
* to save the state to shared preference.
*/
InputMethodPreference(final Context context, final InputMethodInfo imi,
final boolean isImeEnabler, final OnSavePreferenceListener onSaveListener) {
final boolean isImeEnabler, final boolean isAllowedByOrganization,
final OnSavePreferenceListener onSaveListener) {
super(context);
setPersistent(false);
mImi = imi;
mIsAllowedByOrganization = isAllowedByOrganization;
mOnSaveListener = onSaveListener;
if (!isImeEnabler) {
// Hide switch widget.
@@ -178,7 +183,7 @@ class InputMethodPreference extends SwitchPreference implements OnPreferenceClic
mImi, getContext());
// Only when this preference has a switch and an input method should be always enabled,
// this preference should be disabled to prevent accidentally disabling an input method.
setEnabled(!(isAlwaysChecked && isImeEnabler()));
setEnabled(!((isAlwaysChecked && isImeEnabler()) || (!mIsAllowedByOrganization)));
setChecked(mInputMethodSettingValues.isEnabledImi(mImi));
setSummary(getSummaryString());
}
@@ -189,6 +194,9 @@ class InputMethodPreference extends SwitchPreference implements OnPreferenceClic
private String getSummaryString() {
final Context context = getContext();
if (!mIsAllowedByOrganization) {
return context.getString(R.string.accessibility_feature_or_input_method_not_allowed);
}
final InputMethodManager imm = getInputMethodManager();
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(mImi, true);
final ArrayList<CharSequence> subtypeLabels = new ArrayList<>();