Added missing implementation for NdefRecord.
Implemented constructor using a byte array to parse. Added missing exception in method declaration, leading to update api/current.xml Change-Id: I2660484aef1225e90c2f32a572041a2c3aecf288
This commit is contained in:
committed by
Nick Pelly
parent
453c6d449b
commit
dd7341f775
@ -99913,6 +99913,8 @@
|
|||||||
>
|
>
|
||||||
<parameter name="data" type="byte[]">
|
<parameter name="data" type="byte[]">
|
||||||
</parameter>
|
</parameter>
|
||||||
|
<exception name="FormatException" type="android.nfc.FormatException">
|
||||||
|
</exception>
|
||||||
</constructor>
|
</constructor>
|
||||||
<method name="describeContents"
|
<method name="describeContents"
|
||||||
return="int"
|
return="int"
|
||||||
|
@ -200,8 +200,17 @@ public class NdefRecord implements Parcelable {
|
|||||||
*
|
*
|
||||||
* @throws FormatException if the data is not a valid NDEF record
|
* @throws FormatException if the data is not a valid NDEF record
|
||||||
*/
|
*/
|
||||||
public NdefRecord(byte[] data) {
|
public NdefRecord(byte[] data) throws FormatException {
|
||||||
throw new UnsupportedOperationException();
|
/* Prevent compiler to complain about unassigned final fields */
|
||||||
|
mFlags = 0;
|
||||||
|
mTnf = 0;
|
||||||
|
mType = null;
|
||||||
|
mId = null;
|
||||||
|
mPayload = null;
|
||||||
|
/* Perform actual parsing */
|
||||||
|
if (parseNdefRecord(data) == -1) {
|
||||||
|
throw new FormatException("Error while parsing NDEF record");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -280,5 +289,6 @@ public class NdefRecord implements Parcelable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private native int parseNdefRecord(byte[] data);
|
||||||
private native byte[] generate(short flags, short tnf, byte[] type, byte[] id, byte[] data);
|
private native byte[] generate(short flags, short tnf, byte[] type, byte[] id, byte[] data);
|
||||||
}
|
}
|
@ -80,8 +80,92 @@ end:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static jint android_nfc_NdefRecord_parseNdefRecord(JNIEnv *e, jobject o,
|
||||||
|
jbyteArray array)
|
||||||
|
{
|
||||||
|
uint16_t status;
|
||||||
|
jbyte *raw_record;
|
||||||
|
jsize raw_record_size;
|
||||||
|
jint ret = -1;
|
||||||
|
phFriNfc_NdefRecord_t record;
|
||||||
|
|
||||||
|
jfieldID mType, mId, mPayload, mTnf;
|
||||||
|
jbyteArray type = NULL;
|
||||||
|
jbyteArray id = NULL;
|
||||||
|
jbyteArray payload = NULL;
|
||||||
|
|
||||||
|
jclass record_cls = e->GetObjectClass(o);
|
||||||
|
|
||||||
|
raw_record_size = e->GetArrayLength(array);
|
||||||
|
raw_record = e->GetByteArrayElements(array, NULL);
|
||||||
|
if (raw_record == NULL) {
|
||||||
|
goto clean_and_return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGD("phFriNfc_NdefRecord_Parse()");
|
||||||
|
status = phFriNfc_NdefRecord_Parse(&record, (uint8_t *)raw_record);
|
||||||
|
if (status) {
|
||||||
|
LOGE("phFriNfc_NdefRecord_Parse() returned 0x%04x", status);
|
||||||
|
goto clean_and_return;
|
||||||
|
}
|
||||||
|
LOGD("phFriNfc_NdefRecord_Parse() returned 0x%04x", status);
|
||||||
|
|
||||||
|
/* Set TNF field */
|
||||||
|
mTnf = e->GetFieldID(record_cls, "mTnf", "S");
|
||||||
|
e->SetShortField(o, mTnf, record.Tnf);
|
||||||
|
|
||||||
|
/* Set type field */
|
||||||
|
mType = e->GetFieldID(record_cls, "mType", "[B");
|
||||||
|
type = e->NewByteArray(record.TypeLength);
|
||||||
|
if (type == NULL) {
|
||||||
|
goto clean_and_return;
|
||||||
|
}
|
||||||
|
e->SetByteArrayRegion(type, 0, record.TypeLength,
|
||||||
|
(jbyte *)record.Type);
|
||||||
|
e->SetObjectField(o, mType, type);
|
||||||
|
|
||||||
|
/* Set id field */
|
||||||
|
mId = e->GetFieldID(record_cls, "mId", "[B");
|
||||||
|
id = e->NewByteArray(record.IdLength);
|
||||||
|
if (id == NULL) {
|
||||||
|
goto clean_and_return;
|
||||||
|
}
|
||||||
|
e->SetByteArrayRegion(id, 0, record.IdLength,
|
||||||
|
(jbyte *)record.Id);
|
||||||
|
e->SetObjectField(o, mId, id);
|
||||||
|
|
||||||
|
/* Set payload field */
|
||||||
|
mPayload = e->GetFieldID(record_cls, "mPayload", "[B");
|
||||||
|
payload = e->NewByteArray(record.PayloadLength);
|
||||||
|
if (payload == NULL) {
|
||||||
|
goto clean_and_return;
|
||||||
|
}
|
||||||
|
e->SetByteArrayRegion(payload, 0, record.PayloadLength,
|
||||||
|
(jbyte *)record.PayloadData);
|
||||||
|
e->SetObjectField(o, mPayload, payload);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
clean_and_return:
|
||||||
|
if (type != NULL) {
|
||||||
|
e->DeleteLocalRef(type);
|
||||||
|
}
|
||||||
|
if (id != NULL) {
|
||||||
|
e->DeleteLocalRef(id);
|
||||||
|
}
|
||||||
|
if (payload != NULL) {
|
||||||
|
e->DeleteLocalRef(payload);
|
||||||
|
}
|
||||||
|
if (raw_record != NULL) {
|
||||||
|
e->ReleaseByteArrayElements(array, raw_record, JNI_ABORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static JNINativeMethod gMethods[] = {
|
static JNINativeMethod gMethods[] = {
|
||||||
{"generate", "(SS[B[B[B)[B", (void *)android_nfc_NdefRecord_generate},
|
{"generate", "(SS[B[B[B)[B", (void *)android_nfc_NdefRecord_generate},
|
||||||
|
{"parseNdefRecord", "([B)I", (void *)android_nfc_NdefRecord_parseNdefRecord},
|
||||||
};
|
};
|
||||||
|
|
||||||
int register_android_nfc_NdefRecord(JNIEnv *e)
|
int register_android_nfc_NdefRecord(JNIEnv *e)
|
||||||
|
Reference in New Issue
Block a user