From 4dde8a113bce85cbd93809c803ed7c3acd338fcc Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Wed, 10 Jan 2018 15:45:36 -0800 Subject: [PATCH] Allow HIDL to be used in priv-apps. Marking HIDL as SystemApi to allow vendor apps to talk to their own native HIDL services. This includes implementing HIDL callback objects. HIDL (HAL interface design language) is a language that is used to facilitate vendor<->system communication which provides guarantees of ABI stability. For system and vendor services alike, this can also be used for internal communication. Bug: 67725182 Test: boot device, hidl_test_java Change-Id: I9d028cc43ce6f81ea619f01e18f1cd772e17cbfa Merged-In: I9d028cc43ce6f81ea619f01e18f1cd772e17cbfa (cherry picked from commit e8e63aae6f705cbe316a1d9a7780f9f534bc3948) --- Android.bp | 2 + api/system-current.txt | 119 +++++++++++++ core/java/android/os/HidlSupport.java | 16 ++ core/java/android/os/HwBinder.java | 27 +++ core/java/android/os/HwBlob.java | 277 ++++++++++++++++++++++++++++- core/java/android/os/HwParcel.java | 312 ++++++++++++++++++++++++++++++++- core/java/android/os/IHwBinder.java | 21 +++ core/java/android/os/IHwInterface.java | 6 + 8 files changed, 772 insertions(+), 8 deletions(-) diff --git a/Android.bp b/Android.bp index 80df8c541a96..3db1cdea37f1 100644 --- a/Android.bp +++ b/Android.bp @@ -744,7 +744,9 @@ java_library { srcs: [ "core/java/android/os/HidlSupport.java", + "core/java/android/annotation/IntDef.java", "core/java/android/annotation/NonNull.java", + "core/java/android/annotation/SystemApi.java", "core/java/android/os/HwBinder.java", "core/java/android/os/HwBlob.java", "core/java/android/os/HwParcel.java", diff --git a/api/system-current.txt b/api/system-current.txt index 3fc10f7a309f..148ea70f87d0 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -3161,6 +3161,125 @@ package android.os { field public static final java.lang.String ACTION_UPDATE_TZDATA = "android.intent.action.UPDATE_TZDATA"; } + public class HidlSupport { + method public static boolean deepEquals(java.lang.Object, java.lang.Object); + method public static int deepHashCode(java.lang.Object); + method public static boolean interfacesEqual(android.os.IHwInterface, java.lang.Object); + } + + public abstract class HwBinder implements android.os.IHwBinder { + method public static final void configureRpcThreadpool(long, boolean); + method public static final void joinRpcThreadpool(); + } + + public class HwBlob { + ctor public HwBlob(int); + method public final void copyToBoolArray(long, boolean[], int); + method public final void copyToDoubleArray(long, double[], int); + method public final void copyToFloatArray(long, float[], int); + method public final void copyToInt16Array(long, short[], int); + method public final void copyToInt32Array(long, int[], int); + method public final void copyToInt64Array(long, long[], int); + method public final void copyToInt8Array(long, byte[], int); + method public final boolean getBool(long); + method public final double getDouble(long); + method public final float getFloat(long); + method public final short getInt16(long); + method public final int getInt32(long); + method public final long getInt64(long); + method public final byte getInt8(long); + method public final java.lang.String getString(long); + method public final long handle(); + method public final void putBlob(long, android.os.HwBlob); + method public final void putBool(long, boolean); + method public final void putBoolArray(long, boolean[]); + method public final void putDouble(long, double); + method public final void putDoubleArray(long, double[]); + method public final void putFloat(long, float); + method public final void putFloatArray(long, float[]); + method public final void putInt16(long, short); + method public final void putInt16Array(long, short[]); + method public final void putInt32(long, int); + method public final void putInt32Array(long, int[]); + method public final void putInt64(long, long); + method public final void putInt64Array(long, long[]); + method public final void putInt8(long, byte); + method public final void putInt8Array(long, byte[]); + method public final void putString(long, java.lang.String); + method public static java.lang.Boolean[] wrapArray(boolean[]); + method public static java.lang.Long[] wrapArray(long[]); + method public static java.lang.Byte[] wrapArray(byte[]); + method public static java.lang.Short[] wrapArray(short[]); + method public static java.lang.Integer[] wrapArray(int[]); + method public static java.lang.Float[] wrapArray(float[]); + method public static java.lang.Double[] wrapArray(double[]); + } + + public class HwParcel { + ctor public HwParcel(); + method public final void enforceInterface(java.lang.String); + method public final boolean readBool(); + method public final java.util.ArrayList readBoolVector(); + method public final android.os.HwBlob readBuffer(long); + method public final double readDouble(); + method public final java.util.ArrayList readDoubleVector(); + method public final android.os.HwBlob readEmbeddedBuffer(long, long, long, boolean); + method public final float readFloat(); + method public final java.util.ArrayList readFloatVector(); + method public final short readInt16(); + method public final java.util.ArrayList readInt16Vector(); + method public final int readInt32(); + method public final java.util.ArrayList readInt32Vector(); + method public final long readInt64(); + method public final java.util.ArrayList readInt64Vector(); + method public final byte readInt8(); + method public final java.util.ArrayList readInt8Vector(); + method public final java.lang.String readString(); + method public final java.util.ArrayList readStringVector(); + method public final android.os.IHwBinder readStrongBinder(); + method public final void release(); + method public final void releaseTemporaryStorage(); + method public final void send(); + method public final void verifySuccess(); + method public final void writeBool(boolean); + method public final void writeBoolVector(java.util.ArrayList); + method public final void writeBuffer(android.os.HwBlob); + method public final void writeDouble(double); + method public final void writeDoubleVector(java.util.ArrayList); + method public final void writeFloat(float); + method public final void writeFloatVector(java.util.ArrayList); + method public final void writeInt16(short); + method public final void writeInt16Vector(java.util.ArrayList); + method public final void writeInt32(int); + method public final void writeInt32Vector(java.util.ArrayList); + method public final void writeInt64(long); + method public final void writeInt64Vector(java.util.ArrayList); + method public final void writeInt8(byte); + method public final void writeInt8Vector(java.util.ArrayList); + method public final void writeInterfaceToken(java.lang.String); + method public final void writeStatus(int); + method public final void writeString(java.lang.String); + method public final void writeStringVector(java.util.ArrayList); + method public final void writeStrongBinder(android.os.IHwBinder); + field public static final int STATUS_SUCCESS = 0; // 0x0 + } + + public static abstract class HwParcel.Status implements java.lang.annotation.Annotation { + } + + public abstract interface IHwBinder { + method public abstract boolean linkToDeath(android.os.IHwBinder.DeathRecipient, long); + method public abstract boolean unlinkToDeath(android.os.IHwBinder.DeathRecipient); + } + + public static abstract interface IHwBinder.DeathRecipient { + method public abstract void serviceDied(long); + } + + public abstract interface IHwInterface { + method public abstract android.os.IHwBinder asBinder(); + } + public class IncidentManager { method public void reportIncident(android.os.IncidentReportArgs); method public void reportIncident(java.lang.String, byte[]); diff --git a/core/java/android/os/HidlSupport.java b/core/java/android/os/HidlSupport.java index 4d7d9319c94e..335bf9d86fc7 100644 --- a/core/java/android/os/HidlSupport.java +++ b/core/java/android/os/HidlSupport.java @@ -16,6 +16,8 @@ package android.os; +import android.annotation.SystemApi; + import java.util.Arrays; import java.util.Collection; import java.util.Iterator; @@ -25,6 +27,7 @@ import java.util.Objects; import java.util.stream.IntStream; /** @hide */ +@SystemApi public class HidlSupport { /** * Similar to Objects.deepEquals, but also take care of lists. @@ -36,7 +39,9 @@ public class HidlSupport { * 2.3 Both are Lists, elements are checked recursively * 2.4 (If both are collections other than lists or maps, throw an error) * 2.5 lft.equals(rgt) returns true + * @hide */ + @SystemApi public static boolean deepEquals(Object lft, Object rgt) { if (lft == rgt) { return true; @@ -91,6 +96,7 @@ public class HidlSupport { * and should be avoided). * * @param Inner object type. + * @hide */ public static final class Mutable { public E value; @@ -106,7 +112,9 @@ public class HidlSupport { /** * Similar to Arrays.deepHashCode, but also take care of lists. + * @hide */ + @SystemApi public static int deepHashCode(Object o) { if (o == null) { return 0; @@ -133,6 +141,7 @@ public class HidlSupport { return o.hashCode(); } + /** @hide */ private static void throwErrorIfUnsupportedType(Object o) { if (o instanceof Collection && !(o instanceof List)) { throw new UnsupportedOperationException( @@ -146,6 +155,7 @@ public class HidlSupport { } } + /** @hide */ private static int primitiveArrayHashCode(Object o) { Class elementType = o.getClass().getComponentType(); if (elementType == boolean.class) { @@ -185,7 +195,9 @@ public class HidlSupport { * - If both interfaces are stubs, asBinder() returns the object itself. By default, * auto-generated IFoo.Stub does not override equals(), but an implementation can * optionally override it, and {@code interfacesEqual} will use it here. + * @hide */ + @SystemApi public static boolean interfacesEqual(IHwInterface lft, Object rgt) { if (lft == rgt) { return true; @@ -201,6 +213,10 @@ public class HidlSupport { /** * Return PID of process if sharable to clients. + * @hide */ public static native int getPidIfSharable(); + + /** @hide */ + public HidlSupport() {} } diff --git a/core/java/android/os/HwBinder.java b/core/java/android/os/HwBinder.java index 5e2a0815b60d..ecac002940cc 100644 --- a/core/java/android/os/HwBinder.java +++ b/core/java/android/os/HwBinder.java @@ -16,16 +16,20 @@ package android.os; +import android.annotation.SystemApi; + import libcore.util.NativeAllocationRegistry; import java.util.NoSuchElementException; /** @hide */ +@SystemApi public abstract class HwBinder implements IHwBinder { private static final String TAG = "HwBinder"; private static final NativeAllocationRegistry sNativeRegistry; + /** @hide */ public HwBinder() { native_setup(); @@ -34,33 +38,55 @@ public abstract class HwBinder implements IHwBinder { mNativeContext); } + /** @hide */ @Override public final native void transact( int code, HwParcel request, HwParcel reply, int flags) throws RemoteException; + /** @hide */ public abstract void onTransact( int code, HwParcel request, HwParcel reply, int flags) throws RemoteException; + /** @hide */ public native final void registerService(String serviceName) throws RemoteException; + /** @hide */ public static final IHwBinder getService( String iface, String serviceName) throws RemoteException, NoSuchElementException { return getService(iface, serviceName, false /* retry */); } + /** @hide */ public static native final IHwBinder getService( String iface, String serviceName, boolean retry) throws RemoteException, NoSuchElementException; + /** + * Configures how many threads the process-wide hwbinder threadpool + * has to process incoming requests. + * + * @hide + */ + @SystemApi public static native final void configureRpcThreadpool( long maxThreads, boolean callerWillJoin); + /** + * Current thread will join hwbinder threadpool and process + * commands in the pool. Should be called after configuring + * a threadpool with callerWillJoin true and then registering + * the provided service if this thread doesn't need to do + * anything else. + * + * @hide + */ + @SystemApi public static native final void joinRpcThreadpool(); // Returns address of the "freeFunction". @@ -83,6 +109,7 @@ public abstract class HwBinder implements IHwBinder { /** * Notifies listeners that a system property has changed + * @hide */ public static void reportSyspropChanged() { native_report_sysprop_change(); diff --git a/core/java/android/os/HwBlob.java b/core/java/android/os/HwBlob.java index 5e9b9ae3d49a..405651e992a3 100644 --- a/core/java/android/os/HwBlob.java +++ b/core/java/android/os/HwBlob.java @@ -17,10 +17,17 @@ package android.os; import android.annotation.NonNull; +import android.annotation.SystemApi; import libcore.util.NativeAllocationRegistry; -/** @hide */ +/** + * Represents fixed sized allocation of marshalled data used. Helper methods + * allow for access to the unmarshalled data in a variety of ways. + * + * @hide + */ +@SystemApi public class HwBlob { private static final String TAG = "HwBlob"; @@ -34,48 +41,276 @@ public class HwBlob { mNativeContext); } + /** + * @param offset offset to unmarshall a boolean from + * @return the unmarshalled boolean value + * @throws IndexOutOfBoundsException when offset is out of this HwBlob + */ public native final boolean getBool(long offset); + /** + * @param offset offset to unmarshall a byte from + * @return the unmarshalled byte value + * @throws IndexOutOfBoundsException when offset is out of this HwBlob + */ public native final byte getInt8(long offset); + /** + * @param offset offset to unmarshall a short from + * @return the unmarshalled short value + * @throws IndexOutOfBoundsException when offset is out of this HwBlob + */ public native final short getInt16(long offset); + /** + * @param offset offset to unmarshall an int from + * @return the unmarshalled int value + * @throws IndexOutOfBoundsException when offset is out of this HwBlob + */ public native final int getInt32(long offset); + /** + * @param offset offset to unmarshall a long from + * @return the unmarshalled long value + * @throws IndexOutOfBoundsException when offset is out of this HwBlob + */ public native final long getInt64(long offset); + /** + * @param offset offset to unmarshall a float from + * @return the unmarshalled float value + * @throws IndexOutOfBoundsException when offset is out of this HwBlob + */ public native final float getFloat(long offset); + /** + * @param offset offset to unmarshall a double from + * @return the unmarshalled double value + * @throws IndexOutOfBoundsException when offset is out of this HwBlob + */ public native final double getDouble(long offset); + /** + * @param offset offset to unmarshall a string from + * @return the unmarshalled string value + * @throws IndexOutOfBoundsException when offset is out of this HwBlob + */ public native final String getString(long offset); /** - The copyTo... methods copy the blob's data, starting from the given - byte offset, into the array. A total of "size" _elements_ are copied. + * Copy the blobs data starting from the given byte offset into the range, copying + * a total of size elements. + * + * @param offset starting location in blob + * @param array destination array + * @param size total number of elements to copy + * @throws IllegalArgumentException array.length < size + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jboolean)] out of the blob. */ public native final void copyToBoolArray(long offset, boolean[] array, int size); + /** + * Copy the blobs data starting from the given byte offset into the range, copying + * a total of size elements. + * + * @param offset starting location in blob + * @param array destination array + * @param size total number of elements to copy + * @throws IllegalArgumentException array.length < size + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jbyte)] out of the blob. + */ public native final void copyToInt8Array(long offset, byte[] array, int size); + /** + * Copy the blobs data starting from the given byte offset into the range, copying + * a total of size elements. + * + * @param offset starting location in blob + * @param array destination array + * @param size total number of elements to copy + * @throws IllegalArgumentException array.length < size + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jshort)] out of the blob. + */ public native final void copyToInt16Array(long offset, short[] array, int size); + /** + * Copy the blobs data starting from the given byte offset into the range, copying + * a total of size elements. + * + * @param offset starting location in blob + * @param array destination array + * @param size total number of elements to copy + * @throws IllegalArgumentException array.length < size + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jint)] out of the blob. + */ public native final void copyToInt32Array(long offset, int[] array, int size); + /** + * Copy the blobs data starting from the given byte offset into the range, copying + * a total of size elements. + * + * @param offset starting location in blob + * @param array destination array + * @param size total number of elements to copy + * @throws IllegalArgumentException array.length < size + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jlong)] out of the blob. + */ public native final void copyToInt64Array(long offset, long[] array, int size); + /** + * Copy the blobs data starting from the given byte offset into the range, copying + * a total of size elements. + * + * @param offset starting location in blob + * @param array destination array + * @param size total number of elements to copy + * @throws IllegalArgumentException array.length < size + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jfloat)] out of the blob. + */ public native final void copyToFloatArray(long offset, float[] array, int size); + /** + * Copy the blobs data starting from the given byte offset into the range, copying + * a total of size elements. + * + * @param offset starting location in blob + * @param array destination array + * @param size total number of elements to copy + * @throws IllegalArgumentException array.length < size + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jdouble)] out of the blob. + */ public native final void copyToDoubleArray(long offset, double[] array, int size); + /** + * Writes a boolean value at an offset. + * + * @param offset location to write value + * @param x value to write + * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jboolean)] is out of range + */ public native final void putBool(long offset, boolean x); + /** + * Writes a byte value at an offset. + * + * @param offset location to write value + * @param x value to write + * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jbyte)] is out of range + */ public native final void putInt8(long offset, byte x); + /** + * Writes a short value at an offset. + * + * @param offset location to write value + * @param x value to write + * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jshort)] is out of range + */ public native final void putInt16(long offset, short x); + /** + * Writes a int value at an offset. + * + * @param offset location to write value + * @param x value to write + * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jint)] is out of range + */ public native final void putInt32(long offset, int x); + /** + * Writes a long value at an offset. + * + * @param offset location to write value + * @param x value to write + * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jlong)] is out of range + */ public native final void putInt64(long offset, long x); + /** + * Writes a float value at an offset. + * + * @param offset location to write value + * @param x value to write + * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jfloat)] is out of range + */ public native final void putFloat(long offset, float x); + /** + * Writes a double value at an offset. + * + * @param offset location to write value + * @param x value to write + * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jdouble)] is out of range + */ public native final void putDouble(long offset, double x); + /** + * Writes a string value at an offset. + * + * @param offset location to write value + * @param x value to write + * @throws IndexOutOfBoundsException when [offset, offset + sizeof(jstring)] is out of range + */ public native final void putString(long offset, String x); + /** + * Put a boolean array contiguously at an offset in the blob. + * + * @param offset location to write values + * @param x array to write + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jboolean)] out of the blob. + */ public native final void putBoolArray(long offset, boolean[] x); + /** + * Put a byte array contiguously at an offset in the blob. + * + * @param offset location to write values + * @param x array to write + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jbyte)] out of the blob. + */ public native final void putInt8Array(long offset, byte[] x); + /** + * Put a short array contiguously at an offset in the blob. + * + * @param offset location to write values + * @param x array to write + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jshort)] out of the blob. + */ public native final void putInt16Array(long offset, short[] x); + /** + * Put a int array contiguously at an offset in the blob. + * + * @param offset location to write values + * @param x array to write + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jint)] out of the blob. + */ public native final void putInt32Array(long offset, int[] x); + /** + * Put a long array contiguously at an offset in the blob. + * + * @param offset location to write values + * @param x array to write + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jlong)] out of the blob. + */ public native final void putInt64Array(long offset, long[] x); + /** + * Put a float array contiguously at an offset in the blob. + * + * @param offset location to write values + * @param x array to write + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jfloat)] out of the blob. + */ public native final void putFloatArray(long offset, float[] x); + /** + * Put a double array contiguously at an offset in the blob. + * + * @param offset location to write values + * @param x array to write + * @throws IndexOutOfBoundsException [offset, offset + size * sizeof(jdouble)] out of the blob. + */ public native final void putDoubleArray(long offset, double[] x); + /** + * Write another HwBlob into this blob at the specified location. + * + * @param offset location to write value + * @param blob data to write + * @throws IndexOutOfBoundsException if [offset, offset + blob's size] outside of the range of + * this blob. + */ public native final void putBlob(long offset, HwBlob blob); + /** + * @return current handle of HwBlob for reference in a parcelled binder transaction + */ public native final long handle(); + /** + * Convert a primitive to a wrapped array for boolean. + * + * @param array from array + * @return transformed array + */ public static Boolean[] wrapArray(@NonNull boolean[] array) { final int n = array.length; Boolean[] wrappedArray = new Boolean[n]; @@ -85,6 +320,12 @@ public class HwBlob { return wrappedArray; } + /** + * Convert a primitive to a wrapped array for long. + * + * @param array from array + * @return transformed array + */ public static Long[] wrapArray(@NonNull long[] array) { final int n = array.length; Long[] wrappedArray = new Long[n]; @@ -94,6 +335,12 @@ public class HwBlob { return wrappedArray; } + /** + * Convert a primitive to a wrapped array for byte. + * + * @param array from array + * @return transformed array + */ public static Byte[] wrapArray(@NonNull byte[] array) { final int n = array.length; Byte[] wrappedArray = new Byte[n]; @@ -103,6 +350,12 @@ public class HwBlob { return wrappedArray; } + /** + * Convert a primitive to a wrapped array for short. + * + * @param array from array + * @return transformed array + */ public static Short[] wrapArray(@NonNull short[] array) { final int n = array.length; Short[] wrappedArray = new Short[n]; @@ -112,6 +365,12 @@ public class HwBlob { return wrappedArray; } + /** + * Convert a primitive to a wrapped array for int. + * + * @param array from array + * @return transformed array + */ public static Integer[] wrapArray(@NonNull int[] array) { final int n = array.length; Integer[] wrappedArray = new Integer[n]; @@ -121,6 +380,12 @@ public class HwBlob { return wrappedArray; } + /** + * Convert a primitive to a wrapped array for float. + * + * @param array from array + * @return transformed array + */ public static Float[] wrapArray(@NonNull float[] array) { final int n = array.length; Float[] wrappedArray = new Float[n]; @@ -130,6 +395,12 @@ public class HwBlob { return wrappedArray; } + /** + * Convert a primitive to a wrapped array for double. + * + * @param array from array + * @return transformed array + */ public static Double[] wrapArray(@NonNull double[] array) { final int n = array.length; Double[] wrappedArray = new Double[n]; diff --git a/core/java/android/os/HwParcel.java b/core/java/android/os/HwParcel.java index 4ba1144742db..0eb62c95ed71 100644 --- a/core/java/android/os/HwParcel.java +++ b/core/java/android/os/HwParcel.java @@ -16,17 +16,32 @@ package android.os; -import java.util.ArrayList; -import java.util.Arrays; +import android.annotation.IntDef; +import android.annotation.SystemApi; import libcore.util.NativeAllocationRegistry; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.ArrayList; +import java.util.Arrays; + /** @hide */ +@SystemApi public class HwParcel { private static final String TAG = "HwParcel"; + @IntDef(prefix = { "STATUS_" }, value = { + STATUS_SUCCESS, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface Status {} + + /** + * Success return error for a transaction. Written to parcels + * using writeStatus. + */ public static final int STATUS_SUCCESS = 0; - public static final int STATUS_ERROR = -1; private static final NativeAllocationRegistry sNativeRegistry; @@ -38,6 +53,9 @@ public class HwParcel { mNativeContext); } + /** + * Creates an initialized and empty parcel. + */ public HwParcel() { native_setup(true /* allocate */); @@ -46,25 +64,106 @@ public class HwParcel { mNativeContext); } + /** + * Writes an interface token into the parcel used to verify that + * a transaction has made it to the write type of interface. + * + * @param interfaceName fully qualified name of interface message + * is being sent to. + */ public native final void writeInterfaceToken(String interfaceName); + /** + * Writes a boolean value to the end of the parcel. + * @param val to write + */ public native final void writeBool(boolean val); + /** + * Writes a byte value to the end of the parcel. + * @param val to write + */ public native final void writeInt8(byte val); + /** + * Writes a short value to the end of the parcel. + * @param val to write + */ public native final void writeInt16(short val); + /** + * Writes a int value to the end of the parcel. + * @param val to write + */ public native final void writeInt32(int val); + /** + * Writes a long value to the end of the parcel. + * @param val to write + */ public native final void writeInt64(long val); + /** + * Writes a float value to the end of the parcel. + * @param val to write + */ public native final void writeFloat(float val); + /** + * Writes a double value to the end of the parcel. + * @param val to write + */ public native final void writeDouble(double val); + /** + * Writes a String value to the end of the parcel. + * + * Note, this will be converted to UTF-8 when it is written. + * + * @param val to write + */ public native final void writeString(String val); + /** + * Writes an array of boolean values to the end of the parcel. + * @param val to write + */ private native final void writeBoolVector(boolean[] val); + /** + * Writes an array of byte values to the end of the parcel. + * @param val to write + */ private native final void writeInt8Vector(byte[] val); + /** + * Writes an array of short values to the end of the parcel. + * @param val to write + */ private native final void writeInt16Vector(short[] val); + /** + * Writes an array of int values to the end of the parcel. + * @param val to write + */ private native final void writeInt32Vector(int[] val); + /** + * Writes an array of long values to the end of the parcel. + * @param val to write + */ private native final void writeInt64Vector(long[] val); + /** + * Writes an array of float values to the end of the parcel. + * @param val to write + */ private native final void writeFloatVector(float[] val); + /** + * Writes an array of double values to the end of the parcel. + * @param val to write + */ private native final void writeDoubleVector(double[] val); + /** + * Writes an array of String values to the end of the parcel. + * + * Note, these will be converted to UTF-8 as they are written. + * + * @param val to write + */ private native final void writeStringVector(String[] val); + /** + * Helper method to write a list of Booleans to val. + * @param val list to write + */ public final void writeBoolVector(ArrayList val) { final int n = val.size(); boolean[] array = new boolean[n]; @@ -75,6 +174,10 @@ public class HwParcel { writeBoolVector(array); } + /** + * Helper method to write a list of Booleans to the end of the parcel. + * @param val list to write + */ public final void writeInt8Vector(ArrayList val) { final int n = val.size(); byte[] array = new byte[n]; @@ -85,6 +188,10 @@ public class HwParcel { writeInt8Vector(array); } + /** + * Helper method to write a list of Shorts to the end of the parcel. + * @param val list to write + */ public final void writeInt16Vector(ArrayList val) { final int n = val.size(); short[] array = new short[n]; @@ -95,6 +202,10 @@ public class HwParcel { writeInt16Vector(array); } + /** + * Helper method to write a list of Integers to the end of the parcel. + * @param val list to write + */ public final void writeInt32Vector(ArrayList val) { final int n = val.size(); int[] array = new int[n]; @@ -105,6 +216,10 @@ public class HwParcel { writeInt32Vector(array); } + /** + * Helper method to write a list of Longs to the end of the parcel. + * @param val list to write + */ public final void writeInt64Vector(ArrayList val) { final int n = val.size(); long[] array = new long[n]; @@ -115,6 +230,10 @@ public class HwParcel { writeInt64Vector(array); } + /** + * Helper method to write a list of Floats to the end of the parcel. + * @param val list to write + */ public final void writeFloatVector(ArrayList val) { final int n = val.size(); float[] array = new float[n]; @@ -125,6 +244,10 @@ public class HwParcel { writeFloatVector(array); } + /** + * Helper method to write a list of Doubles to the end of the parcel. + * @param val list to write + */ public final void writeDoubleVector(ArrayList val) { final int n = val.size(); double[] array = new double[n]; @@ -135,93 +258,272 @@ public class HwParcel { writeDoubleVector(array); } + /** + * Helper method to write a list of Strings to the end of the parcel. + * @param val list to write + */ public final void writeStringVector(ArrayList val) { writeStringVector(val.toArray(new String[val.size()])); } + /** + * Write a hwbinder object to the end of the parcel. + * @param binder value to write + */ public native final void writeStrongBinder(IHwBinder binder); + /** + * Checks to make sure that the interface name matches the name written by the parcel + * sender by writeInterfaceToken + * + * @throws SecurityException interface doesn't match + */ public native final void enforceInterface(String interfaceName); + + /** + * Reads a boolean value from the current location in the parcel. + * @return value parsed from the parcel + * @throws IllegalArgumentException if the parcel has no more data + */ public native final boolean readBool(); + /** + * Reads a byte value from the current location in the parcel. + * @return value parsed from the parcel + * @throws IllegalArgumentException if the parcel has no more data + */ public native final byte readInt8(); + /** + * Reads a short value from the current location in the parcel. + * @return value parsed from the parcel + * @throws IllegalArgumentException if the parcel has no more data + */ public native final short readInt16(); + /** + * Reads a int value from the current location in the parcel. + * @return value parsed from the parcel + * @throws IllegalArgumentException if the parcel has no more data + */ public native final int readInt32(); + /** + * Reads a long value from the current location in the parcel. + * @return value parsed from the parcel + * @throws IllegalArgumentException if the parcel has no more data + */ public native final long readInt64(); + /** + * Reads a float value from the current location in the parcel. + * @return value parsed from the parcel + * @throws IllegalArgumentException if the parcel has no more data + */ public native final float readFloat(); + /** + * Reads a double value from the current location in the parcel. + * @return value parsed from the parcel + * @throws IllegalArgumentException if the parcel has no more data + */ public native final double readDouble(); + /** + * Reads a String value from the current location in the parcel. + * @return value parsed from the parcel + * @throws IllegalArgumentException if the parcel has no more data + */ public native final String readString(); + /** + * Reads an array of boolean values from the parcel. + * @return array of parsed values + * @throws IllegalArgumentException if the parcel has no more data + */ private native final boolean[] readBoolVectorAsArray(); + /** + * Reads an array of byte values from the parcel. + * @return array of parsed values + * @throws IllegalArgumentException if the parcel has no more data + */ private native final byte[] readInt8VectorAsArray(); + /** + * Reads an array of short values from the parcel. + * @return array of parsed values + * @throws IllegalArgumentException if the parcel has no more data + */ private native final short[] readInt16VectorAsArray(); + /** + * Reads an array of int values from the parcel. + * @return array of parsed values + * @throws IllegalArgumentException if the parcel has no more data + */ private native final int[] readInt32VectorAsArray(); + /** + * Reads an array of long values from the parcel. + * @return array of parsed values + * @throws IllegalArgumentException if the parcel has no more data + */ private native final long[] readInt64VectorAsArray(); + /** + * Reads an array of float values from the parcel. + * @return array of parsed values + * @throws IllegalArgumentException if the parcel has no more data + */ private native final float[] readFloatVectorAsArray(); + /** + * Reads an array of double values from the parcel. + * @return array of parsed values + * @throws IllegalArgumentException if the parcel has no more data + */ private native final double[] readDoubleVectorAsArray(); + /** + * Reads an array of String values from the parcel. + * @return array of parsed values + * @throws IllegalArgumentException if the parcel has no more data + */ private native final String[] readStringVectorAsArray(); + /** + * Convenience method to read a Boolean vector as an ArrayList. + * @return array of parsed values. + * @throws IllegalArgumentException if the parcel has no more data + */ public final ArrayList readBoolVector() { Boolean[] array = HwBlob.wrapArray(readBoolVectorAsArray()); return new ArrayList(Arrays.asList(array)); } + /** + * Convenience method to read a Byte vector as an ArrayList. + * @return array of parsed values. + * @throws IllegalArgumentException if the parcel has no more data + */ public final ArrayList readInt8Vector() { Byte[] array = HwBlob.wrapArray(readInt8VectorAsArray()); return new ArrayList(Arrays.asList(array)); } + /** + * Convenience method to read a Short vector as an ArrayList. + * @return array of parsed values. + * @throws IllegalArgumentException if the parcel has no more data + */ public final ArrayList readInt16Vector() { Short[] array = HwBlob.wrapArray(readInt16VectorAsArray()); return new ArrayList(Arrays.asList(array)); } + /** + * Convenience method to read a Integer vector as an ArrayList. + * @return array of parsed values. + * @throws IllegalArgumentException if the parcel has no more data + */ public final ArrayList readInt32Vector() { Integer[] array = HwBlob.wrapArray(readInt32VectorAsArray()); return new ArrayList(Arrays.asList(array)); } + /** + * Convenience method to read a Long vector as an ArrayList. + * @return array of parsed values. + * @throws IllegalArgumentException if the parcel has no more data + */ public final ArrayList readInt64Vector() { Long[] array = HwBlob.wrapArray(readInt64VectorAsArray()); return new ArrayList(Arrays.asList(array)); } + /** + * Convenience method to read a Float vector as an ArrayList. + * @return array of parsed values. + * @throws IllegalArgumentException if the parcel has no more data + */ public final ArrayList readFloatVector() { Float[] array = HwBlob.wrapArray(readFloatVectorAsArray()); return new ArrayList(Arrays.asList(array)); } + /** + * Convenience method to read a Double vector as an ArrayList. + * @return array of parsed values. + * @throws IllegalArgumentException if the parcel has no more data + */ public final ArrayList readDoubleVector() { Double[] array = HwBlob.wrapArray(readDoubleVectorAsArray()); return new ArrayList(Arrays.asList(array)); } + /** + * Convenience method to read a String vector as an ArrayList. + * @return array of parsed values. + * @throws IllegalArgumentException if the parcel has no more data + */ public final ArrayList readStringVector() { return new ArrayList(Arrays.asList(readStringVectorAsArray())); } + /** + * Reads a strong binder value from the parcel. + * @return binder object read from parcel or null if no binder can be read + * @throws IllegalArgumentException if the parcel has no more data + */ public native final IHwBinder readStrongBinder(); - // Handle is stored as part of the blob. + /** + * Read opaque segment of data as a blob. + * @return blob of size expectedSize + * @throws IllegalArgumentException if the parcel has no more data + */ public native final HwBlob readBuffer(long expectedSize); + /** + * Read a buffer written using scatter gather. + * + * @param expectedSize size that buffer should be + * @param parentHandle handle from which to read the embedded buffer + * @param offset offset into parent + * @param nullable whether or not to allow for a null return + * @return blob of data with size expectedSize + * @throws NoSuchElementException if an embedded buffer is not available to read + * @throws IllegalArgumentException if expectedSize < 0 + * @throws NullPointerException if the transaction specified the blob to be null + * but nullable is false + */ public native final HwBlob readEmbeddedBuffer( long expectedSize, long parentHandle, long offset, boolean nullable); + /** + * Write a buffer into the transaction. + * @param blob blob to write into the parcel. + */ public native final void writeBuffer(HwBlob blob); - + /** + * Write a status value into the blob. + * @param status value to write + */ public native final void writeStatus(int status); + /** + * @throws IllegalArgumentException if a success vaue cannot be read + * @throws RemoteException if success value indicates a transaction error + */ public native final void verifySuccess(); + /** + * Should be called to reduce memory pressure when this object no longer needs + * to be written to. + */ public native final void releaseTemporaryStorage(); + /** + * Should be called when object is no longer needed to reduce possible memory + * pressure if the Java GC does not get to this object in time. + */ public native final void release(); + /** + * Sends the parcel to the specified destination. + */ public native final void send(); // Returns address of the "freeFunction". diff --git a/core/java/android/os/IHwBinder.java b/core/java/android/os/IHwBinder.java index 619f4dc631d5..ce9f6c1654c2 100644 --- a/core/java/android/os/IHwBinder.java +++ b/core/java/android/os/IHwBinder.java @@ -16,26 +16,47 @@ package android.os; +import android.annotation.SystemApi; + /** @hide */ +@SystemApi public interface IHwBinder { // These MUST match their corresponding libhwbinder/IBinder.h definition !!! + /** @hide */ public static final int FIRST_CALL_TRANSACTION = 1; + /** @hide */ public static final int FLAG_ONEWAY = 1; + /** @hide */ public void transact( int code, HwParcel request, HwParcel reply, int flags) throws RemoteException; + /** @hide */ public IHwInterface queryLocalInterface(String descriptor); /** * Interface for receiving a callback when the process hosting a service * has gone away. */ + @SystemApi public interface DeathRecipient { + /** + * Callback for a registered process dying. + */ + @SystemApi public void serviceDied(long cookie); } + /** + * Notifies the death recipient with the cookie when the process containing + * this binder dies. + */ + @SystemApi public boolean linkToDeath(DeathRecipient recipient, long cookie); + /** + * Unregisters the death recipient from this binder. + */ + @SystemApi public boolean unlinkToDeath(DeathRecipient recipient); } diff --git a/core/java/android/os/IHwInterface.java b/core/java/android/os/IHwInterface.java index 7c5ac6f44a49..a2f59a9abb81 100644 --- a/core/java/android/os/IHwInterface.java +++ b/core/java/android/os/IHwInterface.java @@ -16,7 +16,13 @@ package android.os; +import android.annotation.SystemApi; /** @hide */ +@SystemApi public interface IHwInterface { + /** + * Returns the binder object that corresponds to an interface. + */ + @SystemApi public IHwBinder asBinder(); } -- 2.11.0