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

Commit ee69756d authored by Winson Chung's avatar Winson Chung
Browse files

Adding cached value for current user for per-SysUI process components.

- Also ensuring that we don't do additional work for non-current users when
  the task stack changes.

Bug: 38390446
Test: Launch Recents in multiple users, ensure that it works and does not
      make a binder call to get the current user id

Change-Id: If075675edc3874d809bad30d0aa564a8e59771d3
parent a239ed1c
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class PipManager implements BasePipManager {
    TaskStackListener mTaskStackListener = new TaskStackListener() {
        @Override
        public void onActivityPinned(String packageName, int taskId) {
            if (!checkCurrentUserId(false /* debug */)) {
            if (!checkCurrentUserId(mContext, false /* debug */)) {
                return;
            }

@@ -85,7 +85,7 @@ public class PipManager implements BasePipManager {

        @Override
        public void onActivityUnpinned() {
            if (!checkCurrentUserId(false /* debug */)) {
            if (!checkCurrentUserId(mContext, false /* debug */)) {
                return;
            }

@@ -114,7 +114,7 @@ public class PipManager implements BasePipManager {

        @Override
        public void onPinnedActivityRestartAttempt(boolean clearedTask) {
            if (!checkCurrentUserId(false /* debug */)) {
            if (!checkCurrentUserId(mContext, false /* debug */)) {
                return;
            }

+4 −4
Original line number Diff line number Diff line
@@ -577,7 +577,7 @@ public class PipManager implements BasePipManager {
        @Override
        public void onTaskStackChanged() {
            if (DEBUG) Log.d(TAG, "onTaskStackChanged()");
            if (!checkCurrentUserId(DEBUG)) {
            if (!checkCurrentUserId(mContext, DEBUG)) {
                return;
            }
            if (getState() != STATE_NO_PIP) {
@@ -614,7 +614,7 @@ public class PipManager implements BasePipManager {
        @Override
        public void onActivityPinned(String packageName, int taskId) {
            if (DEBUG) Log.d(TAG, "onActivityPinned()");
            if (!checkCurrentUserId(DEBUG)) {
            if (!checkCurrentUserId(mContext, DEBUG)) {
                return;
            }
            StackInfo stackInfo = getPinnedStackInfo();
@@ -641,7 +641,7 @@ public class PipManager implements BasePipManager {
        @Override
        public void onPinnedActivityRestartAttempt(boolean clearedTask) {
            if (DEBUG) Log.d(TAG, "onPinnedActivityRestartAttempt()");
            if (!checkCurrentUserId(DEBUG)) {
            if (!checkCurrentUserId(mContext, DEBUG)) {
                return;
            }
            // If PIPed activity is launched again by Launcher or intent, make it fullscreen.
@@ -651,7 +651,7 @@ public class PipManager implements BasePipManager {
        @Override
        public void onPinnedStackAnimationEnded() {
            if (DEBUG) Log.d(TAG, "onPinnedStackAnimationEnded()");
            if (!checkCurrentUserId(DEBUG)) {
            if (!checkCurrentUserId(mContext, DEBUG)) {
                return;
            }
            switch (getState()) {
+8 −4
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.recents;
import static com.android.systemui.statusbar.phone.StatusBar.SYSTEM_DIALOG_REASON_RECENT_APPS;

import android.app.ActivityManager;
import android.app.UiModeManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -33,7 +32,6 @@ import android.hardware.display.DisplayManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
@@ -41,7 +39,6 @@ import android.provider.Settings;
import android.util.EventLog;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;

import com.android.internal.logging.MetricsLogger;
@@ -60,11 +57,12 @@ import com.android.systemui.recents.events.component.ScreenPinningRequestEvent;
import com.android.systemui.recents.events.component.ShowUserToastEvent;
import com.android.systemui.recents.events.ui.RecentsDrawnEvent;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.model.HighResThumbnailLoader;
import com.android.systemui.recents.model.RecentsTaskLoader;
import com.android.systemui.stackdivider.Divider;
import com.android.systemui.statusbar.CommandQueue;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
@@ -792,4 +790,10 @@ public class Recents extends SystemUI
        }
        return false;
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Recents");
        pw.println("  currentUserId=" + SystemServicesProxy.getInstance(mContext).getCurrentUser());
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -119,6 +119,11 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener

        @Override
        public void onTaskStackChangedBackground() {
            // Check this is for the right user
            if (!checkCurrentUserId(mContext, false /* debug */)) {
                return;
            }

            // Preloads the next task
            RecentsConfiguration config = Recents.getConfiguration();
            if (config.svelteLevel == RecentsConfiguration.SVELTE_NONE) {
@@ -161,6 +166,11 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener

        @Override
        public void onActivityPinned(String packageName, int taskId) {
            // Check this is for the right user
            if (!checkCurrentUserId(mContext, false /* debug */)) {
                return;
            }

            // This time needs to be fetched the same way the last active time is fetched in
            // {@link TaskRecord#touchActiveTime}
            Recents.getConfiguration().getLaunchState().launchedFromPipApp = true;
@@ -172,12 +182,22 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener

        @Override
        public void onActivityUnpinned() {
            // Check this is for the right user
            if (!checkCurrentUserId(mContext, false /* debug */)) {
                return;
            }

            EventBus.getDefault().send(new ActivityUnpinnedEvent());
            sLastPipTime = -1;
        }

        @Override
        public void onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) {
            // Check this is for the right user
            if (!checkCurrentUserId(mContext, false /* debug */)) {
                return;
            }

            EventBus.getDefault().send(new TaskSnapshotChangedEvent(taskId, snapshot));
        }
    }
+19 −12
Original line number Diff line number Diff line
@@ -85,7 +85,6 @@ import android.view.accessibility.AccessibilityManager;

import com.android.internal.app.AssistUtils;
import com.android.internal.os.BackgroundThread;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.UiOffloadThread;
@@ -95,6 +94,8 @@ import com.android.systemui.recents.RecentsDebugFlags;
import com.android.systemui.recents.RecentsImpl;
import com.android.systemui.recents.model.Task;
import com.android.systemui.recents.model.ThumbnailData;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener;

import java.io.IOException;
import java.util.ArrayList;
@@ -102,8 +103,6 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Acts as a shim around the real system services that we need to access data from, and provides
@@ -143,6 +142,7 @@ public class SystemServicesProxy {
    Display mDisplay;
    String mRecentsPackage;
    ComponentName mAssistComponent;
    private int mCurrentUserId;

    boolean mIsSafeMode;
    boolean mHasFreeformWorkspaceSupport;
@@ -185,9 +185,9 @@ public class SystemServicesProxy {
         * TaskStackListener should make this call to verify that we don't act on events from other
         * user's processes.
         */
        protected final boolean checkCurrentUserId(boolean debug) {
        protected final boolean checkCurrentUserId(Context context, boolean debug) {
            int processUserId = UserHandle.myUserId();
            int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
            int currentUserId = SystemServicesProxy.getInstance(context).getCurrentUser();
            if (processUserId != currentUserId) {
                if (debug) {
                    Log.d(TAG, "UID mismatch. SystemUI is running uid=" + processUserId
@@ -284,6 +284,10 @@ public class SystemServicesProxy {
        }
    };

    private final UserInfoController.OnUserInfoChangedListener mOnUserInfoChangedListener =
            (String name, Drawable picture, String userAccount) ->
                    mCurrentUserId = mAm.getCurrentUser();

    /**
     * List of {@link TaskStackListener} registered from {@link #registerTaskStackListener}.
     */
@@ -312,6 +316,7 @@ public class SystemServicesProxy {
                        Settings.Global.getInt(context.getContentResolver(),
                                DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT, 0) != 0;
        mIsSafeMode = mPm.isSafeMode();
        mCurrentUserId = mAm.getCurrentUser();

        // Get the dummy thumbnail width/heights
        Resources res = context.getResources();
@@ -329,6 +334,12 @@ public class SystemServicesProxy {
        // Resolve the assist intent
        mAssistComponent = mAssistUtils.getAssistComponentForUser(UserHandle.myUserId());

        // Since SystemServicesProxy can be accessed from a per-SysUI process component, create a
        // per-process listener to keep track of the current user id to reduce the number of binder
        // calls to fetch it.
        UserInfoController userInfoController = Dependency.get(UserInfoController.class);
        userInfoController.addCallback(mOnUserInfoChangedListener);

        if (RecentsDebugFlags.Static.EnableMockTasks) {
            // Create a dummy icon
            mDummyIcon = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
@@ -1029,15 +1040,11 @@ public class SystemServicesProxy {
    }

    /**
     * Returns the current user id.
     * Returns the current user id.  Used instead of KeyguardUpdateMonitor in SystemUI components
     * that run in the non-primary SystemUI process.
     */
    public int getCurrentUser() {
        if (mAm == null) return 0;

        // This must call through ActivityManager, as the SystemServicesProxy can be called in a
        // secondary user's SystemUI process, and KeyguardUpdateMonitor is only updated in the
        // primary user's SystemUI process
        return mAm.getCurrentUser();
        return mCurrentUserId;
    }

    /**
Loading