blob: 180e8f46e93bf63d2f455db02e094946e531faa8 [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
19import libcore.util.NativeAllocationRegistry;
20
21/** @hide */
22public class HwParcel {
23 private static final String TAG = "HwParcel";
24
25 public static final int STATUS_SUCCESS = 0;
26 public static final int STATUS_ERROR = -1;
27
28 private static final NativeAllocationRegistry sNativeRegistry;
29
30 private HwParcel(boolean allocate) {
31 native_setup(allocate);
32
33 sNativeRegistry.registerNativeAllocation(
34 this,
35 mNativeContext);
36 }
37
38 public HwParcel() {
39 native_setup(true /* allocate */);
40
41 sNativeRegistry.registerNativeAllocation(
42 this,
43 mNativeContext);
44 }
45
46 public native final void writeInterfaceToken(String interfaceName);
Andreas Huber86635bb2016-08-24 16:19:03 -070047 public native final void writeBool(boolean val);
Andreas Huberdab5fc62016-08-15 09:25:02 -070048 public native final void writeInt8(byte val);
49 public native final void writeInt16(short val);
50 public native final void writeInt32(int val);
51 public native final void writeInt64(long val);
52 public native final void writeFloat(float val);
53 public native final void writeDouble(double val);
54 public native final void writeString(String val);
55
Andreas Huber86635bb2016-08-24 16:19:03 -070056 public native final void writeBoolVector(boolean[] val);
Andreas Huberdab5fc62016-08-15 09:25:02 -070057 public native final void writeInt8Vector(byte[] val);
Andreas Huberdab5fc62016-08-15 09:25:02 -070058 public native final void writeInt16Vector(short[] val);
Andreas Huberdab5fc62016-08-15 09:25:02 -070059 public native final void writeInt32Vector(int[] val);
Andreas Huberdab5fc62016-08-15 09:25:02 -070060 public native final void writeInt64Vector(long[] val);
Andreas Huberdab5fc62016-08-15 09:25:02 -070061 public native final void writeFloatVector(float[] val);
Andreas Huberdab5fc62016-08-15 09:25:02 -070062 public native final void writeDoubleVector(double[] val);
Andreas Huberdab5fc62016-08-15 09:25:02 -070063 public native final void writeStringVector(String[] val);
64
65 public native final void writeStrongBinder(IHwBinder binder);
66
67 public native final void enforceInterface(String interfaceName);
Andreas Huber86635bb2016-08-24 16:19:03 -070068 public native final boolean readBool();
Andreas Huberdab5fc62016-08-15 09:25:02 -070069 public native final byte readInt8();
70 public native final short readInt16();
71 public native final int readInt32();
72 public native final long readInt64();
73 public native final float readFloat();
74 public native final double readDouble();
75 public native final String readString();
76
Andreas Huber86635bb2016-08-24 16:19:03 -070077 public native final boolean[] readBoolVector();
Andreas Huberdab5fc62016-08-15 09:25:02 -070078 public native final byte[] readInt8Vector();
Andreas Huberdab5fc62016-08-15 09:25:02 -070079 public native final short[] readInt16Vector();
Andreas Huberdab5fc62016-08-15 09:25:02 -070080 public native final int[] readInt32Vector();
Andreas Huberdab5fc62016-08-15 09:25:02 -070081 public native final long[] readInt64Vector();
Andreas Huberdab5fc62016-08-15 09:25:02 -070082 public native final float[] readFloatVector();
Andreas Huberdab5fc62016-08-15 09:25:02 -070083 public native final double[] readDoubleVector();
Andreas Huberdab5fc62016-08-15 09:25:02 -070084 public native final String[] readStringVector();
85
86 public native final IHwBinder readStrongBinder();
87
Andreas Huber9266f992016-08-25 11:21:21 -070088 // Handle is stored as part of the blob.
89 public native final HwBlob readBuffer();
90
91 public native final HwBlob readEmbeddedBuffer(
92 long parentHandle, long offset);
93
94 public native final void writeBuffer(HwBlob blob);
95
Andreas Huberdab5fc62016-08-15 09:25:02 -070096 public native final void writeStatus(int status);
97 public native final void verifySuccess();
98 public native final void releaseTemporaryStorage();
99
100 public native final void send();
101
102 // Returns address of the "freeFunction".
103 private static native final long native_init();
104
105 private native final void native_setup(boolean allocate);
106
107 static {
108 long freeFunction = native_init();
109
110 sNativeRegistry = new NativeAllocationRegistry(
111 HwParcel.class.getClassLoader(),
112 freeFunction,
113 128 /* size */);
114 }
115
116 private long mNativeContext;
117}
118