Android R WindowManagerService模块 WMS整体架构及启动过程

Posted wa2231a

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android R WindowManagerService模块 WMS整体架构及启动过程相关的知识,希望对你有一定的参考价值。

DisplayArea是android R上新添加的容器,目的就是将复杂的窗口层级管理简单化、低耦合。

而在树结构中,各个容器结构如下:

可以看到,在树结构中,根节点为RootWindowContainer,叶子节点为WindowState。 正是通过这种结构,WMS中将系统中所有的窗口显示管理得井井有条,并将所有窗口以Surface的形式送到SurfacaFlinger中进行合成和显示。

2.WMS启动流程

接下来我们看下WMS的启动过程。WindowManagerService没有继承与SystemService,而是直接继承了IWindowManager.Stub接口,因此启动过程中,和SytemService的启动有区别。在system_server中,通过以下这些操作完成了WMS的启动:

// frameworks/base/services/java/com/android/server/SystemServer.java

private void startOtherServices(@NonNull TimingsTraceAndSlog t)
// 创建WMS
wm = WindowManagerService.main(context, inputManager, !mFirstBoot, mOnlyCore,
new PhoneWindowManager(), mActivityManagerService.mActivityTaskManager);
// 进行初始化
wm.onInitReady();
// 设置InputCallback接口
inputManager.setWindowManagerCallbacks(wm.getInputManagerCallback());
// 进行Display配置更新
wm.displayReady();
// 系统启动完成
wm.systemReady();
// 计算Configuration
final Configuration config = wm.computeNewConfiguration(DEFAULT_DISPLAY);
DisplayMetrics metrics = new DisplayMetrics();
context.getDisplay().getMetrics(metrics);
context.getResources().updateConfiguration(config, metrics);

下面对以上操作分别进行分析。

1.1.WMS#main()创建WMS对象

在执行main()方法后,最终会在android.display线程去创建WMS的实例:

// frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java

private WindowManagerService(Context context, InputManagerService inputManager,
boolean showBootMsgs, boolean onlyCore, WindowManagerPolicy policy,
ActivityTaskManagerService atm, Supplier<SurfaceControl.Transaction> transactionFactory,
Supplier surfaceFactory,
Function<SurfaceSession, SurfaceControl.Builder> surfaceControlFactory)

// Tranaction对象
mTransaction = mTransactionFactory.get();

// 创建WindowAnimator对象
mAnimator = new WindowAnimator(this);
// 创建RootWindowContainer对象
mRoot = new RootWindowContainer(this);
// 创建WindowSurfacePlacer对象
mWindowPlacerLocked = new WindowSurfacePlacer(this);
// 创建TaskSnapshotController对象
mTaskSnapshotController = new TaskSnapshotController(this);
// 创建DisplayWindowListenerController对象
mDisplayNotificationController = new DisplayWindowListenerController(this);

// 创建SurfaceAnimationRunner对象
mSurfaceAnimationRunner = new SurfaceAnimationRunner(mTransactionFactory,
mPowerManagerInternal);
// 创建TaskPositioningController
mTaskPositioningController = new TaskPositioningController(
this, mInputManager, mActivityTaskManager, mH.getLooper());
// 创建DragDropController对象
mDragDropController = new DragDropController(this, mH.getLooper());
// 创建EmbeddedWindowController
mEmbeddedWindowController = new EmbeddedWindowController(mAtmService);
// 创建 DisplayAreaPolicy.Provider对象
mDisplayAreaPolicyProvider = DisplayAreaPolicy.Provider.fromResources(
mContext.getResources());

构造方法中,创建了WMS所用到的多个对象。

2.2.WMS#onInitReady()对Policy进行初始化

接下来执行onInitReady()方法进行初始化,这个方法中,在android.ui线程中调用WindowManagerPolicy#init()方法进行初始化:

// frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java

public void init(Context context, IWindowManager windowManager,
WindowManagerFuncs windowManagerFuncs)
mContext = context;
mWindowManager = windowManager;
mWindowManagerFuncs = windowManagerFuncs;

这个方法中做了大量的初始化操作。PhoneWindowManager继承于WindowManagerPolicy,是WMS中管理窗口过程中的一个策略类,窗口的显示、事件的派发等都受到PhoneWindowManager中的策略影响。 mWindowManagermWindowManagerFuncs都是WMS对象本身。

2.3.IMS#setWindowManagerCallbacks()设置InputCallback回调

这个方法用来向IMS中设置InputManagerCallback回调:

// frameworks/base/services/core/java/com/android/server/input/InputManagerService.java

public void setWindowManagerCallbacks(WindowManagerCallbacks callbacks)
mWindowManagerCallbacks = callbacks;

InputManagerCallback对象在WMS加载时完成创建:

// frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java

// 创建InputManagerCallback对象
final InputManagerCallback mInputManagerCallback = new InputManagerCallback(this);

public InputManagerCallback getInputManagerCallback()
return mInputManagerCallback;

InputManagerCallback接口用于接受IMS中的回调,如input事件派发过程中发生的ANR等,就是通过该接口向WMS中传递。

2.4.WMS#displayReady()更新DisplayContent配置

这个方法用来进行Display相关配置的第一次更新:

// frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java

总结

其实要轻松掌握很简单,要点就两个:

  1. 找到一套好的视频资料,紧跟大牛梳理好的知识框架进行学习。
  2. 多练。 (视频优势是互动感强,容易集中注意力)

你不需要是天才,也不需要具备强悍的天赋,只要做到这两点,短期内成功的概率是非常高的。

对于很多初中级Android工程师而言,想要提升技能,往往是自己摸索成长,不成体系的学习效果低效漫长且无助。下面资料部分截图是我花费几个月时间整理的,诚意满满:特别适合有3-5年开发经验的Android程序员们学习。

A%E8%BF%99%E4%BA%9B%EF%BC%9F%E5%A6%82%E4%BD%95%E9%9D%A2%E8%AF%95%E6%8B%BF%E9%AB%98%E8%96%AA%EF%BC%81.md)】。**

[外链图片转存中…(img-h0e1xQvX-1644026530660)]

Android系统资源图标android.R.drawable

Android™ 2.1 android.R.drawable Icon Resources

This is a list of resources in Android 2.1\'s android.R.drawable that might be useful as icons in your Android applications. You can use them like this:

Java Usage example:
myMenuItem.setIcon(android.R.drawable.ic_menu_save);
Resource Usage example:
android:icon="@android:drawable/ic_menu_save"
alert_dark_frame
alert_dark_frame
alert_light_frame
alert_light_frame
arrow_down_float
arrow_down_float
arrow_up_float
arrow_up_float
bottom_bar
bottom_bar
btn_default
btn_default
btn_default_small
btn_default_small
btn_dialog
btn_dialog
btn_dropdown
btn_dropdown
btn_minus
btn_minus
btn_plus
btn_plus
btn_radio
btn_radio
btn_star
btn_star
btn_star_big_off
btn_star_big_off
btn_star_big_on
btn_star_big_on
button_onoff_indicator_off
button_onoff_indicator_off
button_onoff_indicator_on
button_onoff_indicator_on
checkbox_off_background
checkbox_off_background
checkbox_on_background
checkbox_on_background
dark_header
dark_header
dialog_frame
dialog_frame
divider_horizontal_bright
divider_horizontal_bright
divider_horizontal_dark
divider_horizontal_dark
divider_horizontal_dim_dark
divider_horizontal_dim_dark
divider_horizontal_textfield
divider_horizontal_textfield
edit_text
edit_text
editbox_background
editbox_background
editbox_background_normal
editbox_background_normal
editbox_dropdown_dark_frame
editbox_dropdown_dark_frame
editbox_dropdown_light_frame
editbox_dropdown_light_frame
gallery_thumb
gallery_thumb
ic_btn_speak_now
ic_btn_speak_now
ic_delete
ic_delete
ic_dialog_alert
ic_dialog_alert
ic_dialog_dialer
ic_dialog_dialer
ic_dialog_email
ic_dialog_email
ic_dialog_info
ic_dialog_info
ic_dialog_map
ic_dialog_map
ic_input_add
ic_input_add
ic_input_delete
ic_input_delete
ic_input_get
ic_input_get
ic_lock_idle_alarm
ic_lock_idle_alarm
ic_lock_idle_charging
ic_lock_idle_charging
ic_lock_idle_lock
ic_lock_idle_lock
ic_lock_idle_low_battery
ic_lock_idle_low_battery
ic_lock_lock
ic_lock_lock
ic_lock_power_off
ic_lock_power_off
ic_lock_silent_mode
ic_lock_silent_mode
ic_lock_silent_mode_off
ic_lock_silent_mode_off
ic_media_ff
ic_media_ff
ic_media_next
ic_media_next
ic_media_pause
ic_media_pause
ic_media_play
ic_media_play
ic_media_previous
ic_media_previous
ic_media_rew
ic_media_rew
ic_menu_add
ic_menu_add
ic_menu_agenda
ic_menu_agenda
ic_menu_always_landscape_portrait
ic_menu_always_landscape_portrait
ic_menu_call
ic_menu_call
ic_menu_camera
ic_menu_camera
ic_menu_close_clear_cancel
ic_menu_close_clear_cancel
ic_menu_compass
ic_menu_compass
ic_menu_crop
ic_menu_crop
ic_menu_day
ic_menu_day
ic_menu_delete
ic_menu_delete
ic_menu_directions
ic_menu_directions
ic_menu_edit
ic_menu_edit
ic_menu_gallery
ic_menu_gallery
ic_menu_help
ic_menu_help
ic_menu_info_details
ic_menu_info_details
ic_menu_manage
ic_menu_manage
ic_menu_mapmode
ic_menu_mapmode
ic_menu_month
ic_menu_month
ic_menu_more
ic_menu_more
ic_menu_my_calendar
ic_menu_my_calendar
ic_menu_mylocation
ic_menu_mylocation
ic_menu_myplaces
ic_menu_myplaces
ic_menu_preferences
ic_menu_preferences
ic_menu_recent_history
ic_menu_recent_history
ic_menu_report_image
ic_menu_report_image
ic_menu_revert
ic_menu_revert
ic_menu_rotate
ic_menu_rotate
ic_menu_save
ic_menu_save
ic_menu_search
ic_menu_search
ic_menu_send
ic_menu_send
ic_menu_set_as
ic_menu_set_as
ic_menu_share
ic_menu_share
ic_menu_slideshow
ic_menu_slideshow
ic_menu_sort_alphabetically
ic_menu_sort_alphabetically
ic_menu_sort_by_size
ic_menu_sort_by_size
ic_menu_today
ic_menu_today
ic_menu_upload
ic_menu_upload
ic_menu_upload_you_tube
ic_menu_upload_you_tube
ic_menu_view
ic_menu_view
ic_menu_week
ic_menu_week
ic_menu_zoom
ic_menu_zoom
ic_notification_clear_all
ic_notification_clear_all
ic_notification_overlay
ic_notification_overlay
ic_partial_secure
ic_partial_secure
ic_popup_disk_full
ic_popup_disk_full
ic_popup_reminder
ic_popup_reminder
ic_popup_sync
ic_popup_sync
ic_search_category_default
ic_search_category_default
ic_secure
ic_secure
menu_frame
menu_frame
menu_full_frame
menu_full_frame
picture_frame
picture_frame
presence_away
presence_away
presence_busy
presence_busy
presence_invisible
presence_invisible
presence_offline
presence_offline
presence_online
presence_online
progress_indeterminate_horizontal
progress_indeterminate_horizontal
radiobutton_off_background
radiobutton_off_background
radiobutton_on_background
radiobutton_on_background
spinner_background
spinner_background
spinner_dropdown_background
spinner_dropdown_background
star_big_off
star_big_off
star_big_on
star_big_on
star_off
star_off
star_on
star_on
stat_notify_call_mute
stat_notify_call_mute
stat_notify_chat
stat_notify_chat
stat_notify_error
stat_notify_error
stat_notify_missed_call
stat_notify_missed_call
stat_notify_more
stat_notify_more
stat_notify_sdcard
stat_notify_sdcard
stat_notify_sdcard_prepare
stat_notify_sdcard_prepare
stat_notify_sdcard_usb
stat_notify_sdcard_usb
stat_notify_sync
stat_notify_sync
stat_notify_sync_noanim
stat_notify_sync_noanim
stat_notify_voicemail
stat_notify_voicemail
stat_sys_data_bluetooth
stat_sys_data_bluetooth
stat_sys_download
stat_sys_download
stat_sys_download_done
stat_sys_download_done
stat_sys_headset
stat_sys_headset
stat_sys_phone_call
stat_sys_phone_call
stat_sys_phone_call_forward
stat_sys_phone_call_forward
stat_sys_phone_call_on_hold
stat_sys_phone_call_on_hold
stat_sys_speakerphone
stat_sys_speakerphone
stat_sys_upload
stat_sys_upload
stat_sys_upload_done
stat_sys_upload_done
stat_sys_vp_phone_call
stat_sys_vp_phone_call
stat_sys_vp_phone_call_on_hold
stat_sys_vp_phone_call_on_hold
stat_sys_warning
stat_sys_warning
status_bar_item_app_background
status_bar_item_app_background
status_bar_item_background为啥 Android Studio 将我所有的引用从 R 更改为 android.R?

Android:android.R.id.content 是做啥用的?

Android - 如何获取 android.R.anim.slide_in_right

同时导入 R(android.R 和 <my_package>.R)

com.android.internal.R包怎么导入android里面的。

Android 11(R)版本对于Toast的一些改变

(c)2006-2024 SYSTEM All Rights Reserved IT常识