<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"
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();
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;
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
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);
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;
}
@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();
if ((which == BUTTON_POSITIVE) && (fragment instanceof DefaultAppPickerFragment)) {
import java.util.List;
-import static com.android.settings.Utils.setOverlayAllowed;
-
public class ToggleAccessibilityServicePreferenceFragment
extends ToggleFeaturePreferenceFragment implements DialogInterface.OnClickListener {
private int mShownDialogId;
- private final IBinder mToken = new Binder();
-
@Override
public int getMetricsCategory() {
return MetricsEvent.ACCESSIBILITY_SERVICE;
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();
}