blob: 7a51db2dc5f99df824fe3cc973b47a849951a3a7 [file] [log] [blame]
Andreas Huberdab5fc62016-08-15 09:25:02 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.os;
18
Steven Moreland4dde8a12018-01-10 15:45:36 -080019import android.annotation.IntDef;
20import android.annotation.SystemApi;
Andreas Huberef1a5652016-10-18 09:24:04 -070021
Andreas Huberdab5fc62016-08-15 09:25:02 -070022import libcore.util.NativeAllocationRegistry;
23
Steven Moreland4dde8a12018-01-10 15:45:36 -080024import java.lang.annotation.Retention;
25import java.lang.annotation.RetentionPolicy;
26import java.util.ArrayList;
27import java.util.Arrays;
28
Andreas Huberdab5fc62016-08-15 09:25:02 -070029/** @hide */
Steven Moreland4dde8a12018-01-10 15:45:36 -080030@SystemApi
Andreas Huberdab5fc62016-08-15 09:25:02 -070031public class HwParcel {
32 private static final String TAG = "HwParcel";
33
Steven Moreland4dde8a12018-01-10 15:45:36 -080034 @IntDef(prefix = { "STATUS_" }, value = {
35 STATUS_SUCCESS,
36 })
37 @Retention(RetentionPolicy.SOURCE)
38 public @interface Status {}
39
40 /**
41 * Success return error for a transaction. Written to parcels
42 * using writeStatus.
43 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070044 public static final int STATUS_SUCCESS = 0;
Andreas Huberdab5fc62016-08-15 09:25:02 -070045
46 private static final NativeAllocationRegistry sNativeRegistry;
47
48 private HwParcel(boolean allocate) {
49 native_setup(allocate);
50
51 sNativeRegistry.registerNativeAllocation(
52 this,
53 mNativeContext);
54 }
55
Steven Moreland4dde8a12018-01-10 15:45:36 -080056 /**
57 * Creates an initialized and empty parcel.
58 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070059 public HwParcel() {
60 native_setup(true /* allocate */);
61
62 sNativeRegistry.registerNativeAllocation(
63 this,
64 mNativeContext);
65 }
66
Steven Moreland4dde8a12018-01-10 15:45:36 -080067 /**
68 * Writes an interface token into the parcel used to verify that
69 * a transaction has made it to the write type of interface.
70 *
71 * @param interfaceName fully qualified name of interface message
72 * is being sent to.
73 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070074 public native final void writeInterfaceToken(String interfaceName);
Steven Moreland4dde8a12018-01-10 15:45:36 -080075 /**
76 * Writes a boolean value to the end of the parcel.
77 * @param val to write
78 */
Andreas Huber86635bb2016-08-24 16:19:03 -070079 public native final void writeBool(boolean val);
Steven Moreland4dde8a12018-01-10 15:45:36 -080080 /**
81 * Writes a byte value to the end of the parcel.
82 * @param val to write
83 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070084 public native final void writeInt8(byte val);
Steven Moreland4dde8a12018-01-10 15:45:36 -080085 /**
86 * Writes a short value to the end of the parcel.
87 * @param val to write
88 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070089 public native final void writeInt16(short val);
Steven Moreland4dde8a12018-01-10 15:45:36 -080090 /**
91 * Writes a int value to the end of the parcel.
92 * @param val to write
93 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070094 public native final void writeInt32(int val);
Steven Moreland4dde8a12018-01-10 15:45:36 -080095 /**
96 * Writes a long value to the end of the parcel.
97 * @param val to write
98 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070099 public native final void writeInt64(long val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800100 /**
101 * Writes a float value to the end of the parcel.
102 * @param val to write
103 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700104 public native final void writeFloat(float val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800105 /**
106 * Writes a double value to the end of the parcel.
107 * @param val to write
108 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700109 public native final void writeDouble(double val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800110 /**
111 * Writes a String value to the end of the parcel.
112 *
113 * Note, this will be converted to UTF-8 when it is written.
114 *
115 * @param val to write
116 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700117 public native final void writeString(String val);
Nirav Atre9850dd92018-07-24 17:03:44 -0700118 /**
119 * Writes a native handle (without duplicating the underlying
120 * file descriptors) to the end of the parcel.
121 *
122 * @param val to write
123 */
124 public native final void writeNativeHandle(NativeHandle val);
Andreas Huberdab5fc62016-08-15 09:25:02 -0700125
Steven Moreland4dde8a12018-01-10 15:45:36 -0800126 /**
127 * Writes an array of boolean values to the end of the parcel.
128 * @param val to write
129 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700130 private native final void writeBoolVector(boolean[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800131 /**
132 * Writes an array of byte values to the end of the parcel.
133 * @param val to write
134 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700135 private native final void writeInt8Vector(byte[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800136 /**
137 * Writes an array of short values to the end of the parcel.
138 * @param val to write
139 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700140 private native final void writeInt16Vector(short[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800141 /**
142 * Writes an array of int values to the end of the parcel.
143 * @param val to write
144 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700145 private native final void writeInt32Vector(int[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800146 /**
147 * Writes an array of long values to the end of the parcel.
148 * @param val to write
149 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700150 private native final void writeInt64Vector(long[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800151 /**
152 * Writes an array of float values to the end of the parcel.
153 * @param val to write
154 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700155 private native final void writeFloatVector(float[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800156 /**
157 * Writes an array of double values to the end of the parcel.
158 * @param val to write
159 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700160 private native final void writeDoubleVector(double[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800161 /**
162 * Writes an array of String values to the end of the parcel.
163 *
164 * Note, these will be converted to UTF-8 as they are written.
165 *
166 * @param val to write
167 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700168 private native final void writeStringVector(String[] val);
Nirav Atre9850dd92018-07-24 17:03:44 -0700169 /**
170 * Writes an array of native handles to the end of the parcel.
171 * @param val array of {@link NativeHandle} objects to write
172 */
173 private native final void writeNativeHandleVector(NativeHandle[] val);
Andreas Huberef1a5652016-10-18 09:24:04 -0700174
Steven Moreland4dde8a12018-01-10 15:45:36 -0800175 /**
176 * Helper method to write a list of Booleans to val.
177 * @param val list to write
178 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700179 public final void writeBoolVector(ArrayList<Boolean> val) {
180 final int n = val.size();
181 boolean[] array = new boolean[n];
182 for (int i = 0; i < n; ++i) {
183 array[i] = val.get(i);
184 }
185
186 writeBoolVector(array);
187 }
188
Steven Moreland4dde8a12018-01-10 15:45:36 -0800189 /**
190 * Helper method to write a list of Booleans to the end of the parcel.
191 * @param val list to write
192 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700193 public final void writeInt8Vector(ArrayList<Byte> val) {
194 final int n = val.size();
195 byte[] array = new byte[n];
196 for (int i = 0; i < n; ++i) {
197 array[i] = val.get(i);
198 }
199
200 writeInt8Vector(array);
201 }
202
Steven Moreland4dde8a12018-01-10 15:45:36 -0800203 /**
204 * Helper method to write a list of Shorts to the end of the parcel.
205 * @param val list to write
206 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700207 public final void writeInt16Vector(ArrayList<Short> val) {
208 final int n = val.size();
209 short[] array = new short[n];
210 for (int i = 0; i < n; ++i) {
211 array[i] = val.get(i);
212 }
213
214 writeInt16Vector(array);
215 }
216
Steven Moreland4dde8a12018-01-10 15:45:36 -0800217 /**
218 * Helper method to write a list of Integers to the end of the parcel.
219 * @param val list to write
220 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700221 public final void writeInt32Vector(ArrayList<Integer> val) {
222 final int n = val.size();
223 int[] array = new int[n];
224 for (int i = 0; i < n; ++i) {
225 array[i] = val.get(i);
226 }
227
228 writeInt32Vector(array);
229 }
230
Steven Moreland4dde8a12018-01-10 15:45:36 -0800231 /**
232 * Helper method to write a list of Longs to the end of the parcel.
233 * @param val list to write
234 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700235 public final void writeInt64Vector(ArrayList<Long> val) {
236 final int n = val.size();
237 long[] array = new long[n];
238 for (int i = 0; i < n; ++i) {
239 array[i] = val.get(i);
240 }
241
242 writeInt64Vector(array);
243 }
244
Steven Moreland4dde8a12018-01-10 15:45:36 -0800245 /**
246 * Helper method to write a list of Floats to the end of the parcel.
247 * @param val list to write
248 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700249 public final void writeFloatVector(ArrayList<Float> val) {
250 final int n = val.size();
251 float[] array = new float[n];
252 for (int i = 0; i < n; ++i) {
253 array[i] = val.get(i);
254 }
255
256 writeFloatVector(array);
257 }
258
Steven Moreland4dde8a12018-01-10 15:45:36 -0800259 /**
260 * Helper method to write a list of Doubles to the end of the parcel.
261 * @param val list to write
262 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700263 public final void writeDoubleVector(ArrayList<Double> val) {
264 final int n = val.size();
265 double[] array = new double[n];
266 for (int i = 0; i < n; ++i) {
267 array[i] = val.get(i);
268 }
269
270 writeDoubleVector(array);
271 }
272
Steven Moreland4dde8a12018-01-10 15:45:36 -0800273 /**
274 * Helper method to write a list of Strings to the end of the parcel.
275 * @param val list to write
276 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700277 public final void writeStringVector(ArrayList<String> val) {
278 writeStringVector(val.toArray(new String[val.size()]));
279 }
Andreas Huberdab5fc62016-08-15 09:25:02 -0700280
Steven Moreland4dde8a12018-01-10 15:45:36 -0800281 /**
Nirav Atre9850dd92018-07-24 17:03:44 -0700282 * Helper method to write a list of native handles to the end of the parcel.
283 * @param val list of {@link NativeHandle} objects to write
284 */
285 public final void writeNativeHandleVector(ArrayList<NativeHandle> val) {
286 writeNativeHandleVector(val.toArray(new NativeHandle[val.size()]));
287 }
288
289 /**
Steven Moreland4dde8a12018-01-10 15:45:36 -0800290 * Write a hwbinder object to the end of the parcel.
291 * @param binder value to write
292 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700293 public native final void writeStrongBinder(IHwBinder binder);
294
Steven Moreland4dde8a12018-01-10 15:45:36 -0800295 /**
296 * Checks to make sure that the interface name matches the name written by the parcel
297 * sender by writeInterfaceToken
298 *
299 * @throws SecurityException interface doesn't match
300 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700301 public native final void enforceInterface(String interfaceName);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800302
303 /**
304 * Reads a boolean value from the current location in the parcel.
305 * @return value parsed from the parcel
306 * @throws IllegalArgumentException if the parcel has no more data
307 */
Andreas Huber86635bb2016-08-24 16:19:03 -0700308 public native final boolean readBool();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800309 /**
310 * Reads a byte value from the current location in the parcel.
311 * @return value parsed from the parcel
312 * @throws IllegalArgumentException if the parcel has no more data
313 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700314 public native final byte readInt8();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800315 /**
316 * Reads a short value from the current location in the parcel.
317 * @return value parsed from the parcel
318 * @throws IllegalArgumentException if the parcel has no more data
319 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700320 public native final short readInt16();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800321 /**
322 * Reads a int value from the current location in the parcel.
323 * @return value parsed from the parcel
324 * @throws IllegalArgumentException if the parcel has no more data
325 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700326 public native final int readInt32();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800327 /**
328 * Reads a long value from the current location in the parcel.
329 * @return value parsed from the parcel
330 * @throws IllegalArgumentException if the parcel has no more data
331 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700332 public native final long readInt64();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800333 /**
334 * Reads a float value from the current location in the parcel.
335 * @return value parsed from the parcel
336 * @throws IllegalArgumentException if the parcel has no more data
337 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700338 public native final float readFloat();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800339 /**
340 * Reads a double value from the current location in the parcel.
341 * @return value parsed from the parcel
342 * @throws IllegalArgumentException if the parcel has no more data
343 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700344 public native final double readDouble();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800345 /**
346 * Reads a String value from the current location in the parcel.
347 * @return value parsed from the parcel
348 * @throws IllegalArgumentException if the parcel has no more data
349 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700350 public native final String readString();
Nirav Atre9850dd92018-07-24 17:03:44 -0700351 /**
352 * Reads a native handle (without duplicating the underlying file
353 * descriptors) from the parcel. These file descriptors will only
354 * be open for the duration that the binder window is open. If they
355 * are needed further, you must call {@link NativeHandle#dup()}.
356 *
357 * @return a {@link NativeHandle} instance parsed from the parcel
358 * @throws IllegalArgumentException if the parcel has no more data
359 */
360 public native final NativeHandle readNativeHandle();
361 /**
362 * Reads an embedded native handle (without duplicating the underlying
363 * file descriptors) from the parcel. These file descriptors will only
364 * be open for the duration that the binder window is open. If they
365 * are needed further, you must call {@link NativeHandle#dup()}. You
366 * do not need to call close on the NativeHandle returned from this.
367 *
368 * @param parentHandle handle from which to read the embedded object
369 * @param offset offset into parent
370 * @return a {@link NativeHandle} instance parsed from the parcel
371 * @throws IllegalArgumentException if the parcel has no more data
372 */
373 public native final NativeHandle readEmbeddedNativeHandle(
374 long parentHandle, long offset);
Andreas Huberdab5fc62016-08-15 09:25:02 -0700375
Steven Moreland4dde8a12018-01-10 15:45:36 -0800376 /**
377 * Reads an array of boolean values from the parcel.
378 * @return array of parsed values
379 * @throws IllegalArgumentException if the parcel has no more data
380 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700381 private native final boolean[] readBoolVectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800382 /**
383 * Reads an array of byte values from the parcel.
384 * @return array of parsed values
385 * @throws IllegalArgumentException if the parcel has no more data
386 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700387 private native final byte[] readInt8VectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800388 /**
389 * Reads an array of short values from the parcel.
390 * @return array of parsed values
391 * @throws IllegalArgumentException if the parcel has no more data
392 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700393 private native final short[] readInt16VectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800394 /**
395 * Reads an array of int values from the parcel.
396 * @return array of parsed values
397 * @throws IllegalArgumentException if the parcel has no more data
398 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700399 private native final int[] readInt32VectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800400 /**
401 * Reads an array of long values from the parcel.
402 * @return array of parsed values
403 * @throws IllegalArgumentException if the parcel has no more data
404 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700405 private native final long[] readInt64VectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800406 /**
407 * Reads an array of float values from the parcel.
408 * @return array of parsed values
409 * @throws IllegalArgumentException if the parcel has no more data
410 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700411 private native final float[] readFloatVectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800412 /**
413 * Reads an array of double values from the parcel.
414 * @return array of parsed values
415 * @throws IllegalArgumentException if the parcel has no more data
416 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700417 private native final double[] readDoubleVectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800418 /**
419 * Reads an array of String values from the parcel.
420 * @return array of parsed values
421 * @throws IllegalArgumentException if the parcel has no more data
422 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700423 private native final String[] readStringVectorAsArray();
Nirav Atre9850dd92018-07-24 17:03:44 -0700424 /**
425 * Reads an array of native handles from the parcel.
426 * @return array of {@link NativeHandle} objects
427 * @throws IllegalArgumentException if the parcel has no more data
428 */
429 private native final NativeHandle[] readNativeHandleAsArray();
Andreas Huberef1a5652016-10-18 09:24:04 -0700430
Steven Moreland4dde8a12018-01-10 15:45:36 -0800431 /**
432 * Convenience method to read a Boolean vector as an ArrayList.
433 * @return array of parsed values.
434 * @throws IllegalArgumentException if the parcel has no more data
435 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700436 public final ArrayList<Boolean> readBoolVector() {
437 Boolean[] array = HwBlob.wrapArray(readBoolVectorAsArray());
438
439 return new ArrayList<Boolean>(Arrays.asList(array));
440 }
441
Steven Moreland4dde8a12018-01-10 15:45:36 -0800442 /**
443 * Convenience method to read a Byte vector as an ArrayList.
444 * @return array of parsed values.
445 * @throws IllegalArgumentException if the parcel has no more data
446 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700447 public final ArrayList<Byte> readInt8Vector() {
448 Byte[] array = HwBlob.wrapArray(readInt8VectorAsArray());
449
450 return new ArrayList<Byte>(Arrays.asList(array));
451 }
452
Steven Moreland4dde8a12018-01-10 15:45:36 -0800453 /**
454 * Convenience method to read a Short vector as an ArrayList.
455 * @return array of parsed values.
456 * @throws IllegalArgumentException if the parcel has no more data
457 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700458 public final ArrayList<Short> readInt16Vector() {
459 Short[] array = HwBlob.wrapArray(readInt16VectorAsArray());
460
461 return new ArrayList<Short>(Arrays.asList(array));
462 }
463
Steven Moreland4dde8a12018-01-10 15:45:36 -0800464 /**
465 * Convenience method to read a Integer vector as an ArrayList.
466 * @return array of parsed values.
467 * @throws IllegalArgumentException if the parcel has no more data
468 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700469 public final ArrayList<Integer> readInt32Vector() {
470 Integer[] array = HwBlob.wrapArray(readInt32VectorAsArray());
471
472 return new ArrayList<Integer>(Arrays.asList(array));
473 }
474
Steven Moreland4dde8a12018-01-10 15:45:36 -0800475 /**
476 * Convenience method to read a Long vector as an ArrayList.
477 * @return array of parsed values.
478 * @throws IllegalArgumentException if the parcel has no more data
479 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700480 public final ArrayList<Long> readInt64Vector() {
481 Long[] array = HwBlob.wrapArray(readInt64VectorAsArray());
482
483 return new ArrayList<Long>(Arrays.asList(array));
484 }
485
Steven Moreland4dde8a12018-01-10 15:45:36 -0800486 /**
487 * Convenience method to read a Float vector as an ArrayList.
488 * @return array of parsed values.
489 * @throws IllegalArgumentException if the parcel has no more data
490 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700491 public final ArrayList<Float> readFloatVector() {
492 Float[] array = HwBlob.wrapArray(readFloatVectorAsArray());
493
494 return new ArrayList<Float>(Arrays.asList(array));
495 }
496
Steven Moreland4dde8a12018-01-10 15:45:36 -0800497 /**
498 * Convenience method to read a Double vector as an ArrayList.
499 * @return array of parsed values.
500 * @throws IllegalArgumentException if the parcel has no more data
501 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700502 public final ArrayList<Double> readDoubleVector() {
503 Double[] array = HwBlob.wrapArray(readDoubleVectorAsArray());
504
505 return new ArrayList<Double>(Arrays.asList(array));
506 }
507
Steven Moreland4dde8a12018-01-10 15:45:36 -0800508 /**
509 * Convenience method to read a String vector as an ArrayList.
510 * @return array of parsed values.
511 * @throws IllegalArgumentException if the parcel has no more data
512 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700513 public final ArrayList<String> readStringVector() {
514 return new ArrayList<String>(Arrays.asList(readStringVectorAsArray()));
515 }
Andreas Huberdab5fc62016-08-15 09:25:02 -0700516
Steven Moreland4dde8a12018-01-10 15:45:36 -0800517 /**
Nirav Atre9850dd92018-07-24 17:03:44 -0700518 * Convenience method to read a vector of native handles as an ArrayList.
519 * @return array of {@link NativeHandle} objects.
520 * @throws IllegalArgumentException if the parcel has no more data
521 */
522 public final ArrayList<NativeHandle> readNativeHandleVector() {
523 return new ArrayList<NativeHandle>(Arrays.asList(readNativeHandleAsArray()));
524 }
525
526 /**
Steven Moreland4dde8a12018-01-10 15:45:36 -0800527 * Reads a strong binder value from the parcel.
528 * @return binder object read from parcel or null if no binder can be read
529 * @throws IllegalArgumentException if the parcel has no more data
530 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700531 public native final IHwBinder readStrongBinder();
532
Steven Moreland4dde8a12018-01-10 15:45:36 -0800533 /**
534 * Read opaque segment of data as a blob.
535 * @return blob of size expectedSize
536 * @throws IllegalArgumentException if the parcel has no more data
537 */
Martijn Coenen932b5042017-04-18 15:54:43 -0700538 public native final HwBlob readBuffer(long expectedSize);
Andreas Huber9266f992016-08-25 11:21:21 -0700539
Steven Moreland4dde8a12018-01-10 15:45:36 -0800540 /**
541 * Read a buffer written using scatter gather.
542 *
543 * @param expectedSize size that buffer should be
544 * @param parentHandle handle from which to read the embedded buffer
545 * @param offset offset into parent
546 * @param nullable whether or not to allow for a null return
547 * @return blob of data with size expectedSize
548 * @throws NoSuchElementException if an embedded buffer is not available to read
549 * @throws IllegalArgumentException if expectedSize < 0
550 * @throws NullPointerException if the transaction specified the blob to be null
551 * but nullable is false
552 */
Andreas Huber9266f992016-08-25 11:21:21 -0700553 public native final HwBlob readEmbeddedBuffer(
Martijn Coenen932b5042017-04-18 15:54:43 -0700554 long expectedSize, long parentHandle, long offset,
555 boolean nullable);
Andreas Huber9266f992016-08-25 11:21:21 -0700556
Steven Moreland4dde8a12018-01-10 15:45:36 -0800557 /**
558 * Write a buffer into the transaction.
559 * @param blob blob to write into the parcel.
560 */
Andreas Huber9266f992016-08-25 11:21:21 -0700561 public native final void writeBuffer(HwBlob blob);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800562 /**
563 * Write a status value into the blob.
564 * @param status value to write
565 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700566 public native final void writeStatus(int status);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800567 /**
568 * @throws IllegalArgumentException if a success vaue cannot be read
569 * @throws RemoteException if success value indicates a transaction error
570 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700571 public native final void verifySuccess();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800572 /**
573 * Should be called to reduce memory pressure when this object no longer needs
574 * to be written to.
575 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700576 public native final void releaseTemporaryStorage();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800577 /**
578 * Should be called when object is no longer needed to reduce possible memory
579 * pressure if the Java GC does not get to this object in time.
580 */
Martijn Coenen3d726d12017-03-16 18:46:42 +0100581 public native final void release();
Andreas Huberdab5fc62016-08-15 09:25:02 -0700582
Steven Moreland4dde8a12018-01-10 15:45:36 -0800583 /**
584 * Sends the parcel to the specified destination.
585 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700586 public native final void send();
587
588 // Returns address of the "freeFunction".
589 private static native final long native_init();
590
591 private native final void native_setup(boolean allocate);
592
593 static {
594 long freeFunction = native_init();
595
596 sNativeRegistry = new NativeAllocationRegistry(
597 HwParcel.class.getClassLoader(),
598 freeFunction,
599 128 /* size */);
600 }
601
602 private long mNativeContext;
603}
604