Java Code Examples for android.os.Parcel#marshall()
The following examples show how to use
android.os.Parcel#marshall() .
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: OpenWithActivity.java From dropbox-sdk-java with MIT License | 6 votes |
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)); }
Example 2
Source File: PersistableBundleTest.java From JobSchedulerCompat with MIT License | 6 votes |
@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)); }
Example 3
Source File: CryptoHelper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@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; }
Example 4
Source File: RichInputConnectionAndTextRangeTests.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
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(); }
Example 5
Source File: MarshalQueryableParcelable.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@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(); } }
Example 6
Source File: MasterSecret.java From Silence with GNU General Public License v3.0 | 6 votes |
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; }
Example 7
Source File: SamsungMulticlientRilExecutor.java From AIMSICDL with GNU General Public License v3.0 | 5 votes |
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; }
Example 8
Source File: CacheUtils.java From LLApp with Apache License 2.0 | 5 votes |
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; }
Example 9
Source File: JobStore.java From JobSchedulerCompat with MIT License | 5 votes |
private <T extends Parcelable> byte[] parcelableToByteArray(T parcelable) { Parcel parcel = Parcel.obtain(); parcel.writeParcelable(parcelable, 0); byte[] data = parcel.marshall(); parcel.recycle(); return data; }
Example 10
Source File: TextInfoCompatUtilsTests.java From Indic-Keyboard with Apache License 2.0 | 5 votes |
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; } } }
Example 11
Source File: IntentUtils.java From google-authenticator-android with Apache License 2.0 | 5 votes |
/** * 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(); }
Example 12
Source File: LocationsDbHelper.java From your-local-weather with GNU General Public License v3.0 | 5 votes |
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; }
Example 13
Source File: IntentUtil.java From OpenYOLO-Android with Apache License 2.0 | 5 votes |
/** * 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; }
Example 14
Source File: ServiceTransport.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
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; }
Example 15
Source File: InputMethodSubtypeArray.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
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; } } }
Example 16
Source File: ProcessStatsService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
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(); }
Example 17
Source File: ParcelUtil.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
public static byte[] serialize(Parcelable parceable) { Parcel parcel = Parcel.obtain(); parceable.writeToParcel(parcel, 0); byte[] bytes = parcel.marshall(); parcel.recycle(); return bytes; }
Example 18
Source File: WearBusTools.java From BusWear with Apache License 2.0 | 5 votes |
/** * 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; }
Example 19
Source File: ItemChoiceManager.java From Advanced_Android_Development with Apache License 2.0 | 5 votes |
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(); }
Example 20
Source File: AndroidLocationPlayServiceManager.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public static byte[] marshall(Parcelable parceable) { Parcel parcel = Parcel.obtain(); parceable.writeToParcel(parcel, 0); byte[] bytes = parcel.marshall(); parcel.recycle(); return bytes; }