3Android 12DisplayArea层级结构
Posted Geralt_z_Rivii
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3Android 12DisplayArea层级结构相关的知识,希望对你有一定的参考价值。
1 DisplayArea类的继承关系
DisplayArea类的继承关系,之前已经分析过,这里用一张简单的类图总结:
2 DisplayArea层级结构的生成
既然DisplayContent是作为其代表的屏幕的DisplayArea层级结构的根节点,那么从DisplayContent出发,看一下这棵以DisplayContent为根节点的DisplayArea树是如何生成的。
2.1 DisplayContent.init
/**
* Create new @link DisplayContent instance, add itself to the root window container and
* initialize direct children.
* @param display May not be null.
* @param root @link RootWindowContainer
*/
DisplayContent(Display display, RootWindowContainer root)
// ......
// Setup the policy and build the display area hierarchy.
mDisplayAreaPolicy = mWmService.getDisplayAreaPolicyProvider().instantiate(
mWmService, this /* content */, this /* root */, mImeWindowsContainer);
// ......
在DisplayContent的构造方法中,调用DisplayAreaPolicy.Provider.instantiate方法,去初始化一个DisplayArea层级结构。
2.2 DisplayAreaPolicy.DefaultProvider.instantiate
DisplayAreaPolicy.Provider只是一个接口,instantiate定义为:
/**
* Instantiates a new @link DisplayAreaPolicy. It should set up the @link DisplayArea
* hierarchy.
*
* @see DisplayAreaPolicy#DisplayAreaPolicy
*/
DisplayAreaPolicy instantiate(WindowManagerService wmService, DisplayContent content,
RootDisplayArea root, DisplayArea.Tokens imeContainer);
用来实例化一个DisplayAreaPolicy对象,这个对象应该建立起DisplayArea层级结构,实际走到的则是DisplayAreaPolicy.Provider的实现类DisplayAreaPolicy.DefaultProvider.instantiate方法:
@Override
public DisplayAreaPolicy instantiate(WindowManagerService wmService,
DisplayContent content, RootDisplayArea root,
DisplayArea.Tokens imeContainer)
final TaskDisplayArea defaultTaskDisplayArea = new TaskDisplayArea(content, wmService,
"DefaultTaskDisplayArea", FEATURE_DEFAULT_TASK_CONTAINER);
final List<TaskDisplayArea> tdaList = new ArrayList<>();
tdaList.add(defaultTaskDisplayArea);
// Define the features that will be supported under the root of the whole logical
// display. The policy will build the DisplayArea hierarchy based on this.
final HierarchyBuilder rootHierarchy = new HierarchyBuilder(root);
// Set the essential containers (even if the display doesn't support IME).
rootHierarchy.setImeContainer(imeContainer).setTaskDisplayAreas(tdaList);
if (content.isTrusted())
// Only trusted display can have system decorations.
configureTrustedHierarchyBuilder(rootHierarchy, wmService, content);
// Instantiate the policy with the hierarchy defined above. This will create and attach
// all the necessary DisplayAreas to the root.
return new DisplayAreaPolicyBuilder().setRootHierarchy(rootHierarchy).build(wmService);
2.2.1 创建HierarchyBuilder
首先注意到,这里的RootDisplayArea类型的传参root即是一个DisplayContent对象,毕竟它是要作为后续创建的DisplayArea层阶结构的根节点。然后根据这个传入的DisplayContent,创建一个HierarchyBuilder对象:
// Define the features that will be supported under the root of the whole logical
// display. The policy will build the DisplayArea hierarchy based on this.
final HierarchyBuilder rootHierarchy = new HierarchyBuilder(root);
HierarchyBuilder定义在DisplayAreaPolicyBuilder中:
/**
* Builder to define @link Feature and @link DisplayArea hierarchy under a
* @link RootDisplayArea
*/
static class HierarchyBuilder
HierarchyBuilder用来构建一个DisplayArea层级结构,该层级结构的根节点,则是HierarchyBuilder构造方法中传入的RootDisplayArea:
private final RootDisplayArea mRoot;
// ......
HierarchyBuilder(RootDisplayArea root)
mRoot = root;
这里传入的则是一个DisplayContent对象,那么HierarchyBuilder要以这个DisplayContent对象为根节点,生成一个DisplayArea层级结构。
2.2.2 保存ImeContainer到HierarchyBuilder内部
传参imeContainer,则是DisplayContent的成员变量:
// Contains all IME window containers. Note that the z-ordering of the IME windows will depend
// on the IME target. We mainly have this container grouping so we can keep track of all the IME
// window containers together and move them in-sync if/when needed. We use a subclass of
// WindowContainer which is omitted from screen magnification, as the IME is never magnified.
// TODO(display-area): is "no magnification" in the comment still true?
private final ImeContainer mImeWindowsContainer = new ImeContainer(mWmService);
即ImeContainer类型的DisplayArea,在定义的时候已经初始化。
通过HierarchyBuilder.setImeContainer方法:
@Nullable
private DisplayArea.Tokens mImeContainer;
// ......
/** Sets IME container as a child of this hierarchy root. */
HierarchyBuilder setImeContainer(DisplayArea.Tokens imeContainer)
mImeContainer = imeContainer;
return this;
将DisplayContent的mImeWindowsContainer保存在了HierarchyBuilder的mImeContainer成员变量中,后续创建DisplayArea层级结构时可以直接拿来使用。
2.2.3 创建并保存默认TaskDisplayArea到HierarchyBuilder内部
创建一个名为“DefaultTaskDisplayArea”的TaskDisplayArea:
final TaskDisplayArea defaultTaskDisplayArea = new TaskDisplayArea(content, wmService,
"DefaultTaskDisplayArea", FEATURE_DEFAULT_TASK_CONTAINER);
然后将该TaskDisplayArea添加到一个局部List中,调用HierarchyBuilder.setTaskDisplayAreas方法,将该对象保存在了HierarchyBuilder.mTaskDisplayAreas中。
private final ArrayList<TaskDisplayArea> mTaskDisplayAreas = new ArrayList<>();
// ......
/**
* Sets @link TaskDisplayArea that are children of this hierarchy root.
* @link DisplayArea group must have at least one @link TaskDisplayArea.
*/
HierarchyBuilder setTaskDisplayAreas(List<TaskDisplayArea> taskDisplayAreas)
mTaskDisplayAreas.clear();
mTaskDisplayAreas.addAll(taskDisplayAreas);
return this;
另外看到,虽然TaskDisplayArea是支持嵌套的,并且这里也采用了一个ArrayList来管理TaskDisplayArea,但是目前TaskDisplayArea只在这里被创建,即目前一个DisplayContent只有一个名为“DefaultTaskDisplayArea”的TaskDisplayArea。
因为TaskDisplayArea是用来管理Task的,而Task本身就支持嵌套,再加上TaskOrgnizerController,光这两者已经可以为TaskDisplayArea建立起一个比较复杂的Task层级结构了,因此TaskDisplayArea的嵌套目前显得没有必要。
2.2.4 为HierarchyBuilder添加Feature
调用DisplayAreaPolicy.DefaultProvider.configureTrustedHierarchyBuilder为HierarchyBuilder添加Feature:
if (content.isTrusted())
// Only trusted display can have system decorations.
configureTrustedHierarchyBuilder(rootHierarchy, wmService, content);
接着来看DisplayAreaPolicy.DefaultProvider.configureTrustedHierarchyBuilder方法的具体内容:
private void configureTrustedHierarchyBuilder(HierarchyBuilder rootHierarchy,
WindowManagerService wmService, DisplayContent content)
// WindowedMagnification should be on the top so that there is only one surface
// to be magnified.
rootHierarchy.addFeature(new Feature.Builder(wmService.mPolicy, "WindowedMagnification",
FEATURE_WINDOWED_MAGNIFICATION)
.upTo(TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY)
.except(TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY)
// Make the DA dimmable so that the magnify window also mirrors the dim layer.
.setNewDisplayAreaSupplier(DisplayArea.Dimmable::new)
.build());
if (content.isDefaultDisplay)
// Only default display can have cutout.
// See LocalDisplayAdapter.LocalDisplayDevice#getDisplayDeviceInfoLocked.
rootHierarchy.addFeature(new Feature.Builder(wmService.mPolicy, "HideDisplayCutout",
FEATURE_HIDE_DISPLAY_CUTOUT)
.all()
.except(TYPE_NAVIGATION_BAR, TYPE_NAVIGATION_BAR_PANEL, TYPE_STATUS_BAR,
TYPE_NOTIFICATION_SHADE)
.build())
.addFeature(new Feature.Builder(wmService.mPolicy,
"OneHandedBackgroundPanel",
FEATURE_ONE_HANDED_BACKGROUND_PANEL)
.upTo(TYPE_WALLPAPER)
.build())
.addFeature(new Feature.Builder(wmService.mPolicy, "OneHanded",
FEATURE_ONE_HANDED)
.all()
.except(TYPE_NAVIGATION_BAR, TYPE_NAVIGATION_BAR_PANEL)
.build());
rootHierarchy
.addFeature(new Feature.Builder(wmService.mPolicy, "FullscreenMagnification",
FEATURE_FULLSCREEN_MAGNIFICATION)
.all()
.except(TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY, TYPE_INPUT_METHOD,
TYPE_INPUT_METHOD_DIALOG, TYPE_MAGNIFICATION_OVERLAY,
TYPE_NAVIGATION_BAR, TYPE_NAVIGATION_BAR_PANEL)
.build())
.addFeature(new Feature.Builder(wmService.mPolicy, "ImePlaceholder",
FEATURE_IME_PLACEHOLDER)
.and(TYPE_INPUT_METHOD, TYPE_INPUT_METHOD_DIALOG)
.build());
如果当前DisplayContent是默认屏幕,那么会为HierarchyBuilder添加6种Feature,否则是3种,我们只分析一般情况,即当前屏幕是默认屏幕的情况。
Feature是DisplayAreaPolicyBuilder的内部类:
/**
* A feature that requires @link DisplayArea DisplayArea(s).
*/
static class Feature
private final String mName;
private final int mId;
private final boolean[] mWindowLayers;
private final NewDisplayAreaSupplier mNewDisplayAreaSupplier;
首先Feature代表的是DisplayArea的一个特征,可以根据Feature来对不同的DisplayArea进行划分。
看一下它的成员变量:
- mName,很好理解,这个Feature的名字,如上面的“WindowedMagnification”,“HideDisplayCutout”之类的,后续DisplayArea层级结构建立起来后,每个DisplayArea的名字用的就是当前DisplayArea对应的那个Feature的名字。
- mId,Feature的ID,如上面的FEATURE_WINDOWED_MAGNIFICATION和FEATURE_HIDE_DISPLAY_CUTOUT,虽说是Feature的ID,因为Feature又是DisplayArea的特征,所以这个ID也可以直接代表DisplayArea的一种特征。
- mWindowLayers,代表了这个DisplayArea可以包含哪些层级对应的窗口,后续会分析到。
- mNewDisplayAreaSupplier,
先看第一个Feature:
// WindowedMagnification should be on the top so that there is only one surface
// to be magnified.
rootHierarchy.addFeature(new Feature.Builder(wmService.mPolicy, "WindowedMagnification",
FEATURE_WINDOWED_MAGNIFICATION)
.upTo(TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY)
.except(TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY)
// Make the DA dimmable so that the magnify window also mirrors the dim layer.
.setNewDisplayAreaSupplier(DisplayArea.Dimmable::new)
.build());
1)、设置Feature的mName为"WindowedMagnification"。
2)、设置Feature的mId为FEATURE_WINDOWED_MAGNIFICATION,FEATURE_WINDOWED_MAGNIFICATION定义在DisplayAreaOrganizer中:
/**
* Display area that can be magnified in
* @link Settings.Secure.ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW. It contains all windows
* below @link WindowManager.LayoutParams#TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY.
*/
public static final int FEATURE_WINDOWED_MAGNIFICATION = FEATURE_SYSTEM_FIRST + 4;
代表了该DisplayArea在ACCESSIBILITY_MAGNIFICATION_MODE_WINDOW模式下可以进行放大,该DisplayArea包含了所有比TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY类型的窗口层级低的窗口,为什么这么说,继续看下面。
3)、设置Feature的mWindowLayers:
.upTo(TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY)
.except(TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY)
首先TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY代表的是一种窗口类型:
/**
* Window type: Window for adding accessibility window magnification above other windows.
* This will place the window in the overlay windows.
* @hide
*/
public static final int TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW + 39;
接着看下upTo方法:
/**
* Set that the feature applies window types that are layerd at or below the layer of
* the given window type.
*/
Builder upTo(int typeInclusive)
final int max = layerFromType(typeInclusive, false);
for (int i = 0; i < max; i++)
mLayers[i] = true;
set(typeInclusive, true);
return this;
继续看下layerFromType方法:
private int layerFromType(int type, boolean internalWindows)
return mPolicy.getWindowLayerFromTypeLw(type, internalWindows);
调用的是WindowManagerPolicy.getWindowLayerFromTypeLw方法:
/**
* Returns the layer assignment for the window type. Allows you to control how different
* kinds of windows are ordered on-screen.
*
* @param type The type of window being assigned.
* @param canAddInternalSystemWindow If the owner window associated with the type we are
* evaluating can add internal system windows. I.e they have
* @link Manifest.permission#INTERNAL_SYSTEM_WINDOW. If true, alert window
* types @link android.view.WindowManager.LayoutParams#isSystemAlertWindowType(int)
* can be assigned layers greater than the layer for
* @link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY Else, their
* layers would be lesser.
* @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
*/
default int getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow)
return getWindowLayerFromTypeLw(type, canAddInternalSystemWindow,
false /* roundedCornerOverlay */);
/**
* Returns the layer assignment for the window type. Allows you to control how different
* kinds of windows are ordered on-screen.
*
* @param type The type of window being assigned.
* @param canAddInternalSystemWindow If the owner window associated with the type we are
* evaluating can add internal system windows. I.e they have
* @link Manifest.permission#INTERNAL_SYSTEM_WINDOW. If true, alert window
* types @link android.view.WindowManager.LayoutParams#isSystemAlertWindowType(int)
* can be assigned layers greater than the layer for
* @link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY Else, their
* layers would be lesser.
* @param roundedCornerOverlay #code true to indicate that the owner window is rounded corner
* overlay.
* @return int An arbitrary integer used to order windows, with lower numbers below higher ones.
*/
default int getWindowLayerFromTypeLw(int type, boolean canAddInternalSystemWindow,
boolean roundedCornerOverlay)
// Always put the rounded corner layer to the top most.
if (roundedCornerOverlay && canAddInternalSystemWindow)
return getMaxWindowLayer();
if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
return APPLICATION_LAYER;
switch (type)
case TYPE_WALLPAPER:
// wallpaper is at the bottom, though the window manager may move it.
return 1;
case TYPE_PRESENTATION:
case TYPE_PRIVATE_PRESENTATION:
case TYPE_DOCK_DIVIDER:
case TYPE_QS_DIALOG:
case TYPE_PHONE:
return 3;
case TYPE_SEARCH_BAR:
case TYPE_VOICE_INTERACTION_STARTING:
return 4;
case TYPE_VOICE_INTERACTION:
// voice interaction layer is almost immediately above apps.
return 5;
case TYPE_INPUT_CONSUMER:
return 6;
case TYPE_SYSTEM_DIALOG:
return 7;
case TYPE_TOAST:
// toasts and the plugged-in battery thing
return 8;
case TYPE_PRIORITY_PHONE:
// SIM errors and unlock. Not sure if this really should be in a high layer.
return 9;
case TYPE_SYSTEM_ALERT:
// like the ANR / app crashed dialogs
// Type is deprecated for non-system apps. For system apps, this type should be
// in a higher layer than TYPE_APPLICATION_OVERLAY.
return canAddInternalSystemWindow ? 13 : 10;
case TYPE_APPLICATION_OVERLAY:
return 12;
case TYPE_INPUT_METHOD:
// on-screen keyboards and other such input method user interfaces go here.
return 15;
case TYPE_INPUT_METHOD_DIALOG:
// on-screen keyboards and other such input method user interfaces go here.
return 16;
case TYPE_STATUS_BAR:
return 17;
case TYPE_STATUS_BAR_ADDITIONAL:
return 18;
case TYPE_NOTIFICATION_SHADE:
return 19;
case TYPE_STATUS_BAR_SUB_PANEL:
return 20;
case TYPE_KEYGUARD_DIALOG:
return 21;
case TYPE_VOLUME_OVERLAY:
// the on-screen volume indicator and controller shown when the user
// changes the device volume
return 22;
case TYPE_SYSTEM_OVERLAY:
// the on-screen volume indicator and controller shown when the user
// changes the device volume
return canAddInternalSystemWindow ? 23 : 11;
case TYPE_NAVIGATION_BAR:
// the navigation bar, if available, shows atop most things
return 24;
case TYPE_NAVIGATION_BAR_PANEL:
// some panels (e.g. search) need to show on top of the navigation bar
return 25;
case TYPE_SCREENSHOT:
// screenshot selection layer shouldn't go above system error, but it should cover
// navigation bars at the very least.
return 26;
case TYPE_SYSTEM_ERROR:
// system-level error dialogs
return canAddInternalSystemWindow ? 27 : 10;
case TYPE_MAGNIFICATION_OVERLAY:
// used to highlight the magnified portion of a display
return 28;
case TYPE_DISPLAY_OVERLAY:
// used to simulate secondary display devices
return 29;
case TYPE_DRAG:
// the drag layer: input for drag-and-drop is associated with this window,
// which sits above all other focusable windows
return 30;
case TYPE_ACCESSIBILITY_OVERLAY:
// overlay put by accessibility services to intercept user interaction
return 31;
case TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY:
return 32;
case TYPE_SECURE_SYSTEM_OVERLAY:
return 33;
case TYPE_BOOT_PROGRESS:
return 34;
case TYPE_POINTER:
// the (mouse) pointer layer
return 35;
default:
Slog.e("WindowManager", "Unknown window type: " + type);
return 3;
这个方法返回给定窗口类型对应的层级值。允许你控制不同类型的窗口在屏幕上的排序方式。
看方法内容很简单,对每一种类型的窗口,都规定了一个层级值。层级值反映了这些窗口在Z轴上的排序方式,层级值越高在Z轴上的位置也就越高。但是层级值的大小和窗口类型对应的那个值的大小并没有关系,窗口类型值大的窗口,对应的层级值不一定大。
另外,大部分层级值都唯一对应一种窗口类型,比较特殊的是:
- 层级值2,所有App窗口会被归类到这一个层级。
- 层级值3,该方法中没有提到的窗口类型会被归类到这一个层级。
知道了这些内容再回头看upTo方法,就很容易理解了:
首先找到TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY这个窗口类型对应的层级值,也就是32,接着将mLayers数组从0到32的元素,全部赋值为true。
看下Feature.mBuilder的成员变量mLayers的定义:
static class Builder
// ......
private final boolean[] mLayers;
// ......
/**
* Builds a new feature that applies to a set of window types as specified by the
* builder methods.
*
* <p>The set of types is updated iteratively in the order of the method invocations.
* For example, @code all().except(TYPE_STATUS_BAR) expresses that a feature should
* apply to all types except TYPE_STATUS_BAR.
*
* <p>The builder starts out with the feature not applying to any types.
*
* @param name the name of the feature.
* @param id of the feature. @see Feature#getId
*/
Builder(WindowManagerPolicy policy, String name, int id)
mPolicy = policy;
mName = name;
mId = id;
mLayers = new boolean[mPolicy.getMaxWindowLayer() + 1];
// ......
WindowManagerPolicy.getMaxWindowLayer方法是:
// TODO(b/155340867): consider to remove the logic after using pure Surface for rounded corner
// overlay.
/**
* Returns the max window layer.
* <p>Note that the max window layer should be higher that the maximum value which reported
* by @link #getWindowLayerFromTypeLw(int, boolean) to contain rounded corner overlay.</p>
*
* @see WindowManager.LayoutParams#PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY
*/
default int getMaxWindowLayer()
return 36;
返回了目前WindowManagerPolicy定义的最大层级值,36。
那么Feature.Builder.mLayers数组初始化为:
mLayers = new boolean[37];
Feature.mWindowLayers则是在Feature.Builder.build方法中完全由Feature.Builder.mLayers的值复制过来:
Feature build()
if (mExcludeRoundedCorner)
// Always put the rounded corner layer to the top most layer.
mLayers[mPolicy.getMaxWindowLayer()] = false;
return new Feature(mName, mId, mLayers.clone(), mNewDisplayAreaSupplier);
将Feature.Builde.mLayer数组中的每个元素设置为true的意思是什么呢?打个比方,将Feature.Builde.mLayer[32]设置为true,后续调用Feature.Builder.build后,Feature.mWindowLayers[32]也会被设置true。而Feature.mWindowLayers[32]为true,则表示该Feature对应的DisplayArea,可以包含层级值为32,也就是窗口类型为TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY的窗口。
另外目前看到mExcludeRoundedCorner是始终为true的,也就是说,mLayers[36]始终为false。
看下都有哪些方法来设置Feature.Builde.mLayer:
/**
* Set that the feature applies to all window types.
*/
Builder all()
Arrays.fill(mLayers, true);
return this;
/**
* Set that the feature applies to the given window types.
*/
Builder and(int... types)
for (int i = 0; i < types.length; i++)
int type = types[i];
set(type, true)Android 层级结构梳理
目录
初识Android 系统
Android其本质就是在标准的Linux系统上增加了Java虚拟机Dalvik,并在Dalvik虚拟机上搭建了一个JAVA的application framework,所有的应用程序都是基于JAVA的application framework之上。Android主要应用于ARM平台,但不仅限于ARM,通过编译控制,在X86、MAC等体系结构的机器上同样可以运行。
Android系统的层级结构
APPLICATION
主要为系统中的应用,如桌面,闹铃,设置,日历,电话,短信等系统应用。
APPLICATION FRAMEWORK
Android的应用程序框架为应用程序层的开发者提供APIs,它实际上是一个应用程序的框架。由于上层的应用程序是以JAVA构建的,因此本层次提供了以下服务:
- 丰富而又可扩展的视图(Views),可以用来构建应用程序, 它包括列表(lists),网格(grids),文本框(text boxes),按钮(buttons), 甚至可嵌入的web浏览器;
- 内容提供器(Content Providers)使得应用程序可以访问另一个应用程序的数据(如联系人数据库),或者共享它们自己的数据;
- 资源管理器(Resource Manager)提供非代码资源的访问,如本地字符串,图形,和布局文件( layout files );
- 通知管理器 (Notification Manager) 使得应用程序可以在状态栏中显示自定义的提示信息;
- 活动管理器( Activity Manager) 用来管理应用程序生命周期并提供常用的导航回退功能。
Android Runtime Libraries
- Android 包括了一个核心库,该核心库提供了JAVA编程语言核心库的大多数功能。每一个Android应用程序都在它自己的进程中运行,都拥有一个独立的Dalvik虚拟机实例。Dalvik被设计成一个设备可以同时高效地运行多个虚拟系统。 Dalvik虚拟机执行(.dex)的Dalvik可执行文件,该格式文件针对小内存使用做了优化。同时虚拟机是基于寄存器的,所有的类都经由JAVA编译器编译,然后通过SDK中 的 “dx” 工具转化成.dex格式由虚拟机执行。Dalvik虚拟机依赖于linux内核的一些功能,比如线程机制和底层内存管理机制。
- Android 包含一些C/C++库,这些库能被Android系统中不同的组件使用。它们通过 Android 应用程序框架为开发者提供服务
Linux Kernel
Android 的核心系统服务依赖于 Linux 内核,如安全性,内存管理,进程管理, 网络协议栈和驱动模型。 Linux 内核也同时作为硬件和软件栈之间的抽象层。
Framework简介
常规服务的简单介绍
SystemServer 是framework中非常重要的一个进程,它是在虚拟机启动后运行的第一个java进程,SystemServer启动其他系统服务,这些系统服务都是以一个线程的方式存在于SystemServer进程中。
- EntropyService 提供伪随机数
- PowerManagerService 电源管理服务
- ActivityManagerService 最核心的服务之一,管理Activity
- TelephonyRegistry 通过该服务注册电话模块的事件响应,比如重启、关闭、启动等
- PackageManagerService 程序包管理服务
- AccountManagerService 账户管理服务,是指联系人账户,而不是Linux系统的账户
- ContentService ContentProvider服务,提供跨进程数据交换
- BatteryService 电池管理服务
- LightsService 自然光强度感应传感器服务
- VibratorService 震动器服务
- AlarmManagerService 定时器管理服务,提供定时提醒服务
- WindowManagerService Framework最核心的服务之一,负责窗口管理
- BluetoothService 蓝牙服务
- DevicePolicyManagerService 提供一些系统级别的设置及属性
- StatusBarManagerService 状态栏管理服务
- ClipboardService 系统剪切板服务
- InputMethodManagerService 输入法管理服务
- NetStatService 网络状态服务
- NetworkManagementService 网络管理服务
- ConnectivityService 网络连接管理服务
- AccessibilityManagerService 辅助管理程序截获所有的用户输入,并根据这些输入给用户一些额外的反馈,起到辅助的效果
- MountService 挂载服务,可通过该服务调用Linux层面的mount程序
- NotificationManagerService 通知栏管理服务,Android中的通知栏和状态栏在一起,只是界面上前者在左边,后者在右边
- DeviceStorageMonitorService 磁盘空间状态检测服务
- LocationManagerService 地理位置服务
- SearchManagerService 搜索管理服务
- DropBoxManagerService 通过该服务访问Linux层面的Dropbox程序
- WallpaperManagerService 墙纸管理服务,墙纸不等同于桌面背景,在View系统内部,墙纸可以作为任何窗口的背景
- AudioService 音频管理服务
- BackupManagerService 系统备份服务
- AppWidgetService Widget服务
- RecognitionManagerService 身份识别服务
- DiskStatsService 磁盘统计服务
核心服务介绍
1:ActivityManagerService
ActivityManagerService(以下简称:AMS)是android系统的一个系统服务,是应用进程的管理服务端,直接的控制了应用程序的各个行为,保证了系统中不同的应用程序之间能够和谐的合理的进行调度运行。
AMS是android上层系统最核心的模块之一,其主要的工作是对所有的应用进程及其进程中的四大组件进行管理。(当然这里面也涉及了一些window、电源、权限等内容)
对进程的管理包括:进程的创建与销毁、进程的优先级调整。对组件的管理包括:Activity的调度管理、Service的管理、Broadcast的分发、以及ContentProvider管理。
2:WindowManagerService
对系统中所有窗口进行管理;动画处理 ;Input分发、处理;Display管理(多屏显示) 。
以上是关于3Android 12DisplayArea层级结构的主要内容,如果未能解决你的问题,请参考以下文章
Css权威指南(4th,第四版中文翻译)-3.特异性和层级继承
Android R WindowManagerService模块 WMS整体架构及启动过程
Android 12 - WMS 层级结构 && DisplayAreaGroup 引入
Android 12 - WMS 层级结构 && DisplayAreaGroup 引入