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

The following examples show how to use android.os.Parcel#dataSize() . 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
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 2
@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 3
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 4
Source Project: xDrip   File: BitmapLoader.java    License: 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 5
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
/** @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 Project: FairEmail   File: Helper.java    License: 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
public static boolean isValidBundleSize(@NonNull Bundle bundle) {
    Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);
    return parcel.dataSize() < 500000;
}
 
Example 9
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 Project: delion   File: IntentUtils.java    License: 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 Project: AndroidChromium   File: IntentUtils.java    License: 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 Project: 365browser   File: IntentUtils.java    License: 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();
}