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

Commit a6d0f6e5 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of [19140263, 19136050, 18989968] into tm-release.

Change-Id: Icee4decbd65d8087ec3718f90abd82a9d114dc55
parents 4e647a7f d0283080
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -405,6 +405,8 @@ public class KeyguardService extends Service {

        @Override // Binder interface
        public void setOccluded(boolean isOccluded, boolean animate) {
            Log.d(TAG, "setOccluded(" + isOccluded + ")");

            Trace.beginSection("KeyguardService.mBinder#setOccluded");
            checkPermission();
            mKeyguardViewMediator.setOccluded(isOccluded, animate);
+9 −5
Original line number Diff line number Diff line
@@ -836,9 +836,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
    private final ActivityLaunchAnimator.Controller mOccludeAnimationController =
            new ActivityLaunchAnimator.Controller() {
                @Override
                public void onLaunchAnimationStart(boolean isExpandingFullyAbove) {
                    setOccluded(true /* occluded */, false /* animate */);
                }
                public void onLaunchAnimationStart(boolean isExpandingFullyAbove) {}

                @Override
                public void onLaunchAnimationCancelled() {
@@ -924,6 +922,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
                        RemoteAnimationTarget[] wallpapers,
                        RemoteAnimationTarget[] nonApps,
                        IRemoteAnimationFinishedCallback finishedCallback) throws RemoteException {
                    Log.d(TAG, "UnoccludeAnimator#onAnimationStart. Set occluded = false.");
                    setOccluded(false /* isOccluded */, true /* animate */);

                    if (apps == null || apps.length == 0 || apps[0] == null) {
@@ -1669,6 +1668,8 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
     * Notify us when the keyguard is occluded by another window
     */
    public void setOccluded(boolean isOccluded, boolean animate) {
        Log.d(TAG, "setOccluded(" + isOccluded + ")");

        Trace.beginSection("KeyguardViewMediator#setOccluded");
        if (DEBUG) Log.d(TAG, "setOccluded " + isOccluded);
        mInteractionJankMonitor.cancel(CUJ_LOCKSCREEN_TRANSITION_FROM_AOD);
@@ -1699,6 +1700,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
     */
    private void handleSetOccluded(boolean isOccluded, boolean animate) {
        Trace.beginSection("KeyguardViewMediator#handleSetOccluded");
        Log.d(TAG, "handleSetOccluded(" + isOccluded + ")");
        synchronized (KeyguardViewMediator.this) {
            if (mHiding && isOccluded) {
                // We're in the process of going away but WindowManager wants to show a
@@ -3188,16 +3190,18 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable,
            // internal state to reflect that immediately, vs. waiting for the launch animator to
            // begin. Otherwise, calls to setShowingLocked, etc. will not know that we're about to
            // be occluded and might re-show the keyguard.
            Log.d(TAG, "OccludeAnimator#onAnimationStart. Set occluded = true.");
            setOccluded(true /* isOccluded */, false /* animate */);
        }

        @Override
        public void onAnimationCancelled(boolean isKeyguardOccluded) throws RemoteException {
            super.onAnimationCancelled(isKeyguardOccluded);
            setOccluded(isKeyguardOccluded /* occluded */, false /* animate */);

            Log.d(TAG, "Occlude animation cancelled by WM. "
                    + "Setting occluded state to: " + mOccluded);
                    + "Setting occluded state to: " + isKeyguardOccluded);
            setOccluded(isKeyguardOccluded /* occluded */, false /* animate */);

        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -1760,6 +1760,7 @@ public class CentralSurfacesImpl extends CoreStartable implements
                    // activity is exited.
                    if (mKeyguardStateController.isShowing()
                            && !mKeyguardStateController.isKeyguardGoingAway()) {
                        Log.d(TAG, "Setting occluded = true in #startActivity.");
                        mKeyguardViewMediator.setOccluded(true /* isOccluded */,
                                true /* animate */);
                    }
+3 −1
Original line number Diff line number Diff line
@@ -1482,7 +1482,9 @@ public class OomAdjuster {
        if (!cycleReEval) {
            // Don't reset this flag when doing cycles re-evaluation.
            state.setNoKillOnBgRestrictedAndIdle(false);
            app.mOptRecord.setShouldNotFreeze(false);
            // If this UID is currently allowlisted, it should not be frozen.
            final UidRecord uidRec = app.getUidRecord();
            app.mOptRecord.setShouldNotFreeze(uidRec != null && uidRec.isCurAllowListed());
        }

        final int appUid = app.info.uid;
+54 −39
Original line number Diff line number Diff line
@@ -78,6 +78,10 @@ import static com.android.server.wm.ActivityTaskSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_BOUNDS;
import static com.android.server.wm.LaunchParamsController.LaunchParamsModifier.PHASE_DISPLAY;
import static com.android.server.wm.Task.REPARENT_MOVE_ROOT_TASK_TO_FRONT;
import static com.android.server.wm.TaskFragment.EMBEDDING_ALLOWED;
import static com.android.server.wm.TaskFragment.EMBEDDING_DISALLOWED_MIN_DIMENSION_VIOLATION;
import static com.android.server.wm.TaskFragment.EMBEDDING_DISALLOWED_NEW_TASK;
import static com.android.server.wm.TaskFragment.EMBEDDING_DISALLOWED_UNTRUSTED_HOST;
import static com.android.server.wm.WindowContainer.POSITION_TOP;

import android.annotation.NonNull;
@@ -131,6 +135,7 @@ import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.uri.NeededUriGrants;
import com.android.server.wm.ActivityMetricsLogger.LaunchingState;
import com.android.server.wm.LaunchParamsController.LaunchParams;
import com.android.server.wm.TaskFragment.EmbeddingCheckResult;

import java.io.PrintWriter;
import java.text.DateFormat;
@@ -2038,12 +2043,6 @@ class ActivityStarter {
            }
        }

        if (mInTaskFragment != null && !canEmbedActivity(mInTaskFragment, r, newTask, targetTask)) {
            Slog.e(TAG, "Permission denied: Cannot embed " + r + " to " + mInTaskFragment.getTask()
                    + " targetTask= " + targetTask);
            return START_PERMISSION_DENIED;
        }

        // Do not start the activity if target display's DWPC does not allow it.
        // We can't return fatal error code here because it will crash the caller of
        // startActivity() if they don't catch the exception. We don't expect 3P apps to make
@@ -2070,19 +2069,21 @@ class ActivityStarter {
    }

    /**
     * Return {@code true} if an activity can be embedded to the TaskFragment.
     * Returns whether embedding of {@code starting} is allowed.
     *
     * @param taskFragment the TaskFragment for embedding.
     * @param starting the starting activity.
     * @param newTask whether the starting activity is going to be launched on a new task.
     * @param targetTask the target task for launching activity, which could be different from
     *                   the one who hosting the embedding.
     */
    private boolean canEmbedActivity(@NonNull TaskFragment taskFragment,
            @NonNull ActivityRecord starting, boolean newTask, Task targetTask) {
    @VisibleForTesting
    @EmbeddingCheckResult
    static int canEmbedActivity(@NonNull TaskFragment taskFragment,
            @NonNull ActivityRecord starting, @NonNull Task targetTask) {
        final Task hostTask = taskFragment.getTask();
        // Not allowed embedding a separate task or without host task.
        if (hostTask == null || newTask || targetTask != hostTask) {
            return false;
        if (hostTask == null || targetTask != hostTask) {
            return EMBEDDING_DISALLOWED_NEW_TASK;
        }

        return taskFragment.isAllowedToEmbedActivity(starting);
@@ -2894,19 +2895,16 @@ class ActivityStarter {
        mIntentDelivered = true;
    }

    /** Places {@link #mStartActivity} in {@code task} or an embedded {@link TaskFragment}. */
    private void addOrReparentStartingActivity(@NonNull Task task, String reason) {
        TaskFragment newParent = task;
        if (mInTaskFragment != null) {
            // TODO(b/234351413): remove remaining embedded Task logic.
            // mInTaskFragment is created and added to the leaf task by task fragment organizer's
            // request. If the task was resolved and different than mInTaskFragment, reparent the
            // task to mInTaskFragment for embedding.
            if (mInTaskFragment.getTask() != task) {
                if (shouldReparentInTaskFragment(task)) {
                    task.reparent(mInTaskFragment, POSITION_TOP);
                }
            } else {
            int embeddingCheckResult = canEmbedActivity(mInTaskFragment, mStartActivity, task);
            if (embeddingCheckResult == EMBEDDING_ALLOWED) {
                newParent = mInTaskFragment;
            } else {
                // Start mStartActivity to task instead if it can't be embedded to mInTaskFragment.
                sendCanNotEmbedActivityError(mInTaskFragment, embeddingCheckResult);
            }
        } else {
            TaskFragment candidateTf = mAddingToTaskFragment != null ? mAddingToTaskFragment : null;
@@ -2918,20 +2916,12 @@ class ActivityStarter {
                }
            }
            if (candidateTf != null && candidateTf.isEmbedded()
                    && canEmbedActivity(candidateTf, mStartActivity, false /* newTask */, task)) {
                    && canEmbedActivity(candidateTf, mStartActivity, task) == EMBEDDING_ALLOWED) {
                // Use the embedded TaskFragment of the top activity as the new parent if the
                // activity can be embedded.
                newParent = candidateTf;
            }
        }
        // Start Activity to the Task if mStartActivity's min dimensions are not satisfied.
        if (newParent.isEmbedded() && newParent.smallerThanMinDimension(mStartActivity)) {
            reason += " - MinimumDimensionViolation";
            mService.mWindowOrganizerController.sendMinimumDimensionViolation(
                    newParent, mStartActivity.getMinDimensions(), mRequest.errorCallbackToken,
                    reason);
            newParent = task;
        }
        if (mStartActivity.getTaskFragment() == null
                || mStartActivity.getTaskFragment() == newParent) {
            newParent.addChild(mStartActivity, POSITION_TOP);
@@ -2940,16 +2930,41 @@ class ActivityStarter {
        }
    }

    private boolean shouldReparentInTaskFragment(Task task) {
        // The task has not been embedded. We should reparent the task to TaskFragment.
        if (!task.isEmbedded()) {
            return true;
    /**
     * Notifies the client side that {@link #mStartActivity} cannot be embedded to
     * {@code taskFragment}.
     */
    private void sendCanNotEmbedActivityError(TaskFragment taskFragment,
            @EmbeddingCheckResult int result) {
        final String errMsg;
        switch(result) {
            case EMBEDDING_DISALLOWED_NEW_TASK: {
                errMsg = "Cannot embed " + mStartActivity + " that launched on another task"
                        + ",mLaunchMode=" + mLaunchMode
                        + ",mLaunchFlag=" + Integer.toHexString(mLaunchFlags);
                break;
            }
            case EMBEDDING_DISALLOWED_MIN_DIMENSION_VIOLATION: {
                errMsg = "Cannot embed " + mStartActivity
                        + ". TaskFragment's bounds:" + taskFragment.getBounds()
                        + ", minimum dimensions:" + mStartActivity.getMinDimensions();
                break;
            }
            case EMBEDDING_DISALLOWED_UNTRUSTED_HOST: {
                errMsg = "The app:" + mCallingUid + "is not trusted to " + mStartActivity;
                break;
            }
            default:
                errMsg = "Unhandled embed result:" + result;
        }
        if (taskFragment.isOrganized()) {
            mService.mWindowOrganizerController.sendTaskFragmentOperationFailure(
                    taskFragment.getTaskFragmentOrganizer(), mRequest.errorCallbackToken,
                    new SecurityException(errMsg));
        } else {
            // If the taskFragment is not organized, just dump error message as warning logs.
            Slog.w(TAG, errMsg);
        }
        WindowContainer<?> parent = task.getParent();
        // If the Activity is going to launch on top of embedded Task in the same TaskFragment,
        // we don't need to reparent the Task. Otherwise, the embedded Task should reparent to
        // another TaskFragment.
        return parent.asTaskFragment() != mInTaskFragment;
    }

    private int adjustLaunchFlagsToDocumentMode(ActivityRecord r, boolean launchSingleInstance,
Loading