framework——RootWindowContainer簡介

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)

 

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)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章