【framework】Task简介

1 前言

​ Task 即任务,一个 Task 对应一个 Activity,其父容器为 TaskStack,子容器为 AppWindowToken。

​ 关于其父类及祖父类的介绍,见 → WindowContainer简介ConfigurationContainer简介

img

2 源码

​ 源码地址→/frameworks/base/services/core/java/com/android/server/wm/Task.java

(1)类定义

//AppWindowToken 为子节点类型
class Task extends WindowContainer<AppWindowToken> implements ConfigurationContainerListener

(2)主要属性

//父节点
TaskStack mStack

final int mTaskId

final int mUserId

final Rect mPreparedFrozenBounds = new Rect()

final Configuration mPreparedFrozenMergedConfig = new Configuration()

private final Rect mOverrideDisplayedBounds = new Rect()

private int mLastRotationDisplayId = Display.INVALID_DISPLAY

private int mRotation

private int mResizeMode

private int mDragResizeMode

private TaskDescription mTaskDescription

private Dimmer mDimmer = new Dimmer(this)

TaskRecord mTaskRecord

(3)构造方法

Task(int taskId, TaskStack stack, int userId, WindowManagerService service, int resizeMode, boolean supportsPictureInPicture, TaskDescription taskDescription, TaskRecord taskRecord) {
	super(service);
	mTaskId = taskId;
	mStack = stack;
	mUserId = userId;
	mResizeMode = resizeMode;
	mSupportsPictureInPicture = supportsPictureInPicture;
	mTaskRecord = taskRecord;
	if (mTaskRecord != null) {
		mTaskRecord.registerConfigurationChangeListener(this);
	}
	setBounds(getRequestedOverrideBounds());
	mTaskDescription = taskDescription;
	setOrientation(SCREEN_ORIENTATION_UNSET);
}

(4)节点相关

//position = getAdjustedAddPosition(position)
//super.addChild(wtoken, position)
void addChild(AppWindowToken wtoken, int position)

//position = getAdjustedAddPosition(position)
//super.positionChildAt(position, child, includingParents)
void positionChildAt(int position, AppWindowToken child, boolean includingParents)

//super.removeChild(token)
void removeChild(AppWindowToken token)

//positionChildAt(aToken, POSITION_TOP)
void positionChildAtTop(AppWindowToken aToken)

//positionChildAt(position, aToken, false)
void positionChildAt(AppWindowToken aToken, int position)

//removeImmediately()
void removeIfPossible()

//super.removeImmediately()
void removeImmediately()

(5)Task 相关

//getParent().removeChild(this)
//stack.addTask(this, position, showForAllUsers(), moveParents)
void reparent(TaskStack stack, int position, boolean moveParents)

//isResizeable()
boolean cropWindowsToStackBounds()

//callback.accept(this)
void forAllTasks(Consumer<Task> callback)

//setDragResizing(resizing, DRAG_RESIZE_MODE_DOCKED_DIVIDER)
public void setTaskDockedResizing(boolean resizing)

//mChildren.get(i).cancelAnimation()
void cancelTaskWindowTransition()

//mTaskDescription = taskDescription
void setTaskDescription(TaskDescription taskDescription)

//return mTaskDescription
TaskDescription getTaskDescription()

(6)Display 相关

//mStack.getDisplayContent()
DisplayContent getDisplayContent()

//mWmService.mAtmService.getTaskChangeNotificationController().notifyTaskDisplayChanged(mTaskId, displayId)
void onDisplayChanged(DisplayContent dc)

//return mOverrideDisplayedBounds
public Rect getDisplayedBounds()

//mOverrideDisplayedBounds.set(overrideDisplayedBounds)
void setOverrideDisplayedBounds(Rect overrideDisplayedBounds)

//mOverrideDisplayedBounds
Rect getOverrideDisplayedBounds()

(7)Surface 相关

//super.prepareSurfaces()
void prepareSurfaces()

//return super.makeSurface().setMetadata(METADATA_TASK_ID, mTaskId)
SurfaceControl.Builder makeSurface()

(8)AppToken 相关

//final AppWindowToken token = mChildren.get(i)
//final WindowState win = token.findMainWindow()
//return (win != null && win.mAttrs.isFullscreen()) ? token : null
AppWindowToken getTopFullscreenAppToken()

//final AppWindowToken token = mChildren.get(i)
//return (!token.mIsExiting && !token.isClientHidden() && !token.hiddenRequested) ? token :null
AppWindowToken getTopVisibleAppToken()

(9)Bunds 相关

//return setBounds(bounds)
public int setBounds(Rect bounds, boolean forceResize)

//super.setBounds(bounds)
public int setBounds(Rect bounds)

//mPreparedFrozenBounds.set(getBounds())
//mPreparedFrozenMergedConfig.setTo(getConfiguration())
void prepareFreezingBounds()

void alignToAdjustedBounds(Rect adjustedBounds, Rect tempInsetBounds, boolean alignBottom)

//getDisplayContent().layoutAndAssignWindowLayersIfNeeded()
void resize(boolean relayout, boolean forced)

//mResizeMode = resizeMode
void setResizeable(int resizeMode)

//return ActivityInfo.isResizeableMode(mResizeMode) || mSupportsPictureInPicture || mWmService.mForceResizableTasks
boolean isResizeable()

//return matchParentBounds() || !getWindowConfiguration().canResizeTask()
boolean fillsParent()

(10)动画相关

//return getAppAnimationLayer(ANIMATION_LAYER_HOME)
public SurfaceControl getAnimationLeashParent()

//final RecentsAnimationController recentsAnim = mWmService.getRecentsAnimationController()
//return recentsAnim.isAnimatingTask(this)
boolean isTaskAnimating()

(11)Drag 相关

void setDragResizing(boolean dragResizing, int dragResizeMode)

resetDragResizingChangeReported()

//return mDragResizing
boolean isDragResizing()

//return mDragResizeMode
int getDragResizeMode()

(12)Dim 相关

//return mDimmer
Dimmer getDimmer()

public void getDimBounds(Rect out)

//mDimmer.dontAnimateExit()
void dontAnimateDimExit()

(13)flag 相关

//mCanAffectSystemUiFlags = canAffectSystemUiFlags
void setCanAffectSystemUiFlags(boolean canAffectSystemUiFlags)

//return mCanAffectSystemUiFlags
boolean canAffectSystemUiFlags()

(14)其他方法

//return hasWindowsAlive() && mStack.isSelfOrChildAnimating()
boolean shouldDeferRemoval()

//adjustBoundsForDisplayChangeIfNeeded(getDisplayContent())
void positionAt(int position)

//mChildren.get(i).sendingToBottom = toBottom
void setSendingToBottom(boolean toBottom)

//mTaskRecord.onConfigurationChanged(mTaskRecord.getParent().getConfiguration())
public boolean onDescendantOrientationChanged(IBinder freezeDisplayToken, ConfigurationContainer requestingContainer)

//return (mChildren.size() != 0) && mChildren.get(tokensCount - 1).mShowForAllUsers
boolean showForAllUsers()

//return getWindowConfiguration().tasksAreFloating() && !mStack.isAnimatingBoundsToFullscreen() && !mPreserveNonFloatingState
boolean isFloating()

//getTopVisibleAppToken().findMainWindow()
WindowState getTopVisibleAppMainWindow()

//mChildren.get(i).forceWindowsScaleableInTransaction(force)
void forceWindowsScaleable(boolean force)

//mTaskRecord.onSnapshotChanged(snapshot)
void onSnapshotChanged(ActivityManager.TaskSnapshot snapshot)

//mPreserveNonFloatingState = false
void clearPreserveNonFloatingState()

​ 声明:本文转自【framework】Task简介

posted @   little_fat_sheep  阅读(66)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示