blob: 891330082f3ea5886ca6a567cf7aa6cf5be570f2 [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"
Steven Moreland2279b252017-07-19 09:50:45 -070021#include <nativehelper/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,
Aurimas Liutikas949b05d2019-01-30 17:20:41 -080075 jlong token, jint res_id)
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
Greg Kaiser7bdeca42019-02-04 06:26:03 -080089 st->setSourceResourceId(res_id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 st->restart();
91
Ashok Bhat896043d2014-01-17 16:02:38 +000092 return reinterpret_cast<jlong>(st);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093}
94
95static jint android_content_XmlBlock_nativeNext(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +000096 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097{
Ashok Bhat896043d2014-01-17 16:02:38 +000098 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 if (st == NULL) {
100 return ResXMLParser::END_DOCUMENT;
101 }
102
103 do {
Ashok Bhat896043d2014-01-17 16:02:38 +0000104 ResXMLParser::event_code_t code = st->next();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 switch (code) {
106 case ResXMLParser::START_TAG:
107 return 2;
108 case ResXMLParser::END_TAG:
109 return 3;
110 case ResXMLParser::TEXT:
111 return 4;
112 case ResXMLParser::START_DOCUMENT:
113 return 0;
114 case ResXMLParser::END_DOCUMENT:
115 return 1;
116 case ResXMLParser::BAD_DOCUMENT:
117 goto bad;
Adam Lesinskide898ff2014-01-29 18:20:45 -0800118 default:
119 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 }
121 } while (true);
Elliott Hughes8451b252011-04-07 19:17:57 -0700122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123bad:
Elliott Hughes8451b252011-04-07 19:17:57 -0700124 jniThrowException(env, "org/xmlpull/v1/XmlPullParserException",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 "Corrupt XML binary file");
126 return ResXMLParser::BAD_DOCUMENT;
127}
128
129static jint android_content_XmlBlock_nativeGetNamespace(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000130 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131{
Ashok Bhat896043d2014-01-17 16:02:38 +0000132 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 if (st == NULL) {
134 return -1;
135 }
Elliott Hughes8451b252011-04-07 19:17:57 -0700136
Ashok Bhat896043d2014-01-17 16:02:38 +0000137 return static_cast<jint>(st->getElementNamespaceID());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138}
139
140static jint android_content_XmlBlock_nativeGetName(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000141 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142{
Ashok Bhat896043d2014-01-17 16:02:38 +0000143 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 if (st == NULL) {
145 return -1;
146 }
147
Ashok Bhat896043d2014-01-17 16:02:38 +0000148 return static_cast<jint>(st->getElementNameID());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149}
150
151static jint android_content_XmlBlock_nativeGetText(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000152 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153{
Ashok Bhat896043d2014-01-17 16:02:38 +0000154 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 if (st == NULL) {
156 return -1;
157 }
158
Ashok Bhat896043d2014-01-17 16:02:38 +0000159 return static_cast<jint>(st->getTextID());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160}
161
162static jint android_content_XmlBlock_nativeGetLineNumber(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000163 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164{
Ashok Bhat896043d2014-01-17 16:02:38 +0000165 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700167 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 return 0;
169 }
170
Ashok Bhat896043d2014-01-17 16:02:38 +0000171 return static_cast<jint>(st->getLineNumber());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172}
173
174static jint android_content_XmlBlock_nativeGetAttributeCount(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000175 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176{
Ashok Bhat896043d2014-01-17 16:02:38 +0000177 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700179 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 return 0;
181 }
182
Ashok Bhat896043d2014-01-17 16:02:38 +0000183 return static_cast<jint>(st->getAttributeCount());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184}
185
186static jint android_content_XmlBlock_nativeGetAttributeNamespace(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000187 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188{
Ashok Bhat896043d2014-01-17 16:02:38 +0000189 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700191 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 return 0;
193 }
Elliott Hughes8451b252011-04-07 19:17:57 -0700194
Ashok Bhat896043d2014-01-17 16:02:38 +0000195 return static_cast<jint>(st->getAttributeNamespaceID(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196}
197
198static jint android_content_XmlBlock_nativeGetAttributeName(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000199 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200{
Ashok Bhat896043d2014-01-17 16:02:38 +0000201 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700203 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 return 0;
205 }
206
Ashok Bhat896043d2014-01-17 16:02:38 +0000207 return static_cast<jint>(st->getAttributeNameID(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208}
209
210static jint android_content_XmlBlock_nativeGetAttributeResource(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000211 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212{
Ashok Bhat896043d2014-01-17 16:02:38 +0000213 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700215 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 return 0;
217 }
218
Ashok Bhat896043d2014-01-17 16:02:38 +0000219 return static_cast<jint>(st->getAttributeNameResID(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220}
221
222static jint android_content_XmlBlock_nativeGetAttributeDataType(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000223 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224{
Ashok Bhat896043d2014-01-17 16:02:38 +0000225 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700227 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 return 0;
229 }
230
Ashok Bhat896043d2014-01-17 16:02:38 +0000231 return static_cast<jint>(st->getAttributeDataType(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232}
233
234static jint android_content_XmlBlock_nativeGetAttributeData(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000235 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236{
Ashok Bhat896043d2014-01-17 16:02:38 +0000237 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700239 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 return 0;
241 }
242
Ashok Bhat896043d2014-01-17 16:02:38 +0000243 return static_cast<jint>(st->getAttributeData(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244}
245
246static jint android_content_XmlBlock_nativeGetAttributeStringValue(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000247 jlong token, jint idx)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248{
Ashok Bhat896043d2014-01-17 16:02:38 +0000249 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700251 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 return 0;
253 }
254
Ashok Bhat896043d2014-01-17 16:02:38 +0000255 return static_cast<jint>(st->getAttributeValueStringID(idx));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256}
257
258static jint android_content_XmlBlock_nativeGetAttributeIndex(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000259 jlong token,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 jstring ns, jstring name)
261{
Ashok Bhat896043d2014-01-17 16:02:38 +0000262 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 if (st == NULL || name == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700264 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 return 0;
266 }
267
268 const char16_t* ns16 = NULL;
269 jsize nsLen = 0;
270 if (ns) {
Dan Albert66987492014-11-20 11:41:21 -0800271 ns16 = reinterpret_cast<const char16_t*>(env->GetStringChars(ns, NULL));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 nsLen = env->GetStringLength(ns);
273 }
Elliott Hughes8451b252011-04-07 19:17:57 -0700274
Dan Albert66987492014-11-20 11:41:21 -0800275 const char16_t* name16 = reinterpret_cast<const char16_t*>(
276 env->GetStringChars(name, NULL));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 jsize nameLen = env->GetStringLength(name);
278
Ashok Bhat896043d2014-01-17 16:02:38 +0000279 jint idx = static_cast<jint>(st->indexOfAttribute(ns16, nsLen, name16, nameLen));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280
281 if (ns) {
Dan Albert66987492014-11-20 11:41:21 -0800282 env->ReleaseStringChars(ns, reinterpret_cast<const jchar*>(ns16));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 }
Dan Albert66987492014-11-20 11:41:21 -0800284 env->ReleaseStringChars(name, reinterpret_cast<const jchar*>(name16));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285
286 return idx;
287}
288
289static jint android_content_XmlBlock_nativeGetIdAttribute(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000290 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291{
Ashok Bhat896043d2014-01-17 16:02:38 +0000292 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700294 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 return 0;
296 }
297
298 ssize_t idx = st->indexOfID();
Ashok Bhat896043d2014-01-17 16:02:38 +0000299 return idx >= 0 ? static_cast<jint>(st->getAttributeValueStringID(idx)) : -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300}
301
302static jint android_content_XmlBlock_nativeGetClassAttribute(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000303 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304{
Ashok Bhat896043d2014-01-17 16:02:38 +0000305 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700307 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 return 0;
309 }
Elliott Hughes8451b252011-04-07 19:17:57 -0700310
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 ssize_t idx = st->indexOfClass();
Ashok Bhat896043d2014-01-17 16:02:38 +0000312 return idx >= 0 ? static_cast<jint>(st->getAttributeValueStringID(idx)) : -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313}
314
315static jint android_content_XmlBlock_nativeGetStyleAttribute(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000316 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317{
Ashok Bhat896043d2014-01-17 16:02:38 +0000318 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 if (st == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700320 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 return 0;
322 }
323
324 ssize_t idx = st->indexOfStyle();
325 if (idx < 0) {
326 return 0;
327 }
328
329 Res_value value;
330 if (st->getAttributeValue(idx, &value) < 0) {
331 return 0;
332 }
333
Elliott Hughes8451b252011-04-07 19:17:57 -0700334 return value.dataType == value.TYPE_REFERENCE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 || value.dataType == value.TYPE_ATTRIBUTE
336 ? value.data : 0;
337}
338
Aurimas Liutikas949b05d2019-01-30 17:20:41 -0800339static jint android_content_XmlBlock_nativeGetSourceResId(JNIEnv* env, jobject clazz,
340 jlong token)
341{
342 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
343 if (st == NULL) {
344 return 0;
345 } else {
346 return st->getSourceResourceId();
347 }
348}
349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350static void android_content_XmlBlock_nativeDestroyParseState(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 ResXMLParser* st = reinterpret_cast<ResXMLParser*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 if (st == 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 st;
360}
361
362static void android_content_XmlBlock_nativeDestroy(JNIEnv* env, jobject clazz,
Ashok Bhat896043d2014-01-17 16:02:38 +0000363 jlong token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800364{
Ashok Bhat896043d2014-01-17 16:02:38 +0000365 ResXMLTree* osb = reinterpret_cast<ResXMLTree*>(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 if (osb == NULL) {
Elliott Hughes8451b252011-04-07 19:17:57 -0700367 jniThrowNullPointerException(env, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 return;
369 }
370
371 delete osb;
372}
373
374// ----------------------------------------------------------------------------
375
376/*
377 * JNI registration.
378 */
Daniel Micay76f6a862015-09-19 17:31:01 -0400379static const JNINativeMethod gXmlBlockMethods[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 /* name, signature, funcPtr */
Ashok Bhat896043d2014-01-17 16:02:38 +0000381 { "nativeCreate", "([BII)J",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 (void*) android_content_XmlBlock_nativeCreate },
Ashok Bhat896043d2014-01-17 16:02:38 +0000383 { "nativeGetStringBlock", "(J)J",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 (void*) android_content_XmlBlock_nativeGetStringBlock },
Aurimas Liutikas949b05d2019-01-30 17:20:41 -0800385 { "nativeCreateParseState", "(JI)J",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 (void*) android_content_XmlBlock_nativeCreateParseState },
Ashok Bhat896043d2014-01-17 16:02:38 +0000387 { "nativeDestroyParseState", "(J)V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 (void*) android_content_XmlBlock_nativeDestroyParseState },
Ashok Bhat896043d2014-01-17 16:02:38 +0000389 { "nativeDestroy", "(J)V",
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 (void*) android_content_XmlBlock_nativeDestroy },
John Reck32995222016-10-07 11:02:20 -0700391
392 // ------------------- @FastNative ----------------------
393
394 { "nativeNext", "(J)I",
395 (void*) android_content_XmlBlock_nativeNext },
396 { "nativeGetNamespace", "(J)I",
397 (void*) android_content_XmlBlock_nativeGetNamespace },
398 { "nativeGetName", "(J)I",
399 (void*) android_content_XmlBlock_nativeGetName },
400 { "nativeGetText", "(J)I",
401 (void*) android_content_XmlBlock_nativeGetText },
402 { "nativeGetLineNumber", "(J)I",
403 (void*) android_content_XmlBlock_nativeGetLineNumber },
404 { "nativeGetAttributeCount", "(J)I",
405 (void*) android_content_XmlBlock_nativeGetAttributeCount },
406 { "nativeGetAttributeNamespace","(JI)I",
407 (void*) android_content_XmlBlock_nativeGetAttributeNamespace },
408 { "nativeGetAttributeName", "(JI)I",
409 (void*) android_content_XmlBlock_nativeGetAttributeName },
410 { "nativeGetAttributeResource", "(JI)I",
411 (void*) android_content_XmlBlock_nativeGetAttributeResource },
412 { "nativeGetAttributeDataType", "(JI)I",
413 (void*) android_content_XmlBlock_nativeGetAttributeDataType },
414 { "nativeGetAttributeData", "(JI)I",
415 (void*) android_content_XmlBlock_nativeGetAttributeData },
416 { "nativeGetAttributeStringValue", "(JI)I",
417 (void*) android_content_XmlBlock_nativeGetAttributeStringValue },
418 { "nativeGetAttributeIndex", "(JLjava/lang/String;Ljava/lang/String;)I",
419 (void*) android_content_XmlBlock_nativeGetAttributeIndex },
420 { "nativeGetIdAttribute", "(J)I",
421 (void*) android_content_XmlBlock_nativeGetIdAttribute },
422 { "nativeGetClassAttribute", "(J)I",
423 (void*) android_content_XmlBlock_nativeGetClassAttribute },
424 { "nativeGetStyleAttribute", "(J)I",
425 (void*) android_content_XmlBlock_nativeGetStyleAttribute },
Aurimas Liutikas949b05d2019-01-30 17:20:41 -0800426 { "nativeGetSourceResId", "(J)I",
427 (void*) android_content_XmlBlock_nativeGetSourceResId},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428};
429
430int register_android_content_XmlBlock(JNIEnv* env)
431{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800432 return RegisterMethodsOrDie(env,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 "android/content/res/XmlBlock", gXmlBlockMethods, NELEM(gXmlBlockMethods));
434}
435
436}; // namespace android