のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

InputChannel-JNI

E/InputChannel-JNI( 444): Error 9 dup channel fd -2147483647.

  • 2147483647 = FFFF FFFF 8000 0001
    190 static void android_view_InputChannel_nativeReadFromParcel(JNIEnv* env, jobject obj,
    191         jobject parcelObj) {
    192     if (android_view_InputChannel_getNativeInputChannel(env, obj) != NULL) {
    193         jniThrowException(env, "java/lang/IllegalStateException",
    194                 "This object already has a native input channel.");
    195         return;
    196     }
    197 
    198     Parcel* parcel = parcelForJavaObject(env, parcelObj);
    199     if (parcel) {
    200         bool isInitialized = parcel->readInt32();
    201         if (isInitialized) {
    202             String8 name = parcel->readString8();
    203             int rawFd = parcel->readFileDescriptor();
    204             int dupFd = dup(rawFd);
    205             if (dupFd < 0) {
    206                 ALOGE("Error %d dup channel fd %d.", errno, rawFd); <=======ここでエラーログ
    207                 jniThrowRuntimeException(env,
    208                         "Could not read input channel file descriptors from parcel.");
    209                 return;
    210             }
    211 
    212             InputChannel* inputChannel = new InputChannel(name, dupFd);
    213             NativeInputChannel* nativeInputChannel = new NativeInputChannel(inputChannel);
    214 
    215             android_view_InputChannel_setNativeInputChannel(env, obj, nativeInputChannel);
    216         }
    217     }
    218 }
   1093 int Parcel::readFileDescriptor() const
   1094 {
   1095     const flat_binder_object* flat = readObject(true);
   1096     if (flat) { <= NGパターン1:この値が0だった。
   1097         switch (flat->type) { <= NGパターン2:typeの値がおかしい。
   1098             case BINDER_TYPE_FD: 
   1099                 //ALOGI("Returning file descriptor %ld from parcel %p\n", flat->handle, this);
   1100                 return flat->handle;
   1101         }
   1102     }
   1103     return BAD_TYPE; <=== こっちを通った。
   1104 }
     45 enum {
     46     OK                = 0,    // Everything's swell.
     47     NO_ERROR          = 0,    // No errors.
     48 
     49     UNKNOWN_ERROR       = 0x80000000,
     50 
     51     NO_MEMORY           = -ENOMEM,
     52     INVALID_OPERATION   = -ENOSYS,
     53     BAD_VALUE           = -EINVAL,
     54     BAD_TYPE            = 0x80000001,  <============= この値を使用
     55     NAME_NOT_FOUND      = -ENOENT,
     56     PERMISSION_DENIED   = -EPERM,
     57     NO_INIT             = -ENODEV,
     58     ALREADY_EXISTS      = -EEXIST,
     59     DEAD_OBJECT         = -EPIPE,
     60     FAILED_TRANSACTION  = 0x80000002,
     61     JPARKS_BROKE_IT     = -EPIPE,
     62 #if !defined(HAVE_MS_C_RUNTIME)
     63     BAD_INDEX           = -EOVERFLOW,
     64     NOT_ENOUGH_DATA     = -ENODATA,
     65     WOULD_BLOCK         = -EWOULDBLOCK,
     66     TIMED_OUT           = -ETIMEDOUT,
     67     UNKNOWN_TRANSACTION = -EBADMSG,
     68 #else
     69     BAD_INDEX           = -E2BIG,
     70     NOT_ENOUGH_DATA     = 0x80000003,
     71     WOULD_BLOCK         = 0x80000004,
     72     TIMED_OUT           = 0x80000005,
     73     UNKNOWN_TRANSACTION = 0x80000006,
     74 #endif
     75     FDS_NOT_ALLOWED     = 0x80000007,
     76 };
     39 struct flat_binder_object {
     40    unsigned long type;
     41    unsigned long flags;
     42    union {
     43    /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     44      void *binder;
     45      signed long handle;
     46    };
     47    void *cookie;
     48    /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     49 };

****************************************

    130     public void readFromParcel(Parcel in) {
    131         if (in == null) {
    132             throw new IllegalArgumentException("in must not be null");
    133         }
    134 
    135         nativeReadFromParcel(in);
    136     }

readFromparcelは、いろいろな場所で使われている。
****************************************

E/AndroidRuntime( ): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.intent.action.hoge flg=0x60000010 } in com.android.fuga$21@42989f20

    724             public void run() {
    725                 final BroadcastReceiver receiver = mReceiver;
    726                 final boolean ordered = mOrdered;
    727 
    728                 if (ActivityThread.DEBUG_BROADCAST) {
    729                     int seq = mCurIntent.getIntExtra("seq", -1);
    730                     Slog.i(ActivityThread.TAG, "Dispatching broadcast " + mCurIntent.getAction()
    731                             + " seq=" + seq + " to " + mReceiver);
    732                     Slog.i(ActivityThread.TAG, "  mRegistered=" + mRegistered
    733                             + " mOrderedHint=" + ordered);
    734                 }
    735 
    736                 final IActivityManager mgr = ActivityManagerNative.getDefault();
    737                 final Intent intent = mCurIntent;
    738                 mCurIntent = null;
    739 
    740                 if (receiver == null || mForgotten) {
    741                     if (mRegistered && ordered) {
    742                         if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG,
    743                                 "Finishing null broadcast to " + mReceiver);
    744                         sendFinished(mgr);
    745                     }
    746                     return;
    747                 }
    748 
    749                 Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "broadcastReceiveReg");
    750                 try {
    751                     ClassLoader cl =  mReceiver.getClass().getClassLoader();
    752                     intent.setExtrasClassLoader(cl);
    753                     setExtrasClassLoader(cl);
    754                     receiver.setPendingResult(this);
    755                     receiver.onReceive(mContext, intent);
    756                 } catch (Exception e) {
    757                     if (mRegistered && ordered) {
    758                         if (ActivityThread.DEBUG_BROADCAST) Slog.i(ActivityThread.TAG,
    759                                 "Finishing failed broadcast to " + mReceiver);
    760                         sendFinished(mgr);
    761                     }
    762                     if (mInstrumentation == null ||
    763                             !mInstrumentation.onException(mReceiver, e)) {
    764                         Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    765                         throw new RuntimeException(
    766                             "Error receiving broadcast " + intent
    767                             + " in " + mReceiver, e); <====ここを通った。
    768                     }
    769                 }
    770 
    771                 if (receiver.getPendingResult() != null) {
    772                     finish();
    773                 }
    774                 Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    775             }
    776         }
     22 #define B_PACK_CHARS(c1, c2, c3, c4)   ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
     23 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */

     24 #define B_TYPE_LARGE 0x85

     25 enum {
     26    BINDER_TYPE_BINDER =      B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE),
     27    BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE),
     28 /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
     29    BINDER_TYPE_HANDLE =      B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE),
     30    BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE),
     31    BINDER_TYPE_FD =          B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE),
     32 };
    713 status_t Parcel::writeFileDescriptor(int fd, bool takeOwnership)
    714 {
    715     flat_binder_object obj;
    716     obj.type = BINDER_TYPE_FD;
    717     obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
    718     obj.handle = fd;
    719     obj.cookie = (void*) (takeOwnership ? 1 : 0);
    720     return writeObject(obj, true);
    721 }