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

Commit faabe5dc authored by Yuri Lin's avatar Yuri Lin
Browse files

Don't show notification guts in kiosk mode

If the device is determined to be in kiosk mode (specifically, LOCK_TASK_MODE_LOCKED), it should not be permitted to modify notification settings. This only applies to the fully locked state and not to app pinning (LOCK_TASK_MODE_PINNED).

Bug: 424876676
Test: NotificationGutsManagerTest, manual verification that guts could not open
Flag: EXEMPT bug fix
Change-Id: I1423a8c2d29055b31fc8c7fce8c574e1c19c4841
parent af856965
Loading
Loading
Loading
Loading
+31 −8
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.settings.UserContextProvider
import com.android.systemui.shade.ShadeController
import com.android.systemui.shared.system.activityManagerWrapper
import com.android.systemui.statusbar.NotificationLockscreenUserManager
import com.android.systemui.statusbar.NotificationPresenter
import com.android.systemui.statusbar.notification.AssistantFeedbackController
@@ -86,9 +87,12 @@ import com.android.systemui.statusbar.policy.DeviceProvisionedController
import com.android.systemui.testKosmos
import com.android.systemui.util.kotlin.javaAdapter
import com.android.systemui.wmshell.BubblesManager
import java.util.Optional
import kotlin.test.assertNotNull
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
@@ -113,8 +117,6 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters
import java.util.Optional
import kotlin.test.assertNotNull

/** Tests for [NotificationGutsManager]. */
@SmallTest
@@ -232,6 +234,7 @@ class NotificationGutsManagerTest(flags: FlagsParameterization) : SysuiTestCase(
                metricsLogger,
                headsUpManager,
                activityStarter,
                kosmos.activityManagerWrapper,
            )
        gutsManager.setUpWithPresenter(
            presenter,
@@ -317,6 +320,31 @@ class NotificationGutsManagerTest(flags: FlagsParameterization) : SysuiTestCase(
        }
    }

    @Test
    fun testOpenGutsInKioskMode_doesNotOpen() {
        whenever(kosmos.activityManagerWrapper.isLockTaskKioskModeActive).thenReturn(true)

        val guts = spy(NotificationGuts(mContext))
        whenever(guts.post(any())).thenAnswer { invocation: InvocationOnMock ->
            handler.post(((invocation.arguments[0] as Runnable)))
            null
        }

        // Test doesn't support animation since the guts view is not attached.
        doNothing().whenever(guts).openControls(anyInt(), anyInt(), anyBoolean(), any())

        val realRow = createTestNotificationRow()
        val menuItem = createTestMenuItem(realRow)

        val row = spy(realRow)
        whenever(row.windowToken).thenReturn(Binder())
        whenever(row.guts).thenReturn(guts)

        assertFalse(gutsManager.openGutsInternal(row, 0, 0, menuItem))
        executor.runAllReady()
        verify(guts, never()).openControls(anyInt(), anyInt(), anyBoolean(), any<Runnable>())
    }

    @Test
    fun testLockscreenShadeVisible_visible_gutsNotClosed() =
        testScope.runTest {
@@ -527,12 +555,7 @@ class NotificationGutsManagerTest(flags: FlagsParameterization) : SysuiTestCase(

        whenever(highPriorityProvider.isHighPriority(any())).thenReturn(true)
        whenever(kosmos.mockHighPriorityProvider.isHighPriority(any())).thenReturn(true)
        gutsManager.initializeNotificationInfo(
            row,
            sbn,
            ranking,
            notificationInfoView,
        )
        gutsManager.initializeNotificationInfo(row, sbn, ranking, notificationInfoView)

        verify(notificationInfoView)
            .bindNotification(
+11 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import com.android.systemui.scene.domain.interactor.WindowRootViewVisibilityInte
import com.android.systemui.settings.UserContextProvider;
import com.android.systemui.shade.ShadeController;
import com.android.systemui.shade.ShadeDisplayAware;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationPresenter;
import com.android.systemui.statusbar.StatusBarState;
@@ -147,6 +148,7 @@ public class NotificationGutsManager implements NotifGutsViewManager, CoreStarta
    private NotifGutsViewListener mGutsListener;
    private final HeadsUpManager mHeadsUpManager;
    private final ActivityStarter mActivityStarter;
    private final ActivityManagerWrapper mActivityManagerWrapper;

    @Inject
    public NotificationGutsManager(
@@ -178,7 +180,8 @@ public class NotificationGutsManager implements NotifGutsViewManager, CoreStarta
            DeviceProvisionedController deviceProvisionedController,
            MetricsLogger metricsLogger,
            HeadsUpManager headsUpManager,
            ActivityStarter activityStarter) {
            ActivityStarter activityStarter,
            ActivityManagerWrapper activityManagerWrapper) {
        mContext = context;
        mMainHandler = mainHandler;
        mBgHandler = bgHandler;
@@ -208,6 +211,7 @@ public class NotificationGutsManager implements NotifGutsViewManager, CoreStarta
        mMetricsLogger = metricsLogger;
        mHeadsUpManager = headsUpManager;
        mActivityStarter = activityStarter;
        mActivityManagerWrapper = activityManagerWrapper;
    }

    public void setUpWithPresenter(NotificationPresenter presenter,
@@ -794,6 +798,12 @@ public class NotificationGutsManager implements NotifGutsViewManager, CoreStarta
            return false;
        }

        if (mActivityManagerWrapper.isLockTaskKioskModeActive()) {
            // If the device is locked in kiosk mode, the user should not be able to access
            // notification guts to change any settings.
            return false;
        }

        final ExpandableNotificationRow row = (ExpandableNotificationRow) view;
        if (row.isNotificationRowLongClickable()) {
            view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
+2 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.settings.UserContextProvider
import com.android.systemui.shade.shadeControllerSceneImpl
import com.android.systemui.shared.system.activityManagerWrapper
import com.android.systemui.statusbar.NotificationPresenter
import com.android.systemui.statusbar.notification.AssistantFeedbackController
import com.android.systemui.statusbar.notification.NotificationActivityStarter
@@ -203,6 +204,7 @@ class NotificationGutsManagerWithScenesTest : SysuiTestCase() {
                metricsLogger,
                headsUpManager,
                activityStarter,
                kosmos.activityManagerWrapper,
            )
        gutsManager.setUpWithPresenter(
            presenter,