Example usage for android.os Parcel readStrongBinder

List of usage examples for android.os Parcel readStrongBinder

Introduction

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

Prototype

public final IBinder readStrongBinder() 

Source Link

Document

Read an object from the parcel at the current dataPosition().

Usage

From source file:Main.java

/**
 * Repairs the broken tag on HTC devices running Android 5.x
 * <p/>/*from   ww w.  j a v a2 s  .c  o m*/
 * "It seems, the reason of this bug in TechExtras of NfcA is null. However, TechList contains MifareClassic." -bildin
 * For more information please refer to https://github.com/ikarus23/MifareClassicTool/issues/52#issuecomment-103797115
 * <p/>
 * Code source: https://github.com/ikarus23/MifareClassicTool/issues/52#issuecomment-104277445
 *
 * @param oTag The broken tag
 * @return The fixed tag
 */
public static Tag repairTag(Tag oTag) {
    if (oTag == null)
        return null;

    String[] sTechList = oTag.getTechList();

    Parcel oParcel, nParcel;

    oParcel = Parcel.obtain();
    oTag.writeToParcel(oParcel, 0);
    oParcel.setDataPosition(0);

    int len = oParcel.readInt();
    byte[] id = null;
    if (len >= 0) {
        id = new byte[len];
        oParcel.readByteArray(id);
    }
    int[] oTechList = new int[oParcel.readInt()];
    oParcel.readIntArray(oTechList);
    Bundle[] oTechExtras = oParcel.createTypedArray(Bundle.CREATOR);
    int serviceHandle = oParcel.readInt();
    int isMock = oParcel.readInt();
    IBinder tagService;
    if (isMock == 0) {
        tagService = oParcel.readStrongBinder();
    } else {
        tagService = null;
    }
    oParcel.recycle();

    int nfca_idx = -1;
    int mc_idx = -1;

    for (int idx = 0; idx < sTechList.length; idx++) {
        if (sTechList[idx].equals(NfcA.class.getName())) {
            nfca_idx = idx;
        } else if (sTechList[idx].equals(MifareClassic.class.getName())) {
            mc_idx = idx;
        }
    }

    if (nfca_idx >= 0 && mc_idx >= 0 && oTechExtras[mc_idx] == null) {
        oTechExtras[mc_idx] = oTechExtras[nfca_idx];
    } else {
        return oTag;
    }

    nParcel = Parcel.obtain();
    nParcel.writeInt(id.length);
    nParcel.writeByteArray(id);
    nParcel.writeInt(oTechList.length);
    nParcel.writeIntArray(oTechList);
    nParcel.writeTypedArray(oTechExtras, 0);
    nParcel.writeInt(serviceHandle);
    nParcel.writeInt(isMock);
    if (isMock == 0) {
        nParcel.writeStrongBinder(tagService);
    }
    nParcel.setDataPosition(0);

    Tag nTag = Tag.CREATOR.createFromParcel(nParcel);

    nParcel.recycle();

    return nTag;
}

From source file:com.oasisfeng.nevo.StatusBarNotificationEvo.java

private StatusBarNotificationEvo(final Parcel in) {
    super(in.readString(), null, in.readInt(), in.readInt() != 0 ? in.readString() : null, in.readInt(), 0, 0,
            NULL_NOTIFICATION, UserHandle.readFromParcel(in), in.readLong());
    holder = INotification.Stub.asInterface(in.readStrongBinder());
}

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

public void readFromParcel(Parcel p) {
    int startPos = p.dataPosition();
    header = p.readInt();/* www  .  jav a  2 s .co  m*/

    switch (getType()) {
    case TYPE_NULL:
        // NULL: no need to write any data
        payload = null;
        break;
    case TYPE_DATA:
        // DATA: write parceled data as byte[], so it can be skipped
        // without running untrusted code
        payload = ParceledPayload.fromParcel(p);
        break;
    case TYPE_HANDLE:
        payload = p.readStrongBinder();
        break;
    default:
        throw new IllegalArgumentException(String.format("Unknown CallParam type 0x%02x", header & MASK_TYPE));
    }
    //Log.d(TAG, String.format("Read (%d bytes @0x%x) %s", p.dataPosition() - startPos, startPos, this));
}