Show a security warning dialog when switching a spell checker
Bug: 5402295 Change-Id: I021e6e923fa137248d23c8fa39e68afdf73fead9
This commit is contained in:
@@ -2568,6 +2568,13 @@ found in the list of installed apps.</string>
|
||||
card numbers. It comes from the app
|
||||
<xliff:g id="ime_application_name">%1$s</xliff:g>.
|
||||
Use this input method?</string>
|
||||
<!-- Warning message about security implications of enabling a spell checker, displayed as a dialog
|
||||
message when the user selects to enable a spell checker. -->
|
||||
<string name="spellchecker_security_warning">This spell checker may be able to collect
|
||||
all the text you type, including personal data like passwords and credit
|
||||
card numbers. It comes from the app
|
||||
<xliff:g id="spellchecker_application_name">%1$s</xliff:g>.
|
||||
Use this spell checker?</string>
|
||||
<!-- On Language & input settings screen, heading. Inside the "Language & input settings" screen, this is the header for settings that relate to mouse and trackpad devices. [CHAR LIMIT=40] -->
|
||||
<string name="pointer_settings_category">Mouse/trackpad</string>
|
||||
<!-- On Language & input settings screen, setting summary. Setting for mouse pointer speed. [CHAR LIMIT=35] -->
|
||||
|
@@ -38,7 +38,6 @@ import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
@@ -44,6 +44,7 @@ public class SingleSpellCheckerPreference extends Preference {
|
||||
private final SpellCheckersSettings mFragment;
|
||||
private final Resources mRes;
|
||||
private final TextServicesManager mTsm;
|
||||
private AlertDialog mDialog = null;
|
||||
private TextView mTitleText;
|
||||
private TextView mSummaryText;
|
||||
private View mPrefAll;
|
||||
@@ -127,6 +128,9 @@ public class SingleSpellCheckerPreference extends Preference {
|
||||
}
|
||||
|
||||
private void onSubtypeButtonClicked(View arg0) {
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(mFragment.getActivity());
|
||||
builder.setTitle(R.string.phone_language);
|
||||
final int size = mSpellCheckerInfo.getSubtypeCount();
|
||||
@@ -167,7 +171,8 @@ public class SingleSpellCheckerPreference extends Preference {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
mDialog = builder.create();
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
private void onSettingsButtonClicked(View arg0) {
|
||||
|
@@ -19,14 +19,16 @@ package com.android.settings.inputmethod;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
import android.view.textservice.SpellCheckerInfo;
|
||||
import android.view.textservice.SpellCheckerSubtype;
|
||||
import android.view.textservice.TextServicesManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -36,6 +38,7 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
|
||||
private static final String TAG = SpellCheckersSettings.class.getSimpleName();
|
||||
private static final boolean DBG = false;
|
||||
|
||||
private AlertDialog mDialog = null;
|
||||
private SpellCheckerInfo mCurrentSci;
|
||||
private SpellCheckerInfo[] mEnabledScis;
|
||||
private TextServicesManager mTsm;
|
||||
@@ -96,17 +99,61 @@ public class SpellCheckersSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference arg0) {
|
||||
public boolean onPreferenceClick(Preference pref) {
|
||||
SingleSpellCheckerPreference targetScp = null;
|
||||
for (SingleSpellCheckerPreference scp : mSpellCheckers) {
|
||||
if (arg0.equals(scp)) {
|
||||
if (pref.equals(scp)) {
|
||||
targetScp = scp;
|
||||
}
|
||||
}
|
||||
if (targetScp != null) {
|
||||
if (!isSystemApp(targetScp.getSpellCheckerInfo())) {
|
||||
showSecurityWarnDialog(targetScp);
|
||||
} else {
|
||||
changeCurrentSpellChecker(targetScp);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showSecurityWarnDialog(final SingleSpellCheckerPreference scp) {
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
mDialog = (new AlertDialog.Builder(getActivity()))
|
||||
.setTitle(android.R.string.dialog_alert_title)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
changeCurrentSpellChecker(scp);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
})
|
||||
.create();
|
||||
mDialog.setMessage(getResources().getString(R.string.spellchecker_security_warning,
|
||||
scp.getSpellCheckerInfo().getServiceInfo().applicationInfo.loadLabel(
|
||||
getActivity().getPackageManager())));
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
private void changeCurrentSpellChecker(SingleSpellCheckerPreference scp) {
|
||||
mTsm.setCurrentSpellChecker(scp.getSpellCheckerInfo());
|
||||
}
|
||||
}
|
||||
if (DBG) {
|
||||
Log.d(TAG, "Current spell check is "
|
||||
+ SpellCheckerUtils.getCurrentSpellChecker(mTsm).getId());
|
||||
}
|
||||
updateScreen();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isSystemApp(SpellCheckerInfo sci) {
|
||||
return (sci.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,6 @@ package com.android.settings.inputmethod;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.UserDictionarySettings;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import android.app.Activity;
|
||||
|
Reference in New Issue
Block a user