Merge "Frameworks/base: Add holder to BaseBundle" into nyc-dev am: 58f2072

am: 6ce2774

* commit '6ce27741799f0059e343cde5e0fbef9073c60ee8':
  Frameworks/base: Add holder to BaseBundle

Change-Id: Ia4053ed3e376a08dbe8f1273d86c3ebdb2cca388
This commit is contained in:
Andreas Gampe
2016-04-20 21:15:26 +00:00
committed by android-build-merger
4 changed files with 20 additions and 16 deletions

View File

@@ -65,11 +65,12 @@ public class BaseBundle {
sShouldDefuse = shouldDefuse; sShouldDefuse = shouldDefuse;
} }
// A parcel cannot be obtained during compile-time initialization. Put the
// empty parcel into an inner class that can be initialized separately. This
// allows to initialize BaseBundle, and classes depending on it.
/** {@hide} */ /** {@hide} */
static final Parcel EMPTY_PARCEL; static final class NoImagePreloadHolder {
public static final Parcel EMPTY_PARCEL = Parcel.obtain();
static {
EMPTY_PARCEL = Parcel.obtain();
} }
// Invariant - exactly one of mMap / mParcelledData will be null // Invariant - exactly one of mMap / mParcelledData will be null
@@ -156,8 +157,8 @@ public class BaseBundle {
*/ */
BaseBundle(BaseBundle b) { BaseBundle(BaseBundle b) {
if (b.mParcelledData != null) { if (b.mParcelledData != null) {
if (b.mParcelledData == EMPTY_PARCEL) { if (b.isEmptyParcel()) {
mParcelledData = EMPTY_PARCEL; mParcelledData = NoImagePreloadHolder.EMPTY_PARCEL;
} else { } else {
mParcelledData = Parcel.obtain(); mParcelledData = Parcel.obtain();
mParcelledData.appendFrom(b.mParcelledData, 0, b.mParcelledData.dataSize()); mParcelledData.appendFrom(b.mParcelledData, 0, b.mParcelledData.dataSize());
@@ -236,7 +237,7 @@ public class BaseBundle {
+ "clobber all data inside!", new Throwable()); + "clobber all data inside!", new Throwable());
} }
if (mParcelledData == EMPTY_PARCEL) { if (isEmptyParcel()) {
if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this)) if (DEBUG) Log.d(TAG, "unparcel " + Integer.toHexString(System.identityHashCode(this))
+ ": empty"); + ": empty");
if (mMap == null) { if (mMap == null) {
@@ -284,6 +285,13 @@ public class BaseBundle {
return mParcelledData != null; return mParcelledData != null;
} }
/**
* @hide
*/
public boolean isEmptyParcel() {
return mParcelledData == NoImagePreloadHolder.EMPTY_PARCEL;
}
/** @hide */ /** @hide */
ArrayMap<String, Object> getMap() { ArrayMap<String, Object> getMap() {
unparcel(); unparcel();
@@ -1368,7 +1376,7 @@ public class BaseBundle {
// Keep implementation in sync with writeToParcel() in // Keep implementation in sync with writeToParcel() in
// frameworks/native/libs/binder/PersistableBundle.cpp. // frameworks/native/libs/binder/PersistableBundle.cpp.
if (mParcelledData != null) { if (mParcelledData != null) {
if (mParcelledData == EMPTY_PARCEL) { if (isEmptyParcel()) {
parcel.writeInt(0); parcel.writeInt(0);
} else { } else {
int length = mParcelledData.dataSize(); int length = mParcelledData.dataSize();
@@ -1416,7 +1424,7 @@ public class BaseBundle {
} else if (length == 0) { } else if (length == 0) {
// Empty Bundle or end of data. // Empty Bundle or end of data.
mParcelledData = EMPTY_PARCEL; mParcelledData = NoImagePreloadHolder.EMPTY_PARCEL;
return; return;
} }

View File

@@ -38,12 +38,9 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
public static final Bundle EMPTY; public static final Bundle EMPTY;
static final Parcel EMPTY_PARCEL;
static { static {
EMPTY = new Bundle(); EMPTY = new Bundle();
EMPTY.mMap = ArrayMap.EMPTY; EMPTY.mMap = ArrayMap.EMPTY;
EMPTY_PARCEL = BaseBundle.EMPTY_PARCEL;
} }
/** /**
@@ -1155,7 +1152,7 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
@Override @Override
public synchronized String toString() { public synchronized String toString() {
if (mParcelledData != null) { if (mParcelledData != null) {
if (mParcelledData == EMPTY_PARCEL) { if (isEmptyParcel()) {
return "Bundle[EMPTY_PARCEL]"; return "Bundle[EMPTY_PARCEL]";
} else { } else {
return "Bundle[mParcelledData.dataSize=" + return "Bundle[mParcelledData.dataSize=" +

View File

@@ -38,12 +38,10 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
XmlUtils.WriteMapCallback { XmlUtils.WriteMapCallback {
private static final String TAG_PERSISTABLEMAP = "pbundle_as_map"; private static final String TAG_PERSISTABLEMAP = "pbundle_as_map";
public static final PersistableBundle EMPTY; public static final PersistableBundle EMPTY;
static final Parcel EMPTY_PARCEL;
static { static {
EMPTY = new PersistableBundle(); EMPTY = new PersistableBundle();
EMPTY.mMap = ArrayMap.EMPTY; EMPTY.mMap = ArrayMap.EMPTY;
EMPTY_PARCEL = BaseBundle.EMPTY_PARCEL;
} }
/** @hide */ /** @hide */
@@ -278,7 +276,7 @@ public final class PersistableBundle extends BaseBundle implements Cloneable, Pa
@Override @Override
synchronized public String toString() { synchronized public String toString() {
if (mParcelledData != null) { if (mParcelledData != null) {
if (mParcelledData == EMPTY_PARCEL) { if (isEmptyParcel()) {
return "PersistableBundle[EMPTY_PARCEL]"; return "PersistableBundle[EMPTY_PARCEL]";
} else { } else {
return "PersistableBundle[mParcelledData.dataSize=" + return "PersistableBundle[mParcelledData.dataSize=" +

View File

@@ -1613,6 +1613,7 @@ android.os.AsyncTask$Status
android.os.AsyncTask$WorkerRunnable android.os.AsyncTask$WorkerRunnable
android.os.BadParcelableException android.os.BadParcelableException
android.os.BaseBundle android.os.BaseBundle
android.os.BaseBundle$NoImagePreloadHolder
android.os.BatteryManager android.os.BatteryManager
android.os.Binder android.os.Binder
android.os.BinderProxy android.os.BinderProxy