Add back "Tapping Stop will stop x" dialog while turning off an accessibility service
Bug: 146539308 Test: make RunSettingsRoboTests2 Change-Id: Ic572f9245db016bd79a272030f97004a21f4b672
This commit is contained in:
@@ -21,6 +21,7 @@ import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTE
|
|||||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
import android.text.BidiFormatter;
|
import android.text.BidiFormatter;
|
||||||
@@ -59,13 +60,7 @@ public class AccessibilityServiceWarning {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/** Returns a {@link Dialog} to be shown to confirm that they want to enable a service. */
|
||||||
* 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,
|
public static Dialog createCapabilitiesDialog(Context context,
|
||||||
AccessibilityServiceInfo info, View.OnClickListener listener) {
|
AccessibilityServiceInfo info, View.OnClickListener listener) {
|
||||||
final AlertDialog ad = new AlertDialog.Builder(context)
|
final AlertDialog ad = new AlertDialog.Builder(context)
|
||||||
@@ -137,6 +132,23 @@ public class AccessibilityServiceWarning {
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns a {@link Dialog} to be shown to confirm that they want to disable a service. */
|
||||||
|
public static Dialog createDisableDialog(Context context,
|
||||||
|
AccessibilityServiceInfo info, DialogInterface.OnClickListener listener) {
|
||||||
|
final AlertDialog dialog = new AlertDialog.Builder(context)
|
||||||
|
.setTitle(context.getString(R.string.disable_service_title,
|
||||||
|
info.getResolveInfo().loadLabel(context.getPackageManager())))
|
||||||
|
.setMessage(context.getString(R.string.disable_service_message,
|
||||||
|
context.getString(R.string.accessibility_dialog_button_stop),
|
||||||
|
getServiceName(context, info)))
|
||||||
|
.setCancelable(true)
|
||||||
|
.setPositiveButton(R.string.accessibility_dialog_button_stop, listener)
|
||||||
|
.setNegativeButton(R.string.accessibility_dialog_button_cancel, listener)
|
||||||
|
.create();
|
||||||
|
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the service name and bidi wrap it to protect from bidi side effects.
|
// Get the service name and bidi wrap it to protect from bidi side effects.
|
||||||
private static CharSequence getServiceName(Context context, AccessibilityServiceInfo info) {
|
private static CharSequence getServiceName(Context context, AccessibilityServiceInfo info) {
|
||||||
final Locale locale = context.getResources().getConfiguration().getLocales().get(0);
|
final Locale locale = context.getResources().getConfiguration().getLocales().get(0);
|
||||||
|
@@ -23,6 +23,7 @@ import android.app.admin.DevicePolicyManager;
|
|||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.content.pm.ServiceInfo;
|
import android.content.pm.ServiceInfo;
|
||||||
@@ -129,7 +130,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
}
|
}
|
||||||
mDialog = AccessibilityServiceWarning
|
mDialog = AccessibilityServiceWarning
|
||||||
.createCapabilitiesDialog(getPrefContext(), info,
|
.createCapabilitiesDialog(getPrefContext(), info,
|
||||||
this::onDialogButtonFromToggleClicked);
|
this::onDialogButtonFromEnableToggleClicked);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT: {
|
case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT: {
|
||||||
@@ -142,6 +143,16 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
this::onDialogButtonFromShortcutClicked);
|
this::onDialogButtonFromShortcutClicked);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case DialogEnums.DISABLE_WARNING_FROM_TOGGLE: {
|
||||||
|
final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
|
||||||
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
mDialog = AccessibilityServiceWarning
|
||||||
|
.createDisableDialog(getPrefContext(), info,
|
||||||
|
this::onDialogButtonFromDisableToggleClicked);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL: {
|
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL: {
|
||||||
if (AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())) {
|
if (AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())) {
|
||||||
mDialog = AccessibilityGestureNavigationTutorial
|
mDialog = AccessibilityGestureNavigationTutorial
|
||||||
@@ -165,6 +176,8 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
case DialogEnums.ENABLE_WARNING_FROM_TOGGLE:
|
case DialogEnums.ENABLE_WARNING_FROM_TOGGLE:
|
||||||
case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT:
|
case DialogEnums.ENABLE_WARNING_FROM_SHORTCUT:
|
||||||
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_ENABLE;
|
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_ENABLE;
|
||||||
|
case DialogEnums.DISABLE_WARNING_FROM_TOGGLE:
|
||||||
|
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_DISABLE;
|
||||||
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
|
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
|
||||||
return AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())
|
return AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())
|
||||||
? SettingsEnums.DIALOG_TOGGLE_SCREEN_GESTURE_NAVIGATION
|
? SettingsEnums.DIALOG_TOGGLE_SCREEN_GESTURE_NAVIGATION
|
||||||
@@ -203,7 +216,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION) {
|
if (requestCode == ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION) {
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
handleConfirmServiceEnabled(true);
|
handleConfirmServiceEnabled(/* confirmed= */ true);
|
||||||
// The user confirmed that they accept weaker encryption when
|
// The user confirmed that they accept weaker encryption when
|
||||||
// enabling the accessibility service, so change encryption.
|
// enabling the accessibility service, so change encryption.
|
||||||
// Since we came here asynchronously, check encryption again.
|
// Since we came here asynchronously, check encryption again.
|
||||||
@@ -213,7 +226,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT, 0);
|
Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT, 0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
handleConfirmServiceEnabled(false);
|
handleConfirmServiceEnabled(/* confirmed= */ false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -323,17 +336,31 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
getPackageManager());
|
getPackageManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDialogButtonFromToggleClicked(View view) {
|
private void onDialogButtonFromDisableToggleClicked(DialogInterface dialog, int which) {
|
||||||
if (view.getId() == R.id.permission_enable_allow_button) {
|
switch (which) {
|
||||||
onAllowButtonFromToggleClicked();
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
} else if (view.getId() == R.id.permission_enable_deny_button) {
|
handleConfirmServiceEnabled(/* confirmed= */ false);
|
||||||
onDenyButtonFromToggleClicked();
|
break;
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
handleConfirmServiceEnabled(/* confirmed= */ true);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Unexpected button identifier");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDialogButtonFromEnableToggleClicked(View view) {
|
||||||
|
final int viewId = view.getId();
|
||||||
|
if (viewId == R.id.permission_enable_allow_button) {
|
||||||
|
onAllowButtonFromEnableToggleClicked();
|
||||||
|
} else if (viewId == R.id.permission_enable_deny_button) {
|
||||||
|
onDenyButtonFromEnableToggleClicked();
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unexpected view id");
|
throw new IllegalArgumentException("Unexpected view id");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onAllowButtonFromToggleClicked() {
|
private void onAllowButtonFromEnableToggleClicked() {
|
||||||
if (isFullDiskEncrypted()) {
|
if (isFullDiskEncrypted()) {
|
||||||
final String title = createConfirmCredentialReasonMessage();
|
final String title = createConfirmCredentialReasonMessage();
|
||||||
final Intent intent = ConfirmDeviceCredentialActivity.createIntent(title, /* details= */
|
final Intent intent = ConfirmDeviceCredentialActivity.createIntent(title, /* details= */
|
||||||
@@ -351,15 +378,16 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
mDialog.dismiss();
|
mDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDenyButtonFromToggleClicked() {
|
private void onDenyButtonFromEnableToggleClicked() {
|
||||||
handleConfirmServiceEnabled(/* confirmed= */ false);
|
handleConfirmServiceEnabled(/* confirmed= */ false);
|
||||||
mDialog.dismiss();
|
mDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDialogButtonFromShortcutClicked(View view) {
|
void onDialogButtonFromShortcutClicked(View view) {
|
||||||
if (view.getId() == R.id.permission_enable_allow_button) {
|
final int viewId = view.getId();
|
||||||
|
if (viewId == R.id.permission_enable_allow_button) {
|
||||||
onAllowButtonFromShortcutClicked();
|
onAllowButtonFromShortcutClicked();
|
||||||
} else if (view.getId() == R.id.permission_enable_deny_button) {
|
} else if (viewId == R.id.permission_enable_deny_button) {
|
||||||
onDenyButtonFromShortcutClicked();
|
onDenyButtonFromShortcutClicked();
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unexpected view id");
|
throw new IllegalArgumentException("Unexpected view id");
|
||||||
@@ -384,7 +412,8 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
private boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
private boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
mSwitchBar.setCheckedInternal(false);
|
mSwitchBar.setCheckedInternal(false);
|
||||||
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, false);
|
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED,
|
||||||
|
/* disableService */ false);
|
||||||
if (!mShortcutPreference.getChecked()) {
|
if (!mShortcutPreference.getChecked()) {
|
||||||
showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_TOGGLE);
|
showPopupDialog(DialogEnums.ENABLE_WARNING_FROM_TOGGLE);
|
||||||
} else {
|
} else {
|
||||||
@@ -394,7 +423,10 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
handleConfirmServiceEnabled(/* confirmed= */ false);
|
mSwitchBar.setCheckedInternal(true);
|
||||||
|
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED,
|
||||||
|
/* enableService */ true);
|
||||||
|
showDialog(DialogEnums.DISABLE_WARNING_FROM_TOGGLE);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -258,6 +258,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
/** Denotes the dialog emuns for show dialog */
|
/** Denotes the dialog emuns for show dialog */
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
protected @interface DialogEnums {
|
protected @interface DialogEnums {
|
||||||
|
|
||||||
/** OPEN: Settings > Accessibility > Any toggle service > Shortcut > Settings. */
|
/** OPEN: Settings > Accessibility > Any toggle service > Shortcut > Settings. */
|
||||||
int EDIT_SHORTCUT = 1;
|
int EDIT_SHORTCUT = 1;
|
||||||
|
|
||||||
@@ -265,28 +266,38 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
|||||||
int MAGNIFICATION_EDIT_SHORTCUT = 1001;
|
int MAGNIFICATION_EDIT_SHORTCUT = 1001;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OPEN: Settings > Accessibility > Magnification > Toggle user service in gesture
|
* OPEN: Settings > Accessibility > Downloaded toggle service > Toggle use service to
|
||||||
* navigation.
|
* enable service.
|
||||||
*/
|
*/
|
||||||
int GESTURE_NAVIGATION_TUTORIAL = 1002;
|
int ENABLE_WARNING_FROM_TOGGLE = 1002;
|
||||||
|
|
||||||
|
|
||||||
|
/** OPEN: Settings > Accessibility > Downloaded toggle service > Shortcut checkbox. */
|
||||||
|
int ENABLE_WARNING_FROM_SHORTCUT = 1003;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OPEN: Settings > Accessibility > Downloaded toggle service > Toggle use service to
|
||||||
|
* disable service.
|
||||||
|
*/
|
||||||
|
int DISABLE_WARNING_FROM_TOGGLE = 1004;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OPEN: Settings > Accessibility > Magnification > Toggle user service in button
|
* OPEN: Settings > Accessibility > Magnification > Toggle user service in button
|
||||||
* navigation.
|
* navigation.
|
||||||
*/
|
*/
|
||||||
int ACCESSIBILITY_BUTTON_TUTORIAL = 1003;
|
int ACCESSIBILITY_BUTTON_TUTORIAL = 1005;
|
||||||
|
|
||||||
/** OPEN: Settings > Accessibility > Downloaded toggle service > Toggle user service. */
|
/**
|
||||||
int ENABLE_WARNING_FROM_TOGGLE = 1004;
|
* OPEN: Settings > Accessibility > Magnification > Toggle user service in gesture
|
||||||
|
* navigation.
|
||||||
/** OPEN: Settings > Accessibility > Downloaded toggle service > Shortcut checkbox. */
|
*/
|
||||||
int ENABLE_WARNING_FROM_SHORTCUT = 1005;
|
int GESTURE_NAVIGATION_TUTORIAL = 1006;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OPEN: Settings > Accessibility > Downloaded toggle service > Toggle user service > Show
|
* OPEN: Settings > Accessibility > Downloaded toggle service > Toggle user service > Show
|
||||||
* launch tutorial.
|
* launch tutorial.
|
||||||
*/
|
*/
|
||||||
int LAUNCH_ACCESSIBILITY_TUTORIAL = 1006;
|
int LAUNCH_ACCESSIBILITY_TUTORIAL = 1007;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user