/** * Creates a new {@link AudioRoutesInfo} to be used for updating the Bluetooth audio route. * * @param bluetoothDeviceName the name of the Bluetooth device or null to indicate that the * already-existing Bluetooth A2DP device should be removed */ private static AudioRoutesInfo newAudioRouteInfo(@Nullable String bluetoothDeviceName) { Parcel p = Parcel.obtain(); TextUtils.writeToParcel(bluetoothDeviceName, p, /* parcelableFlags= */ 0); p.setDataPosition(0); return AudioRoutesInfo.CREATOR.createFromParcel(p); }
private static PackageInfo newPackageInfo(PackageInfo orig) { Parcel parcel = Parcel.obtain(); orig.writeToParcel(parcel, 0); parcel.setDataPosition(0); return PackageInfo.CREATOR.createFromParcel(parcel); }
public void onClickLongParcel(final View view) { final long start = System.currentTimeMillis(); final LongParcel longParcel = new LongParcel(); for (int i = 0; i < TIMES; i++) { Parcel p = Parcel.obtain(); longParcel.writeToParcel(p, 0); LongParcel longParcelCopy = new LongParcel(p); } infoAppend("Long Parcel and Alloc [and GC]", start); }
public void onClickIntParcel(final View view) { final long start = System.currentTimeMillis(); final IntParcel intParcel = new IntParcel(); for (int i = 0; i < TIMES; i++) { Parcel p = Parcel.obtain(); intParcel.writeToParcel(p, 0); IntParcel intParcelCopy = new IntParcel(p); } infoAppend("Int Parcel and Alloc [and GC]", start); }
@Before public void setup() { parcel = Parcel.obtain(); }
/** Returns a copy of {@code automaticZenRule}. */ private AutomaticZenRule copyAutomaticZenRule(AutomaticZenRule automaticZenRule) { Parcel parcel = Parcel.obtain(); try { automaticZenRule.writeToParcel(parcel, /* flags= */ 0); parcel.setDataPosition(0); return new AutomaticZenRule(parcel); } finally { parcel.recycle(); } }
private static UserHandle newUserHandle(int uid) { Parcel userParcel = Parcel.obtain(); userParcel.writeInt(uid); userParcel.setDataPosition(0); return new UserHandle(userParcel); } }
@Test @Config(minSdk = Build.VERSION_CODES.O_MR1) public void writeToParcel_shouldNotCrash() throws Exception { try (SharedMemory sharedMemory = SharedMemory.create("foo", 4)) { ByteBuffer fooBuf = sharedMemory.mapReadWrite(); fooBuf.putInt(1234); Parcel parcel = Parcel.obtain(); parcel.writeParcelable(sharedMemory, 0); } } }
private StorageVolume buildAndGetStorageVolume(File file, String description) { Parcel parcel = Parcel.obtain(); parcel.writeInt(0); parcel.setDataPosition(0); UserHandle userHandle = new UserHandle(parcel); StorageVolumeBuilder storageVolumeBuilder = new StorageVolumeBuilder("volume", file, description, userHandle, "mounted"); return storageVolumeBuilder.build(); } }
@Test public void testEventMessageParcelable() { EventMessage eventMessage = new EventMessage("urn:test", "123", 3000, 1000403, new byte[] {0, 1, 2, 3, 4}, 1000); // Write to parcel. Parcel parcel = Parcel.obtain(); eventMessage.writeToParcel(parcel, 0); // Create from parcel. parcel.setDataPosition(0); EventMessage fromParcelEventMessage = EventMessage.CREATOR.createFromParcel(parcel); // Assert equals. assertThat(fromParcelEventMessage).isEqualTo(eventMessage); }
@Test public void shouldBeParcelable() throws Exception { Account expected = new Account("name", "type"); Parcel p = Parcel.obtain(); expected.writeToParcel(p, 0); p.setDataPosition(0); Account actual = Account.CREATOR.createFromParcel(p); assertThat(actual).isEqualTo(expected); }
@Test public void shouldHaveParcelConstructor() throws Exception { Account expected = new Account("name", "type"); Parcel p = Parcel.obtain(); expected.writeToParcel(p, 0); p.setDataPosition(0); Account actual = new Account(p); assertThat(actual).isEqualTo(expected); }
@Test public void testParcelable() { DrmInitData drmInitDataToParcel = new DrmInitData(DATA_1, DATA_2); Parcel parcel = Parcel.obtain(); drmInitDataToParcel.writeToParcel(parcel, 0); parcel.setDataPosition(0); DrmInitData drmInitDataFromParcel = DrmInitData.CREATOR.createFromParcel(parcel); assertThat(drmInitDataFromParcel).isEqualTo(drmInitDataToParcel); parcel.recycle(); }
@Test public void testParcelable() { MdtaMetadataEntry mdtaMetadataEntryToParcel = new MdtaMetadataEntry("test", new byte[] {1, 2}, 3, 4); Parcel parcel = Parcel.obtain(); mdtaMetadataEntryToParcel.writeToParcel(parcel, 0); parcel.setDataPosition(0); MdtaMetadataEntry mdtaMetadataEntryFromParcel = MdtaMetadataEntry.CREATOR.createFromParcel(parcel); assertThat(mdtaMetadataEntryFromParcel).isEqualTo(mdtaMetadataEntryToParcel); parcel.recycle(); } }
@Test public void shouldWriteAndReadFromParcelCorrectly() { Parcel p = Parcel.obtain(); node.setContentDescription("test"); node.writeToParcel(p, 0); p.setDataPosition(0); AccessibilityNodeInfo anotherNode = AccessibilityNodeInfo.CREATOR.createFromParcel(p); assertThat(node).isEqualTo(anotherNode); node.setContentDescription(null); }
/** Tests {@link SelectionOverride}'s {@link android.os.Parcelable} implementation. */ @Test public void testSelectionOverrideParcelable() { int[] tracks = new int[] {2, 3}; SelectionOverride selectionOverrideToParcel = new SelectionOverride(/* groupIndex= */ 1, tracks); Parcel parcel = Parcel.obtain(); selectionOverrideToParcel.writeToParcel(parcel, 0); parcel.setDataPosition(0); SelectionOverride selectionOverrideFromParcel = SelectionOverride.CREATOR.createFromParcel(parcel); assertThat(selectionOverrideFromParcel).isEqualTo(selectionOverrideToParcel); parcel.recycle(); }
@Test public void testParcelable() { Format format1 = Format.createSampleFormat("1", MimeTypes.VIDEO_H264, 0); Format format2 = Format.createSampleFormat("2", MimeTypes.AUDIO_AAC, 0); TrackGroup trackGroupToParcel = new TrackGroup(format1, format2); Parcel parcel = Parcel.obtain(); trackGroupToParcel.writeToParcel(parcel, 0); parcel.setDataPosition(0); TrackGroup trackGroupFromParcel = TrackGroup.CREATOR.createFromParcel(parcel); assertThat(trackGroupFromParcel).isEqualTo(trackGroupToParcel); parcel.recycle(); } }
@Test public void testParcelable() { Id3Frame[] subFrames = new Id3Frame[] { new TextInformationFrame("TIT2", null, "title"), new UrlLinkFrame("WXXX", "description", "url") }; ChapterFrame chapterFrameToParcel = new ChapterFrame("id", 0, 1, 2, 3, subFrames); Parcel parcel = Parcel.obtain(); chapterFrameToParcel.writeToParcel(parcel, 0); parcel.setDataPosition(0); ChapterFrame chapterFrameFromParcel = ChapterFrame.CREATOR.createFromParcel(parcel); assertThat(chapterFrameFromParcel).isEqualTo(chapterFrameToParcel); parcel.recycle(); }
public void testScrollViewSavedState() throws Throwable { Parcel parcel = Parcel.obtain(); ObservableScrollView.SavedState state1 = new ObservableScrollView.SavedState(AbsSavedState.EMPTY_STATE); state1.prevScrollY = 1; state1.scrollY = 2; state1.writeToParcel(parcel, 0); parcel.setDataPosition(0); ObservableScrollView.SavedState state2 = ObservableScrollView.SavedState.CREATOR.createFromParcel(parcel); assertNotNull(state2); assertEquals(state1.prevScrollY, state2.prevScrollY); assertEquals(state1.scrollY, state2.scrollY); }
public void testWebViewSavedState() throws Throwable { Parcel parcel = Parcel.obtain(); ObservableWebView.SavedState state1 = new ObservableWebView.SavedState(AbsSavedState.EMPTY_STATE); state1.prevScrollY = 1; state1.scrollY = 2; state1.writeToParcel(parcel, 0); parcel.setDataPosition(0); ObservableWebView.SavedState state2 = ObservableWebView.SavedState.CREATOR.createFromParcel(parcel); assertNotNull(state2); assertEquals(state1.prevScrollY, state2.prevScrollY); assertEquals(state1.scrollY, state2.scrollY); } }