Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94c52029 authored by Phil Weaver's avatar Phil Weaver
Browse files

Backport overlay security fix

Replacing app opps fix with the flag that is used
elsewhere.

Bug: 37442941
Test: Verified that toast and system overlay still goes
away on permission and a11y service capability screens.

Merged-In: I7c8d8b4143a5dd1cb684c31c4503608c8d5be0e3

Change-Id: I858f3585b2e7d334cddcf38bd0ac6481e778b6b6
parent b4678ce1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,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"
+0 −16
Original line number Diff line number Diff line
@@ -1297,22 +1297,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();
+8 −0
Original line number Diff line number Diff line
@@ -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);
+0 −18
Original line number Diff line number Diff line
@@ -17,8 +17,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;
import android.app.Dialog;
@@ -147,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();
+0 −10
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.settings.accessibility;

import static com.android.settings.Utils.setOverlayAllowed;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.Activity;
import android.app.AlertDialog;
@@ -73,8 +71,6 @@ public class ToggleAccessibilityServicePreferenceFragment

    private int mShownDialogId;

    private final IBinder mToken = new Binder();

    @Override
    public int getMetricsCategory() {
        return MetricsEvent.ACCESSIBILITY_SERVICE;
@@ -105,18 +101,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();
    }