Skip to content

Commit

Permalink
Fix BaseParcelableListSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Mar 19, 2021
1 parent c9afda6 commit 5684e8c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public abstract class BaseParcelableListSlice<T> implements Parcelable {

private static final String TAG = "ParcelableListSlice";
private static final boolean DEBUG = true;
private static final boolean DEBUG = false;

private static final int MAX_IPC_SIZE = 64 * 1024;

Expand Down Expand Up @@ -85,20 +85,22 @@ public final void writeToParcel(Parcel dest, int flags) {
Iterator<T> iterator = mList.iterator();
writeSliceToParcel(iterator, dest, flags);

while (iterator.hasNext()) {
int writeFlags = flags;
IBinder binder = new Binder() {
@Override
protected boolean onTransact(int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) {
if (code != IBinder.FIRST_CALL_TRANSACTION || reply == null) {
return false;
}
writeSliceToParcel(iterator, reply, writeFlags);
return true;
}
};
dest.writeStrongBinder(binder);
if (!iterator.hasNext()) {
return;
}

int writeFlags = flags;
IBinder binder = new Binder() {
@Override
protected boolean onTransact(int code, @NonNull Parcel data, @Nullable Parcel reply, int flags) {
if (code != IBinder.FIRST_CALL_TRANSACTION || reply == null) {
return false;
}
writeSliceToParcel(iterator, reply, writeFlags);
return true;
}
};
dest.writeStrongBinder(binder);
}

private void writeSliceToParcel(Iterator<T> iterator, Parcel dest, int flags) {
Expand All @@ -111,11 +113,11 @@ private void writeSliceToParcel(Iterator<T> iterator, Parcel dest, int flags) {
// and binder has total 1MB buffer size across the process, unless all 16 binder
// threads are doing this at the same time, exceed a little bit could never be
// a problem.
// Also, shrink is not allowed by Parcel and the system's ParceledListSlice class
// has the same implementation, we really don't need to consider this.
// Also, the system's ParceledListSlice class has the same implementation, we
// really don't need to consider this.
while (iterator.hasNext() && dest.dataSize() < MAX_IPC_SIZE) {
writeElement(iterator.next(), dest, flags);
size ++;
size++;
}
int position = dest.dataPosition();
dest.setDataPosition(startPosition);
Expand All @@ -125,5 +127,5 @@ private void writeSliceToParcel(Iterator<T> iterator, Parcel dest, int flags) {

public abstract T readElement(Parcel in);

protected abstract void writeElement(T parcelable, Parcel dest, int writeFlags);
public abstract void writeElement(T parcelable, Parcel dest, int writeFlags);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public T readElement(Parcel in) {
}

@Override
protected void writeElement(T parcelable, Parcel dest, int writeFlags) {
public void writeElement(T parcelable, Parcel dest, int writeFlags) {
dest.writeParcelable(parcelable, writeFlags);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public String readElement(Parcel in) {
}

@Override
protected void writeElement(String string, Parcel dest, int writeFlags) {
public void writeElement(String string, Parcel dest, int writeFlags) {
dest.writeString(string);
}

Expand Down

0 comments on commit 5684e8c

Please sign in to comment.