framework—RootWindowContainer简介
程序员文章站
2022-06-23 09:11:44
1 前言RootWindowContainer 是窗口容器的根容器,子容器是 DisplayContent。关于其父类及祖父类的介绍,见→WindowContainer简介、ConfigurationContainer简介。2 源码...
1 前言
RootWindowContainer 是窗口容器的根容器,子容器是 DisplayContent。关于其父类及祖父类的介绍,见→WindowContainer简介、ConfigurationContainer简介。
本文主要介绍 WallpaperController 和 RootWindowContainer。
2 源码
2.1 WallpaperController
(1)主要属性
private WindowManagerService mService
private final DisplayContent mDisplayContent
private final ArrayList<WallpaperWindowToken> mWallpaperTokens = new ArrayList<>()
private WindowState mWallpaperTarget = null
private WindowState mPrevWallpaperTarget = null
private WindowState mWaitingOnWallpaper
private WindowState mTmpTopWallpaper
WindowState mDeferredHideWallpaper = null
private float mLastWallpaperX = -1
private float mLastWallpaperY = -1
private float mLastWallpaperXStep = -1
private float mLastWallpaperYStep = -1
private int mLastWallpaperDisplayOffsetX = Integer.MIN_VALUE
private int mLastWallpaperDisplayOffsetY = Integer.MIN_VALUE
private long mLastWallpaperTimeoutTime
private final FindWallpaperTargetResult mFindResults = new FindWallpaperTargetResult()
(2)内部类
final private static class FindWallpaperTargetResult {
WindowState topWallpaper = null;
WindowState wallpaperTarget = null;
boolean useTopWallpaperAsTarget = false;
boolean resetTopWallpaper = false
//topWallpaper = win
void setTopWallpaper(WindowState win)
//wallpaperTarget = win
void setWallpaperTarget(WindowState win)
//useTopWallpaperAsTarget = topWallpaperAsTarget
void setUseTopWallpaperAsTarget(boolean topWallpaperAsTarget)
void reset()
}
(3)函数
private final ToBooleanFunction<WindowState> mFindWallpaperTargetFunction = w -> {
//mFindResults.setTopWallpaper(w)
//mFindResults.setWallpaperTarget(w)
}
(4)Wallpaper 相关
//return mWallpaperTarget
WindowState getWallpaperTarget()
//return win == mWallpaperTarget
boolean isWallpaperTarget(WindowState win)
//return mWallpaperTarget != null && mWallpaperTarget.mLayer >= win.mBaseLayer
boolean isBelowWallpaperTarget(WindowState win)
//return isWallpaperVisible(mWallpaperTarget)
boolean isWallpaperVisible()
//mWallpaperTokens.get(i).updateWallpaperVisibility(isWallpaperVisible(mWallpaperTarget))
void updateWallpaperVisibility()
//hideWallpapers(mDeferredHideWallpaper)
void hideDeferredWallpapersIfNeeded()
//mDeferredHideWallpaper = winGoingAway
void hideWallpapers(final WindowState winGoingAway)
boolean updateWallpaperOffset(WindowState wallpaperWin, int dw, int dh, boolean sync)
void setWindowWallpaperPosition(WindowState window, float x, float y, float xStep, float yStep)
void setWindowWallpaperDisplayOffset(WindowState window, int x, int y)
//mWallpaperTokens.get(i).sendWindowWallpaperCommand(action, x, y, z, extras, sync)
Bundle sendWindowWallpaperCommand(WindowState window, String action, int x, int y, int z, Bundle extras, boolean sync)
//mLastWallpaperTimeoutTime = 0
void clearLastWallpaperTimeoutTime()
//mWaitingOnWallpaper = null; mService.mGlobalLock.notifyAll()
void wallpaperCommandComplete(IBinder window)
//mWaitingOnWallpaper = null; mService.mGlobalLock.notifyAll()
void wallpaperOffsetsComplete(IBinder window)
void adjustWallpaperWindows()
void adjustWallpaperWindowsForAppTransitionIfNeeded(ArraySet<AppWindowToken> openingApps, ArraySet<AppWindowToken> changingApps)
//mWallpaperTokens.add(token)
void addWallpaperToken(WallpaperWindowToken token)
//return canScreenshotWallpaper(getTopVisibleWallpaper())
boolean canScreenshotWallpaper()
Bitmap screenshotWallpaperLocked()
(5)动画
//mWallpaperTokens.get(i).startAnimation(a)
void startWallpaperAnimation(Animation a)
boolean isWallpaperTargetAnimating()
//mService.getRecentsAnimationController().startAnimation()
boolean processWallpaperDrawPendingTimeout()
2.2 RootWindowContainer
(1)类定义
//DisplayContent 为子节点
class RootWindowContainer extends WindowContainer<DisplayContent>
(2)主要属性
private Object mLastWindowFreezeSource = null
private Session mHoldScreen = null
private float mScreenBrightness = -1
private long mUserActivityTimeout = -1
WindowState mHoldScreenWindow = null
WindowState mObscuringWindow = null
final WallpaperController mWallpaperController
//mHandler = new MyHandler(service.mH.getLooper())
private final Handler mHandler
//事务
private final SurfaceControl.Transaction mDisplayTransaction = new SurfaceControl.Transaction()
(3)消费者
//关闭系统对话框,w 为 WindowState 类型
private final Consumer<WindowState> mCloseSystemDialogsConsumer = w -> {
if (w.mHasSurface) {
...
w.mClient.closeSystemDialogs(mCloseSystemDialogsReason);
...
}
};
//移除窗口,w 为 WindowState 类型
private static final Consumer<WindowState> sRemoveReplacedWindowsConsumer = w -> {
final AppWindowToken aToken = w.mAppToken;
if (aToken != null) {
aToken.removeReplacedWindowIfNeeded(w);
}
};
Consumer 类如下。
public interface Consumer<T> {
void accept(T t);
default Consumer<T> andThen(Consumer<? super T> after) {
Objects.requireNonNull(after);
return (T t) -> { accept(t); after.accept(t); };
}
}
(4)Handler
private final class MyHandler extends Handler {
...
public void handleMessage(Message msg) {
switch (msg.what) {
//设置屏幕亮度
case SET_SCREEN_BRIGHTNESS_OVERRIDE:
mService.mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(msg.arg1);
break;
//设置屏幕休眠时间
case SET_USER_ACTIVITY_TIMEOUT:
mService.mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager((Long) msg.obj);
break;
...
}
}
}
(5)Window 相关
//mChildren.get(i).findFocusedWindow()
WindowState computeFocusedWindow()
void getWindowsByName(ArrayList<WindowState> output, String name)
//mChildren.get(i).getAppWindowToken(binder)
AppWindowToken getAppWindowToken(IBinder binder)
(6)Display 相关
//displaysInFocusOrder.put(i, mChildren.get(i).getDisplayId())
void getDisplaysInFocusOrder(SparseIntArray displaysInFocusOrder)
//mChildren.get(i).getDisplayId() == displayId ? mChildren.get(i) : null
DisplayContent getDisplayContent(int displayId)
//new DisplayContent(display, mService, mWallpaperController, controller)
DisplayContent createDisplayContent(final Display display, DisplayWindowController controller)
//mChildren.get(i).getWindowToken(token.token) == token ? mChildren.get(i) : null
DisplayContent getWindowTokenDisplay(WindowToken token)
//getDisplayContent(displayId).onOverrideConfigurationChanged(newConfiguration)
int[] setDisplayOverrideConfigurationIfNeeded(Configuration newConfiguration, int displayId)
(7)Surface 相关
//mChildren.get(i).destroyLeakedSurfaces()
//mService.mActivityManager.killPids(pids, "Free memory", secure)
//winAnimator.destroySurface()
//winAnimator.mWin.mAppToken.getController().removeStartingWindow()
//winAnimator.mWin.mClient.dispatchGetNewSurface()
boolean reclaimSomeSurfaceMemory(WindowStateAnimator winAnimator, String operation, boolean secure)
void performSurfacePlacement(boolean recoveringMemory)
(8)Layout 相关
//mChildren.get(i).isLayoutNeeded()
boolean isLayoutNeeded()
//final int pendingChanges = animator.getPendingLayoutChanges(mChildren.get(i).getDisplayId())
//return pendingChanges != 0
boolean hasPendingLayoutChanges(WindowAnimator animator)
boolean copyAnimToLayoutParams()
(9)forAllWindows
//w.mWinAnimator.setSecureLocked(disabled)
void setSecureSurfaceState(int userId, boolean disabled)
//w.setHiddenWhileSuspended(suspended)
void updateHiddenWhileSuspendedState(final ArraySet<String> packages, final boolean suspended)
//w.updateAppOpsState()
void updateAppOpsState()
//forAllWindows(mCloseSystemDialogsConsumer, false)
void closeSystemDialogs(String reason)
//forAllWindows(sRemoveReplacedWindowsConsumer, true)
void removeReplacedWindows()
(9)其他方法
//mChildren.get(i).getStack(windowingMode, activityType)
TaskStack getStack(int windowingMode, int activityType)
//win = getWindow((w) -> w.mSession.mPid == pid && w.isVisibleLw()), return win != null
boolean canShowStrictModeViolation(int pid)
boolean handleNotObscuredLocked(WindowState w, boolean obscured, boolean syswin)
本文地址:https://blog.csdn.net/m0_37602827/article/details/110609056