Java Code Examples for android.os.Bundle#writeToParcel()

The following examples show how to use android.os.Bundle#writeToParcel() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: android_9.0.0_r45   File: CryptoHelper.java    License: Apache License 2.0 6 votes vote down vote up
@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 2
public void onNavigationEvent(int navigationEvent, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsCallback");
        _data.writeInt(navigationEvent);
        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(2, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

}
 
Example 3
public void extraCallback(String callbackName, Bundle args) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsCallback");
        _data.writeString(callbackName);
        if(args != null) {
            _data.writeInt(1);
            args.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(3, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

}
 
Example 4
public int postMessage(ICustomTabsCallback callback, String message, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    int _result;
    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsService");
        _data.writeStrongBinder(callback != null?callback.asBinder():null);
        _data.writeString(message);
        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(8, _data, _reply, 0);
        _reply.readException();
        _result = _reply.readInt();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

    return _result;
}
 
Example 5
Source Project: JWTDecode.Android   File: JWTTest.java    License: MIT License 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Test
public void shouldBeParceled() {
    JWT jwtOrigin = new JWT("eyJhbGciOiJIUzI1NiJ9.e30.K17vlwhE8FCMShdl1_65jEYqsQqBOVMPUU9IgG-QlTM");
    assertThat(jwtOrigin, is(notNullValue()));

    Bundle bundleOrigin = new Bundle();
    bundleOrigin.putParcelable("jwt", jwtOrigin);
    Parcel parcel = Parcel.obtain();
    bundleOrigin.writeToParcel(parcel, 0);

    //Extract bundle from parcel
    parcel.setDataPosition(0);
    Bundle bundleDest = parcel.readBundle(JWT.class.getClassLoader());
    JWT jwtDest = bundleDest.getParcelable("jwt");

    assertThat(jwtDest, is(notNullValue()));
    assertThat(bundleOrigin, is(not(bundleDest)));
    assertThat(jwtOrigin, is(not(jwtDest)));
    assertThat(jwtOrigin.toString(), is(jwtDest.toString()));
}
 
Example 6
public void onMessageChannelReady(ICustomTabsCallback callback, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    try {
        _data.writeInterfaceToken("android.support.customtabs.IPostMessageService");
        _data.writeStrongBinder(callback != null?callback.asBinder():null);
        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(2, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

}
 
Example 7
public void onMessageChannelReady(ICustomTabsCallback callback, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    try {
        _data.writeInterfaceToken("android.support.customtabs.IPostMessageService");
        _data.writeStrongBinder(callback != null?callback.asBinder():null);
        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(2, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

}
 
Example 8
public void extraCallback(String callbackName, Bundle args) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsCallback");
        _data.writeString(callbackName);
        if(args != null) {
            _data.writeInt(1);
            args.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(3, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

}
 
Example 9
public void onMessageChannelReady(ICustomTabsCallback callback, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    try {
        _data.writeInterfaceToken("android.support.customtabs.IPostMessageService");
        _data.writeStrongBinder(callback != null?callback.asBinder():null);
        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(2, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

}
 
Example 10
public void onNavigationEvent(int navigationEvent, Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsCallback");
        _data.writeInt(navigationEvent);
        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(2, _data, _reply, 0);
        _reply.readException();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

}
 
Example 11
@SuppressLint("ParcelClassLoader")
private Bundle createDeepCopy(Bundle original) {
    Parcel temp = Parcel.obtain();
    original.writeToParcel(temp, 0);
    temp.setDataPosition(0);
    Bundle copy = temp.readBundle();
    temp.recycle();
    return copy;
}
 
Example 12
private Bundle createDeepCopy(Bundle original) {
    Parcel temp = Parcel.obtain();
    original.writeToParcel(temp, 0);
    temp.setDataPosition(0);
    Bundle copy = temp.readBundle();
    temp.recycle();
    return copy;
}
 
Example 13
public Bundle extraCommand(String commandName, Bundle args) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    Bundle _result;
    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsService");
        _data.writeString(commandName);
        if(args != null) {
            _data.writeInt(1);
            args.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        this.mRemote.transact(5, _data, _reply, 0);
        _reply.readException();
        if(0 != _reply.readInt()) {
            _result = Bundle.CREATOR.createFromParcel(_reply);
        } else {
            _result = null;
        }
    } finally {
        _reply.recycle();
        _data.recycle();
    }

    return _result;
}
 
Example 14
public boolean mayLaunchUrl(ICustomTabsCallback callback, Uri url, Bundle extras, List<Bundle> otherLikelyBundles) throws RemoteException {
    Parcel _data = Parcel.obtain();
    Parcel _reply = Parcel.obtain();

    boolean _result;
    try {
        _data.writeInterfaceToken("android.support.customtabs.ICustomTabsService");
        _data.writeStrongBinder(callback != null?callback.asBinder():null);
        if(url != null) {
            _data.writeInt(1);
            url.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        if(extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }

        _data.writeTypedList(otherLikelyBundles);
        this.mRemote.transact(4, _data, _reply, 0);
        _reply.readException();
        _result = 0 != _reply.readInt();
    } finally {
        _reply.recycle();
        _data.recycle();
    }

    return _result;
}
 
Example 15
Source Project: letv   File: IMediaControllerCallback.java    License: Apache License 2.0 5 votes vote down vote up
public void onExtrasChanged(Bundle extras) throws RemoteException {
    Parcel _data = Parcel.obtain();
    try {
        _data.writeInterfaceToken(Stub.DESCRIPTOR);
        if (extras != null) {
            _data.writeInt(1);
            extras.writeToParcel(_data, 0);
        } else {
            _data.writeInt(0);
        }
        this.mRemote.transact(7, _data, null, 1);
    } finally {
        _data.recycle();
    }
}
 
Example 16
private Bundle parcelBundle(Bundle in) {
  Parcel parcel = Parcel.obtain();
  in.writeToParcel(parcel, 0);
  parcel.setDataPosition(0);
  Bundle out = Bundle.CREATOR.createFromParcel(parcel);

  out.setClassLoader(this.getClass().getClassLoader());
  // Sanity check that the robolectric shadows haven't done something tricky like give us
  // the same object back instead of a reconstructed bundle.
  assertThat(in, is(not(out)));
  return out;
}
 
Example 17
@Override
public void writeToParcel(Parcel dest, int flags) {
    Bundle bundle = new Bundle();
    bundle.putString(KEY_CLIENT_ID, this.cliendId);
    bundle.writeToParcel(dest, flags);
    this.accessTokenManager.writeToParcel(dest, flags);
}
 
Example 18
Source Project: JobSchedulerCompat   File: GcmIntentParser.java    License: MIT License 4 votes vote down vote up
private static Parcel toParcel(Bundle data) {
    Parcel serialized = Parcel.obtain();
    data.writeToParcel(serialized, 0);
    serialized.setDataPosition(0);
    return serialized;
}
 
Example 19
Source Project: Phantom   File: IntentUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 4.x系统或某些定制机Intent中的Serializable数据反序列化时没有使用intent.setExtrasClassLoader(pluginClassLoader)设置的classloader,
 * 而是使用的VMStack.getClosestUserClassLoader,这意味着4.x的系统插件Intent中包含有自定义的Serializable对象只能在插件的类中
 * 才能被反序列化。为了能在宿主类中合并Intent中的数据,在4.x系统上直接合并Intent的序列化对象mParcelledData。
 * Parcel的内存结构为:
 * ------------------------------------------------------------------------------
 * |   dataLen(int)   |   BUNDLE_MAGIC(int)   |    item_count(int)    |   data
 * ------------------------------------------------------------------------------
 *将Parcel2合并到Parcel1的步骤为:
 * 1.将Parcel2从data开始追加到Parcel1后面
 * 2.修改Parcel1的dataLen为合并都的数据长度
 * 3.修改Parcel1的item_count为合并后台的序列化元素个数
 *
 * 该方法是将intent中的数据合并到originIntent,再用合并后的数据填充intent
 */
private static void mergeExtras(Intent intent, Intent originIntent) {
    Bundle originBundle = originIntent.getExtras();
    if (null == originBundle) {
        return;
    }
    //序列化originIntent中的Bundle
    Parcel originParcel = Parcel.obtain();
    originBundle.writeToParcel(originParcel, 0);

    //序列化intent中的bundle
    Parcel intentParcel = Parcel.obtain();
    Bundle intentBundle = intent.getExtras();
    intentBundle.writeToParcel(intentParcel, 0);

    //读取intentParcel的前3个整数,分别为:数据长度,魔术数,保存的数据个数
    intentParcel.setDataPosition(0);
    int intentParcelLen = intentParcel.readInt();
    intentParcel.readInt();
    int intentParcelOffset = intentParcel.dataPosition();
    int start = intentParcel.dataPosition();
    int intentItemCount = intentParcel.readInt();
    int intSize = intentParcel.dataPosition() - start;

    //读取originParcel的前3个整数,分别为:数据长度,魔术数,保存的数据个数
    originParcel.setDataPosition(0);
    int originParcelLen = originParcel.readInt();
    originParcel.readInt();
    int originParcelOffset = originParcel.dataPosition();
    int originItemCount = originParcel.readInt();
    originParcel.setDataPosition(originParcel.dataPosition() - intSize);
    //修改originParcel的数据个数为合并后的数据个数
    originParcel.writeInt(intentItemCount + originItemCount);

    //将intentParcel追加到originParcel
    originParcel.setDataPosition(originParcelOffset + originParcelLen);
    intentParcel.setDataPosition(intentParcelLen + intentParcelOffset);
    originParcel.appendFrom(intentParcel, intentParcelOffset + intSize, intentParcelLen - intSize);
    originParcel.setDataPosition(0);
    //修改originParcel的数据长度为合并后的数据长度
    originParcel.writeInt(originParcelLen + intentParcelLen - intSize);
    originParcel.setDataPosition(0);

    //用合并后的的数据替换intent中的数据
    Bundle newBundle = new Bundle();
    newBundle.readFromParcel(originParcel);
    intent.replaceExtras(newBundle);
    originParcel.recycle();
    intentParcel.recycle();
}
 
Example 20
public static boolean isValidBundleSize(@NonNull Bundle bundle) {
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    return parcel.dataSize() < 500000;
}