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

Commit 4121d6bd authored by Kazuki Takise's avatar Kazuki Takise
Browse files

Make ATMService#mUiContext mockable

Some vendor-specific (lightweight) unit tests use the real class for
ActivityRecord but mock ActivityTaskManagerService (e.g.
ArcLaunchParamsModifierTest).

The problem is that ActivityRecord directly accesses
ATMService#mUiContext to get the DevicePolicyManager service and the
property itself is marked as final, so this cannot be replaced with a
mock and instantiating ActivityRecord fails.

Bug: 244515960
Test: atest ArcLaunchParamsModifierTest
Change-Id: I2fc015d9f3dc4ce88607355b8e2a2849c2ac7fb4
parent f5ee8436
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -2120,7 +2120,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A


        mActivityRecordInputSink = new ActivityRecordInputSink(this, sourceRecord);
        mActivityRecordInputSink = new ActivityRecordInputSink(this, sourceRecord);


        updateEnterpriseThumbnailDrawable(mAtmService.mUiContext);
        updateEnterpriseThumbnailDrawable(mAtmService.getUiContext());
    }
    }


    /**
    /**
@@ -7433,7 +7433,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
        }
        final Rect frame = win.getRelativeFrame();
        final Rect frame = win.getRelativeFrame();
        final Drawable thumbnailDrawable = task.mUserId == mWmService.mCurrentUserId
        final Drawable thumbnailDrawable = task.mUserId == mWmService.mCurrentUserId
                ? mAtmService.mUiContext.getDrawable(R.drawable.ic_account_circle)
                ? mAtmService.getUiContext().getDrawable(R.drawable.ic_account_circle)
                : mEnterpriseThumbnailDrawable;
                : mEnterpriseThumbnailDrawable;
        final HardwareBuffer thumbnail = getDisplayContent().mAppTransition
        final HardwareBuffer thumbnail = getDisplayContent().mAppTransition
                .createCrossProfileAppsThumbnail(thumbnailDrawable, frame);
                .createCrossProfileAppsThumbnail(thumbnailDrawable, frame);
+5 −1
Original line number Original line Diff line number Diff line
@@ -346,7 +346,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
     * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can
     * This Context is themable and meant for UI display (AlertDialogs, etc.). The theme can
     * change at runtime. Use mContext for non-UI purposes.
     * change at runtime. Use mContext for non-UI purposes.
     */
     */
    final Context mUiContext;
    private final Context mUiContext;
    final ActivityThread mSystemThread;
    final ActivityThread mSystemThread;
    H mH;
    H mH;
    UiHandler mUiHandler;
    UiHandler mUiHandler;
@@ -1041,6 +1041,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
        }
    }
    }


    Context getUiContext() {
        return mUiContext;
    }

    UserManagerService getUserManager() {
    UserManagerService getUserManager() {
        if (mUserManager == null) {
        if (mUserManager == null) {
            IBinder b = ServiceManager.getService(Context.USER_SERVICE);
            IBinder b = ServiceManager.getService(Context.USER_SERVICE);
+1 −1
Original line number Original line Diff line number Diff line
@@ -421,7 +421,7 @@ public class DisplayPolicy {
        mService = service;
        mService = service;
        mContext = displayContent.isDefaultDisplay ? service.mContext
        mContext = displayContent.isDefaultDisplay ? service.mContext
                : service.mContext.createDisplayContext(displayContent.getDisplay());
                : service.mContext.createDisplayContext(displayContent.getDisplay());
        mUiContext = displayContent.isDefaultDisplay ? service.mAtmService.mUiContext
        mUiContext = displayContent.isDefaultDisplay ? service.mAtmService.getUiContext()
                : service.mAtmService.mSystemThread
                : service.mAtmService.mSystemThread
                        .getSystemUiContext(displayContent.getDisplayId());
                        .getSystemUiContext(displayContent.getDisplayId());
        mDisplayContent = displayContent;
        mDisplayContent = displayContent;