Example usage for android.os ParcelFormatException ParcelFormatException

List of usage examples for android.os ParcelFormatException ParcelFormatException

Introduction

In this page you can find the example usage for android.os ParcelFormatException ParcelFormatException.

Prototype

public ParcelFormatException(String reason) 

Source Link

Usage

From source file:edu.umich.flowfence.common.QMDescriptor.java

private static List<String> toNames(Class<?>... classes) {
    if (!ParceledPayload.canParcelTypes(classes)) {
        throw new ParcelFormatException("Can't parcel arguments");
    }/*ww  w.  j  av  a 2 s. com*/
    // ClassUtils.classesTaClassNames doesn't work here, because it emits arrays
    // in their JNI form ([Ljava.lang.String;). Handle array type conversion manually.
    List<String> classNames = new ArrayList<>(classes.length);
    for (Class<?> clazz : classes) {
        int arrayDepth = 0;
        while (clazz.isArray()) {
            arrayDepth++;
            clazz = clazz.getComponentType();
        }
        classNames.add(clazz.getName() + StringUtils.repeat("[]", arrayDepth));
    }
    return classNames;
}

From source file:edu.umich.flowfence.common.QMDescriptor.java

public static QMDescriptor forInstance(Context context, Class<?> definingClass, String methodName,
        Class<?>... paramTypes) {
    if (!ParceledPayload.canParcelType(definingClass)) {
        throw new ParcelFormatException("Can't parcel instance type");
    }/*from   ww  w .  j a  v a  2  s .c  o  m*/
    return new QMDescriptor(KIND_INSTANCE, new ComponentName(context, definingClass), methodName,
            toNames(paramTypes), false);
}

From source file:edu.umich.oasis.common.SodaDescriptor.java

public static SodaDescriptor forInstance(Context context, Class<?> definingClass, String methodName,
        Class<?>... paramTypes) {
    if (!ParceledPayload.canParcelType(definingClass)) {
        throw new ParcelFormatException("Can't parcel instance type");
    }//from w w w. jav a  2 s  .c  o m
    return new SodaDescriptor(KIND_INSTANCE, new ComponentName(context, definingClass), methodName,
            toNames(paramTypes), false);
}

From source file:edu.umich.flowfence.common.QMDescriptor.java

public static QMDescriptor forConstructor(Context context, Class<?> definingClass, Class<?>... paramTypes) {
    if (!ParceledPayload.canParcelType(definingClass)) {
        throw new ParcelFormatException("Can't parcel constructed type");
    }/*from   w w  w. java 2s .  c  om*/
    return new QMDescriptor(KIND_CTOR, new ComponentName(context, definingClass), null, toNames(paramTypes),
            false);
}

From source file:edu.umich.oasis.common.SodaDescriptor.java

public static SodaDescriptor forConstructor(Context context, Class<?> definingClass, Class<?>... paramTypes) {
    if (!ParceledPayload.canParcelType(definingClass)) {
        throw new ParcelFormatException("Can't parcel constructed type");
    }//from  w w  w .j  a v a  2s. com
    return new SodaDescriptor(KIND_CTOR, new ComponentName(context, definingClass), null, toNames(paramTypes),
            false);
}

From source file:edu.umich.flowfence.common.ParceledPayload.java

public static ParceledPayload fromParcel(Parcel p) {
    byte[] data = p.createByteArray();
    if (data == null) {
        // Null data = data's stored in an ashmem region.
        try (ParcelFileDescriptor pfd = p.readFileDescriptor()) {
            FileDescriptor fd = pfd.getFileDescriptor();
            int size = MemoryFile.getSize(fd);
            if (size == -1) {
                throw new ParcelFormatException("ParceledPayload blob is not ashmem");
            }// w w  w. j av  a  2 s . c  om
            data = new byte[size];
            FileInputStream fis = new FileInputStream(fd);
            FileChannel chan = fis.getChannel();
            MappedByteBuffer mapping = chan.map(FileChannel.MapMode.READ_ONLY, 0, size);
            mapping.get(data);
        } catch (IOException e) {
            Log.e(TAG, "Couldn't unparcel - not an ashmem region?", e);
            ParcelFormatException pfe = new ParcelFormatException("Exception reading blob for ParceledPayload");
            pfe.initCause(e);
            throw pfe;
        }
    }
    return new ParceledPayload(data);
}