blob: dc640c95b515014ae336400f5e4585599030e41f [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;
Steven Moreland0ff061a2019-03-04 17:56:30 -080020import android.annotation.NonNull;
21import android.annotation.Nullable;
Steven Moreland4dde8a12018-01-10 15:45:36 -080022import android.annotation.SystemApi;
Steven Moreland14b9eb62019-01-11 10:19:51 -080023import android.annotation.TestApi;
Andreas Huberef1a5652016-10-18 09:24:04 -070024
Andreas Huberdab5fc62016-08-15 09:25:02 -070025import libcore.util.NativeAllocationRegistry;
26
Steven Moreland4dde8a12018-01-10 15:45:36 -080027import java.lang.annotation.Retention;
28import java.lang.annotation.RetentionPolicy;
29import java.util.ArrayList;
30import java.util.Arrays;
31
Andreas Huberdab5fc62016-08-15 09:25:02 -070032/** @hide */
Steven Moreland4dde8a12018-01-10 15:45:36 -080033@SystemApi
Steven Moreland14b9eb62019-01-11 10:19:51 -080034@TestApi
Andreas Huberdab5fc62016-08-15 09:25:02 -070035public class HwParcel {
36 private static final String TAG = "HwParcel";
37
Steven Moreland4dde8a12018-01-10 15:45:36 -080038 @IntDef(prefix = { "STATUS_" }, value = {
39 STATUS_SUCCESS,
40 })
41 @Retention(RetentionPolicy.SOURCE)
42 public @interface Status {}
43
44 /**
45 * Success return error for a transaction. Written to parcels
46 * using writeStatus.
47 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070048 public static final int STATUS_SUCCESS = 0;
Andreas Huberdab5fc62016-08-15 09:25:02 -070049
50 private static final NativeAllocationRegistry sNativeRegistry;
51
52 private HwParcel(boolean allocate) {
53 native_setup(allocate);
54
55 sNativeRegistry.registerNativeAllocation(
56 this,
57 mNativeContext);
58 }
59
Steven Moreland4dde8a12018-01-10 15:45:36 -080060 /**
61 * Creates an initialized and empty parcel.
62 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070063 public HwParcel() {
64 native_setup(true /* allocate */);
65
66 sNativeRegistry.registerNativeAllocation(
67 this,
68 mNativeContext);
69 }
70
Steven Moreland4dde8a12018-01-10 15:45:36 -080071 /**
72 * Writes an interface token into the parcel used to verify that
73 * a transaction has made it to the write type of interface.
74 *
75 * @param interfaceName fully qualified name of interface message
76 * is being sent to.
77 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070078 public native final void writeInterfaceToken(String interfaceName);
Steven Moreland4dde8a12018-01-10 15:45:36 -080079 /**
80 * Writes a boolean value to the end of the parcel.
81 * @param val to write
82 */
Andreas Huber86635bb2016-08-24 16:19:03 -070083 public native final void writeBool(boolean val);
Steven Moreland4dde8a12018-01-10 15:45:36 -080084 /**
85 * Writes a byte value to the end of the parcel.
86 * @param val to write
87 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070088 public native final void writeInt8(byte val);
Steven Moreland4dde8a12018-01-10 15:45:36 -080089 /**
90 * Writes a short value to the end of the parcel.
91 * @param val to write
92 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070093 public native final void writeInt16(short val);
Steven Moreland4dde8a12018-01-10 15:45:36 -080094 /**
95 * Writes a int value to the end of the parcel.
96 * @param val to write
97 */
Andreas Huberdab5fc62016-08-15 09:25:02 -070098 public native final void writeInt32(int val);
Steven Moreland4dde8a12018-01-10 15:45:36 -080099 /**
100 * Writes a long value to the end of the parcel.
101 * @param val to write
102 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700103 public native final void writeInt64(long val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800104 /**
105 * Writes a float value to the end of the parcel.
106 * @param val to write
107 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700108 public native final void writeFloat(float val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800109 /**
110 * Writes a double value to the end of the parcel.
111 * @param val to write
112 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700113 public native final void writeDouble(double val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800114 /**
115 * Writes a String value to the end of the parcel.
116 *
117 * Note, this will be converted to UTF-8 when it is written.
118 *
119 * @param val to write
120 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700121 public native final void writeString(String val);
Nirav Atre9850dd92018-07-24 17:03:44 -0700122 /**
123 * Writes a native handle (without duplicating the underlying
124 * file descriptors) to the end of the parcel.
125 *
126 * @param val to write
127 */
Steven Moreland0ff061a2019-03-04 17:56:30 -0800128 public native final void writeNativeHandle(@Nullable NativeHandle val);
Andreas Huberdab5fc62016-08-15 09:25:02 -0700129
Steven Moreland4dde8a12018-01-10 15:45:36 -0800130 /**
131 * Writes an array of boolean values to the end of the parcel.
132 * @param val to write
133 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700134 private native final void writeBoolVector(boolean[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800135 /**
136 * Writes an array of byte values to the end of the parcel.
137 * @param val to write
138 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700139 private native final void writeInt8Vector(byte[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800140 /**
141 * Writes an array of short values to the end of the parcel.
142 * @param val to write
143 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700144 private native final void writeInt16Vector(short[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800145 /**
146 * Writes an array of int values to the end of the parcel.
147 * @param val to write
148 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700149 private native final void writeInt32Vector(int[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800150 /**
151 * Writes an array of long values to the end of the parcel.
152 * @param val to write
153 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700154 private native final void writeInt64Vector(long[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800155 /**
156 * Writes an array of float values to the end of the parcel.
157 * @param val to write
158 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700159 private native final void writeFloatVector(float[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800160 /**
161 * Writes an array of double values to the end of the parcel.
162 * @param val to write
163 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700164 private native final void writeDoubleVector(double[] val);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800165 /**
166 * Writes an array of String values to the end of the parcel.
167 *
168 * Note, these will be converted to UTF-8 as they are written.
169 *
170 * @param val to write
171 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700172 private native final void writeStringVector(String[] val);
Nirav Atre9850dd92018-07-24 17:03:44 -0700173 /**
174 * Writes an array of native handles to the end of the parcel.
Steven Moreland0ff061a2019-03-04 17:56:30 -0800175 *
176 * Individual elements may be null but not the whole array.
177 *
Nirav Atre9850dd92018-07-24 17:03:44 -0700178 * @param val array of {@link NativeHandle} objects to write
179 */
180 private native final void writeNativeHandleVector(NativeHandle[] val);
Andreas Huberef1a5652016-10-18 09:24:04 -0700181
Steven Moreland4dde8a12018-01-10 15:45:36 -0800182 /**
183 * Helper method to write a list of Booleans to val.
184 * @param val list to write
185 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700186 public final void writeBoolVector(ArrayList<Boolean> val) {
187 final int n = val.size();
188 boolean[] array = new boolean[n];
189 for (int i = 0; i < n; ++i) {
190 array[i] = val.get(i);
191 }
192
193 writeBoolVector(array);
194 }
195
Steven Moreland4dde8a12018-01-10 15:45:36 -0800196 /**
197 * Helper method to write a list of Booleans to the end of the parcel.
198 * @param val list to write
199 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700200 public final void writeInt8Vector(ArrayList<Byte> val) {
201 final int n = val.size();
202 byte[] array = new byte[n];
203 for (int i = 0; i < n; ++i) {
204 array[i] = val.get(i);
205 }
206
207 writeInt8Vector(array);
208 }
209
Steven Moreland4dde8a12018-01-10 15:45:36 -0800210 /**
211 * Helper method to write a list of Shorts to the end of the parcel.
212 * @param val list to write
213 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700214 public final void writeInt16Vector(ArrayList<Short> val) {
215 final int n = val.size();
216 short[] array = new short[n];
217 for (int i = 0; i < n; ++i) {
218 array[i] = val.get(i);
219 }
220
221 writeInt16Vector(array);
222 }
223
Steven Moreland4dde8a12018-01-10 15:45:36 -0800224 /**
225 * Helper method to write a list of Integers to the end of the parcel.
226 * @param val list to write
227 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700228 public final void writeInt32Vector(ArrayList<Integer> val) {
229 final int n = val.size();
230 int[] array = new int[n];
231 for (int i = 0; i < n; ++i) {
232 array[i] = val.get(i);
233 }
234
235 writeInt32Vector(array);
236 }
237
Steven Moreland4dde8a12018-01-10 15:45:36 -0800238 /**
239 * Helper method to write a list of Longs to the end of the parcel.
240 * @param val list to write
241 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700242 public final void writeInt64Vector(ArrayList<Long> val) {
243 final int n = val.size();
244 long[] array = new long[n];
245 for (int i = 0; i < n; ++i) {
246 array[i] = val.get(i);
247 }
248
249 writeInt64Vector(array);
250 }
251
Steven Moreland4dde8a12018-01-10 15:45:36 -0800252 /**
253 * Helper method to write a list of Floats to the end of the parcel.
254 * @param val list to write
255 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700256 public final void writeFloatVector(ArrayList<Float> val) {
257 final int n = val.size();
258 float[] array = new float[n];
259 for (int i = 0; i < n; ++i) {
260 array[i] = val.get(i);
261 }
262
263 writeFloatVector(array);
264 }
265
Steven Moreland4dde8a12018-01-10 15:45:36 -0800266 /**
267 * Helper method to write a list of Doubles to the end of the parcel.
268 * @param val list to write
269 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700270 public final void writeDoubleVector(ArrayList<Double> val) {
271 final int n = val.size();
272 double[] array = new double[n];
273 for (int i = 0; i < n; ++i) {
274 array[i] = val.get(i);
275 }
276
277 writeDoubleVector(array);
278 }
279
Steven Moreland4dde8a12018-01-10 15:45:36 -0800280 /**
281 * Helper method to write a list of Strings to the end of the parcel.
282 * @param val list to write
283 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700284 public final void writeStringVector(ArrayList<String> val) {
285 writeStringVector(val.toArray(new String[val.size()]));
286 }
Andreas Huberdab5fc62016-08-15 09:25:02 -0700287
Steven Moreland4dde8a12018-01-10 15:45:36 -0800288 /**
Nirav Atre9850dd92018-07-24 17:03:44 -0700289 * Helper method to write a list of native handles to the end of the parcel.
290 * @param val list of {@link NativeHandle} objects to write
291 */
Steven Moreland0ff061a2019-03-04 17:56:30 -0800292 public final void writeNativeHandleVector(@NonNull ArrayList<NativeHandle> val) {
Nirav Atre9850dd92018-07-24 17:03:44 -0700293 writeNativeHandleVector(val.toArray(new NativeHandle[val.size()]));
294 }
295
296 /**
Steven Moreland4dde8a12018-01-10 15:45:36 -0800297 * Write a hwbinder object to the end of the parcel.
298 * @param binder value to write
299 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700300 public native final void writeStrongBinder(IHwBinder binder);
301
Steven Moreland4dde8a12018-01-10 15:45:36 -0800302 /**
303 * Checks to make sure that the interface name matches the name written by the parcel
304 * sender by writeInterfaceToken
305 *
306 * @throws SecurityException interface doesn't match
307 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700308 public native final void enforceInterface(String interfaceName);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800309
310 /**
311 * Reads a boolean value from the current location in the parcel.
312 * @return value parsed from the parcel
313 * @throws IllegalArgumentException if the parcel has no more data
314 */
Andreas Huber86635bb2016-08-24 16:19:03 -0700315 public native final boolean readBool();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800316 /**
317 * Reads a byte value from the current location in the parcel.
318 * @return value parsed from the parcel
319 * @throws IllegalArgumentException if the parcel has no more data
320 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700321 public native final byte readInt8();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800322 /**
323 * Reads a short value from the current location in the parcel.
324 * @return value parsed from the parcel
325 * @throws IllegalArgumentException if the parcel has no more data
326 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700327 public native final short readInt16();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800328 /**
329 * Reads a int value from the current location in the parcel.
330 * @return value parsed from the parcel
331 * @throws IllegalArgumentException if the parcel has no more data
332 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700333 public native final int readInt32();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800334 /**
335 * Reads a long value from the current location in the parcel.
336 * @return value parsed from the parcel
337 * @throws IllegalArgumentException if the parcel has no more data
338 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700339 public native final long readInt64();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800340 /**
341 * Reads a float value from the current location in the parcel.
342 * @return value parsed from the parcel
343 * @throws IllegalArgumentException if the parcel has no more data
344 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700345 public native final float readFloat();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800346 /**
347 * Reads a double value from the current location in the parcel.
348 * @return value parsed from the parcel
349 * @throws IllegalArgumentException if the parcel has no more data
350 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700351 public native final double readDouble();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800352 /**
353 * Reads a String value from the current location in the parcel.
354 * @return value parsed from the parcel
355 * @throws IllegalArgumentException if the parcel has no more data
356 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700357 public native final String readString();
Nirav Atre9850dd92018-07-24 17:03:44 -0700358 /**
359 * Reads a native handle (without duplicating the underlying file
360 * descriptors) from the parcel. These file descriptors will only
361 * be open for the duration that the binder window is open. If they
362 * are needed further, you must call {@link NativeHandle#dup()}.
363 *
364 * @return a {@link NativeHandle} instance parsed from the parcel
365 * @throws IllegalArgumentException if the parcel has no more data
366 */
Steven Moreland0ff061a2019-03-04 17:56:30 -0800367 public native final @Nullable NativeHandle readNativeHandle();
Nirav Atre9850dd92018-07-24 17:03:44 -0700368 /**
369 * Reads an embedded native handle (without duplicating the underlying
370 * file descriptors) from the parcel. These file descriptors will only
371 * be open for the duration that the binder window is open. If they
372 * are needed further, you must call {@link NativeHandle#dup()}. You
373 * do not need to call close on the NativeHandle returned from this.
374 *
375 * @param parentHandle handle from which to read the embedded object
376 * @param offset offset into parent
377 * @return a {@link NativeHandle} instance parsed from the parcel
378 * @throws IllegalArgumentException if the parcel has no more data
379 */
Steven Moreland0ff061a2019-03-04 17:56:30 -0800380 public native final @Nullable NativeHandle readEmbeddedNativeHandle(
Nirav Atre9850dd92018-07-24 17:03:44 -0700381 long parentHandle, long offset);
Andreas Huberdab5fc62016-08-15 09:25:02 -0700382
Steven Moreland4dde8a12018-01-10 15:45:36 -0800383 /**
384 * Reads an array of boolean values from the parcel.
385 * @return array of parsed values
386 * @throws IllegalArgumentException if the parcel has no more data
387 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700388 private native final boolean[] readBoolVectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800389 /**
390 * Reads an array of byte values from the parcel.
391 * @return array of parsed values
392 * @throws IllegalArgumentException if the parcel has no more data
393 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700394 private native final byte[] readInt8VectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800395 /**
396 * Reads an array of short values from the parcel.
397 * @return array of parsed values
398 * @throws IllegalArgumentException if the parcel has no more data
399 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700400 private native final short[] readInt16VectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800401 /**
402 * Reads an array of int values from the parcel.
403 * @return array of parsed values
404 * @throws IllegalArgumentException if the parcel has no more data
405 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700406 private native final int[] readInt32VectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800407 /**
408 * Reads an array of long values from the parcel.
409 * @return array of parsed values
410 * @throws IllegalArgumentException if the parcel has no more data
411 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700412 private native final long[] readInt64VectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800413 /**
414 * Reads an array of float values from the parcel.
415 * @return array of parsed values
416 * @throws IllegalArgumentException if the parcel has no more data
417 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700418 private native final float[] readFloatVectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800419 /**
420 * Reads an array of double values from the parcel.
421 * @return array of parsed values
422 * @throws IllegalArgumentException if the parcel has no more data
423 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700424 private native final double[] readDoubleVectorAsArray();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800425 /**
426 * Reads an array of String values from the parcel.
427 * @return array of parsed values
428 * @throws IllegalArgumentException if the parcel has no more data
429 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700430 private native final String[] readStringVectorAsArray();
Nirav Atre9850dd92018-07-24 17:03:44 -0700431 /**
432 * Reads an array of native handles from the parcel.
433 * @return array of {@link NativeHandle} objects
434 * @throws IllegalArgumentException if the parcel has no more data
435 */
436 private native final NativeHandle[] readNativeHandleAsArray();
Andreas Huberef1a5652016-10-18 09:24:04 -0700437
Steven Moreland4dde8a12018-01-10 15:45:36 -0800438 /**
439 * Convenience method to read a Boolean vector as an ArrayList.
440 * @return array of parsed values.
441 * @throws IllegalArgumentException if the parcel has no more data
442 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700443 public final ArrayList<Boolean> readBoolVector() {
444 Boolean[] array = HwBlob.wrapArray(readBoolVectorAsArray());
445
446 return new ArrayList<Boolean>(Arrays.asList(array));
447 }
448
Steven Moreland4dde8a12018-01-10 15:45:36 -0800449 /**
450 * Convenience method to read a Byte vector as an ArrayList.
451 * @return array of parsed values.
452 * @throws IllegalArgumentException if the parcel has no more data
453 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700454 public final ArrayList<Byte> readInt8Vector() {
455 Byte[] array = HwBlob.wrapArray(readInt8VectorAsArray());
456
457 return new ArrayList<Byte>(Arrays.asList(array));
458 }
459
Steven Moreland4dde8a12018-01-10 15:45:36 -0800460 /**
461 * Convenience method to read a Short vector as an ArrayList.
462 * @return array of parsed values.
463 * @throws IllegalArgumentException if the parcel has no more data
464 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700465 public final ArrayList<Short> readInt16Vector() {
466 Short[] array = HwBlob.wrapArray(readInt16VectorAsArray());
467
468 return new ArrayList<Short>(Arrays.asList(array));
469 }
470
Steven Moreland4dde8a12018-01-10 15:45:36 -0800471 /**
472 * Convenience method to read a Integer vector as an ArrayList.
473 * @return array of parsed values.
474 * @throws IllegalArgumentException if the parcel has no more data
475 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700476 public final ArrayList<Integer> readInt32Vector() {
477 Integer[] array = HwBlob.wrapArray(readInt32VectorAsArray());
478
479 return new ArrayList<Integer>(Arrays.asList(array));
480 }
481
Steven Moreland4dde8a12018-01-10 15:45:36 -0800482 /**
483 * Convenience method to read a Long vector as an ArrayList.
484 * @return array of parsed values.
485 * @throws IllegalArgumentException if the parcel has no more data
486 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700487 public final ArrayList<Long> readInt64Vector() {
488 Long[] array = HwBlob.wrapArray(readInt64VectorAsArray());
489
490 return new ArrayList<Long>(Arrays.asList(array));
491 }
492
Steven Moreland4dde8a12018-01-10 15:45:36 -0800493 /**
494 * Convenience method to read a Float vector as an ArrayList.
495 * @return array of parsed values.
496 * @throws IllegalArgumentException if the parcel has no more data
497 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700498 public final ArrayList<Float> readFloatVector() {
499 Float[] array = HwBlob.wrapArray(readFloatVectorAsArray());
500
501 return new ArrayList<Float>(Arrays.asList(array));
502 }
503
Steven Moreland4dde8a12018-01-10 15:45:36 -0800504 /**
505 * Convenience method to read a Double vector as an ArrayList.
506 * @return array of parsed values.
507 * @throws IllegalArgumentException if the parcel has no more data
508 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700509 public final ArrayList<Double> readDoubleVector() {
510 Double[] array = HwBlob.wrapArray(readDoubleVectorAsArray());
511
512 return new ArrayList<Double>(Arrays.asList(array));
513 }
514
Steven Moreland4dde8a12018-01-10 15:45:36 -0800515 /**
516 * Convenience method to read a String vector as an ArrayList.
517 * @return array of parsed values.
518 * @throws IllegalArgumentException if the parcel has no more data
519 */
Andreas Huberef1a5652016-10-18 09:24:04 -0700520 public final ArrayList<String> readStringVector() {
521 return new ArrayList<String>(Arrays.asList(readStringVectorAsArray()));
522 }
Andreas Huberdab5fc62016-08-15 09:25:02 -0700523
Steven Moreland4dde8a12018-01-10 15:45:36 -0800524 /**
Nirav Atre9850dd92018-07-24 17:03:44 -0700525 * Convenience method to read a vector of native handles as an ArrayList.
526 * @return array of {@link NativeHandle} objects.
527 * @throws IllegalArgumentException if the parcel has no more data
528 */
Steven Moreland0ff061a2019-03-04 17:56:30 -0800529 public final @NonNull ArrayList<NativeHandle> readNativeHandleVector() {
Nirav Atre9850dd92018-07-24 17:03:44 -0700530 return new ArrayList<NativeHandle>(Arrays.asList(readNativeHandleAsArray()));
531 }
532
533 /**
Steven Moreland4dde8a12018-01-10 15:45:36 -0800534 * Reads a strong binder value from the parcel.
535 * @return binder object read from parcel or null if no binder can be read
536 * @throws IllegalArgumentException if the parcel has no more data
537 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700538 public native final IHwBinder readStrongBinder();
539
Steven Moreland4dde8a12018-01-10 15:45:36 -0800540 /**
541 * Read opaque segment of data as a blob.
542 * @return blob of size expectedSize
543 * @throws IllegalArgumentException if the parcel has no more data
544 */
Martijn Coenen932b5042017-04-18 15:54:43 -0700545 public native final HwBlob readBuffer(long expectedSize);
Andreas Huber9266f992016-08-25 11:21:21 -0700546
Steven Moreland4dde8a12018-01-10 15:45:36 -0800547 /**
548 * Read a buffer written using scatter gather.
549 *
550 * @param expectedSize size that buffer should be
551 * @param parentHandle handle from which to read the embedded buffer
552 * @param offset offset into parent
553 * @param nullable whether or not to allow for a null return
554 * @return blob of data with size expectedSize
555 * @throws NoSuchElementException if an embedded buffer is not available to read
556 * @throws IllegalArgumentException if expectedSize < 0
557 * @throws NullPointerException if the transaction specified the blob to be null
558 * but nullable is false
559 */
Andreas Huber9266f992016-08-25 11:21:21 -0700560 public native final HwBlob readEmbeddedBuffer(
Martijn Coenen932b5042017-04-18 15:54:43 -0700561 long expectedSize, long parentHandle, long offset,
562 boolean nullable);
Andreas Huber9266f992016-08-25 11:21:21 -0700563
Steven Moreland4dde8a12018-01-10 15:45:36 -0800564 /**
565 * Write a buffer into the transaction.
566 * @param blob blob to write into the parcel.
567 */
Andreas Huber9266f992016-08-25 11:21:21 -0700568 public native final void writeBuffer(HwBlob blob);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800569 /**
570 * Write a status value into the blob.
571 * @param status value to write
572 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700573 public native final void writeStatus(int status);
Steven Moreland4dde8a12018-01-10 15:45:36 -0800574 /**
575 * @throws IllegalArgumentException if a success vaue cannot be read
576 * @throws RemoteException if success value indicates a transaction error
577 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700578 public native final void verifySuccess();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800579 /**
580 * Should be called to reduce memory pressure when this object no longer needs
581 * to be written to.
582 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700583 public native final void releaseTemporaryStorage();
Steven Moreland4dde8a12018-01-10 15:45:36 -0800584 /**
585 * Should be called when object is no longer needed to reduce possible memory
586 * pressure if the Java GC does not get to this object in time.
587 */
Martijn Coenen3d726d12017-03-16 18:46:42 +0100588 public native final void release();
Andreas Huberdab5fc62016-08-15 09:25:02 -0700589
Steven Moreland4dde8a12018-01-10 15:45:36 -0800590 /**
591 * Sends the parcel to the specified destination.
592 */
Andreas Huberdab5fc62016-08-15 09:25:02 -0700593 public native final void send();
594
595 // Returns address of the "freeFunction".
596 private static native final long native_init();
597
598 private native final void native_setup(boolean allocate);
599
600 static {
601 long freeFunction = native_init();
602
603 sNativeRegistry = new NativeAllocationRegistry(
604 HwParcel.class.getClassLoader(),
605 freeFunction,
606 128 /* size */);
607 }
608
609 private long mNativeContext;
610}
611