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

Commit e459c63f authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Reduce getting thread statically

- So the threads won't be bring back right after tear down
  and execute something unexpectedly.
- Add annotation to make AnimatingActivityRegistryTest thread safe.
- Remove the dependency of test base from
  PendingRemoteAnimationRegistryTest that reduces 90% execution time.

Bug: 144611135
Test: atest AnimatingActivityRegistryTest
            PendingRemoteAnimationRegistryTest

Change-Id: I281c475a6f6ae9ab4fb99b2f8cad200688774f21
parent fbe8eca9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ public class ActivityStartController {
        mHandler = new StartHandler(mService.mH.getLooper());
        mFactory = factory;
        mFactory.setController(this);
        mPendingRemoteAnimationRegistry = new PendingRemoteAnimationRegistry(service,
        mPendingRemoteAnimationRegistry = new PendingRemoteAnimationRegistry(service.mGlobalLock,
                service.mH);
    }

+1 −2
Original line number Diff line number Diff line
@@ -230,7 +230,6 @@ import com.android.internal.util.function.pooled.PooledConsumer;
import com.android.internal.util.function.pooled.PooledFunction;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.internal.util.function.pooled.PooledPredicate;
import com.android.server.AnimationThread;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.protolog.common.ProtoLog;
import com.android.server.wm.utils.DisplayRotationUtil;
@@ -982,7 +981,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

        AnimationHandler animationHandler = new AnimationHandler();
        mBoundsAnimationController = new BoundsAnimationController(mWmService.mContext,
                mAppTransition, AnimationThread.getHandler(), animationHandler);
                mAppTransition, mWmService.mAnimationHandler, animationHandler);

        final InputChannel inputChannel = mWmService.mInputManager.monitorInput(
                "PointerEventDispatcher" + mDisplayId, mDisplayId);
+1 −2
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ import android.view.InputEventReceiver;
import android.view.InputWindowHandle;
import android.view.SurfaceControl;

import com.android.server.AnimationThread;
import com.android.server.policy.WindowManagerPolicy;
import com.android.server.protolog.common.ProtoLog;

@@ -157,7 +156,7 @@ final class InputMonitor {
        mDisplayContent = mService.mRoot.getDisplayContent(displayId);
        mDisplayId = displayId;
        mInputTransaction = mService.mTransactionFactory.get();
        mHandler = AnimationThread.getHandler();
        mHandler = mService.mAnimationHandler;
        mUpdateInputForAllWindowsConsumer = new UpdateInputForAllWindowsConsumer();
    }

+5 −7
Original line number Diff line number Diff line
@@ -22,12 +22,10 @@ import android.os.Handler;
import android.util.ArrayMap;
import android.view.RemoteAnimationAdapter;

import com.android.server.am.ActivityManagerService;

/**
 * Registry to keep track of remote animations to be run for activity starts from a certain package.
 *
 * @see ActivityManagerService#registerRemoteAnimationForNextActivityStart
 * @see ActivityTaskManagerService#registerRemoteAnimationForNextActivityStart
 */
class PendingRemoteAnimationRegistry {

@@ -35,10 +33,10 @@ class PendingRemoteAnimationRegistry {

    private final ArrayMap<String, Entry> mEntries = new ArrayMap<>();
    private final Handler mHandler;
    private final ActivityTaskManagerService mService;
    private final WindowManagerGlobalLock mLock;

    PendingRemoteAnimationRegistry(ActivityTaskManagerService service, Handler handler) {
        mService = service;
    PendingRemoteAnimationRegistry(WindowManagerGlobalLock lock, Handler handler) {
        mLock = lock;
        mHandler = handler;
    }

@@ -76,7 +74,7 @@ class PendingRemoteAnimationRegistry {
            this.packageName = packageName;
            this.adapter = adapter;
            mHandler.postDelayed(() -> {
                synchronized (mService.mGlobalLock) {
                synchronized (mLock) {
                    final Entry entry = mEntries.get(packageName);
                    if (entry == this) {
                        mEntries.remove(packageName);
+6 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.hardware.power.V1_0.PowerHint;
import android.os.Handler;
import android.os.PowerManagerInternal;
import android.util.ArrayMap;
import android.view.Choreographer;
@@ -57,6 +58,8 @@ class SurfaceAnimationRunner {
    @VisibleForTesting
    Choreographer mChoreographer;

    private final Handler mAnimationThreadHandler = AnimationThread.getHandler();
    private final Handler mSurfaceAnimationHandler = SurfaceAnimationThread.getHandler();
    private final Runnable mApplyTransactionRunnable = this::applyTransaction;
    private final AnimationHandler mAnimationHandler;
    private final Transaction mFrameTransaction;
@@ -85,7 +88,7 @@ class SurfaceAnimationRunner {
    SurfaceAnimationRunner(@Nullable AnimationFrameCallbackProvider callbackProvider,
            AnimatorFactory animatorFactory, Transaction frameTransaction,
            PowerManagerInternal powerManagerInternal) {
        SurfaceAnimationThread.getHandler().runWithScissors(() -> mChoreographer = getSfInstance(),
        mSurfaceAnimationHandler.runWithScissors(() -> mChoreographer = getSfInstance(),
                0 /* timeout */);
        mFrameTransaction = frameTransaction;
        mAnimationHandler = new AnimationHandler();
@@ -152,7 +155,7 @@ class SurfaceAnimationRunner {
                synchronized (mCancelLock) {
                    anim.mCancelled = true;
                }
                SurfaceAnimationThread.getHandler().post(() -> {
                mSurfaceAnimationHandler.post(() -> {
                    anim.mAnim.cancel();
                    applyTransaction();
                });
@@ -211,7 +214,7 @@ class SurfaceAnimationRunner {
                        if (!a.mCancelled) {

                            // Post on other thread that we can push final state without jank.
                            AnimationThread.getHandler().post(a.mFinishCallback);
                            mAnimationThreadHandler.post(a.mFinishCallback);
                        }
                    }
                }
Loading