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

Commit a49eb792 authored by Julia Reynolds's avatar Julia Reynolds Committed by Nolen Johnson
Browse files

[BACKPORT] Prevent long press on profile notifs when locked

Test: NotificationGutsManagerTest
Bug: 378087531
Flag: EXEMPT BUGFIX

(cherry picked from commit a6280c4ccf96685eed5dc57c2bd9cbbe04209bf1)
Cherrypick-From: https://googleplex-android-review.googlesource.com/q/commit:2feb7e286a93196e44fef97ac00fb69f6f3d3ca9
Merged-In: Ic4ab842763d2d9473adcfc426a64434aec5c6ed2
Change-Id: Ic4ab842763d2d9473adcfc426a64434aec5c6ed2
parent 280890ff
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.ArraySet;
@@ -123,6 +124,8 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
    private final CurrentUserContextTracker mContextTracker;
    private final Provider<PriorityOnboardingDialogController.Builder> mBuilderProvider;
    private final UiEventLogger mUiEventLogger;
    private final UserManager mUserManager;


    /**
     * Injected constructor. See {@link NotificationsModule}.
@@ -154,6 +157,7 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
        mChannelEditorDialogController = channelEditorDialogController;
        mBubbleController = bubbleController;
        mUiEventLogger = uiEventLogger;
        mUserManager = context.getSystemService(UserManager.class);
    }

    public void setUpWithPresenter(NotificationPresenter presenter,
@@ -591,6 +595,10 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
        }

        final ExpandableNotificationRow row = (ExpandableNotificationRow) view;
        if (affectedByWorkProfileLock(row)) {
            return false;
        }

        view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        if (row.areGutsExposed()) {
            closeAndSaveGuts(false /* removeLeavebehind */, false /* force */,
@@ -647,6 +655,12 @@ public class NotificationGutsManager implements Dumpable, NotificationLifetimeEx
        return true;
    }

    boolean affectedByWorkProfileLock(ExpandableNotificationRow row) {
        int userId = row.getEntry().getSbn().getNormalizedUserId();
        return mUserManager.isManagedProfile(userId)
                && mLockscreenUserManager.isLockscreenPublicMode(userId);
    }

    @Override
    public void setCallback(NotificationSafeToRemoveCallback callback) {
        mNotificationLifetimeFinishedCallback = callback;