Example #1
0
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);
    }
}
static jboolean
android_media_MediaPlayer_getMetadata(JNIEnv *env, jobject thiz, jboolean update_only,
                                      jboolean apply_filter, jobject reply)
{
    sp<MediaPlayer> media_player = getMediaPlayer(env, thiz);
    if (media_player == NULL ) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return JNI_FALSE;
    }

    Parcel *metadata = parcelForJavaObject(env, reply);

    if (metadata == NULL ) {
        jniThrowException(env, "java/lang/RuntimeException", "Reply parcel is null");
        return JNI_FALSE;
    }

    metadata->freeData();
    // On return metadata is positioned at the beginning of the
    // metadata. Note however that the parcel actually starts with the
    // return code so you should not rewind the parcel using
    // setDataPosition(0).
    if (media_player->getMetadata(update_only, apply_filter, metadata) == OK) {
        return JNI_TRUE;
    } else {
        return JNI_FALSE;
    }
}
static void android_os_Parcel_freeBuffer(JNIEnv* env, jclass clazz, jlong nativePtr)
{
    Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
    if (parcel != NULL) {
        parcel->freeData();
    }
}
TEST_F(PointerCoordsTest, Parcel) {
    Parcel parcel;

    PointerCoords inCoords;
    inCoords.clear();
    PointerCoords outCoords;

    // Round trip with empty coords.
    inCoords.writeToParcel(&parcel);
    parcel.setDataPosition(0);
    outCoords.readFromParcel(&parcel);

    ASSERT_EQ(0ULL, outCoords.bits);

    // Round trip with some values.
    parcel.freeData();
    inCoords.setAxisValue(2, 5);
    inCoords.setAxisValue(5, 8);

    inCoords.writeToParcel(&parcel);
    parcel.setDataPosition(0);
    outCoords.readFromParcel(&parcel);

    ASSERT_EQ(outCoords.bits, inCoords.bits);
    ASSERT_EQ(outCoords.values[0], inCoords.values[0]);
    ASSERT_EQ(outCoords.values[1], inCoords.values[1]);
}