Migrate to new overlay-stopping flag
Bug: 62196835 Test: Started an accessibility service that displays an app overlay and verified that it disappears when approving an accessibility service's capabilities. Change-Id: I7c8d8b4143a5dd1cb684c31c4503608c8d5be0e3
This commit is contained in:
@@ -83,6 +83,7 @@
|
||||
<uses-permission android:name="android.permission.MANAGE_NOTIFICATIONS"/>
|
||||
<uses-permission android:name="android.permission.DELETE_PACKAGES"/>
|
||||
<uses-permission android:name="android.permission.MANAGE_APP_OPS_RESTRICTIONS"/>
|
||||
<uses-permission android:name="android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS"/>
|
||||
|
||||
<application android:label="@string/settings_label"
|
||||
android:icon="@drawable/ic_launcher_settings"
|
||||
|
@@ -1285,20 +1285,6 @@ public final class Utils extends com.android.settingslib.Utils {
|
||||
return info.enabled ? R.string.installed : R.string.disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Control if other apps can display overlays. By default this is allowed. Be sure to
|
||||
* re-enable overlays, as the effect is system-wide.
|
||||
*/
|
||||
public static void setOverlayAllowed(Context context, IBinder token, boolean allowed) {
|
||||
AppOpsManager appOpsManager = context.getSystemService(AppOpsManager.class);
|
||||
if (appOpsManager != null) {
|
||||
appOpsManager.setUserRestriction(AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
|
||||
!allowed, token);
|
||||
appOpsManager.setUserRestriction(AppOpsManager.OP_TOAST_WINDOW,
|
||||
!allowed, token);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isVolumeValid(VolumeInfo volume) {
|
||||
return (volume != null) && (volume.getType() == VolumeInfo.TYPE_PRIVATE)
|
||||
&& volume.isMountedReadable();
|
||||
|
@@ -27,6 +27,8 @@ import android.text.BidiFormatter;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@@ -37,6 +39,8 @@ import com.android.settings.R;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
|
||||
/**
|
||||
* Utility class for creating the dialog that asks users for explicit permission to grant
|
||||
* all of the requested capabilities to an accessibility service before the service is enabled
|
||||
@@ -65,6 +69,10 @@ public class AccessibilityServiceWarning {
|
||||
return false;
|
||||
};
|
||||
|
||||
Window window = ad.getWindow();
|
||||
WindowManager.LayoutParams params = window.getAttributes();
|
||||
params.privateFlags |= PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
window.setAttributes(params);
|
||||
ad.create();
|
||||
ad.getButton(AlertDialog.BUTTON_POSITIVE).setOnTouchListener(filterTouchListener);
|
||||
ad.setCanceledOnTouchOutside(true);
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static android.content.DialogInterface.BUTTON_POSITIVE;
|
||||
import static com.android.settings.Utils.setOverlayAllowed;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.app.Activity;
|
||||
@@ -146,22 +145,6 @@ public class ShortcutServicePickerFragment extends DefaultAppPickerFragment {
|
||||
return AccessibilityServiceWarning.createCapabilitiesDialog(getActivity(), info, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (mToken != null) {
|
||||
setOverlayAllowed(getActivity(), mToken, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (mToken != null) {
|
||||
setOverlayAllowed(getActivity(), mToken, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final Fragment fragment = getTargetFragment();
|
||||
|
@@ -48,8 +48,6 @@ import com.android.settingslib.accessibility.AccessibilityUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.android.settings.Utils.setOverlayAllowed;
|
||||
|
||||
public class ToggleAccessibilityServicePreferenceFragment
|
||||
extends ToggleFeaturePreferenceFragment implements DialogInterface.OnClickListener {
|
||||
|
||||
@@ -72,8 +70,6 @@ public class ToggleAccessibilityServicePreferenceFragment
|
||||
|
||||
private int mShownDialogId;
|
||||
|
||||
private final IBinder mToken = new Binder();
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ACCESSIBILITY_SERVICE;
|
||||
@@ -96,18 +92,12 @@ public class ToggleAccessibilityServicePreferenceFragment
|
||||
public void onResume() {
|
||||
mSettingsContentObserver.register(getContentResolver());
|
||||
updateSwitchBarToggleSwitch();
|
||||
if (mToken != null) {
|
||||
setOverlayAllowed(getActivity(), mToken, false);
|
||||
}
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mSettingsContentObserver.unregister(getContentResolver());
|
||||
if (mToken != null) {
|
||||
setOverlayAllowed(getActivity(), mToken, true);
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user