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

Commit a10fc7e2 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Don't show alert window notifications when in Vr mode.

Change-Id: I6ef60682197f6581fb101598290b2390ea676091
Fixes: 35854095
Test: manual
parent 087daa0d
Loading
Loading
Loading
Loading
+13 −10
Original line number Original line Diff line number Diff line
@@ -2385,9 +2385,13 @@ public class ActivityManagerService extends IActivityManager.Stub
                idleUids();
                idleUids();
            } break;
            } break;
            case VR_MODE_CHANGE_MSG: {
            case VR_MODE_CHANGE_MSG: {
                if (mVrController.onVrModeChanged((ActivityRecord) msg.obj)) {
                if (!mVrController.onVrModeChanged((ActivityRecord) msg.obj)) {
                    return;
                }
                synchronized (ActivityManagerService.this) {
                synchronized (ActivityManagerService.this) {
                        if (mVrController.shouldDisableNonVrUiLocked()) {
                    final boolean disableNonVrUi = mVrController.shouldDisableNonVrUiLocked();
                    mWindowManager.disableNonVrUi(disableNonVrUi);
                    if (disableNonVrUi) {
                        // If we are in a VR mode where Picture-in-Picture mode is unsupported,
                        // If we are in a VR mode where Picture-in-Picture mode is unsupported,
                        // then remove the pinned stack.
                        // then remove the pinned stack.
                        final PinnedActivityStack pinnedStack = mStackSupervisor.getStack(
                        final PinnedActivityStack pinnedStack = mStackSupervisor.getStack(
@@ -2397,7 +2401,6 @@ public class ActivityManagerService extends IActivityManager.Stub
                        }
                        }
                    }
                    }
                }
                }
                }
            } break;
            } break;
            case NOTIFY_VR_SLEEPING_MSG: {
            case NOTIFY_VR_SLEEPING_MSG: {
                notifyVrManagerOfSleepState(msg.arg1 != 0);
                notifyVrManagerOfSleepState(msg.arg1 != 0);
+11 −4
Original line number Original line Diff line number Diff line
@@ -50,7 +50,7 @@ class AlertWindowNotification {
    private String mNotificationTag;
    private String mNotificationTag;
    private final NotificationManager mNotificationManager;
    private final NotificationManager mNotificationManager;
    private final String mPackageName;
    private final String mPackageName;
    private boolean mCancelled;
    private boolean mPosted;
    private IconUtilities mIconUtilities;
    private IconUtilities mIconUtilities;


    AlertWindowNotification(WindowManagerService service, String packageName) {
    AlertWindowNotification(WindowManagerService service, String packageName) {
@@ -61,7 +61,9 @@ class AlertWindowNotification {
        mNotificationTag = CHANNEL_PREFIX + mPackageName;
        mNotificationTag = CHANNEL_PREFIX + mPackageName;
        mRequestCode = sNextRequestCode++;
        mRequestCode = sNextRequestCode++;
        mIconUtilities = new IconUtilities(mService.mContext);
        mIconUtilities = new IconUtilities(mService.mContext);
    }


    void post() {
        // We can't create/post the notification while the window manager lock is held since it will
        // We can't create/post the notification while the window manager lock is held since it will
        // end up calling into activity manager. So, we post a message to do it later.
        // end up calling into activity manager. So, we post a message to do it later.
        mService.mH.post(this::onPostNotification);
        mService.mH.post(this::onPostNotification);
@@ -76,16 +78,21 @@ class AlertWindowNotification {


    /** Don't call with the window manager lock held! */
    /** Don't call with the window manager lock held! */
    private void onCancelNotification() {
    private void onCancelNotification() {
        if (!mPosted) {
            // Notification isn't currently posted...
            return;
        }
        mPosted = false;
        mNotificationManager.cancel(mNotificationTag, NOTIFICATION_ID);
        mNotificationManager.cancel(mNotificationTag, NOTIFICATION_ID);
        mCancelled = true;
    }
    }


    /** Don't call with the window manager lock held! */
    /** Don't call with the window manager lock held! */
    private void onPostNotification() {
    private void onPostNotification() {
        if (mCancelled) {
        if (mPosted) {
            // Notification was cancelled, so nothing more to do...
            // Notification already posted...
            return;
            return;
        }
        }
        mPosted = true;


        final Context context = mService.mContext;
        final Context context = mService.mContext;
        final PackageManager pm = context.getPackageManager();
        final PackageManager pm = context.getPackageManager();
+16 −0
Original line number Original line Diff line number Diff line
@@ -81,6 +81,7 @@ public class Session extends IWindowSession.Stub
    private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>();
    private final Set<WindowSurfaceController> mAlertWindowSurfaces = new HashSet<>();
    final boolean mCanAddInternalSystemWindow;
    final boolean mCanAddInternalSystemWindow;
    private AlertWindowNotification mAlertWindowNotification;
    private AlertWindowNotification mAlertWindowNotification;
    private boolean mShowingAlertWindowNotificationAllowed;
    private boolean mClientDead = false;
    private boolean mClientDead = false;
    private float mLastReportedAnimatorScale;
    private float mLastReportedAnimatorScale;
    private String mPackageName;
    private String mPackageName;
@@ -95,6 +96,7 @@ public class Session extends IWindowSession.Stub
        mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
        mLastReportedAnimatorScale = service.getCurrentAnimatorScale();
        mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
        mCanAddInternalSystemWindow = service.mContext.checkCallingOrSelfPermission(
                INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
                INTERNAL_SYSTEM_WINDOW) == PERMISSION_GRANTED;
        mShowingAlertWindowNotificationAllowed = mService.mShowAlertWindowNotifications;
        StringBuilder sb = new StringBuilder();
        StringBuilder sb = new StringBuilder();
        sb.append("Session{");
        sb.append("Session{");
        sb.append(Integer.toHexString(System.identityHashCode(this)));
        sb.append(Integer.toHexString(System.identityHashCode(this)));
@@ -591,6 +593,9 @@ public class Session extends IWindowSession.Stub
                    cancelAlertWindowNotification();
                    cancelAlertWindowNotification();
                } else if (mAlertWindowNotification == null){
                } else if (mAlertWindowNotification == null){
                    mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
                    mAlertWindowNotification = new AlertWindowNotification(mService, mPackageName);
                    if (mShowingAlertWindowNotificationAllowed) {
                        mAlertWindowNotification.post();
                    }
                }
                }
            }
            }
        }
        }
@@ -612,6 +617,17 @@ public class Session extends IWindowSession.Stub
        }
        }
    }
    }


    void setShowingAlertWindowNotificationAllowed(boolean allowed) {
        mShowingAlertWindowNotificationAllowed = allowed;
        if (mAlertWindowNotification != null) {
            if (allowed) {
                mAlertWindowNotification.post();
            } else {
                mAlertWindowNotification.cancel();
            }
        }
    }

    private void killSessionLocked() {
    private void killSessionLocked() {
        if (mNumWindow > 0 || !mClientDead) {
        if (mNumWindow > 0 || !mClientDead) {
            return;
            return;
+20 −0
Original line number Original line Diff line number Diff line
@@ -402,6 +402,9 @@ public class WindowManagerService extends IWindowManager.Stub


    final DisplaySettings mDisplaySettings;
    final DisplaySettings mDisplaySettings;


    /** If the system should display notifications for apps displaying an alert window. */
    boolean mShowAlertWindowNotifications = true;

    /**
    /**
     * All currently active sessions with clients.
     * All currently active sessions with clients.
     */
     */
@@ -7370,4 +7373,21 @@ public class WindowManagerService extends IWindowManager.Stub
            }
            }
        }
        }
    }
    }

    /** Called to inform window manager if non-Vr UI shoul be disabled or not. */
    public void disableNonVrUi(boolean disable) {
        synchronized (mWindowMap) {
            // Allow alert window notifications to be shown if non-vr UI is enabled.
            final boolean showAlertWindowNotifications = !disable;
            if (showAlertWindowNotifications == mShowAlertWindowNotifications) {
                return;
            }
            mShowAlertWindowNotifications = showAlertWindowNotifications;

            for (int i = mSessions.size() - 1; i >= 0; --i) {
                final Session s = mSessions.valueAt(i);
                s.setShowingAlertWindowNotificationAllowed(mShowAlertWindowNotifications);
            }
        }
    }
}
}