我们知道按键是底层通过input系统传值上来的,这里面相关的服务是InputManagerService.java,对应的代码路径在frameworks\base\services\java\com\android\server\input\inputManagerService.java
frameworks\base\services\java\com\android\server目录下有很多Android源生的服务,大家有兴趣的可以去研究。

这里面提到的inputManagerService又是在哪里被启动的呢,Android系统被启动的过程中创建的第一个进程zygote,在他的fork函数里面会创建SystemServer对象,我们可以看看SystemServer这个类又做了哪些事情。SystemServer的路径在frameworks/base/services/java/com/android/server/SystemServer.java
他的main函数如下:

public static void main(String[] args) {        /*         * In case the runtime switched since last boot (such as when         * the old runtime was removed in an OTA), set the system         * property so that it is in sync. We can't do this in         * libnativehelper's JniInvocation::Init code where we already         * had to fallback to a different runtime because it is         * running as root and we need to be the system user to set         * the property. http://b/11463182         */        SystemProperties.set("persist.sys.dalvik.vm.lib",                             VMRuntime.getRuntime().vmLibrary());        if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {            // If a device's clock is before 1970 (before 0), a lot of            // APIs crash dealing with negative numbers, notably            // java.io.File#setLastModified, so instead we fake it and            // hope that time from cell towers or NTP fixes it            // shortly.            Slog.w(TAG, "System clock is before 1970; setting to 1970.");            SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);        }        if (SamplingProfilerIntegration.isEnabled()) {            SamplingProfilerIntegration.start();            timer = new Timer();            timer.schedule(new TimerTask() {                @Override                public void run() {                    SamplingProfilerIntegration.writeSnapshot("system_server", null);                }            }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);        }        // Mmmmmm... more memory!        dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();        // The system server has to run all of the time, so it needs to be        // as efficient as possible with its memory usage.        VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);        Environment.setUserRequired(true);        System.loadLibrary("android_servers");        Slog.i(TAG, "Entered the Android system server!");        // Initialize native services.        nativeInit();        // This used to be its own separate thread, but now it is        // just the loop we run on the main thread.        ServerThread thr = new ServerThread();        thr.initAndLoop();    }

这里面有个线程是执行initAndLoop方法,我们打开这个方法就会发现inputManagerService对象被new出来了。相关代码如下:

           Slog.i(TAG, "Input Manager");            inputManager = new InputManagerService(context, wmHandler);            Slog.i(TAG, "Window Manager");            wm = WindowManagerService.main(context, power, display, inputManager,                    wmHandler, factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,                    !firstBoot, onlyCore);            ServiceManager.addService(Context.WINDOW_SERVICE, wm);            ServiceManager.addService(Context.INPUT_SERVICE, inputManager);            ActivityManagerService.self().setWindowManager(wm);            inputManager.setWindowManagerCallbacks(wm.getInputMonitor());            inputManager.start();            display.setWindowManager(wm);            display.setInputManager(inputManager);

更多相关文章

  1. Android Intent传递对象
  2. Android 保存文件路径方法
  3. Android JNI cpp文件创建 java bean 对象并返回
  4. Android高手进阶教程(十六)---Android中Intent传递对象的两种方
  5. Android上在两个Activity之间传递Bitmap对象
  6. [置顶] Android 调用js,传对象到js里面使用addJavascriptInterfac
  7. 如何在Windows上设置Android环境变量/路径

随机推荐

  1. android support v4、v7、v13的区别及作
  2. 【安卓开发】Facebook工程师是如何改进他
  3. 接入新浪、腾讯微博和人人网的Android客
  4. Google Android内核编译教程
  5. Android(安卓)Vitamio 直播视频播放功能
  6. Eclipse同时附加javadoc和android文档
  7. [置顶] Android的Activity屏幕切换动画(
  8. 【Android】android中Invalidate和postIn
  9. Android盈利模式,哪种更靠谱?
  10. 爱奇艺Android移动客户端app瘦身经验