Accessibility scary dialog for android R changed.
Show scary dialog only once when toggle shortcut preference and use service. Fix: b/142532185 Test: manual test Change-Id: Ic36fdd5eec8ec20ead79ce47cd5e5e19d2ef5768
This commit is contained in:
@@ -51,13 +51,13 @@ import com.android.settings.accessibility.AccessibilityUtil.PreferredShortcutTyp
|
|||||||
import com.android.settings.password.ConfirmDeviceCredentialActivity;
|
import com.android.settings.password.ConfirmDeviceCredentialActivity;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
import com.android.settings.widget.ToggleSwitch;
|
import com.android.settings.widget.ToggleSwitch;
|
||||||
import com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
|
|
||||||
import com.android.settingslib.accessibility.AccessibilityUtils;
|
import com.android.settingslib.accessibility.AccessibilityUtils;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/** Fragment for providing toggle bar and basic accessibility service setup. */
|
/** Fragment for providing toggle bar and basic accessibility service setup. */
|
||||||
public class ToggleAccessibilityServicePreferenceFragment extends
|
public class ToggleAccessibilityServicePreferenceFragment extends
|
||||||
@@ -75,7 +75,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
public static final int ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION = 1;
|
public static final int ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION = 1;
|
||||||
private CharSequence mDialogTitle;
|
private CharSequence mDialogTitle;
|
||||||
private LockPatternUtils mLockPatternUtils;
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
private AtomicBoolean mIsDialogShown = new AtomicBoolean(/* initialValue= */ false);
|
||||||
|
|
||||||
private final SettingsContentObserver mSettingsContentObserver =
|
private final SettingsContentObserver mSettingsContentObserver =
|
||||||
new SettingsContentObserver(new Handler()) {
|
new SettingsContentObserver(new Handler()) {
|
||||||
@@ -87,27 +87,13 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
|
|
||||||
private Dialog mDialog;
|
private Dialog mDialog;
|
||||||
|
|
||||||
private final View.OnClickListener mViewOnClickListener =
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
(View view) -> {
|
private @interface DialogType {
|
||||||
if (view.getId() == R.id.permission_enable_allow_button) {
|
int ENABLE_WARNING_FROM_TOGGLE = 1;
|
||||||
if (isFullDiskEncrypted()) {
|
int ENABLE_WARNING_FROM_SHORTCUT = 2;
|
||||||
String title = createConfirmCredentialReasonMessage();
|
int LAUNCH_ACCESSIBILITY_TUTORIAL = 3;
|
||||||
Intent intent = ConfirmDeviceCredentialActivity.createIntent(title, null);
|
int EDIT_SHORTCUT = 4;
|
||||||
startActivityForResult(intent,
|
|
||||||
ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION);
|
|
||||||
} else {
|
|
||||||
handleConfirmServiceEnabled(true);
|
|
||||||
if (isServiceSupportAccessibilityButton()) {
|
|
||||||
showDialog(DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (view.getId() == R.id.permission_enable_deny_button) {
|
|
||||||
handleConfirmServiceEnabled(false);
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
mDialog.dismiss();
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
@@ -182,13 +168,24 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(int dialogId) {
|
public Dialog onCreateDialog(int dialogId) {
|
||||||
switch (dialogId) {
|
switch (dialogId) {
|
||||||
case DialogType.ENABLE_WARNING: {
|
case DialogType.ENABLE_WARNING_FROM_TOGGLE: {
|
||||||
final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
|
final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
mDialog = AccessibilityServiceWarning
|
mDialog = AccessibilityServiceWarning
|
||||||
.createCapabilitiesDialog(getActivity(), info, mViewOnClickListener);
|
.createCapabilitiesDialog(getActivity(), info,
|
||||||
|
this::onDialogButtonFromToggleClicked);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DialogType.ENABLE_WARNING_FROM_SHORTCUT: {
|
||||||
|
final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
|
||||||
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
mDialog = AccessibilityServiceWarning
|
||||||
|
.createCapabilitiesDialog(getActivity(), info,
|
||||||
|
this::onDialogButtonFromShortcutClicked);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL: {
|
case DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL: {
|
||||||
@@ -319,7 +316,8 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
@Override
|
@Override
|
||||||
public int getDialogMetricsCategory(int dialogId) {
|
public int getDialogMetricsCategory(int dialogId) {
|
||||||
switch (dialogId) {
|
switch (dialogId) {
|
||||||
case DialogType.ENABLE_WARNING:
|
case DialogType.ENABLE_WARNING_FROM_TOGGLE:
|
||||||
|
case DialogType.ENABLE_WARNING_FROM_SHORTCUT:
|
||||||
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_ENABLE;
|
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_ENABLE;
|
||||||
case DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL:
|
case DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL:
|
||||||
return AccessibilityUtil.isGestureNavigateEnabled(getContext())
|
return AccessibilityUtil.isGestureNavigateEnabled(getContext())
|
||||||
@@ -464,28 +462,21 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
@Override
|
@Override
|
||||||
protected void onInstallSwitchBarToggleSwitch() {
|
protected void onInstallSwitchBarToggleSwitch() {
|
||||||
super.onInstallSwitchBarToggleSwitch();
|
super.onInstallSwitchBarToggleSwitch();
|
||||||
mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() {
|
mToggleSwitch.setOnBeforeCheckedChangeListener(this::onBeforeCheckedChanged);
|
||||||
@Override
|
|
||||||
public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
|
||||||
if (checked) {
|
|
||||||
mSwitchBar.setCheckedInternal(false);
|
|
||||||
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, false);
|
|
||||||
showDialog(DialogType.ENABLE_WARNING);
|
|
||||||
} else {
|
|
||||||
handleConfirmServiceEnabled(false);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCheckboxClicked(ShortcutPreference preference) {
|
public void onCheckboxClicked(ShortcutPreference preference) {
|
||||||
if (preference.getChecked()) {
|
if (preference.getChecked()) {
|
||||||
// TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
|
if (!getArguments().getBoolean(AccessibilitySettings.EXTRA_CHECKED)) {
|
||||||
// preferred key.
|
preference.setChecked(false);
|
||||||
|
showPopupDialog(DialogType.ENABLE_WARNING_FROM_SHORTCUT);
|
||||||
|
} else {
|
||||||
|
// TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog
|
||||||
|
// shortcut preferred key.
|
||||||
AccessibilityUtil.optInValueToSettings(getContext(), PreferredShortcutType.SOFTWARE,
|
AccessibilityUtil.optInValueToSettings(getContext(), PreferredShortcutType.SOFTWARE,
|
||||||
mComponentName);
|
mComponentName);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
|
// TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
|
||||||
// preferred key.
|
// preferred key.
|
||||||
@@ -497,7 +488,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
@Override
|
@Override
|
||||||
public void onSettingsClicked(ShortcutPreference preference) {
|
public void onSettingsClicked(ShortcutPreference preference) {
|
||||||
mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
|
mPreferredShortcutType = getPreferredShortcutType(getPrefContext());
|
||||||
showDialog(DialogType.EDIT_SHORTCUT);
|
showPopupDialog(DialogType.EDIT_SHORTCUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -534,10 +525,94 @@ public class ToggleAccessibilityServicePreferenceFragment extends
|
|||||||
getPackageManager());
|
getPackageManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
private void onDialogButtonFromToggleClicked(View view) {
|
||||||
private @interface DialogType {
|
if (view.getId() == R.id.permission_enable_allow_button) {
|
||||||
int ENABLE_WARNING = 1;
|
onAllowButtonFromToggleClicked();
|
||||||
int LAUNCH_ACCESSIBILITY_TUTORIAL = 2;
|
} else if (view.getId() == R.id.permission_enable_deny_button) {
|
||||||
int EDIT_SHORTCUT = 3;
|
onDenyButtonFromToggleClicked();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unexpected view id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onAllowButtonFromToggleClicked() {
|
||||||
|
if (isFullDiskEncrypted()) {
|
||||||
|
final String title = createConfirmCredentialReasonMessage();
|
||||||
|
final Intent intent = ConfirmDeviceCredentialActivity.createIntent(title, /* details= */
|
||||||
|
null);
|
||||||
|
startActivityForResult(intent,
|
||||||
|
ACTIVITY_REQUEST_CONFIRM_CREDENTIAL_FOR_WEAKER_ENCRYPTION);
|
||||||
|
} else {
|
||||||
|
handleConfirmServiceEnabled(/* confirmed= */ true);
|
||||||
|
if (isServiceSupportAccessibilityButton()) {
|
||||||
|
mIsDialogShown.set(false);
|
||||||
|
showPopupDialog(DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mDialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDenyButtonFromToggleClicked() {
|
||||||
|
handleConfirmServiceEnabled(/* confirmed= */ false);
|
||||||
|
mDialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDialogButtonFromShortcutClicked(View view) {
|
||||||
|
if (view.getId() == R.id.permission_enable_allow_button) {
|
||||||
|
onAllowButtonFromShortcutClicked();
|
||||||
|
} else if (view.getId() == R.id.permission_enable_deny_button) {
|
||||||
|
onDenyButtonFromShortcutClicked();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unexpected view id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onAllowButtonFromShortcutClicked() {
|
||||||
|
final ShortcutPreference shortcutPreference = findPreference(getShortcutPreferenceKey());
|
||||||
|
shortcutPreference.setChecked(true);
|
||||||
|
// TODO(b/142531156): Replace PreferredShortcutType.SOFTWARE value with dialog shortcut
|
||||||
|
// preferred key.
|
||||||
|
AccessibilityUtil.optInValueToSettings(getContext(), PreferredShortcutType.SOFTWARE,
|
||||||
|
mComponentName);
|
||||||
|
|
||||||
|
mDialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDenyButtonFromShortcutClicked() {
|
||||||
|
final ShortcutPreference shortcutPreference = findPreference(getShortcutPreferenceKey());
|
||||||
|
shortcutPreference.setChecked(false);
|
||||||
|
|
||||||
|
mDialog.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
|
||||||
|
if (checked) {
|
||||||
|
mSwitchBar.setCheckedInternal(false);
|
||||||
|
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, false);
|
||||||
|
|
||||||
|
final ShortcutPreference shortcutPreference = findPreference(
|
||||||
|
getShortcutPreferenceKey());
|
||||||
|
if (!shortcutPreference.getChecked()) {
|
||||||
|
showPopupDialog(DialogType.ENABLE_WARNING_FROM_TOGGLE);
|
||||||
|
} else {
|
||||||
|
handleConfirmServiceEnabled(/* confirmed= */ true);
|
||||||
|
if (isServiceSupportAccessibilityButton()) {
|
||||||
|
showPopupDialog(DialogType.LAUNCH_ACCESSIBILITY_TUTORIAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
handleConfirmServiceEnabled(/* confirmed= */ false);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showPopupDialog(int dialogId) {
|
||||||
|
if (mIsDialogShown.compareAndSet(/* expect= */ false, /* update= */ true)) {
|
||||||
|
showDialog(dialogId);
|
||||||
|
setOnDismissListener(
|
||||||
|
dialog -> mIsDialogShown.compareAndSet(/* expect= */ true, /* update= */
|
||||||
|
false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user