WindowManagerService-->InputChannle的产生

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)😉

XMind -文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值