static jbyteArray android_os_Parcel_marshall(JNIEnv* env, jclass clazz, jlong nativePtr) { Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr); if (parcel == NULL) { return NULL; } // do not marshall if there are binder objects in the parcel if (parcel->objectsCount()) { jniThrowException(env, "java/lang/RuntimeException", "Tried to marshall a Parcel that contained Binder objects."); return NULL; } jbyteArray ret = env->NewByteArray(parcel->dataSize()); if (ret != NULL) { jbyte* array = (jbyte*)env->GetPrimitiveArrayCritical(ret, 0); if (array != NULL) { memcpy(array, parcel->data(), parcel->dataSize()); env->ReleasePrimitiveArrayCritical(ret, array, 0); } } return ret; }
status_t BnMcuService::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { ALOGI("BnMcuService::onTransact, code[%d]", code); switch (code) { case GET_TEST: { CHECK_INTERFACE(IMcuService, data, reply); int result = getTest(); reply->writeInt32(result); return NO_ERROR; } break; case obtain_info: { CHECK_INTERFACE(IMcuService, data, reply); int domain = data.readInt32(); int cmd = data.readInt32(); Parcel out; bool res = obtainInfo(domain, cmd, out); reply->appendFrom(&out, 0, out.dataSize()); reply->writeInt32(res?1:0); out.freeData(); return NO_ERROR; } break; case send_info: { CHECK_INTERFACE(IMcuService, data, reply); int domain = data.readInt32(); int cmd = data.readInt32(); Parcel in; if(data.dataAvail() >0) { in.appendFrom(&data, data.dataPosition(), data.dataSize()-data.dataPosition()); in.setDataPosition(0); } bool res = sendInfo(domain, cmd, in); reply->writeInt32(res?1:0); in.freeData(); return NO_ERROR; } break; case regist_data_changed_listener: { CHECK_INTERFACE(IMcuService, data, reply); int domain = data.readInt32(); sp<IDataChangedListener> client = interface_cast<IDataChangedListener>(data.readStrongBinder()); bool res = registDataChanagedListener(domain, client); reply->writeInt32((res?1:0)); return NO_ERROR; } break; case unregist_data_changed_listener: { CHECK_INTERFACE(IMcuService, data, reply); int domain = data.readInt32(); sp<IDataChangedListener> client = interface_cast<IDataChangedListener>(data.readStrongBinder()); bool res = unregistDataChanagedListener(domain, client); reply->writeInt32((res?1:0)); return NO_ERROR; } break; default: return BBinder::onTransact(code, data, reply, flags); } }
status_t setParameter(int key, const Parcel& request) { Parcel data, reply; data.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor()); data.writeInt32(key); if (request.dataSize() > 0) { data.appendFrom(const_cast<Parcel *>(&request), 0, request.dataSize()); } remote()->transact(SET_PARAMETER, data, &reply); return reply.readInt32(); }
NS_IMETHOD Run() { assertIsNfcServiceThread(); Parcel parcel; parcel.writeInt32(0); // Parcel Size. mHandler->Marshall(parcel, mOptions); parcel.setDataPosition(0); uint32_t sizeBE = htonl(parcel.dataSize() - sizeof(int)); parcel.writeInt32(sizeBE); mConsumer->PostToNfcDaemon(parcel.data(), parcel.dataSize()); return NS_OK; }
status_t MediaPlayer::setParameter(int key, const Parcel& request) { ALOGV("MediaPlayer::setParameter(%d)", key); status_t status = INVALID_OPERATION; Mutex::Autolock _l(mLock); if (checkStateForKeySet_l(key) != OK) { return status; } switch (key) { case KEY_PARAMETER_AUDIO_ATTRIBUTES: // save the marshalled audio attributes if (mAudioAttributesParcel != NULL) { delete mAudioAttributesParcel; }; mAudioAttributesParcel = new Parcel(); mAudioAttributesParcel->appendFrom(&request, 0, request.dataSize()); status = OK; break; default: ALOGV_IF(mPlayer == NULL, "setParameter: no active player"); break; } if (mPlayer != NULL) { status = mPlayer->setParameter(key, request); } return status; }
static jboolean android_os_BinderProxy_transact(JNIEnv* env, jobject obj, jint code, jobject dataObj, jobject replyObj, jint flags) // throws RemoteException { if (dataObj == NULL) { jniThrowNullPointerException(env, NULL); return JNI_FALSE; } Parcel* data = parcelForJavaObject(env, dataObj); if (data == NULL) { return JNI_FALSE; } Parcel* reply = parcelForJavaObject(env, replyObj); if (reply == NULL && replyObj != NULL) { return JNI_FALSE; } IBinder* target = getBPNativeData(env, obj)->mObject.get(); if (target == NULL) { jniThrowException(env, "java/lang/IllegalStateException", "Binder has been finalized!"); return JNI_FALSE; } ALOGV("Java code calling transact on %p in Java object %p with code %" PRId32 "\n", target, obj, code); bool time_binder_calls; int64_t start_millis; if (kEnableBinderSample) { // Only log the binder call duration for things on the Java-level main thread. // But if we don't time_binder_calls = should_time_binder_calls(); if (time_binder_calls) { start_millis = uptimeMillis(); } } //printf("Transact from Java code to %p sending: ", target); data->print(); status_t err = target->transact(code, *data, reply, flags); //if (reply) printf("Transact from Java code to %p received: ", target); reply->print(); if (kEnableBinderSample) { if (time_binder_calls) { conditionally_log_binder_call(start_millis, target, code); } } if (err == NO_ERROR) { return JNI_TRUE; } else if (err == UNKNOWN_TRANSACTION) { return JNI_FALSE; } signalExceptionForError(env, obj, err, true /*canThrowRemoteException*/, data->dataSize()); return JNI_FALSE; }
status_t BpBinder::pingBinder() { Parcel send; Parcel reply; status_t err = transact(PING_TRANSACTION, send, &reply); if (err != NO_ERROR) return err; if (reply.dataSize() < sizeof(status_t)) return NOT_ENOUGH_DATA; return (status_t)reply.readInt32(); }
_status_t MagPlayerClient::invoke(const Parcel& request, Parcel *reply) { Mutex::Autolock _l(mLock); const bool hasBeenInitialized = (mCurrentState == MAG_PLAYER_RUNNING); if ((mPlayer != NULL) && hasBeenInitialized) { AGILE_LOGV("invoke %d", request.dataSize()); return mPlayer->invoke(request, reply); } AGILE_LOGE("invoke failed: wrong state %X", mCurrentState); return MAG_INVALID_OPERATION; }
status_t MediaPlayer::invoke(const Parcel& request, Parcel *reply) { Mutex::Autolock _l(mLock); if ((mPlayer != NULL) && ( mCurrentState & MEDIA_PLAYER_INITIALIZED )) { LOGV("invoke %d", request.dataSize()); return mPlayer->invoke(request, reply); } LOGE("invoke failed: wrong state %X", mCurrentState); return INVALID_OPERATION; }
bool sendInfo(int domain, int cmd, Parcel& info) { //done in java client Parcel data, reply; data.writeInterfaceToken(IMcuService::getInterfaceDescriptor()); data.writeInt32(domain); data.writeInt32(cmd); data.appendFrom(&info, 0, info.dataSize()); remote()->transact(send_info, data, &reply); return (reply.readInt32() == 1); }
status_t MediaPlayer::invoke(const Parcel& request, Parcel *reply) { Mutex::Autolock _l(mLock); const bool hasBeenInitialized = (mCurrentState != MEDIA_PLAYER_STATE_ERROR) && ((mCurrentState & MEDIA_PLAYER_IDLE) != MEDIA_PLAYER_IDLE); if ((mPlayer != NULL) && hasBeenInitialized) { ALOGV("invoke %d", request.dataSize()); return mPlayer->invoke(request, reply); } ALOGE("invoke failed: wrong state %X", mCurrentState); return INVALID_OPERATION; }
/* * packRILcommandString * Used for packing standard AT command string to RIL command. * * IN *inStr : AT command string with NULL terminate * IN *prefix : prefix of AT response * OUT **outCmd : RAW RIL command out. Caller is responsible to free this resource. * RETUURN : Length of outCmd data. */ size_t packRILCommand(char *inStr, char *prefix, char **outCmd) { /* |Request Enum |Request Token|Number of Strings|Srings.....| * |<--4 bytes-->|<--4 bytes-->|<--- 4 bytes --->|<------ ->| */ size_t length = 0; char *cmdStr[2] = {NULL,NULL}; char *pData = NULL; Parcel p; static int s_token = 0; if ((NULL == inStr)||(NULL == outCmd)) { return 0; } cmdStr[0] = inStr; cmdStr[1] = prefix; // p.writeInt32(length); /* fake write to reserve space */ p.writeInt32(RIL_REQUEST_OEM_HOOK_STRINGS); p.writeInt32(s_token++); packStrings(p,cmdStr,2*sizeof(char *)); /* ONLY support 1 string now */ length = p.dataSize(); #if 0 offset = p.dataPosition(); /* Store data position */ p.setDataPosition(0); /* Move to the buffer pointer to head */ p.writeInt32(length - 4); /* Update data length */ p.setDataPosition(offset); /* Restore data position */ #endif /* 0 */ pData = (char *) malloc(length); if (NULL != pData) { memcpy(pData,p.data(),length); *outCmd = pData; LOGI("packRILCommand: %d bytes\n",length); printRawData((const void *) pData, length); } else { return 0; } return length; }
static jint android_os_Parcel_dataSize(JNIEnv* env, jclass clazz, jlong nativePtr) { Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr); return parcel ? parcel->dataSize() : 0; }