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

Commit 2ee64ec5 authored by Wale Ogunwale's avatar Wale Ogunwale Committed by android-build-merger
Browse files

Merge "Don't show alert window notifications when in Vr mode." into oc-dev

am: 77d23337

Change-Id: I6c978ab89f31308e359119e6196df909812b3e77
parents ab13d9f9 77d23337
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -2385,9 +2385,13 @@ public class ActivityManagerService extends IActivityManager.Stub
                idleUids();
            } break;
            case VR_MODE_CHANGE_MSG: {
                if (mVrController.onVrModeChanged((ActivityRecord) msg.obj)) {
                if (!mVrController.onVrModeChanged((ActivityRecord) msg.obj)) {
                    return;
                }
                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,
                        // then remove the pinned stack.
                        final PinnedActivityStack pinnedStack = mStackSupervisor.getStack(
@@ -2397,7 +2401,6 @@ public class ActivityManagerService extends IActivityManager.Stub
                        }
                    }
                }
                }
            } break;
            case NOTIFY_VR_SLEEPING_MSG: {
                notifyVrManagerOfSleepState(msg.arg1 != 0);
+11 −4
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ class AlertWindowNotification {
    private String mNotificationTag;
    private final NotificationManager mNotificationManager;
    private final String mPackageName;
    private boolean mCancelled;
    private boolean mPosted;
    private IconUtilities mIconUtilities;

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

    void post() {
        // 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.
        mService.mH.post(this::onPostNotification);
@@ -76,16 +78,21 @@ class AlertWindowNotification {

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

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

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

    final DisplaySettings mDisplaySettings;

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

    /**
     * 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);
            }
        }
    }
}