WindowManagerService–>InputChannle配置
观察InputChannel加载:
WindowManagerService#addWindow
final boolean openInputChannels = (outInputChannel != null
&& (attrs.inputFeatures & INPUT_FEATURE_NO_INPUT_CHANNEL) == 0);
if (openInputChannels) {
win.openInputChannel(outInputChannel);
}
win.openInputChannel(outInputChannel);
public int addWindow(Session session, IWindow client, int seq,
LayoutParams attrs, int viewVisibility, int displayId, Rect outFrame,
Rect outContentInsets, Rect outStableInsets, Rect outOutsets,
DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
InsetsState outInsetsState) {
final boolean openInputChannels = (outInputChannel != null
&& (attrs.inputFeatures & INPUT_FEATURE_NO_INPUT_CHANNEL) == 0);
if (openInputChannels) {
Slog.w(TAG_WM, "WindowManagerService=openInputChannels= " + “true”);
win.openInputChannel(outInputChannel);
} else {
Slog.w(TAG_WM, "WindowManagerService=openInputChannels= " + “false”);
win.openInputChannel(outInputChannel);
}
}
-
WindowState#openInputChannel(){}
-
InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
-
InputChannel.java#openInputChannelPair(name);
public static InputChannel[] openInputChannelPair(String name) {
Slog.d(TAG, “Opening input channel pair========= '” + name + “’”);
if (name == null) {
throw new IllegalArgumentException(“name must not be null”);*An input channel specifies the file descriptors used to send input events to
* a window in another process.It is Parcelable so that it can be sent
* to the process that is to receive events.Only one thread should be reading
*from an InputChannel at a time.
*@hide
}if (DEBUG) { Slog.d(TAG, "Opening input channel pair '" + name + "'"); } return nativeOpenInputChannelPair(name);
}
-
openInputChannelPair(name){}->nativeOpenInputChannelPair(name);
public static InputChannel[] openInputChannelPair(String name) {
.
.
.
return nativeOpenInputChannelPair(name);
}-
android_view_InputChannel.cpp
-
枚举 JNINativeMethod gInputChannelMethods[]
/* name, signature, funcPtr /
{ “nativeOpenInputChannelPair”, “(Ljava/lang/String;)[Landroid/view/InputChannel;”,
(void)android_view_InputChannel_nativeOpenInputChannelPair },
{ “nativeDispose”, “(Z)V”,
(void*)android_view_InputChannel_nativeDispose },
{ “nativeTransferTo”, “(Landroid/view/InputChannel;)V”,
(void*)android_view_InputChannel_nativeTransferTo },
{ “nativeReadFromParcel”, “(Landroid/os/Parcel;)V”,
(void*)android_view_InputChannel_nativeReadFromParcel },
{ “nativeWriteToParcel”, “(Landroid/os/Parcel;)V”,
(void*)android_view_InputChannel_nativeWriteToParcel },
{ “nativeGetName”, “()Ljava/lang/String;”,
(void*)android_view_InputChannel_nativeGetName },
{ “nativeDup”, “(Landroid/view/InputChannel;)V”,
(void*)android_view_InputChannel_nativeDup },
{ “nativeGetToken”, “()Landroid/os/IBinder;”,
(void*)android_view_InputChannel_nativeGetToken },
{ “nativeSetToken”, “(Landroid/os/IBinder;)V”,
(void*)android_view_InputChannel_nativeSetToken }
}; -
register_android_view_InputChannel
int register_android_view_InputChannel(JNIEnv* env) {
int res = RegisterMethodsOrDie(env, “android/view/InputChannel”, gInputChannelMethods,
NELEM(gInputChannelMethods));jclass clazz = FindClassOrDie(env, "android/view/InputChannel"); gInputChannelClassInfo.clazz = MakeGlobalRefOrDie(env, clazz); gInputChannelClassInfo.mPtr = GetFieldIDOrDie(env, gInputChannelClassInfo.clazz, "mPtr", "J"); gInputChannelClassInfo.ctor = GetMethodIDOrDie(env, gInputChannelClassInfo.clazz, "<init>", "()V"); return res;
}
-
-
-
-
-
mWmService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder());
-
IMS.#registerInputChannel(InputChannel inputChannel, IBinder token){
nativeRegisterInputChannel(mPtr, inputChannel, Display.INVALID_DISPLAY);
}-
com_android_server_input_InputManagerService.cpp#nativeRegisterInputChannel()
static void nativeRegisterInputChannel(JNIEnv env, jclass / clazz */,
jlong ptr, jobject inputChannelObj, jint displayId) {
NativeInputManager *im = reinterpret_cast<NativeInputManager *>(ptr);sp <InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env, inputChannelObj); if (inputChannel == nullptr) { throwInputChannelNotInitialized(env); return; } status_t status = im->registerInputChannel(env, inputChannel, displayId); if (status) { std::string message; message += StringPrintf("Failed to register input channel. status=%d", status); jniThrowRuntimeException(env, message.c_str()); return; } android_view_InputChannel_setDisposeCallback(env, inputChannelObj, handleInputChannelDisposed, im);
}
- sp inputChannel = android_view_InputChannel_getInputChannel(env,inputChannelObj);
- status_t status = im->registerInputChannel(env, inputChannel, displayId);
- android_view_InputChannel_setDisposeCallback(env, inputChannelObj,handleInputChannelDisposed, im);
-
-
-
InputManagerService mInputManager
-
InputManagerService#registerInputChannel()
public void registerInputChannel(InputChannel inputChannel, IBinder token) {
if (inputChannel == null) {
throw new IllegalArgumentException(“inputChannel must not be null.”);
}if (token == null) { token = new Binder(); } inputChannel.setToken(token); nativeRegisterInputChannel(mPtr, inputChannel, Display.INVALID_DISPLAY);
}
- nativeRegisterInputChannel((mPtr, inputChannel, Display.INVALID_DISPLAY)😉