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

Commit 440f88b4 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Add task snapshot for home task

The real home activity usually takes longer time than a
snapshot to complete drawing. Especially when unlocking
to home, the duration becomes more noticeable.

This CL enables snapshot of home task when turning screen
off. And because the snapshot is only used when entering
home from a sleeping state, the snapshot will be removed
once it is used.

Also provide a method for home activity to remove its
snapshot while the content of home activity has significant
change after taking the snapshot.

Bug: 140811348
Test: 1. Set an unlock method that doesn't need to show
         lockscreen when unlocking.
      2. Turn off screen while home is on top.
      3. Unlock device to enter home.
      4. Check the duration of trace "screenTurningOn".

Change-Id: Ic516cdcfd84ca4a85e19798537f9f5a85077392b
parent c3527d7e
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -404,6 +404,14 @@ interface IActivityTaskManager {
     */
    void setDisablePreviewScreenshots(IBinder token, boolean disable);

    /**
     * It should only be called from home activity to remove its outdated snapshot. The home
     * snapshot is used to speed up entering home from screen off. If the content of home activity
     * is significantly different from before taking the snapshot, then the home activity can use
     * this method to avoid inconsistent transition.
     */
    void invalidateHomeTaskSnapshot(IBinder homeToken);

    /**
     * Return the user id of last resumed activity.
     */
+18 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECOND
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;

import android.annotation.NonNull;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RecentTaskInfo;
import android.app.ActivityManager.RunningTaskInfo;
@@ -160,6 +161,23 @@ public class ActivityManagerWrapper {
        }
    }

    /**
     * Removes the outdated snapshot of home task.
     */
    public void invalidateHomeTaskSnapshot(final Activity homeActivity) {
        mBackgroundExecutor.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    ActivityTaskManager.getService().invalidateHomeTaskSnapshot(
                            homeActivity.getActivityToken());
                } catch (RemoteException e) {
                    Log.w(TAG, "Failed to invalidate home snapshot", e);
                }
            }
        });
    }

    /**
     * @return the activity label, badging if necessary.
     */
+3 −0
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ import android.os.ServiceManager;
import android.os.StrictMode;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UEventObserver;
import android.os.UserHandle;
import android.os.VibrationEffect;
@@ -4603,6 +4604,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    public void screenTurningOn(final ScreenOnListener screenOnListener) {
        if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");

        Trace.asyncTraceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenTurningOn", 0 /* cookie */);
        updateScreenOffSleepToken(false);
        mDefaultDisplayPolicy.screenTurnedOn(screenOnListener);

@@ -4665,6 +4667,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        if (!mDefaultDisplayPolicy.finishScreenTurningOn()) {
            return; // Spurious or not ready yet.
        }
        Trace.asyncTraceEnd(Trace.TRACE_TAG_WINDOW_MANAGER, "screenTurningOn", 0 /* cookie */);

        final boolean enableScreen;
        final boolean awake = mDefaultDisplayPolicy.isAwake();
+11 −0
Original line number Diff line number Diff line
@@ -1640,6 +1640,17 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
                allowTaskSnapshot, activityCreated, fromRecents, snapshot);

        if (type == STARTING_WINDOW_TYPE_SNAPSHOT) {
            if (isActivityTypeHome()) {
                // The snapshot of home is only used once because it won't be updated while screen
                // is on (see {@link TaskSnapshotController#screenTurningOff}).
                mWmService.mTaskSnapshotController.removeSnapshotCache(task.mTaskId);
                // TODO(b/9684093): Use more general condition to specify the case.
                if (mDisplayContent.mAppTransition
                        .getAppTransition() != WindowManager.TRANSIT_KEYGUARD_GOING_AWAY) {
                    // Only use snapshot of home as starting window when unlocking.
                    return false;
                }
            }
            return createSnapshot(snapshot);
        }

+11 −0
Original line number Diff line number Diff line
@@ -4572,6 +4572,17 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        }
    }

    @Override
    public void invalidateHomeTaskSnapshot(IBinder token) {
        synchronized (mGlobalLock) {
            final ActivityRecord r = ActivityRecord.isInStackLocked(token);
            if (r == null || !r.isActivityTypeHome()) {
                return;
            }
            mWindowManager.mTaskSnapshotController.removeSnapshotCache(r.getTask().mTaskId);
        }
    }

    /** Return the user id of the last resumed activity. */
    @Override
    public @UserIdInt
Loading