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

Commit db6a4dd3 authored by Josep del Rio's avatar Josep del Rio
Browse files

Send close system dialogs for current user

It has been reported that the Escape key will not properly close
some system dialogs when in HSUM; the current way to call it will
send it as the system user instead of the current one, so this CL
addresses this.

Bug: 385008668
Test: Manual
Flag: EXEMPT bugfix
Change-Id: I6215dccdfe2c79d30854ad59e62ad0848081006d
parent 45dd9f93
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ import android.app.ActivityOptions;
import android.app.ActivityTaskManager;
import android.app.ActivityTaskManager.RootTaskInfo;
import android.app.AppOpsManager;
import android.app.BroadcastOptions;
import android.app.IActivityManager;
import android.app.IUiModeManager;
import android.app.NotificationManager;
@@ -3608,7 +3609,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                break;
            case KeyGestureEvent.KEY_GESTURE_TYPE_CLOSE_ALL_DIALOGS:
                if (complete) {
                    mContext.closeSystemDialogs();
                    closeSystemDialogsAsUser(UserHandle.CURRENT_OR_SELF);
                }
                break;
            case KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK:
@@ -4063,6 +4064,21 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    @SuppressLint("MissingPermission")
    private void closeSystemDialogsAsUser(UserHandle handle) {
        final Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
                .addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        final Bundle options = BroadcastOptions.makeBasic()
                .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
                .setDeferralPolicy(BroadcastOptions.DEFERRAL_POLICY_UNTIL_ACTIVE)
                .toBundle();
        mContext.sendBroadcastAsUser(
                intent,
                handle,
                null /* receiverPermission */,
                options);
    }

    private void preloadRecentApps() {
        mPreloadedRecentApps = true;
        StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
+7 −1
Original line number Diff line number Diff line
@@ -742,7 +742,13 @@ class TestPhoneWindowManager {
    }

    void assertCloseAllDialogs() {
        verify(mContext).closeSystemDialogs();
        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mContext).sendBroadcastAsUser(intentCaptor.capture(), any(), any(), any());
        Assert.assertEquals(
                Intent.ACTION_CLOSE_SYSTEM_DIALOGS,
                intentCaptor.getValue().getAction());
        // Reset verifier for next call.
        Mockito.clearInvocations(mContext);
    }

    void assertDreamRequest() {