blob: 99882cc002d7be5f725980ece7602cf3b9bfc1ae [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/* //device/libs/android_runtime/android_util_XmlBlock.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
Elliott Hughes8451b252011-04-07 19:17:57 -07005** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08008**
Elliott Hughes8451b252011-04-07 19:17:57 -07009** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080010**
Elliott Hughes8451b252011-04-07 19:17:57 -070011** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080015** limitations under the License.
16*/
17
18#define LOG_TAG "XmlBlock"
19
20#include "jni.h"
Elliott Hughes8451b252011-04-07 19:17:57 -070021#include "JNIHelp.h"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080022#include <core_jni_helpers.h>
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080023#include <androidfw/AssetManager.h>
24#include <androidfw/ResourceTypes.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025#include <utils/Log.h>
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080026#include <utils/misc.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
28#include <stdio.h>
29
30namespace android {
31
32// ----------------------------------------------------------------------------
33
Ashok Bhat896043d2014-01-17 16:02:38 +000034static jlong android_content_XmlBlock_nativeCreate(JNIEnv* env, jobject clazz,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 jbyteArray bArray,
36 jint off, jint len)
37{
38 if (bArray == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -070039 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 return 0;
41 }
42
43 jsize bLen = env->GetArrayLength(bArray);
44 if (off < 0 || off >= bLen || len < 0 || len > bLen || (off+len) > bLen) {
Elliott Hughes8451b252011-04-07 19:17:57 -070045 jniThrowException(env, "java/lang/IndexOutOfBoundsException", NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 return 0;
47 }
48
49 jbyte* b = env->GetByteArrayElements(bArray, NULL);
Adam Lesinskide898ff2014-01-29 18:20:45 -080050 ResXMLTree* osb = new ResXMLTree();
51 osb->setTo(b+off, len, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 env->ReleaseByteArrayElements(bArray, b, 0);
53
Adam Lesinskide898ff2014-01-29 18:20:45 -080054 if (osb->getError() != NO_ERROR) {
Elliott Hughes8451b252011-04-07 19:17:57 -070055 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 return 0;
57 }
58
Ashok Bhat896043d2014-01-17 16:02:38 +000059 return reinterpret_cast<jlong>(osb);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060}
61
Ashok Bhat896043d2014-01-17 16:02:38 +000062static jlong android_content_XmlBlock_nativeGetStringBlock(JNIEnv* env, jobject clazz,
63 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064{
Ashok Bhat896043d2014-01-17 16:02:38 +000065 ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 if (osb == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -070067 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 return 0;
69 }
70
Ashok Bhat896043d2014-01-17 16:02:38 +000071 return reinterpret_cast<jlong>(&osb->getStrings());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072}
73
Ashok Bhat896043d2014-01-17 16:02:38 +000074static jlong android_content_XmlBlock_nativeCreateParseState(JNIEnv* env, jobject clazz,
75 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076{
Ashok Bhat896043d2014-01-17 16:02:38 +000077 ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 if (osb == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -070079 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 return 0;
81 }
82
83 ResXMLParser* st = new ResXMLParser(*osb);
84 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -070085 jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 return 0;
87 }
88
89 st->restart();
90
Ashok Bhat896043d2014-01-17 16:02:38 +000091 return reinterpret_cast<jlong>(st);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092}
93
94static jint android_content_XmlBlock_nativeNext(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +000095 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096{
Ashok Bhat896043d2014-01-17 16:02:38 +000097 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 if (st == NULL) {
99 return ResXMLParser::END_DOCUMENT;
100 }
101
102 do {
Ashok Bhat896043d2014-01-17 16:02:38 +0000103 ResXMLParser::event_code_t code = st->next();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 switch (code) {
105 case ResXMLParser::START_TAG:
106 return 2;
107 case ResXMLParser::END_TAG:
108 return 3;
109 case ResXMLParser::TEXT:
110 return 4;
111 case ResXMLParser::START_DOCUMENT:
112 return 0;
113 case ResXMLParser::END_DOCUMENT:
114 return 1;
115 case ResXMLParser::BAD_DOCUMENT:
116 goto bad;
Adam Lesinskide898ff2014-01-29 18:20:45 -0800117 default:
118 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 }
120 } while (true);
Elliott Hughes8451b252011-04-07 19:17:57 -0700121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122bad:
Elliott Hughes8451b252011-04-07 19:17:57 -0700123 jniThrowException(env, "org/xmlpull/v1/XmlPullParserException",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 "Corrupt XML binary file");
125 return ResXMLParser::BAD_DOCUMENT;
126}
127
128static jint android_content_XmlBlock_nativeGetNamespace(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000129 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130{
Ashok Bhat896043d2014-01-17 16:02:38 +0000131 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 if (st == NULL) {
133 return -1;
134 }
Elliott Hughes8451b252011-04-07 19:17:57 -0700135
Ashok Bhat896043d2014-01-17 16:02:38 +0000136 return static_cast<jint>(st->getElementNamespaceID());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137}
138
139static jint android_content_XmlBlock_nativeGetName(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000140 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141{
Ashok Bhat896043d2014-01-17 16:02:38 +0000142 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 if (st == NULL) {
144 return -1;
145 }
146
Ashok Bhat896043d2014-01-17 16:02:38 +0000147 return static_cast<jint>(st->getElementNameID());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148}
149
150static jint android_content_XmlBlock_nativeGetText(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000151 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152{
Ashok Bhat896043d2014-01-17 16:02:38 +0000153 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 if (st == NULL) {
155 return -1;
156 }
157
Ashok Bhat896043d2014-01-17 16:02:38 +0000158 return static_cast<jint>(st->getTextID());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159}
160
161static jint android_content_XmlBlock_nativeGetLineNumber(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000162 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163{
Ashok Bhat896043d2014-01-17 16:02:38 +0000164 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700166 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 return 0;
168 }
169
Ashok Bhat896043d2014-01-17 16:02:38 +0000170 return static_cast<jint>(st->getLineNumber());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171}
172
173static jint android_content_XmlBlock_nativeGetAttributeCount(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000174 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175{
Ashok Bhat896043d2014-01-17 16:02:38 +0000176 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700178 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 return 0;
180 }
181
Ashok Bhat896043d2014-01-17 16:02:38 +0000182 return static_cast<jint>(st->getAttributeCount());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183}
184
185static jint android_content_XmlBlock_nativeGetAttributeNamespace(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000186 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187{
Ashok Bhat896043d2014-01-17 16:02:38 +0000188 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700190 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 return 0;
192 }
Elliott Hughes8451b252011-04-07 19:17:57 -0700193
Ashok Bhat896043d2014-01-17 16:02:38 +0000194 return static_cast<jint>(st->getAttributeNamespaceID(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195}
196
197static jint android_content_XmlBlock_nativeGetAttributeName(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000198 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199{
Ashok Bhat896043d2014-01-17 16:02:38 +0000200 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800201 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700202 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 return 0;
204 }
205
Ashok Bhat896043d2014-01-17 16:02:38 +0000206 return static_cast<jint>(st->getAttributeNameID(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207}
208
209static jint android_content_XmlBlock_nativeGetAttributeResource(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000210 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211{
Ashok Bhat896043d2014-01-17 16:02:38 +0000212 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700214 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 return 0;
216 }
217
Ashok Bhat896043d2014-01-17 16:02:38 +0000218 return static_cast<jint>(st->getAttributeNameResID(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219}
220
221static jint android_content_XmlBlock_nativeGetAttributeDataType(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000222 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223{
Ashok Bhat896043d2014-01-17 16:02:38 +0000224 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700226 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 return 0;
228 }
229
Ashok Bhat896043d2014-01-17 16:02:38 +0000230 return static_cast<jint>(st->getAttributeDataType(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231}
232
233static jint android_content_XmlBlock_nativeGetAttributeData(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000234 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235{
Ashok Bhat896043d2014-01-17 16:02:38 +0000236 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700238 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 return 0;
240 }
241
Ashok Bhat896043d2014-01-17 16:02:38 +0000242 return static_cast<jint>(st->getAttributeData(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243}
244
245static jint android_content_XmlBlock_nativeGetAttributeStringValue(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000246 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247{
Ashok Bhat896043d2014-01-17 16:02:38 +0000248 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700250 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 return 0;
252 }
253
Ashok Bhat896043d2014-01-17 16:02:38 +0000254 return static_cast<jint>(st->getAttributeValueStringID(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255}
256
257static jint android_content_XmlBlock_nativeGetAttributeIndex(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000258 jlong token,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 jstring ns, jstring name)
260{
Ashok Bhat896043d2014-01-17 16:02:38 +0000261 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 if (st == NULL || name == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700263 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 return 0;
265 }
266
267 const char16_t* ns16 = NULL;
268 jsize nsLen = 0;
269 if (ns) {
Dan Albert66987492014-11-20 11:41:21 -0800270 ns16 = reinterpret_cast<const char16_t*>(env->GetStringChars(ns, NULL));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 nsLen = env->GetStringLength(ns);
272 }
Elliott Hughes8451b252011-04-07 19:17:57 -0700273
Dan Albert66987492014-11-20 11:41:21 -0800274 const char16_t* name16 = reinterpret_cast<const char16_t*>(
275 env->GetStringChars(name, NULL));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 jsize nameLen = env->GetStringLength(name);
277
Ashok Bhat896043d2014-01-17 16:02:38 +0000278 jint idx = static_cast<jint>(st->indexOfAttribute(ns16, nsLen, name16, nameLen));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279
280 if (ns) {
Dan Albert66987492014-11-20 11:41:21 -0800281 env->ReleaseStringChars(ns, reinterpret_cast<const jchar*>(ns16));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 }
Dan Albert66987492014-11-20 11:41:21 -0800283 env->ReleaseStringChars(name, reinterpret_cast<const jchar*>(name16));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284
285 return idx;
286}
287
288static jint android_content_XmlBlock_nativeGetIdAttribute(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000289 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290{
Ashok Bhat896043d2014-01-17 16:02:38 +0000291 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700293 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 return 0;
295 }
296
297 ssize_t idx = st->indexOfID();
Ashok Bhat896043d2014-01-17 16:02:38 +0000298 return idx >= 0 ? static_cast<jint>(st->getAttributeValueStringID(idx)) : -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299}
300
301static jint android_content_XmlBlock_nativeGetClassAttribute(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000302 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303{
Ashok Bhat896043d2014-01-17 16:02:38 +0000304 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700306 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 return 0;
308 }
Elliott Hughes8451b252011-04-07 19:17:57 -0700309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 ssize_t idx = st->indexOfClass();
Ashok Bhat896043d2014-01-17 16:02:38 +0000311 return idx >= 0 ? static_cast<jint>(st->getAttributeValueStringID(idx)) : -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800312}
313
314static jint android_content_XmlBlock_nativeGetStyleAttribute(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000315 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316{
Ashok Bhat896043d2014-01-17 16:02:38 +0000317 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700319 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 return 0;
321 }
322
323 ssize_t idx = st->indexOfStyle();
324 if (idx < 0) {
325 return 0;
326 }
327
328 Res_value value;
329 if (st->getAttributeValue(idx, &value) < 0) {
330 return 0;
331 }
332
Elliott Hughes8451b252011-04-07 19:17:57 -0700333 return value.dataType == value.TYPE_REFERENCE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800334 || value.dataType == value.TYPE_ATTRIBUTE
335 ? value.data : 0;
336}
337
338static void android_content_XmlBlock_nativeDestroyParseState(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000339 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340{
Ashok Bhat896043d2014-01-17 16:02:38 +0000341 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700343 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344 return;
345 }
346
347 delete st;
348}
349
350static void android_content_XmlBlock_nativeDestroy(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000351 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352{
Ashok Bhat896043d2014-01-17 16:02:38 +0000353 ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 if (osb == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700355 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 return;
357 }
358
359 delete osb;
360}
361
362// ----------------------------------------------------------------------------
363
364/*
365 * JNI registration.
366 */
Daniel Micay76f6a862015-09-19 17:31:01 -0400367static const JNINativeMethod gXmlBlockMethods[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 /* name, signature, funcPtr */
Ashok Bhat896043d2014-01-17 16:02:38 +0000369 { "nativeCreate", "([BII)J",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 (void*) android_content_XmlBlock_nativeCreate },
Ashok Bhat896043d2014-01-17 16:02:38 +0000371 { "nativeGetStringBlock", "(J)J",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 (void*) android_content_XmlBlock_nativeGetStringBlock },
Ashok Bhat896043d2014-01-17 16:02:38 +0000373 { "nativeCreateParseState", "(J)J",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 (void*) android_content_XmlBlock_nativeCreateParseState },
Ashok Bhat896043d2014-01-17 16:02:38 +0000375 { "nativeDestroyParseState", "(J)V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 (void*) android_content_XmlBlock_nativeDestroyParseState },
Ashok Bhat896043d2014-01-17 16:02:38 +0000377 { "nativeDestroy", "(J)V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 (void*) android_content_XmlBlock_nativeDestroy },
John Reck32995222016-10-07 11:02:20 -0700379
380 // ------------------- @FastNative ----------------------
381
382 { "nativeNext", "(J)I",
383 (void*) android_content_XmlBlock_nativeNext },
384 { "nativeGetNamespace", "(J)I",
385 (void*) android_content_XmlBlock_nativeGetNamespace },
386 { "nativeGetName", "(J)I",
387 (void*) android_content_XmlBlock_nativeGetName },
388 { "nativeGetText", "(J)I",
389 (void*) android_content_XmlBlock_nativeGetText },
390 { "nativeGetLineNumber", "(J)I",
391 (void*) android_content_XmlBlock_nativeGetLineNumber },
392 { "nativeGetAttributeCount", "(J)I",
393 (void*) android_content_XmlBlock_nativeGetAttributeCount },
394 { "nativeGetAttributeNamespace","(JI)I",
395 (void*) android_content_XmlBlock_nativeGetAttributeNamespace },
396 { "nativeGetAttributeName", "(JI)I",
397 (void*) android_content_XmlBlock_nativeGetAttributeName },
398 { "nativeGetAttributeResource", "(JI)I",
399 (void*) android_content_XmlBlock_nativeGetAttributeResource },
400 { "nativeGetAttributeDataType", "(JI)I",
401 (void*) android_content_XmlBlock_nativeGetAttributeDataType },
402 { "nativeGetAttributeData", "(JI)I",
403 (void*) android_content_XmlBlock_nativeGetAttributeData },
404 { "nativeGetAttributeStringValue", "(JI)I",
405 (void*) android_content_XmlBlock_nativeGetAttributeStringValue },
406 { "nativeGetAttributeIndex", "(JLjava/lang/String;Ljava/lang/String;)I",
407 (void*) android_content_XmlBlock_nativeGetAttributeIndex },
408 { "nativeGetIdAttribute", "(J)I",
409 (void*) android_content_XmlBlock_nativeGetIdAttribute },
410 { "nativeGetClassAttribute", "(J)I",
411 (void*) android_content_XmlBlock_nativeGetClassAttribute },
412 { "nativeGetStyleAttribute", "(J)I",
413 (void*) android_content_XmlBlock_nativeGetStyleAttribute },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414};
415
416int register_android_content_XmlBlock(JNIEnv* env)
417{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800418 return RegisterMethodsOrDie(env,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 "android/content/res/XmlBlock", gXmlBlockMethods, NELEM(gXmlBlockMethods));
420}
421
422}; // namespace android