/** {@inheritDoc} */ @Override public void writeToParcel(Parcel dest, int flags) { boolean[] validDataList = new boolean[MemberData.values().length]; int validDataPos = dest.dataPosition(); dest.writeBooleanArray(validDataList); // Placeholder for real array. if (mPluginId != null) { validDataList[MemberData.PLUGIN_ID.ordinal()] = true; dest.writeString(mPluginId); } if (mNetwork != null) { validDataList[MemberData.NETWORK.ordinal()] = true; dest.writeString(mNetwork); } if (mNetworkUrl != null) { validDataList[MemberData.NETWORK_URL.ordinal()] = true; dest.writeString(mNetworkUrl.toString()); } if (mIconUrl != null) { validDataList[MemberData.ICON_URL.ordinal()] = true; dest.writeString(mIconUrl.toString()); } if (mAuthType != null) { validDataList[MemberData.AUTH_TYPE.ordinal()] = true; dest.writeString(mAuthType); } if (mIconMime != null) { validDataList[MemberData.ICON_MIME.ordinal()] = true; dest.writeString(mIconMime); } if (mOrder != -1) { validDataList[MemberData.ORDER.ordinal()] = true; dest.writeInt(mOrder); } if (mName != null) { validDataList[MemberData.NAME.ordinal()] = true; dest.writeString(mName); } if (mCapabilities != null) { dest.writeInt(mCapabilities.size()); for (IdentityCapability cap : mCapabilities) { cap.writeToParcel(dest, 0); } } else { dest.writeInt(0); } int currentPos = dest.dataPosition(); dest.setDataPosition(validDataPos); dest.writeBooleanArray(validDataList); // Real array. dest.setDataPosition(currentPos); }
/** * * Check a parcel containing metadata is well formed. The header is checked as well as the * individual records format. However, the data inside the record is not checked because we do * lazy access (we check/unmarshall only data the user asks for.) * * <p>Format of a metadata parcel: * * <pre> * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | metadata total size | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | 'M' | 'E' | 'T' | 'A' | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * | .... metadata records .... | * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * </pre> * * @param parcel With the serialized data. Metadata keeps a reference on it to access it later on. * The caller should not modify the parcel after this call (and not call recycle on it.) * @return false if an error occurred. {@hide} */ public boolean parse(Parcel parcel) { if (parcel.dataAvail() < kMetaHeaderSize) { Log.e(TAG, "Not enough data " + parcel.dataAvail()); return false; } final int pin = parcel.dataPosition(); // to roll back in case of errors. final int size = parcel.readInt(); // The extra kInt32Size below is to account for the int32 'size' just read. if (parcel.dataAvail() + kInt32Size < size || size < kMetaHeaderSize) { Log.e(TAG, "Bad size " + size + " avail " + parcel.dataAvail() + " position " + pin); parcel.setDataPosition(pin); return false; } // Checks if the 'M' 'E' 'T' 'A' marker is present. final int kShouldBeMetaMarker = parcel.readInt(); if (kShouldBeMetaMarker != kMetaMarker) { Log.e(TAG, "Marker missing " + Integer.toHexString(kShouldBeMetaMarker)); parcel.setDataPosition(pin); return false; } // Scan the records to collect metadata ids and offsets. if (!scanAllRecords(parcel, size - kMetaHeaderSize)) { parcel.setDataPosition(pin); return false; } mParcel = parcel; return true; }
@DSSafe(DSCat.SAFE_OTHERS) @DSGenerator( tool_name = "Doppelganger", tool_version = "2.0", generated_on = "2013-12-30 12:34:55.755 -0500", hash_original_method = "8E491D44C01D53B45589AFC0F51C5901", hash_generated_method = "F2CB1E3ED7E70E38911746D19D4C2C4E") public ParceledListSlice createFromParcel(Parcel in) { final int numItems = in.readInt(); final boolean lastSlice = in.readInt() == 1; if (numItems > 0) { final int parcelSize = in.readInt(); // Advance within this Parcel int offset = in.dataPosition(); in.setDataPosition(offset + parcelSize); Parcel p = Parcel.obtain(); p.setDataPosition(0); p.appendFrom(in, offset, parcelSize); p.setDataPosition(0); return new ParceledListSlice(p, numItems, lastSlice); } else { return new ParceledListSlice(); } }
public static Parcelable readValueFromDisk(File file) { try { FileInputStream istream = new FileInputStream(file); // Read file into byte array byte[] dataWritten = new byte[(int) file.length()]; BufferedInputStream bistream = new BufferedInputStream(istream); bistream.read(dataWritten); bistream.close(); // Create parcel with cached data Parcel parcelIn = Parcel.obtain(); parcelIn.unmarshall(dataWritten, 0, dataWritten.length); parcelIn.setDataPosition(0); // Read class name from parcel and use the class loader to read parcel String className = parcelIn.readString(); // In case this sometimes hits a null value if (className == null) { return null; } Class<?> clazz = Class.forName(className); return parcelIn.readParcelable(clazz.getClassLoader()); } catch (IOException ex) { ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
@MediumTest public void testWebView() throws Exception { final RemoteViewsActivity activity = getActivity(); RemoteViews orig = new RemoteViews("com.android.frameworktest", R.layout.remote_view_test_bad_2); Parcel p = Parcel.obtain(); orig.writeToParcel(p, 0); p.setDataPosition(0); RemoteViews r = RemoteViews.CREATOR.createFromParcel(p); ViewGroup parent = (ViewGroup) activity.findViewById(R.id.parent); boolean exceptionThrown = false; View result = null; try { result = r.apply(activity, parent); } catch (InflateException e) { exceptionThrown = true; } p.recycle(); assertTrue("WebView allowed to be inflated", exceptionThrown); assertNull("WebView allowed to be inflated", result); }
public void testSavedState() throws InterruptedException { MockLayoutManager mlm = new MockLayoutManager(); mRecyclerView.setLayoutManager(mlm); mRecyclerView.setAdapter(new MockAdapter(3)); layout(); Parcelable savedState = mRecyclerView.onSaveInstanceState(); // we append a suffix to the parcelable to test out of bounds String parcelSuffix = UUID.randomUUID().toString(); Parcel parcel = Parcel.obtain(); savedState.writeToParcel(parcel, 0); parcel.writeString(parcelSuffix); // reset for reading parcel.setDataPosition(0); // re-create savedState = RecyclerView.SavedState.CREATOR.createFromParcel(parcel); RecyclerView restored = new RecyclerView(mContext); MockLayoutManager mlmRestored = new MockLayoutManager(); restored.setLayoutManager(mlmRestored); restored.setAdapter(new MockAdapter(3)); restored.onRestoreInstanceState(savedState); assertEquals("Parcel reading should not go out of bounds", parcelSuffix, parcel.readString()); assertEquals("When unmarshalling, all of the parcel should be read", 0, parcel.dataAvail()); assertEquals( "uuid in layout manager should be preserved properly", mlm.mUuid, mlmRestored.mUuid); assertNotSame( "stateless parameter should not be preserved", mlm.mLayoutCount, mlmRestored.mLayoutCount); layout(); }
/** * Sets alert in AlarmManger and StatusBar. This is what will actually launch the alert when the * alarm triggers. * * @param alarm Alarm. * @param atTimeInMillis milliseconds since epoch */ private static void enableAlert(Context context, final Alarm alarm, final long atTimeInMillis) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(ALARM_ALERT_ACTION); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // XXX: This is a slight hack to avoid an exception in the remote // AlarmManagerService process. The AlarmManager adds extra data to // this Intent which causes it to inflate. Since the remote process // does not know about the Alarm class, it throws a // ClassNotFoundException. // // To avoid this, we marshall the data ourselves and then parcel a plain // byte[] array. The AlarmReceiver class knows to build the Alarm // object from the byte[] array. Parcel out = Parcel.obtain(); alarm.writeToParcel(out, 0); out.setDataPosition(0); intent.putExtra(ALARM_RAW_DATA, out.marshall()); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.RTC, atTimeInMillis, sender); // am.set(4, atTimeInMillis, sender); // setStatusBarIcon(context, true); Calendar c = Calendar.getInstance(); c.setTimeInMillis(atTimeInMillis); String timeString = formatDayAndTime(context, c); saveNextAlarm(context, timeString); }
@MediumTest public void testGood() throws Exception { final RemoteViewsActivity activity = getActivity(); RemoteViews orig = new RemoteViews("com.android.frameworktest", R.layout.remote_view_test_good); Parcel p = Parcel.obtain(); orig.writeToParcel(p, 0); p.setDataPosition(0); RemoteViews r = RemoteViews.CREATOR.createFromParcel(p); ViewGroup parent = (ViewGroup) activity.findViewById(R.id.parent); View result = r.apply(activity, parent); p.recycle(); assertTrue("LinearLayout not inflated", result.findViewById(R.id.linear) != null); assertTrue("TextView not inflated", result.findViewById(R.id.text) != null); assertTrue("ImageView not inflated", result.findViewById(R.id.image) != null); assertTrue("FrameLayout not inflated", result.findViewById(R.id.frame) != null); assertTrue("RelateiveLayout not inflated", result.findViewById(R.id.relative) != null); assertTrue("AbsoluteLayout not inflated", result.findViewById(R.id.absolute) != null); assertTrue("ProgressBar not inflated", result.findViewById(R.id.progress) != null); assertTrue("ImageButton not inflated", result.findViewById(R.id.image_button) != null); assertTrue("Button not inflated", result.findViewById(R.id.button) != null); }
public void testWriteMessengerOrNullToParcel() { Parcel parcelWithMessenger = Parcel.obtain(); Messenger.writeMessengerOrNullToParcel(mMessenger, parcelWithMessenger); parcelWithMessenger.setDataPosition(0); Messenger messenger = Messenger.readMessengerOrNullFromParcel(parcelWithMessenger); assertNotNull(messenger); assertTrue(messenger.equals(mMessenger)); parcelWithMessenger.recycle(); Parcel parcelWithNull = Parcel.obtain(); Messenger.writeMessengerOrNullToParcel(null, parcelWithNull); parcelWithNull.setDataPosition(0); messenger = Messenger.readMessengerOrNullFromParcel(parcelWithNull); assertNull(messenger); parcelWithNull.recycle(); }
/** * Constructor by copy * * @param callInfo */ public SipCallSession(SipCallSession callInfo) { Parcel p = Parcel.obtain(); callInfo.writeToParcel(p, 0); p.setDataPosition(0); initFromParcel(p); p.recycle(); }
public void testSavedStateWithStatelessLayoutManager() throws InterruptedException { mRecyclerView.setLayoutManager( new MockLayoutManager() { @Override public Parcelable onSaveInstanceState() { return null; } }); mRecyclerView.setAdapter(new MockAdapter(3)); Parcel parcel = Parcel.obtain(); String parcelSuffix = UUID.randomUUID().toString(); Parcelable savedState = mRecyclerView.onSaveInstanceState(); savedState.writeToParcel(parcel, 0); parcel.writeString(parcelSuffix); // reset position for reading parcel.setDataPosition(0); RecyclerView restored = new RecyclerView(mContext); restored.setLayoutManager(new MockLayoutManager()); mRecyclerView.setAdapter(new MockAdapter(3)); // restore savedState = RecyclerView.SavedState.CREATOR.createFromParcel(parcel); restored.onRestoreInstanceState(savedState); assertEquals("Parcel reading should not go out of bounds", parcelSuffix, parcel.readString()); assertEquals("When unmarshalling, all of the parcel should be read", 0, parcel.dataAvail()); }
public void testWriteToParcel() { Parcel parcel = Parcel.obtain(); mMessenger.writeToParcel(parcel, 0); parcel.setDataPosition(0); Messenger messenger = Messenger.CREATOR.createFromParcel(parcel); assertTrue(messenger.equals(mMessenger)); parcel.recycle(); }
public static nn h(byte[] var0) { Parcel var1 = Parcel.obtain(); var1.unmarshall(var0, 0, var0.length); var1.setDataPosition(0); nn var2 = CREATOR.cN(var1); var1.recycle(); return var2; }
/** * * Go over all the records, collecting metadata keys and records' type field offset in the * Parcel. These are stored in mKeyToPosMap for latter retrieval. Format of a metadata record: * * <pre> * 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | record size | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | metadata key | // TITLE * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | metadata type | // STRING_VAL * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | | * | .... metadata payload .... | * | | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * </pre> * * @param parcel With the serialized records. * @param bytesLeft How many bytes in the parcel should be processed. * @return false if an error occurred during parsing. */ private boolean scanAllRecords(Parcel parcel, int bytesLeft) { int recCount = 0; boolean error = false; mKeyToPosMap.clear(); while (bytesLeft > kRecordHeaderSize) { final int start = parcel.dataPosition(); // Check the size. final int size = parcel.readInt(); if (size <= kRecordHeaderSize) { // at least 1 byte should be present. Log.e(TAG, "Record is too short"); error = true; break; } // Check the metadata key. final int metadataId = parcel.readInt(); if (!checkMetadataId(metadataId)) { error = true; break; } // Store the record offset which points to the type // field so we can later on read/unmarshall the record // payload. if (mKeyToPosMap.containsKey(metadataId)) { Log.e(TAG, "Duplicate metadata ID found"); error = true; break; } mKeyToPosMap.put(metadataId, parcel.dataPosition()); // Check the metadata type. final int metadataType = parcel.readInt(); if (metadataType <= 0 || metadataType > LAST_TYPE) { Log.e(TAG, "Invalid metadata type " + metadataType); error = true; break; } // Skip to the next one. parcel.setDataPosition(start + size); bytesLeft -= size; ++recCount; } if (0 != bytesLeft || error) { Log.e(TAG, "Ran out of data or error on record " + recCount); mKeyToPosMap.clear(); return false; } else { return true; } }
@MediumTest public void testParcelable() throws Exception { ServiceResourceIdentifier sri = new ServiceResourceIdentifier(); sri.setIdentifier(new URI("http://alec.societies.org")); sri.setServiceInstanceIdentifier("alecBundle123"); ServiceImplementation serviceImp = new ServiceImplementation(); serviceImp.setServiceClient("TestClient"); serviceImp.setServiceNameSpace("http://soceities.org/test/namespace"); serviceImp.setServiceProvider("TestProvider"); serviceImp.setServiceVersion("V0.1.1b"); ServiceInstance serInstance = new ServiceInstance(); serInstance.setCssJid("john.societies.local"); serInstance.setFullJid("[email protected]/android"); serInstance.setParentJid("parent.societies.local"); serInstance.setXMPPNode("john.societies.local"); serInstance.setParentIdentifier(sri); serInstance.setServiceImpl(serviceImp); assertEquals(0, serviceImp.describeContents()); Parcel parcel = Parcel.obtain(); serInstance.writeToParcel(parcel, 0); // done writing, now reset parcel for reading parcel.setDataPosition(0); // finish round trip ServiceInstance createFromParcel = ServiceInstance.CREATOR.createFromParcel(parcel); assertEquals(serInstance.getCssJid(), createFromParcel.getCssJid()); assertEquals(serInstance.getFullJid(), createFromParcel.getFullJid()); assertEquals(serInstance.getParentJid(), createFromParcel.getParentJid()); assertEquals(serInstance.getXMPPNode(), createFromParcel.getXMPPNode()); // CAN'T COMPARE SRI'S DIRECTLY, MUST COMPARE EACH PROPERTY assertEquals( serInstance.getParentIdentifier().getServiceInstanceIdentifier(), createFromParcel.getParentIdentifier().getServiceInstanceIdentifier()); assertEquals( serInstance.getParentIdentifier().getIdentifier(), createFromParcel.getParentIdentifier().getIdentifier()); // CAN'T COMPARE ServiceImpl'S DIRECTLY, MUST COMPARE EACH PROPERTY assertEquals( serInstance.getServiceImpl().getServiceClient(), createFromParcel.getServiceImpl().getServiceClient()); assertEquals( serInstance.getServiceImpl().getServiceNameSpace(), createFromParcel.getServiceImpl().getServiceNameSpace()); assertEquals( serInstance.getServiceImpl().getServiceProvider(), createFromParcel.getServiceImpl().getServiceProvider()); assertEquals( serInstance.getServiceImpl().getServiceVersion(), createFromParcel.getServiceImpl().getServiceVersion()); }
@Override protected void processUnsolicited(Parcel p) { Object ret; int dataPosition = p.dataPosition(); // save off position within the Parcel int response = p.readInt(); switch (response) { case RIL_UNSOL_RIL_CONNECTED: // Fix for NV/RUIM setting on CDMA SIM devices // skip getcdmascriptionsource as if qualcomm handles it in the ril binary ret = responseInts(p); setRadioPower(false, null); setPreferredNetworkType(mPreferredNetworkType, null); int cdmaSubscription = Settings.Global.getInt( mContext.getContentResolver(), Settings.Global.CDMA_SUBSCRIPTION_MODE, -1); if (cdmaSubscription != -1) { setCdmaSubscriptionSource(mCdmaSubscription, null); } setCellInfoListRate(Integer.MAX_VALUE, null); notifyRegistrantsRilConnectionChanged(((int[]) ret)[0]); break; case RIL_UNSOL_NITZ_TIME_RECEIVED: handleNitzTimeReceived(p); break; // SAMSUNG STATES case SamsungExynos4RIL.RIL_UNSOL_AM: ret = responseString(p); String amString = (String) ret; Rlog.d(RILJ_LOG_TAG, "Executing AM: " + amString); try { Runtime.getRuntime().exec("am " + amString); } catch (IOException e) { e.printStackTrace(); Rlog.e(RILJ_LOG_TAG, "am " + amString + " could not be executed."); } break; case SamsungExynos4RIL.RIL_UNSOL_RESPONSE_HANDOVER: ret = responseVoid(p); break; case 1036: ret = responseVoid(p); break; case SamsungExynos4RIL.RIL_UNSOL_WB_AMR_STATE: ret = responseInts(p); setWbAmr(((int[]) ret)[0]); break; default: // Rewind the Parcel p.setDataPosition(dataPosition); // Forward responses that we are not overriding to the super class super.processUnsolicited(p); return; } }
@Test public void test() throws Exception { String schemaName = "TestSchema"; int schemaVersion = 10; TypedID target = new TypedID(TypedID.Types.THING, "thing1234"); TypedID issuer = new TypedID(TypedID.Types.USER, "user1234"); List<Action> actions = new ArrayList<Action>(); SetColor setColor = new SetColor(128, 0, 255); SetColorTemperature setColorTemperature = new SetColorTemperature(25); actions.add(setColor); actions.add(setColorTemperature); SetColorResult setColorResult = new SetColorResult(true); SetColorTemperatureResult setColorTemperatureResult = new SetColorTemperatureResult(false); String commandID = "command1234"; CommandState commandState = CommandState.DELIVERED; String firedByTriggerID = "trigger1234"; Long created = 123456789L; Long modified = 987654321L; Command command = new Command(schemaName, schemaVersion, target, issuer, actions); command.addActionResult(setColorResult); command.addActionResult(setColorTemperatureResult); command.setCommandID(commandID); command.setCommandState(commandState); command.setFiredByTriggerID(firedByTriggerID); command.setCreated(created); command.setModified(modified); Parcel parcel = Parcel.obtain(); command.writeToParcel(parcel, 0); parcel.setDataPosition(0); Command deserializedCommand = Command.CREATOR.createFromParcel(parcel); Assert.assertEquals(schemaName, deserializedCommand.getSchemaName()); Assert.assertEquals(schemaVersion, deserializedCommand.getSchemaVersion()); Assert.assertEquals(target, deserializedCommand.getTargetID()); Assert.assertEquals(issuer, deserializedCommand.getIssuerID()); Assert.assertEquals(2, deserializedCommand.getActions().size()); Assert.assertArrayEquals( setColor.color, ((SetColor) deserializedCommand.getActions().get(0)).color); Assert.assertEquals( setColorTemperature.colorTemperature, ((SetColorTemperature) deserializedCommand.getActions().get(1)).colorTemperature); Assert.assertEquals( setColorResult.succeeded, ((SetColorResult) deserializedCommand.getActionResults().get(0)).succeeded); Assert.assertEquals( setColorTemperatureResult.succeeded, ((SetColorTemperatureResult) deserializedCommand.getActionResults().get(1)).succeeded); Assert.assertEquals(commandID, deserializedCommand.getCommandID()); Assert.assertEquals(commandState, deserializedCommand.getCommandState()); Assert.assertEquals(firedByTriggerID, deserializedCommand.getFiredByTriggerID()); Assert.assertEquals(created, deserializedCommand.getCreated()); Assert.assertEquals(modified, deserializedCommand.getModified()); }
/** * Check the type of the data match what is expected. */ private void checkType(final int key, final int expectedType) { final int pos = mKeyToPosMap.get(key); mParcel.setDataPosition(pos); final int type = mParcel.readInt(); if (type != expectedType) { throw new IllegalStateException("Wrong type " + expectedType + " but got " + type); } }
void readParcel() { logReadInfo("before reading"); p.setDataPosition(0); logReadInfo("byte = " + p.readByte()); logReadInfo("int = " + p.readInt()); logReadInfo("long = " + p.readLong()); logReadInfo("float = " + p.readFloat()); logReadInfo("double = " + p.readDouble()); logReadInfo("string = " + p.readString()); }
// orphaned legacy method public ParceledListSlice createFromParcel(Parcel in) { final int numItems = in.readInt(); final boolean lastSlice = in.readInt() == 1; if (numItems > 0) { final int parcelSize = in.readInt(); int offset = in.dataPosition(); in.setDataPosition(offset + parcelSize); Parcel p = Parcel.obtain(); p.setDataPosition(0); p.appendFrom(in, offset, parcelSize); p.setDataPosition(0); return new ParceledListSlice(p, numItems, lastSlice); } else { return new ParceledListSlice(); } }
@Test public void parcelEquality() { final Parcel parcel = Parcel.obtain(); mPaymentMethod.writeToParcel(parcel, 0); parcel.setDataPosition(0); final ImmutablePaymentMethodImpl paymentMethod = ImmutablePaymentMethodImpl.CREATOR.createFromParcel(parcel); assertNotNull(paymentMethod); assertEquals(paymentMethod, mPaymentMethod); }
@Override public void writeToParcel(Parcel out, int flags) { if (callInfo != null) { out.writeInt(dialogSize); for (int i = 0; i < dialogSize; i++) { String[] callPull = callInfo.get(i); out.writeStringArray(callPull); } out.setDataPosition(0); } }
private static BookmarkNode parcelNode(BookmarkNode node) { Parcel output = Parcel.obtain(); Parcel input = Parcel.obtain(); node.writeToParcel(output, 0); byte[] bytes = output.marshall(); input.unmarshall(bytes, 0, bytes.length); input.setDataPosition(0); return BookmarkNode.CREATOR.createFromParcel(input); }
@Test public void testParcelable() { Parcel parcel = Parcel.obtain(); movie.writeToParcel(parcel, movie.describeContents()); parcel.setDataPosition(0); Movie movieFromParcel = Movie.CREATOR.createFromParcel(parcel); assertEquals(movie, movieFromParcel); }
public void testWriteToParcel() { Parcel p = Parcel.obtain(); try { URLSpan urlSpan = new URLSpan(TEST_URL); urlSpan.writeToParcel(p, 0); p.setDataPosition(0); URLSpan u = new URLSpan(p); assertEquals(TEST_URL, u.getURL()); } finally { p.recycle(); } }
public void testTypeParceling() { WaypointCreationRequest original = WaypointCreationRequest.DEFAULT_WAYPOINT; Parcel p = Parcel.obtain(); original.writeToParcel(p, 0); p.setDataPosition(0); WaypointCreationRequest copy = WaypointCreationRequest.CREATOR.createFromParcel(p); assertEquals(original.getType(), copy.getType()); assertFalse(copy.isTrackStatistics()); assertNull(copy.getName()); assertNull(copy.getDescription()); assertNull(copy.getIconUrl()); }
@Test public void writeAndReadFromParcel() { Parcel parcel = Parcel.obtain(); message.writeToParcel(parcel, 0); // Reset parcel for reading parcel.setDataPosition(0); VehicleMessage createdFromParcel = VehicleMessage.CREATOR.createFromParcel(parcel); assertThat(createdFromParcel, instanceOf(CanMessage.class)); assertEquals(message, createdFromParcel); }
@SuppressWarnings("Recycle") protected void readSyncState() throws ContactsStorageException { @Cleanup("recycle") Parcel parcel = Parcel.obtain(); byte[] raw = getSyncState(); syncState.clear(); if (raw != null) { parcel.unmarshall(raw, 0, raw.length); parcel.setDataPosition(0); syncState.putAll(parcel.readBundle()); } }
public void testConstructor() { URLSpan urlSpan = new URLSpan(TEST_URL); final Parcel p = Parcel.obtain(); try { urlSpan.writeToParcel(p, 0); p.setDataPosition(0); new URLSpan(p); } finally { p.recycle(); } }
public static <T extends Parcelable> List<T> bytesToParcelableList(byte[] data, Class<T> cls) { if (data == null || data.length == 0) return null; Parcel in = Parcel.obtain(); in.unmarshall(data, 0, data.length); in.setDataPosition(0); List<T> t; t = readListFromParcel(in, cls); in.recycle(); return t; }