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

The following examples show how to use android.os.Parcel#dataPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenPgpMetadata.java    From openpgp-api with Apache License 2.0 6 votes vote down vote up
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 2
Source File: OpenPgpMetadata.java    From openpgp-api with Apache License 2.0 6 votes vote down vote up
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 3
Source File: OpenPgpDecryptionResult.java    From openpgp-api with Apache License 2.0 6 votes vote down vote up
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 4
Source File: OpenPgpError.java    From openpgp-api with Apache License 2.0 6 votes vote down vote up
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 5
Source File: OpenPgpError.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
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 6
Source File: OpenPgpDecryptionResult.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
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 7
Source File: OpenPgpMetadata.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
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
Source File: OpenPgpDecryptionResult.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
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 9
Source File: OpenPgpError.java    From openpgp-api with Apache License 2.0 5 votes vote down vote up
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 10
Source File: NavigationModelKeeper.java    From AndroidMvc with Apache License 2.0 5 votes vote down vote up
private void readLocation(Parcel in, NavLocation curLoc, int end) {
    int pos = in.dataPosition();
    if(pos < end) {
        String str = in.readString();
        NavLocation location = new NavLocation();
        location._setLocationId(str);
        curLoc._setPreviousLocation(location);
        readLocation(in, location, end);
    }
}
 
Example 11
Source File: AutocryptPeerUpdate.java    From openpgp-api with Apache License 2.0 5 votes vote down vote up
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 12
Source File: OpenPgpSignatureResult.java    From openpgp-api with Apache License 2.0 5 votes vote down vote up
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);
    // version 4
    if (signatureTimestamp != null) {
        dest.writeInt(1);
        dest.writeLong(signatureTimestamp.getTime());
    } else {
        dest.writeInt(0);
    }
    // version 5
    writeEnumWithNull(dest, autocryptPeerentityResult);
    // Go back and write the size
    int parcelableSize = dest.dataPosition() - startPosition;
    dest.setDataPosition(sizePosition);
    dest.writeInt(parcelableSize);
    dest.setDataPosition(startPosition + parcelableSize);
}
 
Example 13
Source File: AutocryptPeerUpdate.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: UserHandles.java    From deagle with Apache License 2.0 5 votes vote down vote up
private static UserHandle from(final @UserIdInt int user_id) {
	if (MY_USER_HANDLE.hashCode() == user_id) return MY_USER_HANDLE;
	final Parcel parcel = Parcel.obtain();
	try {
		final int begin = parcel.dataPosition();
		parcel.writeInt(user_id);
		parcel.setDataPosition(begin);
		return UserHandle.CREATOR.createFromParcel(parcel);
	} finally {
		parcel.recycle();
	}
}
 
Example 15
Source File: OpenPgpSignatureResult.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
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 16
Source File: OpenPgpError.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
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 17
Source File: PackageParserCacheHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.  Prepare a parcel, and install it self as a read-write helper.
 */
public WriteHelper(Parcel p) {
    mParcel = p;
    mStartPos = p.dataPosition();
    mParcel.writeInt(0); // We come back later here and write the pool position.

    mParcel.setReadWriteHelper(this);
}
 
Example 18
Source File: AssistStructure.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void writeToParcel(AssistStructure as, Parcel out) {
    int start = out.dataPosition();
    mNumWrittenWindows = 0;
    mNumWrittenViews = 0;
    boolean more = writeToParcelInner(as, out);
    Log.i(TAG, "Flattened " + (more ? "partial" : "final") + " assist data: "
            + (out.dataPosition() - start)
            + " bytes, containing " + mNumWrittenWindows + " windows, "
            + mNumWrittenViews + " views");
}
 
Example 19
Source File: NetworkEvent.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public NetworkEvent createFromParcel(Parcel in) {
    final int initialPosition = in.dataPosition();
    final int parcelToken = in.readInt();
    // we need to move back to the position from before we read parcelToken
    in.setDataPosition(initialPosition);
    switch (parcelToken) {
        case PARCEL_TOKEN_DNS_EVENT:
            return DnsEvent.CREATOR.createFromParcel(in);
        case PARCEL_TOKEN_CONNECT_EVENT:
            return ConnectEvent.CREATOR.createFromParcel(in);
        default:
            throw new ParcelFormatException("Unexpected NetworkEvent token in parcel: "
                    + parcelToken);
    }
}
 
Example 20
Source File: UsageEvents.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void writeToParcel(Parcel dest, int flags) {
    Parcel data = Parcel.obtain();
    data.writeInt(mEventCount);
    data.writeInt(mIndex);
    if (mEventCount > 0) {
        data.writeStringArray(mStringPool);

        if (mEventsToWrite != null) {
            // Write out the events
            Parcel p = Parcel.obtain();
            try {
                p.setDataPosition(0);
                for (int i = 0; i < mEventCount; i++) {
                    final Event event = mEventsToWrite.get(i);
                    writeEventToParcel(event, p, flags);
                }

                final int listByteLength = p.dataPosition();

                // Write the total length of the data.
                data.writeInt(listByteLength);

                // Write our current position into the data.
                data.writeInt(0);

                // Write the data.
                data.appendFrom(p, 0, listByteLength);
            } finally {
                p.recycle();
            }

        } else if (mParcel != null) {
            // Write the total length of the data.
            data.writeInt(mParcel.dataSize());

            // Write out current position into the data.
            data.writeInt(mParcel.dataPosition());

            // Write the data.
            data.appendFrom(mParcel, 0, mParcel.dataSize());
        } else {
            throw new IllegalStateException(
                    "Either mParcel or mEventsToWrite must not be null");
        }
    }
    // Data can be too large for a transact. Write the data as a Blob, which will be written to
    // ashmem if too large.
    dest.writeBlob(data.marshall());
}