Settings crash if android:settingsActivity AccessibilityServiceInfo XML is incorrect.
1. The code was not checking whether the settings activity exists before passing in to the SettingCheckboxClass. bug:5038386 Change-Id: Iba4f5e2e5f6f3ed9c0fed5a5103d2e9a34399d97
This commit is contained in:
@@ -51,6 +51,7 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class AccessibilitySettings extends SettingsPreferenceFragment implements DialogCreatable,
|
public class AccessibilitySettings extends SettingsPreferenceFragment implements DialogCreatable,
|
||||||
Preference.OnPreferenceChangeListener {
|
Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
private static final String DEFAULT_SCREENREADER_MARKET_LINK =
|
private static final String DEFAULT_SCREENREADER_MARKET_LINK =
|
||||||
"market://search?q=pname:com.google.android.marvin.talkback";
|
"market://search?q=pname:com.google.android.marvin.talkback";
|
||||||
|
|
||||||
@@ -362,7 +363,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
private void persistEnabledAccessibilityServices() {
|
private void persistEnabledAccessibilityServices() {
|
||||||
StringBuilder builder = new StringBuilder(256);
|
StringBuilder builder = new StringBuilder(256);
|
||||||
|
|
||||||
int firstEnabled = -1;
|
|
||||||
for (String key : mAccessibilityServices.keySet()) {
|
for (String key : mAccessibilityServices.keySet()) {
|
||||||
CheckBoxPreference preference = (CheckBoxPreference) findPreference(key);
|
CheckBoxPreference preference = (CheckBoxPreference) findPreference(key);
|
||||||
if (preference.isChecked()) {
|
if (preference.isChecked()) {
|
||||||
@@ -399,16 +399,18 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
String key = accessibilityServiceInfo.getId();
|
String key = accessibilityServiceInfo.getId();
|
||||||
|
|
||||||
if (mAccessibilityServices.put(key, accessibilityServiceInfo) == null) {
|
if (mAccessibilityServices.put(key, accessibilityServiceInfo) == null) {
|
||||||
String settingsActivityName = accessibilityServiceInfo.getSettingsActivityName();
|
SettingsCheckBoxPreference preference = null;
|
||||||
Intent settingsIntent = null;
|
Intent settingsIntent = null;
|
||||||
|
String settingsActivityName = accessibilityServiceInfo.getSettingsActivityName();
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(settingsActivityName)) {
|
if (!TextUtils.isEmpty(settingsActivityName)) {
|
||||||
String packageName = accessibilityServiceInfo.getResolveInfo()
|
|
||||||
.serviceInfo.packageName;
|
|
||||||
settingsIntent = new Intent(Intent.ACTION_MAIN);
|
settingsIntent = new Intent(Intent.ACTION_MAIN);
|
||||||
settingsIntent.setClassName(packageName, settingsActivityName);
|
settingsIntent.setClassName(
|
||||||
|
accessibilityServiceInfo.getResolveInfo().serviceInfo.packageName,
|
||||||
|
settingsActivityName);
|
||||||
}
|
}
|
||||||
SettingsCheckBoxPreference preference = new SettingsCheckBoxPreference(
|
|
||||||
getActivity(), settingsIntent);
|
preference = new SettingsCheckBoxPreference(getActivity(), settingsIntent);
|
||||||
preference.setKey(key);
|
preference.setKey(key);
|
||||||
preference.setOrder(i);
|
preference.setOrder(i);
|
||||||
ServiceInfo serviceInfo = accessibilityServiceInfo.getResolveInfo().serviceInfo;
|
ServiceInfo serviceInfo = accessibilityServiceInfo.getResolveInfo().serviceInfo;
|
||||||
|
@@ -38,14 +38,15 @@ public class SettingsCheckBoxPreference extends CheckBoxPreference {
|
|||||||
private final Intent mSettingsIntent;
|
private final Intent mSettingsIntent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance. The constructor is checking whether the
|
||||||
|
* settings intent is resolved to an activity and acts accordingly.
|
||||||
*
|
*
|
||||||
* @param context Context for accessing resources.
|
* @param context Context for accessing resources.
|
||||||
* @param settingsIntent Intent to use as settings for the item represented by
|
* @param intent Intent to use as settings for the item represented by
|
||||||
* this preference. Pass <code>null</code> if there is no associated
|
* this preference. Pass <code>null</code> if there is no associated
|
||||||
* settings activity.
|
* settings activity.
|
||||||
*/
|
*/
|
||||||
public SettingsCheckBoxPreference(Context context, Intent settingsIntent) {
|
public SettingsCheckBoxPreference(Context context, Intent intent) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
if (sDimAlpha == Integer.MIN_VALUE) {
|
if (sDimAlpha == Integer.MIN_VALUE) {
|
||||||
@@ -54,7 +55,13 @@ public class SettingsCheckBoxPreference extends CheckBoxPreference {
|
|||||||
sDimAlpha = (int) (outValue.getFloat() * 255);
|
sDimAlpha = (int) (outValue.getFloat() * 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
mSettingsIntent = settingsIntent;
|
if (intent != null
|
||||||
|
&& !context.getPackageManager().queryIntentActivities(intent, 0).isEmpty()) {
|
||||||
|
mSettingsIntent = intent;
|
||||||
|
} else {
|
||||||
|
mSettingsIntent = null;
|
||||||
|
}
|
||||||
|
|
||||||
setWidgetLayoutResource(R.layout.preference_settings_checkbox_widget);
|
setWidgetLayoutResource(R.layout.preference_settings_checkbox_widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user