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

The following examples show how to use android.os.Parcel#dataSize() . 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: BitmapLoader.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static int getBundleSizeInBytes(Bundle bundle) {
    final Parcel parcel = Parcel.obtain();
    parcel.writeBundle(bundle);
    final int size = parcel.dataSize();
    parcel.recycle();
    return size;
}
 
Example 2
Source File: AssistStructure.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
boolean writeToParcelInner(AssistStructure as, Parcel out) {
    if (mNumWindows == 0) {
        return false;
    }
    if (DEBUG_PARCEL) Log.d(TAG, "Creating PooledStringWriter @ " + out.dataPosition());
    PooledStringWriter pwriter = new PooledStringWriter(out);
    while (writeNextEntryToParcel(as, out, pwriter)) {
        // If the parcel is above the IPC limit, then we are getting too
        // large for a single IPC so stop here and let the caller come back when it
        // is ready for more.
        if (out.dataSize() > IBinder.MAX_IPC_SIZE) {
            if (DEBUG_PARCEL) Log.d(TAG, "Assist data size is " + out.dataSize()
                    + " @ pos " + out.dataPosition() + "; returning partial result");
            out.writeInt(0);
            out.writeStrongBinder(this);
            if (DEBUG_PARCEL) Log.d(TAG, "Finishing PooledStringWriter @ "
                    + out.dataPosition() + ", size " + pwriter.getStringCount());
            pwriter.finish();
            return true;
        }
    }
    if (DEBUG_PARCEL) Log.d(TAG, "Finishing PooledStringWriter @ "
            + out.dataPosition() + ", size " + pwriter.getStringCount());
    pwriter.finish();
    mViewStack.clear();
    return false;
}
 
Example 3
Source File: Bundler.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@NonNull public Bundle end() {
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    int size = parcel.dataSize();
    Logger.e(size);
    if (size > 500000) {
        bundle.clear();
    }
    return get();
}
 
Example 4
Source File: BundleHelper.java    From OpenHub with GNU General Public License v3.0 5 votes vote down vote up
public Bundle build(){
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    if (parcel.dataSize() > 512 * 1024) {
        bundle.clear();
        throw new IllegalArgumentException("bundle data is too large, please reduce date size to avoid Exception");
    }
    return bundle;
}
 
Example 5
Source File: BitmapLoader.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static int getBundleSizeInBytes(Bundle bundle) {
    final Parcel parcel = Parcel.obtain();
    parcel.writeBundle(bundle);
    final int size = parcel.dataSize();
    parcel.recycle();
    return size;
}
 
Example 6
Source File: DefaultJobValidator.java    From firebase-jobdispatcher-android with Apache License 2.0 5 votes vote down vote up
/** @see #MAX_EXTRAS_SIZE_BYTES */
private static int measureBundleSize(Bundle extras) {
  Parcel p = Parcel.obtain();
  extras.writeToParcel(p, 0);
  int sizeInBytes = p.dataSize();
  p.recycle();

  return sizeInBytes;
}
 
Example 7
Source File: Helper.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
static int getSize(Bundle bundle) {
    Parcel p = Parcel.obtain();
    bundle.writeToParcel(p, 0);
    return p.dataSize();
}
 
Example 8
Source File: Bundler.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isValidBundleSize(@NonNull Bundle bundle) {
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    return parcel.dataSize() < 500000;
}
 
Example 9
Source File: LocalRouterServiceTests.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void corruptParcel(int testWith){
	Parcel p =  Parcel.obtain();
	p.writeInt(4);
	p.writeLong(System.currentTimeMillis());
	p.writeParcelable(new ComponentName(mContext, "test"), 0);
	p.writeParcelable(new Intent(), 0);
	p.setDataPosition(0);
	
	SdlRouterService.LocalRouterService local = getLocalRouterService(testWith, p);

	assertNotNull(local);
	assertNull(local.launchIntent);
	assertNull(local.name);
	
	p.recycle();
	//---------------------------------------------------------------------------
	
	p =  Parcel.obtain();
	p.writeInt(4);
	p.writeLong(System.currentTimeMillis());
	p.writeParcelable(null,0);
	p.writeParcelable(null,0);
	p.setDataPosition(0);
	
	local = getLocalRouterService(testWith, p);

	assertNotNull(local);
	assertNull(local.launchIntent);
	assertNull(local.name);
	
	p.recycle();
	//---------------------------------------------------------------------------
	
	p =  Parcel.obtain();
	p.writeInt(4);
	p.writeLong(System.currentTimeMillis());
	p.setDataPosition(0);
	
	local = getLocalRouterService(testWith, p);

	assertNotNull(local);
	assertNull(local.launchIntent);
	assertNull(local.name);
	
	p.recycle();
	
	//---------------------------------------------------------------------------
	local = null;
	p = null;
	
	p =  Parcel.obtain();
	p.writeInt(4);
	p.writeLong(System.currentTimeMillis());
	int space = p.dataSize();
	p.writeParcelable(new Intent(), 0);
	p.writeParcelable(new ComponentName(mContext, "test"), 0);
	p.setDataPosition(0);
	
	byte[] raw = p.marshall();
	for(;space<raw.length;space++){
		raw[space] = 0x00;
	}
	p.recycle();
	p = Parcel.obtain();
	p.unmarshall(raw, 0, raw.length);
	p.setDataPosition(0);
	
	
	local = getLocalRouterService(testWith, p);

	assertNotNull(local);
	assertNull(local.launchIntent);
	assertNull(local.name);
	
	p.recycle();
	
}
 
Example 10
Source File: IntentUtils.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Returns how large the Intent will be in Parcel form, which is helpful for gauging whether
 * Android will deliver the Intent instead of throwing a TransactionTooLargeException.
 *
 * @param intent Intent to get the size of.
 * @return Number of bytes required to parcel the Intent.
 */
public static int getParceledIntentSize(Intent intent) {
    Parcel parcel = Parcel.obtain();
    intent.writeToParcel(parcel, 0);
    return parcel.dataSize();
}
 
Example 11
Source File: IntentUtils.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Returns how large the Intent will be in Parcel form, which is helpful for gauging whether
 * Android will deliver the Intent instead of throwing a TransactionTooLargeException.
 *
 * @param intent Intent to get the size of.
 * @return Number of bytes required to parcel the Intent.
 */
public static int getParceledIntentSize(Intent intent) {
    Parcel parcel = Parcel.obtain();
    intent.writeToParcel(parcel, 0);
    return parcel.dataSize();
}
 
Example 12
Source File: IntentUtils.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Returns how large the Intent will be in Parcel form, which is helpful for gauging whether
 * Android will deliver the Intent instead of throwing a TransactionTooLargeException.
 *
 * @param intent Intent to get the size of.
 * @return Number of bytes required to parcel the Intent.
 */
public static int getParceledIntentSize(Intent intent) {
    Parcel parcel = Parcel.obtain();
    intent.writeToParcel(parcel, 0);
    return parcel.dataSize();
}