本文主要简单介绍WMShell动画调用堆栈
代码环境:repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-14.0.0_r7
Systemserver侧
TAG: at com.android.server.wm.Transition.onTransactionReady(Transition.java:1575)
TAG: at com.android.server.wm.BLASTSyncEngine$SyncGroup.finishNow(BLASTSyncEngine.java:263)
TAG: at com.android.server.wm.BLASTSyncEngine$SyncGroup.tryFinish(BLASTSyncEngine.java:202)
TAG: at com.android.server.wm.BLASTSyncEngine$SyncGroup.-$$Nest$mtryFinish(BLASTSyncEngine.java:0)
TAG: at com.android.server.wm.BLASTSyncEngine.onSurfacePlacement(BLASTSyncEngine.java:552)
TAG: at com.android.server.wm.RootWindowContainer.performSurfacePlacementNoTrace(RootWindowContainer.java:810)
TAG: at com.android.server.wm.RootWindowContainer.performSurfacePlacement(RootWindowContainer.java:756)
TAG: at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacementLoop(WindowSurfacePlacer.java:177)
TAG: at com.android.server.wm.WindowSurfacePlacer.performSurfacePlacement(WindowSurfacePlacer.java:126)
TAG: at com.android.server.wm.WindowManagerService.relayoutWindow(WindowManagerService.java:2410)
TAG: at com.android.server.wm.Session.relayout(Session.java:249)
TAG: at com.android.server.wm.Session.relayoutAsync(Session.java:263)
TAG: at android.view.IWindowSession$Stub.onTransact(IWindowSession.java:731)
TAG: at com.android.server.wm.Session.onTransact(Session.java:178)
TAG: at android.os.Binder.execTransactInternal(Binder.java:1344)
TAG: at android.os.Binder.execTransact(Binder.java:1275)
调用WMShell动画是从relayout流程开始,真正去调用WMShell动画的方法是RootWindowContainer.performSurfacePlacementNoTrace方法中的这句mWmService.mSyncEngine.onSurfacePlacement()
Systemserver侧调用的结束点在Transition.onTransactionReady方法
代码路径frameworks/base/services/core/java/com/android/server/wm/Transition.java
@Override
public void onTransactionReady(int syncId, SurfaceControl.Transaction transaction) {......mController.getTransitionPlayer().onTransitionReady(mToken, info, transaction, mFinishTransaction);......
}
这里通过ITransitionPlayer跨进程通信到SystemUI,进入wmshell动画
private ITransitionPlayer mTransitionPlayer;
@Nullable ITransitionPlayer getTransitionPlayer() {return mTransitionPlayer;
}
调用ITransitionPlayer对象的onTransitionReady方法,该方法在Transitions中实现
SystemUI侧
代码路径:frameworks/base/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java
@BinderThread
private class TransitionPlayerImpl extends ITransitionPlayer.Stub {@Overridepublic void onTransitionReady(IBinder iBinder, TransitionInfo transitionInfo,SurfaceControl.Transaction t, SurfaceControl.Transaction finishT)throws RemoteException {mMainExecutor.execute(() -> Transitions.this.onTransitionReady(iBinder, transitionInfo, t, finishT));}......
}
TAG: java.lang.Exception
TAG: at com.android.wm.shell.transition.Transitions.playTransition(go/retraceme 691c0b649c5b78e8be353184a2cf4f8453b1bbeba9558d5f9cdae4325458fb69:885)
TAG: at com.android.wm.shell.transition.Transitions.processReadyQueue(go/retraceme 691c0b649c5b78e8be353184a2cf4f8453b1bbeba9558d5f9cdae4325458fb69:819)
TAG: at com.android.wm.shell.transition.Transitions.dispatchReady(go/retraceme 691c0b649c5b78e8be353184a2cf4f8453b1bbeba9558d5f9cdae4325458fb69:760)
TAG: at com.android.wm.shell.transition.Transitions.onTransitionReady(go/retraceme 691c0b649c5b78e8be353184a2cf4f8453b1bbeba9558d5f9cdae4325458fb69:669)
TAG: at com.android.wm.shell.transition.Transitions$TransitionPlayerImpl.lambda$onTransitionReady$0(go/retraceme 691c0b649c5b78e8be353184a2cf4f8453b1bbeba9558d5f9cdae4325458fb69:1353)
TAG: at com.android.wm.shell.transition.Transitions$TransitionPlayerImpl.$r8$lambda$qsRfWn1ItrZqnFeABBdxU50jPc4(go/retraceme 691c0b649c5b78e8be353184a2cf4f8453b1bbeba9558d5f9cdae4325458fb69:0)
TAG: at com.android.wm.shell.transition.Transitions$TransitionPlayerImpl$$ExternalSyntheticLambda0.run(go/retraceme 691c0b649c5b78e8be353184a2cf4f8453b1bbeba9558d5f9cdae4325458fb69:0)
TAG: at android.os.Handler.handleCallback(Handler.java:958)
TAG: at android.os.Handler.dispatchMessage(Handler.java:99)
TAG: at android.os.Looper.loopOnce(Looper.java:205)
TAG: at android.os.Looper.loop(Looper.java:294)
TAG: at android.os.HandlerThread.run(HandlerThread.java:67)
代码路径:frameworks/base/libs/WindowManager/Shell/src/com/android/wm/shell/transition/Transitions.java
private void playTransition(@NonNull ActiveTransition active) {ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TRANSITIONS, "Playing animation for %s", active);......// If a handler already chose to run this animation, try delegating to it first.if (active.mHandler != null) {ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TRANSITIONS, " try firstHandler %s",active.mHandler);boolean consumed = active.mHandler.startAnimation(active.mToken, active.mInfo,active.mStartT, active.mFinishT, (wct, cb) -> onFinish(active, wct, cb));......}...... }
这里主要关注active.mHandler.startAnimation
方法,是Transitions中TransitionHandler接口的方法
关键在这个startAnimation的实现,从代码上看在多处均有实现,常见的例如画中画(PipTranstion)、分屏(StageCoordinator)等。