Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb159195 authored by Steven Moreland's avatar Steven Moreland Committed by Android (Google) Code Review
Browse files

Merge "Allow HIDL to be used in priv-apps."

parents 65b79f7e e8e63aae
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -828,7 +828,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",
+119 −0
Original line number Diff line number Diff line
@@ -3483,6 +3483,125 @@ package android.os {
    field public static final java.lang.String ACTION_UPDATE_SMS_SHORT_CODES = "android.intent.action.UPDATE_SMS_SHORT_CODES";
  }

  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<java.lang.Boolean> readBoolVector();
    method public final android.os.HwBlob readBuffer(long);
    method public final double readDouble();
    method public final java.util.ArrayList<java.lang.Double> readDoubleVector();
    method public final android.os.HwBlob readEmbeddedBuffer(long, long, long, boolean);
    method public final float readFloat();
    method public final java.util.ArrayList<java.lang.Float> readFloatVector();
    method public final short readInt16();
    method public final java.util.ArrayList<java.lang.Short> readInt16Vector();
    method public final int readInt32();
    method public final java.util.ArrayList<java.lang.Integer> readInt32Vector();
    method public final long readInt64();
    method public final java.util.ArrayList<java.lang.Long> readInt64Vector();
    method public final byte readInt8();
    method public final java.util.ArrayList<java.lang.Byte> readInt8Vector();
    method public final java.lang.String readString();
    method public final java.util.ArrayList<java.lang.String> 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<java.lang.Boolean>);
    method public final void writeBuffer(android.os.HwBlob);
    method public final void writeDouble(double);
    method public final void writeDoubleVector(java.util.ArrayList<java.lang.Double>);
    method public final void writeFloat(float);
    method public final void writeFloatVector(java.util.ArrayList<java.lang.Float>);
    method public final void writeInt16(short);
    method public final void writeInt16Vector(java.util.ArrayList<java.lang.Short>);
    method public final void writeInt32(int);
    method public final void writeInt32Vector(java.util.ArrayList<java.lang.Integer>);
    method public final void writeInt64(long);
    method public final void writeInt64Vector(java.util.ArrayList<java.lang.Long>);
    method public final void writeInt8(byte);
    method public final void writeInt8Vector(java.util.ArrayList<java.lang.Byte>);
    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<java.lang.String>);
    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[]);
+16 −0
Original line number Diff line number Diff line
@@ -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 <E> Inner object type.
     * @hide
     */
    public static final class Mutable<E> {
        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() {}
}
+27 −0
Original line number Diff line number Diff line
@@ -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();
+274 −3
Original line number Diff line number Diff line
@@ -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];
Loading