frameworks/base/services/java/com/android/server/SystemServer.java
frameworks/base/services/java/com/android/server/wm/WindowManagerService.java
frameworks/base/services/java/com/android/server/wm/InputManager.java
frameworks/base/services/jni/com_android_server_InputManager.cpp
frameworks/base/services/input/Android.mk
frameworks/base/services/input/EventHub.cpp
frameworks/base/services/input/EventHub.h
frameworks/base/services/input/InputApplication.cpp
frameworks/base/services/input/InputDispatcher.cpp
frameworks/base/services/input/InputListener.cpp
frameworks/base/services/input/InputDispatcher.h
frameworks/base/services/input/InputListener.h
frameworks/base/services/input/InputManager.cpp
frameworks/base/services/input/InputManager.h
frameworks/base/services/input/InputReader.cpp
frameworks/base/services/input/InputReader.h
frameworks/base/services/input/InputWindow.cpp
frameworks/base/services/input/InputWindow.h
frameworks/base/services/input/PointerController.cpp
frameworks/base/services/input/PointerController.h
frameworks/base/services/input/SpriteController.cpp
frameworks/base/services/input/SpriteController.h
2.Service and WindowManagerService
- Source code:frameworks/base/services/java/com/android/server/SystemServer.java
- class ServerThread extends Thread {
- private static final String TAG = "SystemServer";
- /*。。。。。。。。。。處略過若干行。。。。。。。。。*/
- Slog.i(TAG, "Window Manager");
- wm = WindowManagerService.main(context, power,
- factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
- !firstBoot);
- ServiceManager.addService(Context.WINDOW_SERVICE, wm);
- ActivityManagerService.self().setWindowManager(wm);
- }
--WindowManagerService的構造方法
- Source code:frameworks/base/services/java/com/android/server/wm/WindowManagerService.java
- private WindowManagerService(Context context, PowerManagerService pm,
- boolean haveInputMethods, boolean showBootMsgs) {
- mInputManager = new InputManager(context, this);/*構造InputManager*/
- PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
- thr.start();
- /*debug by Joyce*/
- synchronized (thr) {
- while (!thr.mRunning) {
- try {
- thr.wait();
- } catch (InterruptedException e) {
- }
- }
- }
- mInputManager.start();/*啓動InputManager*/
- }
2)開啓InputManager(由InputManager本身start()方法實現)
--InputManager構造方法以及start()方法的實現
- Source code:frameworks/base/services/java/com/android/server/wm/InputManager.java
- public InputManager(Context context, WindowManagerService windowManagerService) {
- this.mContext = context;
- this.mWindowManagerService = windowManagerService;
- this.mCallbacks = new Callbacks();
- /*現在知道爲何與WindowManagerService有關係了吧
- *因爲InputManager的各種需求
- */
- /*獲取Looper循環隊列?說實話我已經忘記了,只不過還記得那一副經典的圖*/
- Looper looper = windowManagerService.mH.getLooper();
- Slog.i(TAG, "Initializing input manager");
- nativeInit(mContext, mCallbacks, looper.getQueue());/*初始化InputManager*/
- }
- /*debug by Joyce*/
- public void start() {
- Slog.i(TAG, "Hey Joyce Starting input manager");
- nativeStart();/*啓動InputManager的本地實現*/
- }
- }
2)調用JNI本地框架中的nativeStart方法來開啓InputManager
3.JNI本地框架的實現
--com_android_server_InputManager中給上層InputManager所提供的兩個本地AP的實現
- Source code:frameworks/base/services/jni/com_android_server_InputManager.cpp
- /*方法映射表*/
- static JNINativeMethod gInputManagerMethods[] = {
- /* name, signature, funcPtr */
- { "nativeInit", "(Landroid/content/Context;"
- "Lcom/android/server/wm/InputManager$Callbacks;Landroid/os/MessageQueue;)V",
- (void*) android_server_InputManager_nativeInit },
- { "nativeStart", "()V",
- (void*) android_server_InputManager_nativeStart },
- }
- static void android_server_InputManager_nativeInit(JNIEnv* env, jclass clazz,
- jobject contextObj, jobject callbacksObj, jobject messageQueueObj) {
- if (gNativeInputManager == NULL) {/*首次調用肯定爲NULL*/
- sp<Looper> looper = android_os_MessageQueue_getLooper(env, messageQueueObj);
- gNativeInputManager = new NativeInputManager(contextObj, callbacksObj, looper);
- } else {
- LOGE("Input manager already initialized.");
- jniThrowRuntimeException(env, "Input manager already initialized.");
- }
- }
- --NativeInputManager本地類的構造函數
- NativeInputManager::NativeInputManager(jobject contextObj,
- jobject callbacksObj, const sp<Looper>& looper) :
- mLooper(looper) {
- JNIEnv* env = jniEnv();
- /*程序到這裏就已經爲我們創建一個inputdevice HAL 的實例了*/
- sp<EventHub> eventHub = new EventHub();/*creat the EventHub 一系列的memset*/
- /*並以eventHub爲參數爲我們創建了一個InputManager本地實例,注意這個InputManager
- 是上層InputManager的本地實現定義在InputManager.cpp中
- */
- mInputManager = new InputManager(eventHub, this, this);
- }
- --InputManager構造函數的實現
- Source code:frameworks/base/services/input/InputManager.cpp
- InputManager::InputManager(
- const sp<EventHubInterface>& eventHub,
- const sp<InputReaderPolicyInterface>& readerPolicy,
- const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) {
- mDispatcher = new InputDispatcher(dispatcherPolicy);
- mReader = new InputReader(eventHub, readerPolicy, mDispatcher);
- initialize();
- }
功能描述:1)創建NativeInputManager對象並保存成gNativeInputManager,該變量馬上就會被用到
2)創建NativeInputManager對象的同時創建EventHub對象,並將創建的EventHub對象mEventHub作爲參數傳遞給InputManager
的構造函數創建InputManager對象mInputManager
3)構建InputManager的同時會爲我們構建InputDispatcher和InputReader對象
4)好了其實到這裏就已經進入了本地C++框架層了,先到此打住,把下面這個JNI方法先分析一番
------------------>B部分
- static void android_server_InputManager_nativeStart(JNIEnv* env, jclass clazz) {
- if (checkInputManagerUnitialized(env)) {
- return;
- }
- status_t result = gNativeInputManager->getInputManager()->start();
- if (result) {
- jniThrowRuntimeException(env, "Input manager could not be started.");
- }
- }
2)再由mInputManager去調用它本身的start()方法來啓動InputManager
3)從上面的這些方法可以得知在上層我們開啓InputManager實質是開啓了本地C++框架中的InputManager
4.C++Input框架的實現