android耳机插入\拔出事件上报流程

kernel发现有设备状态变动后发送uevent到WiredAccessoryObserver.java:
WiredAccessoryObserver.java->onUEvent()->updateState()->update()->mHandler.handlemessage()->setDevicesState()->setDevicesState()->mAudioManager.setWiredDeviceConnectionState().

AudioService.java-> setWiredDeviceConnectionState()->queueMsgUnderWakeLock()->sendMsg()->mAudioHandler.handlemessage(MSG_SET_WIRED_DEVICE_CONNECTION_STATE)->onSetWiredDeviceConnectionState().
onSetWiredDeviceConnectionState()->handleDeviceConnection()->AudioSystem.setDeviceConnectionState():告诉audiosysystem有设备的state变动了。
onSetWiredDeviceConnectionState()->sendDeviceConnectionIntent():
做两件事,一是切换声道:
      synchronized (mCurAudioRoutes) {
            if (connType != 0) {
                int newConn = mCurAudioRoutes.mMainType;
                if (state != 0) {
                    newConn |= connType;
                } else {
                    newConn &= ~connType;
                }
                if (newConn != mCurAudioRoutes.mMainType) {
                    mCurAudioRoutes.mMainType = newConn;
                    sendMsg(mAudioHandler, MSG_REPORT_NEW_ROUTES,
                            SENDMSG_NOOP, 0, 0, null, 0);
                }
            }
        }
二是给上层发广播,进行事件通知:
ActivityManagerNative.broadcastStickyIntent(intent, null);
上层注册了该广播的接收到广播后按逻辑做事。

你可能感兴趣的:(android)