Fix "Cannot get activity context when service off".
1. Unify getPrefContext() usage in Accessibility Settings 2. Correct the dialog emuns order Test: local test Change-Id: Idc51f7b15b5813bbae7b32e1ae3c7f00c71cea50
This commit is contained in:
@@ -19,7 +19,6 @@ package com.android.settings.accessibility;
|
||||
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -60,10 +59,17 @@ public class AccessibilityServiceWarning {
|
||||
return false;
|
||||
};
|
||||
|
||||
public static Dialog createCapabilitiesDialog(Activity parentActivity,
|
||||
/**
|
||||
* Gets a content View for a dialog to confirm that they want to enable a service.
|
||||
*
|
||||
* @param context A valid context
|
||||
* @param info The info about a service
|
||||
* @return A content view suitable for viewing
|
||||
*/
|
||||
public static Dialog createCapabilitiesDialog(Context context,
|
||||
AccessibilityServiceInfo info, View.OnClickListener listener) {
|
||||
final AlertDialog ad = new AlertDialog.Builder(parentActivity)
|
||||
.setView(createEnableDialogContentView(parentActivity, info, listener))
|
||||
final AlertDialog ad = new AlertDialog.Builder(context)
|
||||
.setView(createEnableDialogContentView(context, info, listener))
|
||||
.create();
|
||||
|
||||
Window window = ad.getWindow();
|
||||
@@ -77,7 +83,7 @@ public class AccessibilityServiceWarning {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the device is encrypted with legacy full disk encryption. Newer devices
|
||||
* Returns whether the device is encrypted with legacy full disk encryption. Newer devices
|
||||
* should be using File Based Encryption.
|
||||
*
|
||||
* @return true if device is encrypted
|
||||
@@ -86,13 +92,6 @@ public class AccessibilityServiceWarning {
|
||||
return StorageManager.isNonDefaultBlockEncrypted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a content View for a dialog to confirm that they want to enable a service.
|
||||
*
|
||||
* @param context A valid context
|
||||
* @param info The info about a service
|
||||
* @return A content view suitable for viewing
|
||||
*/
|
||||
private static View createEnableDialogContentView(Context context,
|
||||
AccessibilityServiceInfo info, View.OnClickListener listener) {
|
||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(
|
||||
|
@@ -23,7 +23,6 @@ import android.app.admin.DevicePolicyManager;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
@@ -98,7 +97,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
@Override
|
||||
public void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||
ComponentName toggledService = ComponentName.unflattenFromString(preferenceKey);
|
||||
AccessibilityUtils.setAccessibilityServiceState(getActivity(), toggledService, enabled);
|
||||
AccessibilityUtils.setAccessibilityServiceState(getPrefContext(), toggledService, enabled);
|
||||
}
|
||||
|
||||
// IMPORTANT: Refresh the info since there are dynamically changing
|
||||
@@ -129,7 +128,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
return null;
|
||||
}
|
||||
mDialog = AccessibilityServiceWarning
|
||||
.createCapabilitiesDialog(getActivity(), info,
|
||||
.createCapabilitiesDialog(getPrefContext(), info,
|
||||
this::onDialogButtonFromToggleClicked);
|
||||
break;
|
||||
}
|
||||
@@ -139,17 +138,17 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
return null;
|
||||
}
|
||||
mDialog = AccessibilityServiceWarning
|
||||
.createCapabilitiesDialog(getActivity(), info,
|
||||
.createCapabilitiesDialog(getPrefContext(), info,
|
||||
this::onDialogButtonFromShortcutClicked);
|
||||
break;
|
||||
}
|
||||
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL: {
|
||||
if (AccessibilityUtil.isGestureNavigateEnabled(getContext())) {
|
||||
if (AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())) {
|
||||
mDialog = AccessibilityGestureNavigationTutorial
|
||||
.showGestureNavigationTutorialDialog(getActivity());
|
||||
.showGestureNavigationTutorialDialog(getPrefContext());
|
||||
} else {
|
||||
mDialog = AccessibilityGestureNavigationTutorial
|
||||
.showAccessibilityButtonTutorialDialog(getActivity());
|
||||
.showAccessibilityButtonTutorialDialog(getPrefContext());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -185,7 +184,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
}
|
||||
|
||||
private void updateSwitchBarToggleSwitch() {
|
||||
final boolean checked = AccessibilityUtils.getEnabledServicesFromSettings(getActivity())
|
||||
final boolean checked = AccessibilityUtils.getEnabledServicesFromSettings(getPrefContext())
|
||||
.contains(mComponentName);
|
||||
mSwitchBar.setCheckedInternal(checked);
|
||||
}
|
||||
@@ -220,8 +219,8 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
}
|
||||
|
||||
private boolean isServiceSupportAccessibilityButton() {
|
||||
final AccessibilityManager ams = (AccessibilityManager) getContext().getSystemService(
|
||||
Context.ACCESSIBILITY_SERVICE);
|
||||
final AccessibilityManager ams = getPrefContext().getSystemService(
|
||||
AccessibilityManager.class);
|
||||
final List<AccessibilityServiceInfo> services = ams.getInstalledAccessibilityServiceList();
|
||||
|
||||
for (AccessibilityServiceInfo info : services) {
|
||||
@@ -268,17 +267,17 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
|
||||
@Override
|
||||
public void onCheckboxClicked(ShortcutPreference preference) {
|
||||
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
if (preference.getChecked()) {
|
||||
if (!getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED)) {
|
||||
preference.setChecked(false);
|
||||
showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_SHORTCUT);
|
||||
} else {
|
||||
AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes,
|
||||
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
|
||||
mComponentName);
|
||||
}
|
||||
} else {
|
||||
AccessibilityUtil.optOutAllValuesFromSettings(getContext(), shortcutTypes,
|
||||
AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes,
|
||||
mComponentName);
|
||||
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, false);
|
||||
}
|
||||
@@ -370,8 +369,8 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
||||
private void onAllowButtonFromShortcutClicked() {
|
||||
mShortcutPreference.setChecked(true);
|
||||
|
||||
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||
AccessibilityUtil.optInAllValuesToSettings(getContext(), shortcutTypes, mComponentName);
|
||||
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
|
||||
|
||||
mDialog.dismiss();
|
||||
}
|
||||
|
@@ -114,7 +114,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
final int resId = getPreferenceScreenResId();
|
||||
if (resId <= 0) {
|
||||
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(
|
||||
getActivity());
|
||||
getPrefContext());
|
||||
setPreferenceScreen(preferenceScreen);
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
if (mImageUri != null) {
|
||||
final AnimatedImagePreference animatedImagePreference = new AnimatedImagePreference(
|
||||
preferenceScreen.getContext());
|
||||
getPrefContext());
|
||||
animatedImagePreference.setImageUri(mImageUri);
|
||||
animatedImagePreference.setDividerAllowedAbove(true);
|
||||
preferenceScreen.addPreference(animatedImagePreference);
|
||||
@@ -158,7 +158,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
|
||||
// Show the "Settings" menu as if it were a preference screen.
|
||||
if (mSettingsTitle != null && mSettingsIntent != null) {
|
||||
mSettingsPreference = new Preference(preferenceScreen.getContext());
|
||||
mSettingsPreference = new Preference(getPrefContext());
|
||||
mSettingsPreference.setTitle(mSettingsTitle);
|
||||
mSettingsPreference.setIconSpaceReserved(true);
|
||||
mSettingsPreference.setIntent(mSettingsIntent);
|
||||
@@ -177,7 +177,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
|
||||
if (mStaticDescription != null) {
|
||||
final StaticTextPreference staticTextPreference = new StaticTextPreference(
|
||||
preferenceScreen.getContext());
|
||||
getPrefContext());
|
||||
staticTextPreference.setSummary(mStaticDescription);
|
||||
staticTextPreference.setSelectable(/* selectable= */ false);
|
||||
footerCategory.addPreference(staticTextPreference);
|
||||
@@ -189,7 +189,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
unsupportedTagList.add(ANCHOR_TAG);
|
||||
|
||||
final HtmlTextPreference htmlTextPreference = new HtmlTextPreference(
|
||||
preferenceScreen.getContext());
|
||||
getPrefContext());
|
||||
htmlTextPreference.setSummary(mHtmlDescription);
|
||||
htmlTextPreference.setImageGetter(mImageGetter);
|
||||
htmlTextPreference.setUnsupportedTagList(unsupportedTagList);
|
||||
@@ -234,10 +234,10 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
public Dialog onCreateDialog(int dialogId) {
|
||||
switch (dialogId) {
|
||||
case DialogEnums.EDIT_SHORTCUT:
|
||||
final CharSequence dialogTitle = getActivity().getString(
|
||||
final CharSequence dialogTitle = getPrefContext().getString(
|
||||
R.string.accessibility_shortcut_edit_dialog_title, mPackageName);
|
||||
Dialog dialog = AccessibilityEditDialogUtils.showEditShortcutDialog(getActivity(),
|
||||
dialogTitle, this::callOnAlertDialogCheckboxClicked);
|
||||
Dialog dialog = AccessibilityEditDialogUtils.showEditShortcutDialog(
|
||||
getPrefContext(), dialogTitle, this::callOnAlertDialogCheckboxClicked);
|
||||
initializeDialogCheckBox(dialog);
|
||||
return dialog;
|
||||
default:
|
||||
@@ -258,37 +258,35 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
/** Denotes the dialog emuns for show dialog */
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
protected @interface DialogEnums {
|
||||
int UNKNOWN = 0;
|
||||
|
||||
/** OPEN: Settings > Accessibility > Any toggle service > Shortcut > Settings. */
|
||||
int EDIT_SHORTCUT = 1;
|
||||
|
||||
/** OPEN: Settings > Accessibility > Magnification > Shortcut > Settings. */
|
||||
int MAGNIFICATION_EDIT_SHORTCUT = 2;
|
||||
int MAGNIFICATION_EDIT_SHORTCUT = 1001;
|
||||
|
||||
/**
|
||||
* OPEN: Settings > Accessibility > Magnification > Toggle user service in gesture
|
||||
* navigation.
|
||||
*/
|
||||
int GESTURE_NAVIGATION_TUTORIAL = 1001;
|
||||
int GESTURE_NAVIGATION_TUTORIAL = 1002;
|
||||
|
||||
/**
|
||||
* OPEN: Settings > Accessibility > Magnification > Toggle user service in button
|
||||
* navigation.
|
||||
*/
|
||||
int ACCESSIBILITY_BUTTON_TUTORIAL = 1002;
|
||||
int ACCESSIBILITY_BUTTON_TUTORIAL = 1003;
|
||||
|
||||
/** OPEN: Settings > Accessibility > Downloaded toggle service > Toggle user service. */
|
||||
int ENABLE_WARNING_FROM_TOGGLE = 1003;
|
||||
int ENABLE_WARNING_FROM_TOGGLE = 1004;
|
||||
|
||||
/** OPEN: Settings > Accessibility > Downloaded toggle service > Shortcut checkbox. */
|
||||
int ENABLE_WARNING_FROM_SHORTCUT = 1004;
|
||||
int ENABLE_WARNING_FROM_SHORTCUT = 1005;
|
||||
|
||||
/**
|
||||
* OPEN: Settings > Accessibility > Downloaded toggle service > Toggle user service > Show
|
||||
* launch tutorial.
|
||||
*/
|
||||
int LAUNCH_ACCESSIBILITY_TUTORIAL = 1005;
|
||||
int LAUNCH_ACCESSIBILITY_TUTORIAL = 1006;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -364,7 +362,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
|
||||
private Drawable getDrawableFromUri(Uri imageUri) {
|
||||
if (mImageGetterCacheView == null) {
|
||||
mImageGetterCacheView = new ImageView(getContext());
|
||||
mImageGetterCacheView = new ImageView(getPrefContext());
|
||||
}
|
||||
|
||||
mImageGetterCacheView.setAdjustViewBounds(true);
|
||||
|
@@ -241,16 +241,17 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
switch (dialogId) {
|
||||
case DialogEnums.GESTURE_NAVIGATION_TUTORIAL:
|
||||
return AccessibilityGestureNavigationTutorial
|
||||
.showGestureNavigationTutorialDialog(getActivity());
|
||||
.showGestureNavigationTutorialDialog(getPrefContext());
|
||||
case DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL:
|
||||
return AccessibilityGestureNavigationTutorial
|
||||
.showAccessibilityButtonTutorialDialog(getActivity());
|
||||
.showAccessibilityButtonTutorialDialog(getPrefContext());
|
||||
case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
|
||||
final CharSequence dialogTitle = getActivity().getText(
|
||||
final CharSequence dialogTitle = getPrefContext().getText(
|
||||
R.string.accessibility_shortcut_edit_dialog_title_magnification);
|
||||
final AlertDialog dialog =
|
||||
AccessibilityEditDialogUtils.showMagnificationEditShortcutDialog(
|
||||
getActivity(), dialogTitle, this::callOnAlertDialogCheckboxClicked);
|
||||
getPrefContext(), dialogTitle,
|
||||
this::callOnAlertDialogCheckboxClicked);
|
||||
initializeDialogCheckBox(dialog);
|
||||
return dialog;
|
||||
}
|
||||
@@ -425,7 +426,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
if (enabled && TextUtils.equals(
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
|
||||
preferenceKey)) {
|
||||
showDialog(AccessibilityUtil.isGestureNavigateEnabled(getContext())
|
||||
showDialog(AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())
|
||||
? DialogEnums.GESTURE_NAVIGATION_TUTORIAL
|
||||
: DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL);
|
||||
}
|
||||
@@ -457,11 +458,11 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
|
||||
@Override
|
||||
public void onCheckboxClicked(ShortcutPreference preference) {
|
||||
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
if (preference.getChecked()) {
|
||||
optInAllMagnificationValuesToSettings(getContext(), shortcutTypes);
|
||||
optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
|
||||
} else {
|
||||
optOutAllMagnificationValuesFromSettings(getContext(), shortcutTypes);
|
||||
optOutAllMagnificationValuesFromSettings(getPrefContext(), shortcutTypes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,31 +484,19 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
}
|
||||
|
||||
private void initShortcutPreference() {
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
mShortcutPreference = new ShortcutPreference(
|
||||
preferenceScreen.getContext(), null);
|
||||
mShortcutPreference = new ShortcutPreference(getPrefContext(), null);
|
||||
mShortcutPreference.setPersistent(false);
|
||||
mShortcutPreference.setKey(getShortcutPreferenceKey());
|
||||
mShortcutPreference.setKey(KEY_SHORTCUT_PREFERENCE);
|
||||
mShortcutPreference.setTitle(R.string.accessibility_magnification_shortcut_title);
|
||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||
mShortcutPreference.setOnClickListener(this);
|
||||
}
|
||||
|
||||
private void updateShortcutPreference() {
|
||||
final PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
final ShortcutPreference shortcutPreference = preferenceScreen.findPreference(
|
||||
getShortcutPreferenceKey());
|
||||
|
||||
if (shortcutPreference != null) {
|
||||
final int shortcutTypes = getUserShortcutType(getContext(), UserShortcutType.SOFTWARE);
|
||||
shortcutPreference.setChecked(
|
||||
hasMagnificationValuesInSettings(getContext(), shortcutTypes));
|
||||
shortcutPreference.setSummary(getShortcutTypeSummary(getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
private String getShortcutPreferenceKey() {
|
||||
return KEY_SHORTCUT_PREFERENCE;
|
||||
final int shortcutTypes = getUserShortcutType(getPrefContext(), UserShortcutType.SOFTWARE);
|
||||
mShortcutPreference.setChecked(
|
||||
hasMagnificationValuesInSettings(getPrefContext(), shortcutTypes));
|
||||
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
|
||||
}
|
||||
|
||||
private void updateConfigurationWarningIfNeeded() {
|
||||
|
Reference in New Issue
Block a user