Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.os; |
| 18 | |
| 19 | import libcore.util.NativeAllocationRegistry; |
| 20 | |
| 21 | /** @hide */ |
| 22 | public 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 Huber | 86635bb | 2016-08-24 16:19:03 -0700 | [diff] [blame] | 47 | public native final void writeBool(boolean val); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 48 | 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 Huber | 86635bb | 2016-08-24 16:19:03 -0700 | [diff] [blame] | 56 | public native final void writeBoolVector(boolean[] val); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 57 | public native final void writeInt8Vector(byte[] val); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 58 | public native final void writeInt16Vector(short[] val); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 59 | public native final void writeInt32Vector(int[] val); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 60 | public native final void writeInt64Vector(long[] val); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 61 | public native final void writeFloatVector(float[] val); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 62 | public native final void writeDoubleVector(double[] val); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 63 | 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 Huber | 86635bb | 2016-08-24 16:19:03 -0700 | [diff] [blame] | 68 | public native final boolean readBool(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 69 | 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 Huber | 86635bb | 2016-08-24 16:19:03 -0700 | [diff] [blame] | 77 | public native final boolean[] readBoolVector(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 78 | public native final byte[] readInt8Vector(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 79 | public native final short[] readInt16Vector(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 80 | public native final int[] readInt32Vector(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 81 | public native final long[] readInt64Vector(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 82 | public native final float[] readFloatVector(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 83 | public native final double[] readDoubleVector(); |
Andreas Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 84 | public native final String[] readStringVector(); |
| 85 | |
| 86 | public native final IHwBinder readStrongBinder(); |
| 87 | |
Andreas Huber | 9266f99 | 2016-08-25 11:21:21 -0700 | [diff] [blame] | 88 | // 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 Huber | dab5fc6 | 2016-08-15 09:25:02 -0700 | [diff] [blame] | 96 | 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 | |