Java Code Examples for android.os.Parcel.dataPosition()

The following are Jave code examples for showing how to use dataPosition() of the android.os.Parcel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: q-mail   File: SMimeError.java   View Source Code Vote up 6 votes
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();
    // version 1
    dest.writeInt(errorId);
    dest.writeString(message);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 2
Project: q-mail   File: SMimeDecryptionResult.java   View Source Code Vote up 6 votes
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();
    // version 1
    dest.writeInt(result);
    // version 2
    dest.writeByteArray(sessionKey);
    dest.writeByteArray(decryptedSessionKey);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 3
Project: q-mail   File: SMimeDecryptionResult.java   View Source Code Vote up 6 votes
public SMimeDecryptionResult createFromParcel(final Parcel source) {
    int version = source.readInt(); // parcelableVersion
    int parcelableSize = source.readInt();
    int startPosition = source.dataPosition();

    int result = source.readInt();
    byte[] sessionKey = version > 1 ? source.createByteArray() : null;
    byte[] decryptedSessionKey = version > 1 ? source.createByteArray() : null;

    SMimeDecryptionResult vr = new SMimeDecryptionResult(result, sessionKey, decryptedSessionKey);

    // skip over all fields added in future versions of this parcel
    source.setDataPosition(startPosition + parcelableSize);

    return vr;
}
 
Example 4
Project: q-mail   File: SMimeMetadata.java   View Source Code Vote up 6 votes
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();
    // version 1
    dest.writeString(filename);
    dest.writeString(mimeType);
    dest.writeLong(modificationTime);
    dest.writeLong(originalSize);
    // version 2
    dest.writeString(charset);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 5
Project: q-mail   File: SMimeMetadata.java   View Source Code Vote up 6 votes
public SMimeMetadata createFromParcel(final Parcel source) {
    int version = source.readInt(); // parcelableVersion
    int parcelableSize = source.readInt();
    int startPosition = source.dataPosition();

    SMimeMetadata vr = new SMimeMetadata();
    vr.filename = source.readString();
    vr.mimeType = source.readString();
    vr.modificationTime = source.readLong();
    vr.originalSize = source.readLong();
    if (version >= 2) {
        vr.charset = source.readString();
    }

    // skip over all fields added in future versions of this parcel
    source.setDataPosition(startPosition + parcelableSize);

    return vr;
}
 
Example 6
Project: q-mail   File: OpenPgpError.java   View Source Code Vote up 6 votes
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();
    // version 1
    dest.writeInt(errorId);
    dest.writeString(message);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 7
Project: q-mail   File: OpenPgpMetadata.java   View Source Code Vote up 6 votes
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();
    // version 1
    dest.writeString(filename);
    dest.writeString(mimeType);
    dest.writeLong(modificationTime);
    dest.writeLong(originalSize);
    // version 2
    dest.writeString(charset);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 8
Project: q-mail   File: OpenPgpMetadata.java   View Source Code Vote up 6 votes
public OpenPgpMetadata createFromParcel(final Parcel source) {
    int version = source.readInt(); // parcelableVersion
    int parcelableSize = source.readInt();
    int startPosition = source.dataPosition();

    OpenPgpMetadata vr = new OpenPgpMetadata();
    vr.filename = source.readString();
    vr.mimeType = source.readString();
    vr.modificationTime = source.readLong();
    vr.originalSize = source.readLong();
    if (version >= 2) {
        vr.charset = source.readString();
    }

    // skip over all fields added in future versions of this parcel
    source.setDataPosition(startPosition + parcelableSize);

    return vr;
}
 
Example 9
Project: q-mail   File: OpenPgpDecryptionResult.java   View Source Code Vote up 6 votes
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();
    // version 1
    dest.writeInt(result);
    // version 2
    dest.writeByteArray(sessionKey);
    dest.writeByteArray(decryptedSessionKey);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 10
Project: q-mail   File: OpenPgpDecryptionResult.java   View Source Code Vote up 6 votes
public OpenPgpDecryptionResult createFromParcel(final Parcel source) {
    int version = source.readInt(); // parcelableVersion
    int parcelableSize = source.readInt();
    int startPosition = source.dataPosition();

    int result = source.readInt();
    byte[] sessionKey = version > 1 ? source.createByteArray() : null;
    byte[] decryptedSessionKey = version > 1 ? source.createByteArray() : null;

    OpenPgpDecryptionResult vr = new OpenPgpDecryptionResult(result, sessionKey, decryptedSessionKey);

    // skip over all fields added in future versions of this parcel
    source.setDataPosition(startPosition + parcelableSize);

    return vr;
}
 
Example 11
Project: MessageOnTap_API   File: TaskData.java   View Source Code Vote up 6 votes
private TaskData(Parcel in) {
    int parcelableSize = in.readInt();
    int startPosition = in.dataPosition();
    this.mSID = in.readLong();
    this.mTID = in.readLong();
    this.mContent = in.readString();
    this.mType = in.readString();
    this.mMethod = in.readString();
    if (TextUtils.isEmpty(this.mContent)) {
        this.mContent = null;
    }
    if (TextUtils.isEmpty(this.mType)) {
        this.mType = null;
    }
    if (TextUtils.isEmpty(this.mMethod)) {
        this.mMethod = null;
    }
}
 
Example 12
Project: MessageOnTap_API   File: TaskData.java   View Source Code Vote up 6 votes
@Override
public void writeToParcel(Parcel parcel, int i) {
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = parcel.dataPosition();
    parcel.writeInt(0);
    int startPosition = parcel.dataPosition();
    parcel.writeLong(mSID);
    parcel.writeLong(mTID);
    parcel.writeString(TextUtils.isEmpty(mContent) ? "" : mContent);
    parcel.writeString(TextUtils.isEmpty(mType) ? "" : mType);
    parcel.writeString(TextUtils.isEmpty(mMethod) ? "" : mMethod);
    // Go back and write the size
    int parcelableSize = parcel.dataPosition() - startPosition;
    parcel.setDataPosition(sizePosition);
    parcel.writeInt(parcelableSize);
    parcel.setDataPosition(startPosition + parcelableSize);
}
 
Example 13
Project: q-mail   File: SMimeError.java   View Source Code Vote up 5 votes
public SMimeError createFromParcel(final Parcel source) {
    source.readInt(); // parcelableVersion
    int parcelableSize = source.readInt();
    int startPosition = source.dataPosition();

    SMimeError error = new SMimeError();
    error.errorId = source.readInt();
    error.message = source.readString();

    // skip over all fields added in future versions of this parcel
    source.setDataPosition(startPosition + parcelableSize);

    return error;
}
 
Example 14
Project: q-mail   File: SMimeSignatureResult.java   View Source Code Vote up 5 votes
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();
    // version 1
    dest.writeInt(result);
    // signatureOnly is deprecated since version 3. we pass a dummy value for compatibility
    dest.writeByte((byte) 0);
    dest.writeString(primaryUserId);
    dest.writeLong(keyId);
    // version 2
    dest.writeStringList(userIds);
    // version 3
    writeEnumWithNull(dest, senderStatusResult);
    dest.writeStringList(confirmedUserIds);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 15
Project: q-mail   File: OpenPgpError.java   View Source Code Vote up 5 votes
public OpenPgpError createFromParcel(final Parcel source) {
    source.readInt(); // parcelableVersion
    int parcelableSize = source.readInt();
    int startPosition = source.dataPosition();

    OpenPgpError error = new OpenPgpError();
    error.errorId = source.readInt();
    error.message = source.readString();

    // skip over all fields added in future versions of this parcel
    source.setDataPosition(startPosition + parcelableSize);

    return error;
}
 
Example 16
Project: q-mail   File: OpenPgpSignatureResult.java   View Source Code Vote up 5 votes
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();
    // version 1
    dest.writeInt(result);
    // signatureOnly is deprecated since version 3. we pass a dummy value for compatibility
    dest.writeByte((byte) 0);
    dest.writeString(primaryUserId);
    dest.writeLong(keyId);
    // version 2
    dest.writeStringList(userIds);
    // version 3
    writeEnumWithNull(dest, senderStatusResult);
    dest.writeStringList(confirmedUserIds);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 17
Project: q-mail   File: AutocryptPeerUpdate.java   View Source Code Vote up 5 votes
public void writeToParcel(Parcel dest, int flags) {
    /**
     * NOTE: When adding fields in the process of updating this API, make sure to bump
     * {@link #PARCELABLE_VERSION}.
     */
    dest.writeInt(PARCELABLE_VERSION);
    // Inject a placeholder that will store the parcel size from this point on
    // (not including the size itself).
    int sizePosition = dest.dataPosition();
    dest.writeInt(0);
    int startPosition = dest.dataPosition();

    // version 1
    dest.writeByteArray(keyData);
    if (effectiveDate != null) {
        dest.writeInt(1);
        dest.writeLong(effectiveDate.getTime());
    } else {
        dest.writeInt(0);
    }

    dest.writeInt(preferEncrypt.ordinal());

    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 18
Project: aos-MediaLib   File: MediaMetadata.java   View Source Code Vote up 5 votes
/**
 * Check a parcel containing metadata is well formed. The header
 * is checked as well as the individual records format. However, the
 * data inside the record is not checked because we do lazy access
 * (we check/unmarshall only data the user asks for.)
 *
 * Format of a metadata parcel:
 <pre>
                     1                   2                   3
  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                     metadata total size                       |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |     'M'       |     'E'       |     'T'       |     'A'       |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                                                               |
  |                .... metadata records ....                     |
  |                                                               |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 </pre>
 *
 * @param parcel With the serialized data. Metadata keeps a
 *               reference on it to access it later on. The caller
 *               should not modify the parcel after this call (and
 *               not call recycle on it.)
 * @return false if an error occurred.
 * {@hide}
 */
public boolean parse(Parcel parcel) {
    if (parcel.dataAvail() < kMetaHeaderSize) {
        Log.e(TAG, "Not enough data " + parcel.dataAvail());
        return false;
    }

    final int pin = parcel.dataPosition();  // to roll back in case of errors.
    final int size = parcel.readInt();

    // The extra kInt32Size below is to account for the int32 'size' just read.
    if (parcel.dataAvail() + kInt32Size < size || size < kMetaHeaderSize) {
        Log.e(TAG, "Bad size " + size + " avail " + parcel.dataAvail() + " position " + pin);
        parcel.setDataPosition(pin);
        return false;
    }

    // Checks if the 'M' 'E' 'T' 'A' marker is present.
    final int kShouldBeMetaMarker = parcel.readInt();
    if (kShouldBeMetaMarker != kMetaMarker ) {
        Log.e(TAG, "Marker missing " + Integer.toHexString(kShouldBeMetaMarker));
        parcel.setDataPosition(pin);
        return false;
    }

    // Scan the records to collect metadata ids and offsets.
    if (!scanAllRecords(parcel, size - kMetaHeaderSize)) {
        parcel.setDataPosition(pin);
        return false;
    }
    mBegin = pin;
    mParcel = parcel;
    return true;
}
 
Example 19
Project: aos-MediaLib   File: MediaMetadata.java   View Source Code Vote up 4 votes
/**
 * Go over all the records, collecting metadata keys and records'
 * type field offset in the Parcel. These are stored in
 * mKeyToPosMap for latter retrieval.
 * Format of a metadata record:
 <pre>
                     1                   2                   3
  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                     record size                               |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                     metadata key                              |  // TITLE
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                     metadata type                             |  // STRING_VAL
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                                                               |
  |                .... metadata payload ....                     |
  |                                                               |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 </pre>
 * @param parcel With the serialized records.
 * @param bytesLeft How many bytes in the parcel should be processed.
 * @return false if an error occurred during parsing.
 */
private boolean scanAllRecords(Parcel parcel, int bytesLeft) {
    int recCount = 0;
    boolean error = false;

    mKeyToPosMap.clear();
    while (bytesLeft > kRecordHeaderSize) {
        final int start = parcel.dataPosition();
        // Check the size.
        final int size = parcel.readInt();

        if (size <= kRecordHeaderSize) {  // at least 1 byte should be present.
            Log.e(TAG, "Record is too short");
            error = true;
            break;
        }

        // Check the metadata key.
        final int metadataId = parcel.readInt();

        // Store the record offset which points to the type
        // field so we can later on read/unmarshall the record
        // payload.
        if (mKeyToPosMap.containsKey(metadataId)) {
            Log.e(TAG, "Duplicate metadata ID found");
            error = true;
            break;
        }

        mKeyToPosMap.put(metadataId, parcel.dataPosition());

        // Check the metadata type.
        final int metadataType = parcel.readInt();
        if (metadataType <= 0 || metadataType > LAST_TYPE) {
            Log.e(TAG, "Invalid metadata type " + metadataType);
            error = true;
            break;
        }

        // Skip to the next one.
        parcel.setDataPosition(start + size);
        bytesLeft -= size;
        ++recCount;
    }

    if (0 != bytesLeft || error) {
        Log.e(TAG, "Ran out of data or error on record " + recCount);
        mKeyToPosMap.clear();
        return false;
    } else {
        return true;
    }
}