3244931 ANR while in settings attempting to enable Accessibility->Talkabout (IKXEVEREST-1847)
Change-Id: Ifea9324671d0e80a417f4b2fe6dbbe981f8b0679
This commit is contained in:
@@ -21,10 +21,7 @@ import android.app.Dialog;
|
|||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
@@ -51,7 +48,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
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";
|
||||||
|
|
||||||
private final String TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX =
|
private final String TOGGLE_ACCESSIBILITY_CHECKBOX =
|
||||||
"toggle_accessibility_service_checkbox";
|
"toggle_accessibility_service_checkbox";
|
||||||
|
|
||||||
private static final String ACCESSIBILITY_SERVICES_CATEGORY =
|
private static final String ACCESSIBILITY_SERVICES_CATEGORY =
|
||||||
@@ -63,9 +60,12 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
private static final String POWER_BUTTON_CATEGORY =
|
private static final String POWER_BUTTON_CATEGORY =
|
||||||
"power_button_category";
|
"power_button_category";
|
||||||
|
|
||||||
private final String POWER_BUTTON_ENDS_CALL_CHECKBOX =
|
private static final String POWER_BUTTON_ENDS_CALL_CHECKBOX =
|
||||||
"power_button_ends_call";
|
"power_button_ends_call";
|
||||||
|
|
||||||
|
private final String KEY_TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX =
|
||||||
|
"key_toggle_accessibility_service_checkbox";
|
||||||
|
|
||||||
private static final int DIALOG_ID_DISABLE_ACCESSIBILITY = 1;
|
private static final int DIALOG_ID_DISABLE_ACCESSIBILITY = 1;
|
||||||
private static final int DIALOG_ID_ENABLE_SCRIPT_INJECTION = 2;
|
private static final int DIALOG_ID_ENABLE_SCRIPT_INJECTION = 2;
|
||||||
private static final int DIALOG_ID_ENABLE_ACCESSIBILITY_SERVICE = 3;
|
private static final int DIALOG_ID_ENABLE_ACCESSIBILITY_SERVICE = 3;
|
||||||
@@ -96,7 +96,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
(PreferenceGroup) findPreference(ACCESSIBILITY_SERVICES_CATEGORY);
|
(PreferenceGroup) findPreference(ACCESSIBILITY_SERVICES_CATEGORY);
|
||||||
|
|
||||||
mToggleAccessibilityCheckBox = (CheckBoxPreference) findPreference(
|
mToggleAccessibilityCheckBox = (CheckBoxPreference) findPreference(
|
||||||
TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX);
|
TOGGLE_ACCESSIBILITY_CHECKBOX);
|
||||||
|
|
||||||
mToggleScriptInjectionCheckBox = (CheckBoxPreference) findPreference(
|
mToggleScriptInjectionCheckBox = (CheckBoxPreference) findPreference(
|
||||||
TOGGLE_ACCESSIBILITY_SCRIPT_INJECTION_CHECKBOX);
|
TOGGLE_ACCESSIBILITY_SCRIPT_INJECTION_CHECKBOX);
|
||||||
@@ -131,16 +131,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onPause();
|
|
||||||
|
|
||||||
persistEnabledAccessibilityServices();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
|
|
||||||
addAccessibilitServicePreferences();
|
addAccessibilitServicePreferences();
|
||||||
|
|
||||||
final HashSet<String> enabled = new HashSet<String>();
|
final HashSet<String> enabled = new HashSet<String>();
|
||||||
@@ -169,6 +160,9 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
if (!accessibilityServices.isEmpty()) {
|
if (!accessibilityServices.isEmpty()) {
|
||||||
if (serviceState == 1) {
|
if (serviceState == 1) {
|
||||||
mToggleAccessibilityCheckBox.setChecked(true);
|
mToggleAccessibilityCheckBox.setChecked(true);
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
restoreInstanceStrate(savedInstanceState);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setAccessibilityServicePreferencesState(false);
|
setAccessibilityServicePreferencesState(false);
|
||||||
}
|
}
|
||||||
@@ -182,7 +176,41 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
mToggleAccessibilityCheckBox.setEnabled(false);
|
mToggleAccessibilityCheckBox.setEnabled(false);
|
||||||
// Notify user that they do not have any accessibility apps
|
// Notify user that they do not have any accessibility apps
|
||||||
// installed and direct them to Market to get TalkBack
|
// installed and direct them to Market to get TalkBack
|
||||||
displayNoAppsAlert();
|
showDialog(DIALOG_ID_NO_ACCESSIBILITY_SERVICES);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
|
||||||
|
persistEnabledAccessibilityServices();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
if (mToggleAccessibilityServiceCheckBox != null) {
|
||||||
|
outState.putString(KEY_TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX,
|
||||||
|
mToggleAccessibilityServiceCheckBox.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restores the instance state from <code>savedInstanceState</code>.
|
||||||
|
*/
|
||||||
|
private void restoreInstanceStrate(Bundle savedInstanceState) {
|
||||||
|
String key = savedInstanceState.getString(KEY_TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX);
|
||||||
|
if (key != null) {
|
||||||
|
Preference preference = findPreference(key);
|
||||||
|
if (!(preference instanceof CheckBoxPreference)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
KEY_TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX
|
||||||
|
+ " must be mapped to an instance of a "
|
||||||
|
+ CheckBoxPreference.class.getName());
|
||||||
|
}
|
||||||
|
mToggleAccessibilityServiceCheckBox = (CheckBoxPreference) preference;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +236,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||||
final String key = preference.getKey();
|
final String key = preference.getKey();
|
||||||
|
|
||||||
if (TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX.equals(key)) {
|
if (TOGGLE_ACCESSIBILITY_CHECKBOX.equals(key)) {
|
||||||
handleEnableAccessibilityStateChange((CheckBoxPreference) preference);
|
handleEnableAccessibilityStateChange((CheckBoxPreference) preference);
|
||||||
} else if (POWER_BUTTON_ENDS_CALL_CHECKBOX.equals(key)) {
|
} else if (POWER_BUTTON_ENDS_CALL_CHECKBOX.equals(key)) {
|
||||||
boolean isChecked = ((CheckBoxPreference) preference).isChecked();
|
boolean isChecked = ((CheckBoxPreference) preference).isChecked();
|
||||||
@@ -327,22 +355,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Displays a message telling the user that they do not have any accessibility
|
|
||||||
* related apps installed and that they can get TalkBack (Google's free screen
|
|
||||||
* reader) from Market.
|
|
||||||
*/
|
|
||||||
private void displayNoAppsAlert() {
|
|
||||||
try {
|
|
||||||
PackageManager pm = getActivity().getPackageManager();
|
|
||||||
ApplicationInfo info = pm.getApplicationInfo("com.android.vending", 0);
|
|
||||||
showDialog(DIALOG_ID_NO_ACCESSIBILITY_SERVICES);
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
// This is a no-op if the user does not have Android Market
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(int dialogId) {
|
public Dialog onCreateDialog(int dialogId) {
|
||||||
switch (dialogId) {
|
switch (dialogId) {
|
||||||
|
@@ -23,7 +23,6 @@ import android.app.Fragment;
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
@@ -49,9 +48,6 @@ public class SettingsPreferenceFragment extends PreferenceFragment
|
|||||||
|
|
||||||
private SettingsDialogFragment mDialogFragment;
|
private SettingsDialogFragment mDialogFragment;
|
||||||
|
|
||||||
private int mResultCode = Activity.RESULT_CANCELED;
|
|
||||||
private Intent mResultData;
|
|
||||||
|
|
||||||
private Button mNextButton;
|
private Button mNextButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,18 +110,55 @@ public class SettingsPreferenceFragment extends PreferenceFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class SettingsDialogFragment extends DialogFragment {
|
public static class SettingsDialogFragment extends DialogFragment {
|
||||||
|
private static final String KEY_DIALOG_ID = "key_dialog_id";
|
||||||
|
private static final String KEY_PARENT_FRAGMENT_ID = "key_parent_fragment_id";
|
||||||
|
|
||||||
private int mDialogId;
|
private int mDialogId;
|
||||||
|
|
||||||
private DialogCreatable mFragment;
|
private Fragment mParentFragment;
|
||||||
|
|
||||||
|
public SettingsDialogFragment() {
|
||||||
|
/* do nothing */
|
||||||
|
}
|
||||||
|
|
||||||
public SettingsDialogFragment(DialogCreatable fragment, int dialogId) {
|
public SettingsDialogFragment(DialogCreatable fragment, int dialogId) {
|
||||||
mDialogId = dialogId;
|
mDialogId = dialogId;
|
||||||
mFragment = fragment;
|
if (!(fragment instanceof Fragment)) {
|
||||||
|
throw new IllegalArgumentException("fragment argument must be an instance of "
|
||||||
|
+ Fragment.class.getName());
|
||||||
|
}
|
||||||
|
mParentFragment = (Fragment) fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
mDialogId = savedInstanceState.getInt(KEY_DIALOG_ID, 0);
|
||||||
|
int mParentFragmentId = savedInstanceState.getInt(KEY_PARENT_FRAGMENT_ID, -1);
|
||||||
|
if (mParentFragmentId > -1) {
|
||||||
|
mParentFragment = getFragmentManager().findFragmentById(mParentFragmentId);
|
||||||
|
if (!(mParentFragment instanceof DialogCreatable)) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
KEY_PARENT_FRAGMENT_ID + " must implement "
|
||||||
|
+ DialogCreatable.class.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
if (mParentFragment != null) {
|
||||||
|
outState.putInt(KEY_DIALOG_ID, mDialogId);
|
||||||
|
outState.putInt(KEY_PARENT_FRAGMENT_ID, mParentFragment.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
return mFragment.onCreateDialog(mDialogId);
|
return ((DialogCreatable) mParentFragment).onCreateDialog(mDialogId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDialogId() {
|
public int getDialogId() {
|
||||||
|
Reference in New Issue
Block a user