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

Commit 595f03c2 authored by Ben Lin's avatar Ben Lin
Browse files

App-to-Web: Use userContext when getting DomainVerificationManager.

Since DVM uses context.userId in its implementation, we need to supply
the right user context when retriving DVM so it saves to the correct
user.

Bug: 399181562
Test: Manual. on HSUM devices, choosing the dialog option -> reopen, see
option sticks
Flag: EXEMPT bugfix

Change-Id: I83cb0d93a81bdb282e16bcdc9c472855eea6e83d
parent c797432f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import kotlinx.coroutines.withContext
 */
internal class OpenByDefaultDialog(
    private val context: Context,
    private val userContext: Context,
    private val taskInfo: RunningTaskInfo,
    private val taskSurface: SurfaceControl,
    private val displayController: DisplayController,
@@ -75,7 +76,7 @@ internal class OpenByDefaultDialog(
    private lateinit var openInBrowserButton: RadioButton

    private val domainVerificationManager =
        context.getSystemService(DomainVerificationManager::class.java)!!
        userContext.getSystemService(DomainVerificationManager::class.java)!!
    private val packageName = taskInfo.baseActivity?.packageName!!

    private var loadAppInfoJob: Job? = null
+3 −2
Original line number Diff line number Diff line
@@ -1232,7 +1232,8 @@ public abstract class WMShellModule {
            Optional<CompatUIHandler> compatUI,
            DesksOrganizer desksOrganizer,
            ShellDesktopState shelldesktopState,
            DesktopConfig desktopConfig
            DesktopConfig desktopConfig,
            UserProfileContexts userProfileContexts
    ) {
        if (!shelldesktopState.canEnterDesktopModeOrShowAppHandle()) {
            return Optional.empty();
@@ -1251,7 +1252,7 @@ public abstract class WMShellModule {
                desktopModeUiEventLogger, taskResourceLoader, recentsTransitionHandler,
                desktopModeCompatPolicy, desktopTilingDecorViewModel,
                multiDisplayDragMoveIndicatorController, compatUI.orElse(null),
                desksOrganizer, shelldesktopState, desktopConfig));
                desksOrganizer, shelldesktopState, desktopConfig, userProfileContexts));
    }

    @WMSingleton
+10 −4
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ import com.android.wm.shell.common.MultiDisplayDragMoveIndicatorController;
import com.android.wm.shell.common.MultiInstanceHelper;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.common.UserProfileContexts;
import com.android.wm.shell.compatui.CompatUIController;
import com.android.wm.shell.compatui.api.CompatUIHandler;
import com.android.wm.shell.compatui.impl.CompatUIRequests;
@@ -262,6 +263,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
    private final MultiDisplayDragMoveIndicatorController mMultiDisplayDragMoveIndicatorController;
    private final LatencyTracker mLatencyTracker;
    private final CompatUIHandler mCompatUI;
    private final UserProfileContexts mUserProfileContexts;

    public DesktopModeWindowDecorViewModel(
            Context context,
@@ -306,7 +308,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
            CompatUIHandler compatUI,
            DesksOrganizer desksOrganizer,
            ShellDesktopState shellDesktopState,
            DesktopConfig desktopConfig) {
            DesktopConfig desktopConfig,
            UserProfileContexts userProfileContexts) {
        this(
                context,
                shellExecutor,
@@ -357,7 +360,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                compatUI,
                desksOrganizer,
                shellDesktopState,
                desktopConfig);
                desktopConfig,
                userProfileContexts);
    }

    @VisibleForTesting
@@ -411,7 +415,8 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
            CompatUIHandler compatUI,
            DesksOrganizer desksOrganizer,
            ShellDesktopState shellDesktopState,
            DesktopConfig desktopConfig) {
            DesktopConfig desktopConfig,
            UserProfileContexts userProfileContexts) {
        mContext = context;
        mMainExecutor = shellExecutor;
        mMainHandler = mainHandler;
@@ -453,6 +458,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
        mAssistContentRequester = assistContentRequester;
        mWindowDecorViewHostSupplier = windowDecorViewHostSupplier;
        mCompatUI = compatUI;
        mUserProfileContexts = userProfileContexts;
        mOnDisplayChangingListener = (displayId, fromRotation, toRotation, displayAreaInfo, t) -> {
            DesktopModeWindowDecoration decoration;
            RunningTaskInfo taskInfo;
@@ -1914,7 +1920,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                        DesktopExperienceFlags.ENABLE_BUG_FIXES_FOR_SECONDARY_DISPLAY.isTrue()
                                ? mDisplayController.getDisplayContext(taskInfo.displayId)
                                : mContext,
                        mContext.createContextAsUser(UserHandle.of(taskInfo.userId), 0 /* flags */),
                        mUserProfileContexts.getOrCreate(taskInfo.userId),
                        mDisplayController,
                        mTaskResourceLoader,
                        mSplitScreenController,
+1 −0
Original line number Diff line number Diff line
@@ -1272,6 +1272,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        if (isOpenByDefaultDialogActive()) return;
        mOpenByDefaultDialog = new OpenByDefaultDialog(
                mContext,
                mUserContext,
                mTaskInfo,
                mTaskSurface,
                mDisplayController,
+5 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import com.android.wm.shell.common.DisplayInsetsController
import com.android.wm.shell.common.DisplayLayout
import com.android.wm.shell.common.MultiDisplayDragMoveIndicatorController
import com.android.wm.shell.common.MultiInstanceHelper
import com.android.wm.shell.common.UserProfileContexts
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.compatui.api.CompatUIHandler
import com.android.wm.shell.desktopmode.DesktopActivityOrientationChangeHandler
@@ -177,6 +178,7 @@ open class DesktopModeWindowDecorViewModelTestsBase : ShellTestCase() {
    protected lateinit var desktopState: FakeDesktopState
    protected lateinit var shellDesktopState: FakeShellDesktopState
    protected lateinit var desktopConfig: FakeDesktopConfig
    private val mockUserProfileContexts = mock<UserProfileContexts>()

    private val transactionFactory = Supplier<SurfaceControl.Transaction> {
        SurfaceControl.Transaction()
@@ -215,6 +217,8 @@ open class DesktopModeWindowDecorViewModelTestsBase : ShellTestCase() {
        whenever(display.type).thenReturn(Display.TYPE_INTERNAL)
        whenever(mockDesktopUserRepositories.getProfile(anyInt()))
            .thenReturn(mockDesktopRepository)
        whenever(mockUserProfileContexts[anyInt()]).thenReturn(spyContext)
        whenever(mockUserProfileContexts.getOrCreate(anyInt())).thenReturn(spyContext)
        desktopModeCompatPolicy = DesktopModeCompatPolicy(spyContext)
        appHandleAndHeaderVisibilityHelper = AppHandleAndHeaderVisibilityHelper(
            displayController = mockDisplayController,
@@ -273,6 +277,7 @@ open class DesktopModeWindowDecorViewModelTestsBase : ShellTestCase() {
            mockDesksOrganizer,
            shellDesktopState,
            desktopConfig,
            mockUserProfileContexts,
        )
        desktopModeWindowDecorViewModel.setSplitScreenController(mockSplitScreenController)
        whenever(mockDisplayController.getDisplayLayout(any())).thenReturn(mockDisplayLayout)