bool MtpProperty::read(MtpDataPacket& packet) { uint8_t temp8; if (!packet.getUInt16(mCode)) return false; bool deviceProp = isDeviceProperty(); if (!packet.getUInt16(mType)) return false; if (!packet.getUInt8(temp8)) return false; mWriteable = (temp8 == 1); switch (mType) { case MTP_TYPE_AINT8: case MTP_TYPE_AUINT8: case MTP_TYPE_AINT16: case MTP_TYPE_AUINT16: case MTP_TYPE_AINT32: case MTP_TYPE_AUINT32: case MTP_TYPE_AINT64: case MTP_TYPE_AUINT64: case MTP_TYPE_AINT128: case MTP_TYPE_AUINT128: mDefaultArrayValues = readArrayValues(packet, mDefaultArrayLength); if (!mDefaultArrayValues) return false; if (deviceProp) { mCurrentArrayValues = readArrayValues(packet, mCurrentArrayLength); if (!mCurrentArrayValues) return false; } break; default: if (!readValue(packet, mDefaultValue)) return false; if (deviceProp) { if (!readValue(packet, mCurrentValue)) return false; } } if (!deviceProp) { if (!packet.getUInt32(mGroupCode)) return false; } if (!packet.getUInt8(mFormFlag)) return false; if (mFormFlag == kFormRange) { if (!readValue(packet, mMinimumValue)) return false; if (!readValue(packet, mMaximumValue)) return false; if (!readValue(packet, mStepSize)) return false; } else if (mFormFlag == kFormEnum) { if (!packet.getUInt16(mEnumLength)) return false; mEnumValues = new MtpPropertyValue[mEnumLength]; for (int i = 0; i < mEnumLength; i++) { if (!readValue(packet, mEnumValues[i])) return false; } } return true; }
MtpResponseCode MyMtpDatabase::setObjectPropertyValue(MtpObjectHandle handle, MtpObjectProperty property, MtpDataPacket& packet) { int type; if (!getObjectPropertyInfo(property, type)) return MTP_RESPONSE_OBJECT_PROP_NOT_SUPPORTED; JNIEnv* env = AndroidRuntime::getJNIEnv(); jlong longValue = 0; jstring stringValue = NULL; switch (type) { case MTP_TYPE_INT8: longValue = packet.getInt8(); break; case MTP_TYPE_UINT8: longValue = packet.getUInt8(); break; case MTP_TYPE_INT16: longValue = packet.getInt16(); break; case MTP_TYPE_UINT16: longValue = packet.getUInt16(); break; case MTP_TYPE_INT32: longValue = packet.getInt32(); break; case MTP_TYPE_UINT32: longValue = packet.getUInt32(); break; case MTP_TYPE_INT64: longValue = packet.getInt64(); break; case MTP_TYPE_UINT64: longValue = packet.getUInt64(); break; case MTP_TYPE_STR: { MtpStringBuffer buffer; packet.getString(buffer); stringValue = env->NewStringUTF((const char *)buffer); break; } default: ALOGE("unsupported type in setObjectPropertyValue\n"); return MTP_RESPONSE_INVALID_OBJECT_PROP_FORMAT; } jint result = env->CallIntMethod(mDatabase, method_setObjectProperty, (jint)handle, (jint)property, longValue, stringValue); if (stringValue) env->DeleteLocalRef(stringValue); checkAndClearExceptionFromCallback(env, __FUNCTION__); return result; }
bool MtpProperty::readValue(MtpDataPacket& packet, MtpPropertyValue& value) { MtpStringBuffer stringBuffer; switch (mType) { case MTP_TYPE_INT8: case MTP_TYPE_AINT8: if (!packet.getInt8(value.u.i8)) return false; break; case MTP_TYPE_UINT8: case MTP_TYPE_AUINT8: if (!packet.getUInt8(value.u.u8)) return false; break; case MTP_TYPE_INT16: case MTP_TYPE_AINT16: if (!packet.getInt16(value.u.i16)) return false; break; case MTP_TYPE_UINT16: case MTP_TYPE_AUINT16: if (!packet.getUInt16(value.u.u16)) return false; break; case MTP_TYPE_INT32: case MTP_TYPE_AINT32: if (!packet.getInt32(value.u.i32)) return false; break; case MTP_TYPE_UINT32: case MTP_TYPE_AUINT32: if (!packet.getUInt32(value.u.u32)) return false; break; case MTP_TYPE_INT64: case MTP_TYPE_AINT64: if (!packet.getInt64(value.u.i64)) return false; break; case MTP_TYPE_UINT64: case MTP_TYPE_AUINT64: if (!packet.getUInt64(value.u.u64)) return false; break; case MTP_TYPE_INT128: case MTP_TYPE_AINT128: if (!packet.getInt128(value.u.i128)) return false; break; case MTP_TYPE_UINT128: case MTP_TYPE_AUINT128: if (!packet.getUInt128(value.u.u128)) return false; break; case MTP_TYPE_STR: if (!packet.getString(stringBuffer)) return false; value.str = strdup(stringBuffer); break; default: ALOGE("unknown type %04X in MtpProperty::readValue", mType); return false; } return true; }
void MtpProperty::readValue(MtpDataPacket& packet, MtpPropertyValue& value) { MtpStringBuffer stringBuffer; switch (mType) { case MTP_TYPE_INT8: case MTP_TYPE_AINT8: value.u.i8 = packet.getInt8(); break; case MTP_TYPE_UINT8: case MTP_TYPE_AUINT8: value.u.u8 = packet.getUInt8(); break; case MTP_TYPE_INT16: case MTP_TYPE_AINT16: value.u.i16 = packet.getInt16(); break; case MTP_TYPE_UINT16: case MTP_TYPE_AUINT16: value.u.u16 = packet.getUInt16(); break; case MTP_TYPE_INT32: case MTP_TYPE_AINT32: value.u.i32 = packet.getInt32(); break; case MTP_TYPE_UINT32: case MTP_TYPE_AUINT32: value.u.u32 = packet.getUInt32(); break; case MTP_TYPE_INT64: case MTP_TYPE_AINT64: value.u.i64 = packet.getInt64(); break; case MTP_TYPE_UINT64: case MTP_TYPE_AUINT64: value.u.u64 = packet.getUInt64(); break; case MTP_TYPE_INT128: case MTP_TYPE_AINT128: packet.getInt128(value.u.i128); break; case MTP_TYPE_UINT128: case MTP_TYPE_AUINT128: packet.getUInt128(value.u.u128); break; case MTP_TYPE_STR: packet.getString(stringBuffer); value.str = strdup(stringBuffer); break; default: LOG(ERROR) << "unknown type " << std::hex << mType << std::dec << " in MtpProperty::readValue"; } }
void MtpProperty::read(MtpDataPacket& packet) { mCode = packet.getUInt16(); bool deviceProp = isDeviceProperty(); mType = packet.getUInt16(); mWriteable = (packet.getUInt8() == 1); switch (mType) { case MTP_TYPE_AINT8: case MTP_TYPE_AUINT8: case MTP_TYPE_AINT16: case MTP_TYPE_AUINT16: case MTP_TYPE_AINT32: case MTP_TYPE_AUINT32: case MTP_TYPE_AINT64: case MTP_TYPE_AUINT64: case MTP_TYPE_AINT128: case MTP_TYPE_AUINT128: mDefaultArrayValues = readArrayValues(packet, mDefaultArrayLength); if (deviceProp) mCurrentArrayValues = readArrayValues(packet, mCurrentArrayLength); break; default: readValue(packet, mDefaultValue); if (deviceProp) readValue(packet, mCurrentValue); } if (!deviceProp) mGroupCode = packet.getUInt32(); mFormFlag = packet.getUInt8(); if (mFormFlag == kFormRange) { readValue(packet, mMinimumValue); readValue(packet, mMaximumValue); readValue(packet, mStepSize); } else if (mFormFlag == kFormEnum) { mEnumLength = packet.getUInt16(); mEnumValues = new MtpPropertyValue[mEnumLength]; for (int i = 0; i < mEnumLength; i++) readValue(packet, mEnumValues[i]); } }