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

Commit 577bfc96 authored by Jorge Gil's avatar Jorge Gil
Browse files

Use task's userId to obtain PackageManager instance

This is a follow up to Ia4b2cf80278e49fe1b6d26ea99d4be48110c7232 with a
proper fix. Instead of using MATCH_UNINSTALLED_PACKAGES, which worked
because the package is technically "uninstalled" for the current user
(because it's installed for another user), this change now builds a user
context using the userId in TaskInfo, and whose PackageManager can now
obtain the ActivityInfo without additional flags.

Bug: 354884302
Fix: 355306146
Test: with HSUM enabled, app name and icon can be obtained through
PackageManager without crashing
Flag: EXEMPT bugfix

Change-Id: I54c3a4332dbb330b0c4ff9df0e86ec038716f7ff
parent 6b9f4da5
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.graphics.Region;
import android.hardware.input.InputManager;
import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;
import android.util.SparseArray;
@@ -288,6 +289,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
        final CaptionWindowDecoration windowDecoration =
                new CaptionWindowDecoration(
                        mContext,
                        mContext.createContextAsUser(UserHandle.of(taskInfo.userId), 0 /* flags */),
                        mDisplayController,
                        mTaskOrganizer,
                        taskInfo,
+2 −1
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL

    CaptionWindowDecoration(
            Context context,
            @NonNull Context userContext,
            DisplayController displayController,
            ShellTaskOrganizer taskOrganizer,
            RunningTaskInfo taskInfo,
@@ -85,7 +86,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL
            @ShellBackgroundThread ShellExecutor bgExecutor,
            Choreographer choreographer,
            SyncTransactionQueue syncQueue) {
        super(context, displayController, taskOrganizer, taskInfo, taskSurface);
        super(context, userContext, displayController, taskOrganizer, taskInfo, taskSurface);
        mHandler = handler;
        mBgExecutor = bgExecutor;
        mChoreographer = choreographer;
+2 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
import android.util.SparseArray;
import android.view.Choreographer;
@@ -1149,6 +1150,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
        final DesktopModeWindowDecoration windowDecoration =
                mDesktopModeWindowDecorFactory.create(
                        mContext,
                        mContext.createContextAsUser(UserHandle.of(taskInfo.userId), 0 /* flags */),
                        mDisplayController,
                        mSplitScreenController,
                        mTaskOrganizer,
+9 −9
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin

    DesktopModeWindowDecoration(
            Context context,
            @NonNull Context userContext,
            DisplayController displayController,
            SplitScreenController splitScreenController,
            ShellTaskOrganizer taskOrganizer,
@@ -171,8 +172,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            SyncTransactionQueue syncQueue,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer,
            AppToWebGenericLinksParser genericLinksParser) {
        this (context, displayController, splitScreenController, taskOrganizer, taskInfo,
                taskSurface, handler, bgExecutor, choreographer, syncQueue,
        this (context, userContext, displayController, splitScreenController, taskOrganizer,
                taskInfo, taskSurface, handler, bgExecutor, choreographer, syncQueue,
                rootTaskDisplayAreaOrganizer, genericLinksParser, SurfaceControl.Builder::new,
                SurfaceControl.Transaction::new,  WindowContainerTransaction::new,
                SurfaceControl::new, new SurfaceControlViewHostFactory() {},
@@ -181,6 +182,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin

    DesktopModeWindowDecoration(
            Context context,
            @NonNull Context userContext,
            DisplayController displayController,
            SplitScreenController splitScreenController,
            ShellTaskOrganizer taskOrganizer,
@@ -199,7 +201,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            SurfaceControlViewHostFactory surfaceControlViewHostFactory,
            MaximizeMenuFactory maximizeMenuFactory,
            HandleMenuFactory handleMenuFactory) {
        super(context, displayController, taskOrganizer, taskInfo, taskSurface,
        super(context, userContext, displayController, taskOrganizer, taskInfo, taskSurface,
                surfaceControlBuilderSupplier, surfaceControlTransactionSupplier,
                windowContainerTransactionSupplier, surfaceControlSupplier,
                surfaceControlViewHostFactory);
@@ -737,12 +739,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                Slog.e(TAG, "Base activity component not found in task");
                return;
            }
            final PackageManager pm = mContext.getApplicationContext().getPackageManager();
            final ActivityInfo activityInfo = pm.getActivityInfo(baseActivity,
                    // Include uninstalled apps. Despite its name, adding this flag is a workaround
                    // to #getActivityInfo throwing a NameNotFoundException for installed packages
                    // when HSUM is enabled. See b/354884302.
                    PackageManager.MATCH_UNINSTALLED_PACKAGES);
            final PackageManager pm = mUserContext.getPackageManager();
            final ActivityInfo activityInfo = pm.getActivityInfo(baseActivity, 0 /* flags */);
            final IconProvider provider = new IconProvider(mContext);
            final Drawable appIconDrawable = provider.getIcon(activityInfo);
            final BaseIconFactory headerIconFactory = createIconFactory(mContext,
@@ -1264,6 +1262,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin

        DesktopModeWindowDecoration create(
                Context context,
                @NonNull Context userContext,
                DisplayController displayController,
                SplitScreenController splitScreenController,
                ShellTaskOrganizer taskOrganizer,
@@ -1277,6 +1276,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                AppToWebGenericLinksParser genericLinksParser) {
            return new DesktopModeWindowDecoration(
                    context,
                    userContext,
                    displayController,
                    splitScreenController,
                    taskOrganizer,
+5 −2
Original line number Diff line number Diff line
@@ -106,6 +106,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
     * System-wide context. Only used to create context with overridden configurations.
     */
    final Context mContext;
    final @NonNull Context mUserContext;
    final @NonNull DisplayController mDisplayController;
    final ShellTaskOrganizer mTaskOrganizer;
    final Supplier<SurfaceControl.Builder> mSurfaceControlBuilderSupplier;
@@ -147,11 +148,12 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>

    WindowDecoration(
            Context context,
            @NonNull Context userContext,
            DisplayController displayController,
            ShellTaskOrganizer taskOrganizer,
            RunningTaskInfo taskInfo,
            SurfaceControl taskSurface) {
        this(context, displayController, taskOrganizer, taskInfo, taskSurface,
        this(context, userContext, displayController, taskOrganizer, taskInfo, taskSurface,
                SurfaceControl.Builder::new, SurfaceControl.Transaction::new,
                WindowContainerTransaction::new, SurfaceControl::new,
                new SurfaceControlViewHostFactory() {});
@@ -159,6 +161,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>

    WindowDecoration(
            Context context,
            @NonNull Context userContext,
            @NonNull DisplayController displayController,
            ShellTaskOrganizer taskOrganizer,
            RunningTaskInfo taskInfo,
@@ -169,6 +172,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
            Supplier<SurfaceControl> surfaceControlSupplier,
            SurfaceControlViewHostFactory surfaceControlViewHostFactory) {
        mContext = context;
        mUserContext = userContext;
        mDisplayController = displayController;
        mTaskOrganizer = taskOrganizer;
        mTaskInfo = taskInfo;
@@ -177,7 +181,6 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer>
        mSurfaceControlTransactionSupplier = surfaceControlTransactionSupplier;
        mWindowContainerTransactionSupplier = windowContainerTransactionSupplier;
        mSurfaceControlViewHostFactory = surfaceControlViewHostFactory;

        mDisplay = mDisplayController.getDisplay(mTaskInfo.displayId);
    }

Loading