android.os.Parcel#marshall ( )源码实例Demo

下面列出了android.os.Parcel#marshall ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dropbox-sdk-java   文件: OpenWithActivity.java
protected String encodeOpenWithIntent(Intent owpIntent) {
    /*
     * Encode OpenWith intent
     * Real 3rd party apps should never run this function as DropboxApp does this entirely
     */

    Bundle extras = owpIntent.getExtras();
    extras.putString("_action", owpIntent.getAction());
    extras.putParcelable("_uri", owpIntent.getData());
    extras.putString("_type", owpIntent.getType());

    // marshall it!
    final Parcel parcel = Parcel.obtain();
    parcel.writeBundle(extras);
    byte[] b = parcel.marshall();
    parcel.recycle();
    return new String(Base64.encode(b, 0));
}
 
源代码2 项目: android_9.0.0_r45   文件: CryptoHelper.java
@NonNull
/* default */ Bundle encryptBundle(@NonNull Bundle bundle) throws GeneralSecurityException {
    Preconditions.checkNotNull(bundle, "Cannot encrypt null bundle.");
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    byte[] clearBytes = parcel.marshall();
    parcel.recycle();

    Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
    cipher.init(Cipher.ENCRYPT_MODE, mEncryptionKey);
    byte[] encryptedBytes = cipher.doFinal(clearBytes);
    byte[] iv = cipher.getIV();
    byte[] mac = createMac(encryptedBytes, iv);

    Bundle encryptedBundle = new Bundle();
    encryptedBundle.putByteArray(KEY_CIPHER, encryptedBytes);
    encryptedBundle.putByteArray(KEY_MAC, mac);
    encryptedBundle.putByteArray(KEY_IV, iv);

    return encryptedBundle;
}
 
@Override
public int calculateMarshalSize(T value) {
    Parcel parcel = Parcel.obtain();
    try {
        value.writeToParcel(parcel, /*flags*/0);
        int length = parcel.marshall().length;

        if (DEBUG) {
            Log.v(TAG, "calculateMarshalSize, length when parceling "
                    + value + " is " + length);
        }

        return length;
    } finally {
        parcel.recycle();
    }
}
 
源代码4 项目: Silence   文件: MasterSecret.java
public MasterSecret parcelClone() {
  Parcel thisParcel = Parcel.obtain();
  Parcel thatParcel = Parcel.obtain();
  byte[] bytes      = null;

  thisParcel.writeValue(this);
  bytes = thisParcel.marshall();

  thatParcel.unmarshall(bytes, 0, bytes.length);
  thatParcel.setDataPosition(0);

  MasterSecret that = (MasterSecret)thatParcel.readValue(MasterSecret.class.getClassLoader());

  thisParcel.recycle();
  thatParcel.recycle();

  return that;
}
 
public MockConnection(final CharSequence text, final int cursorPosition) {
    super(null, false);
    // Interaction of spans with Parcels is completely non-trivial, but in the actual case
    // the CharSequences do go through Parcels because they go through IPC. There
    // are some significant differences between the behavior of Spanned objects that
    // have and that have not gone through parceling, so it's much easier to simulate
    // the environment with Parcels than try to emulate things by hand.
    final Parcel p = Parcel.obtain();
    TextUtils.writeToParcel(text.subSequence(0, cursorPosition), p, 0 /* flags */);
    TextUtils.writeToParcel(text.subSequence(cursorPosition, text.length()), p,
            0 /* flags */);
    final byte[] marshalled = p.marshall();
    p.unmarshall(marshalled, 0, marshalled.length);
    p.setDataPosition(0);
    mTextBefore = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
    mTextAfter = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(p);
    mExtractedText = null;
    p.recycle();
}
 
@Test
public void testParcelling() {
    PersistableBundle bundle = new PersistableBundle();
    bundle.putString("string", "string");
    bundle.putInt("int", 0);
    bundle.putLong("long", 0);
    bundle.putBoolean("boolean", true);
    // Can't use double or any array, as the instances would be different and equals() would fail.
    Parcel parcel = Parcel.obtain();
    parcel.writeValue(bundle);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    PersistableBundle parcelledBundle =
            (PersistableBundle) parcel.readValue(PersistableBundle.class.getClassLoader());

    assertEquals(bundle.toMap(1), parcelledBundle.toMap(1));
}
 
源代码7 项目: LLApp   文件: CacheUtils.java
private static byte[] parcelable2Bytes(Parcelable parcelable) {
    if (parcelable == null) return null;
    Parcel parcel = Parcel.obtain();
    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}
 
public static byte[] marshall(Parcelable parceable) {
    Parcel parcel = Parcel.obtain();
    parceable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}
 
public void onSaveInstanceState(Bundle outState) {
    Parcel outParcel = Parcel.obtain();
    outParcel.writeSparseBooleanArray(mCheckStates);
    final int numStates = mCheckedIdStates.size();
    outParcel.writeInt(numStates);
    for (int i=0; i<numStates; i++) {
        outParcel.writeLong(mCheckedIdStates.keyAt(i));
        outParcel.writeInt(mCheckedIdStates.valueAt(i));
    }
    byte[] states = outParcel.marshall();
    outState.putByteArray(SELECTED_ITEMS_KEY, states);
    outParcel.recycle();
}
 
源代码10 项目: BusWear   文件: WearBusTools.java
/**
 * Converts the Parcelable object to a byte[]
 *
 * @param parcelable
 * @return
 */
public static byte[] parcelToByte(@NonNull Parcelable parcelable) {
    Parcel parcel = Parcel.obtain();
    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}
 
源代码11 项目: deltachat-android   文件: ParcelUtil.java
public static byte[] serialize(Parcelable parceable) {
  Parcel parcel = Parcel.obtain();
  parceable.writeToParcel(parcel, 0);
  byte[] bytes = parcel.marshall();
  parcel.recycle();
  return bytes;
}
 
源代码12 项目: android_9.0.0_r45   文件: ProcessStatsService.java
public byte[] getCurrentStats(List<ParcelFileDescriptor> historic) {
    mAm.mContext.enforceCallingOrSelfPermission(
            android.Manifest.permission.PACKAGE_USAGE_STATS, null);
    Parcel current = Parcel.obtain();
    synchronized (mAm) {
        long now = SystemClock.uptimeMillis();
        mProcessStats.mTimePeriodEndRealtime = SystemClock.elapsedRealtime();
        mProcessStats.mTimePeriodEndUptime = now;
        mProcessStats.writeToParcel(current, now, 0);
    }
    mWriteLock.lock();
    try {
        if (historic != null) {
            ArrayList<String> files = getCommittedFiles(0, false, true);
            if (files != null) {
                for (int i=files.size()-1; i>=0; i--) {
                    try {
                        ParcelFileDescriptor pfd = ParcelFileDescriptor.open(
                                new File(files.get(i)), ParcelFileDescriptor.MODE_READ_ONLY);
                        historic.add(pfd);
                    } catch (IOException e) {
                        Slog.w(TAG, "Failure opening procstat file " + files.get(i), e);
                    }
                }
            }
        }
    } finally {
        mWriteLock.unlock();
    }
    return current.marshall();
}
 
private static byte[] marshall(final InputMethodSubtype[] array) {
    Parcel parcel = null;
    try {
        parcel = Parcel.obtain();
        parcel.writeTypedArray(array, 0);
        return parcel.marshall();
    } finally {
        if (parcel != null) {
            parcel.recycle();
            parcel = null;
        }
    }
}
 
源代码14 项目: AndroidAPS   文件: ServiceTransport.java
public ServiceTransport clone() {
    Parcel p = Parcel.obtain();
    Parcel p2 = Parcel.obtain();
    getMap().writeToParcel(p, 0);
    byte[] bytes = p.marshall();
    p2.unmarshall(bytes, 0, bytes.length);
    p2.setDataPosition(0);
    Bundle b = p2.readBundle();
    ServiceTransport rval = new ServiceTransport();
    rval.setMap(b);
    return rval;
}
 
源代码15 项目: OpenYOLO-Android   文件: IntentUtil.java
/**
 * Serializes the provided intent to a byte array.
 */
@NonNull
public static byte[] toBytes(@NonNull Intent intent) {
    require(intent, notNullValue());

    Parcel parcel = Parcel.obtain();
    parcel.writeParcelable(intent, 0);
    byte[] intentBytes = parcel.marshall();
    parcel.recycle();

    return intentBytes;
}
 
源代码16 项目: your-local-weather   文件: LocationsDbHelper.java
public static byte[] getAddressAsBytes(Address address) {
    if (address == null) {
        return null;
    }
    final Parcel parcel = Parcel.obtain();
    address.writeToParcel(parcel, 0);
    byte[] addressBytes = parcel.marshall();
    parcel.recycle();
    return addressBytes;
}
 
源代码17 项目: google-authenticator-android   文件: IntentUtils.java
/**
 * Marshalls a list of {@link Parcelable} into parcel bytes for adding into an {@link Intent}
 * extras. Workaround for bug: https://code.google.com/p/android/issues/detail?id=6822
 */
public static byte[] marshallParcelableList(ArrayList<? extends Parcelable> parcelables) {
  Parcel parcel = Parcel.obtain();
  parcel.writeList(parcelables);
  parcel.setDataPosition(0);
  return parcel.marshall();
}
 
源代码18 项目: Indic-Keyboard   文件: TextInfoCompatUtilsTests.java
private static byte[] marshall(final CharSequence cahrSequence) {
    Parcel parcel = null;
    try {
        parcel = Parcel.obtain();
        TextUtils.writeToParcel(cahrSequence, parcel, 0);
        return parcel.marshall();
    } finally {
        if (parcel != null) {
            parcel.recycle();
            parcel = null;
        }
    }
}
 
源代码19 项目: JobSchedulerCompat   文件: JobStore.java
private <T extends Parcelable> byte[] parcelableToByteArray(T parcelable) {
    Parcel parcel = Parcel.obtain();
    parcel.writeParcelable(parcelable, 0);
    byte[] data = parcel.marshall();
    parcel.recycle();
    return data;
}
 
源代码20 项目: AIMSICDL   文件: SamsungMulticlientRilExecutor.java
private byte[] marshallRequest(int token, byte data[]) {
    Parcel p = Parcel.obtain();
    p.writeInt(RIL_REQUEST_OEM_RAW);
    p.writeInt(token);
    p.writeByteArray(data);
    byte[] res = p.marshall();
    p.recycle();
    return res;
}
 
 方法所在类
 同类方法