1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.os;
18 
19 import static java.util.Objects.requireNonNull;
20 
21 import android.annotation.IntDef;
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.annotation.SuppressLint;
25 import android.compat.annotation.UnsupportedAppUsage;
26 import android.util.ArrayMap;
27 import android.util.Size;
28 import android.util.SizeF;
29 import android.util.SparseArray;
30 import android.util.proto.ProtoOutputStream;
31 
32 import com.android.internal.annotations.VisibleForTesting;
33 
34 import java.io.Serializable;
35 import java.lang.annotation.Retention;
36 import java.lang.annotation.RetentionPolicy;
37 import java.util.ArrayList;
38 import java.util.List;
39 
40 /**
41  * A mapping from String keys to various {@link Parcelable} values.
42  *
43  * <p><b>Warning:</b> Note that {@link Bundle} is a lazy container and as such it does NOT implement
44  * {@link #equals(Object)} or {@link #hashCode()}.
45  *
46  * @see PersistableBundle
47  */
48 @android.ravenwood.annotation.RavenwoodKeepWholeClass
49 public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
50     @VisibleForTesting
51     static final int FLAG_HAS_FDS = 1 << 8;
52 
53     @VisibleForTesting
54     static final int FLAG_HAS_FDS_KNOWN = 1 << 9;
55 
56     @VisibleForTesting
57     static final int FLAG_ALLOW_FDS = 1 << 10;
58 
59     @VisibleForTesting
60     static final int FLAG_HAS_BINDERS_KNOWN = 1 << 11;
61 
62     @VisibleForTesting
63     static final int FLAG_HAS_BINDERS = 1 << 12;
64 
65 
66     /**
67      * Status when the Bundle can <b>assert</b> that the underlying Parcel DOES NOT contain
68      * Binder object(s).
69      *
70      * @hide
71      */
72     public static final int STATUS_BINDERS_NOT_PRESENT = 0;
73 
74     /**
75      * Status when the Bundle can <b>assert</b> that there are Binder object(s) in the Parcel.
76      *
77      * @hide
78      */
79     public static final int STATUS_BINDERS_PRESENT = 1;
80 
81     /**
82      * Status when the Bundle cannot be checked for Binders and there is no parcelled data
83      * available to check either.
84      * <p> This could happen when a Bundle is unparcelled or was never parcelled, and modified such
85      * that it is not possible to assert if the Bundle has any Binder objects in the current state.
86      *
87      * For e.g. calling {@link #putParcelable} or {@link #putBinder} could have added a Binder
88      * object to the Bundle but it is not possible to assert this fact unless the Bundle is written
89      * to a Parcel.
90      * </p>
91      *
92      * @hide
93      */
94     public static final int STATUS_BINDERS_UNKNOWN = 2;
95 
96     /** @hide */
97     @IntDef(flag = true, prefix = {"STATUS_BINDERS_"}, value = {
98             STATUS_BINDERS_PRESENT,
99             STATUS_BINDERS_UNKNOWN,
100             STATUS_BINDERS_NOT_PRESENT
101     })
102     @Retention(RetentionPolicy.SOURCE)
103     public @interface HasBinderStatus {
104     }
105 
106     /** An unmodifiable {@code Bundle} that is always {@link #isEmpty() empty}. */
107     public static final Bundle EMPTY;
108 
109     /**
110      * Special extras used to denote extras have been stripped off.
111      * @hide
112      */
113     public static final Bundle STRIPPED;
114 
115     static {
116         EMPTY = new Bundle();
117         EMPTY.mMap = ArrayMap.EMPTY;
118 
119         STRIPPED = new Bundle();
120         STRIPPED.putInt("STRIPPED", 1);
121     }
122 
123     /**
124      * Constructs a new, empty Bundle.
125      */
Bundle()126     public Bundle() {
127         super();
128         mFlags = FLAG_HAS_FDS_KNOWN | FLAG_HAS_BINDERS_KNOWN | FLAG_ALLOW_FDS;
129     }
130 
131     /**
132      * Constructs a Bundle whose data is stored as a Parcel.  The data
133      * will be unparcelled on first contact, using the assigned ClassLoader.
134      *
135      * @param parcelledData a Parcel containing a Bundle
136      *
137      * @hide
138      */
139     @VisibleForTesting
Bundle(Parcel parcelledData)140     public Bundle(Parcel parcelledData) {
141         super(parcelledData);
142         mFlags = FLAG_ALLOW_FDS;
143         maybePrefillHasFds();
144     }
145 
146     /**
147      * Constructor from a parcel for when the length is known *and is not stored in the parcel.*
148      * The other constructor that takes a parcel assumes the length is in the parcel.
149      *
150      * @hide
151      */
152     @VisibleForTesting
Bundle(Parcel parcelledData, int length)153     public Bundle(Parcel parcelledData, int length) {
154         super(parcelledData, length);
155         mFlags = FLAG_ALLOW_FDS;
156         maybePrefillHasFds();
157     }
158 
159     /**
160      * Constructs a {@link Bundle} containing a copy of {@code from}.
161      *
162      * @param from The bundle to be copied.
163      * @param deep Whether is a deep or shallow copy.
164      * @hide
165      */
Bundle(Bundle from, boolean deep)166     Bundle(Bundle from, boolean deep) {
167         super(from, deep);
168     }
169 
170     /**
171      * If {@link #mParcelledData} is not null, copy the HAS FDS bit from it because it's fast.
172      * Otherwise (if {@link #mParcelledData} is already null), leave {@link #FLAG_HAS_FDS_KNOWN}
173      * unset, because scanning a map is slower.  We'll do it lazily in
174      * {@link #hasFileDescriptors()}.
175      */
maybePrefillHasFds()176     private void maybePrefillHasFds() {
177         if (mParcelledData != null) {
178             if (mParcelledData.hasFileDescriptors()) {
179                 mFlags |= FLAG_HAS_FDS | FLAG_HAS_FDS_KNOWN;
180             } else {
181                 mFlags |= FLAG_HAS_FDS_KNOWN;
182             }
183         }
184     }
185 
186     /**
187      * Constructs a new, empty Bundle that uses a specific ClassLoader for
188      * instantiating Parcelable and Serializable objects.
189      *
190      * @param loader An explicit ClassLoader to use when instantiating objects
191      * inside of the Bundle.
192      */
Bundle(ClassLoader loader)193     public Bundle(ClassLoader loader) {
194         super(loader);
195         mFlags = FLAG_HAS_FDS_KNOWN | FLAG_HAS_BINDERS_KNOWN | FLAG_ALLOW_FDS;
196     }
197 
198     /**
199      * Constructs a new, empty Bundle sized to hold the given number of
200      * elements. The Bundle will grow as needed.
201      *
202      * @param capacity the initial capacity of the Bundle
203      */
Bundle(int capacity)204     public Bundle(int capacity) {
205         super(capacity);
206         mFlags = FLAG_HAS_FDS_KNOWN | FLAG_HAS_BINDERS_KNOWN | FLAG_ALLOW_FDS;
207     }
208 
209     /**
210      * Constructs a Bundle containing a copy of the mappings from the given
211      * Bundle.  Does only a shallow copy of the original Bundle -- see
212      * {@link #deepCopy()} if that is not what you want.
213      *
214      * @param b a Bundle to be copied.
215      *
216      * @see #deepCopy()
217      */
Bundle(Bundle b)218     public Bundle(Bundle b) {
219         super(b);
220         mFlags = b.mFlags;
221     }
222 
223     /**
224      * Constructs a Bundle containing a copy of the mappings from the given
225      * PersistableBundle.  Does only a shallow copy of the PersistableBundle -- see
226      * {@link PersistableBundle#deepCopy()} if you don't want that.
227      *
228      * @param b a PersistableBundle to be copied.
229      */
Bundle(PersistableBundle b)230     public Bundle(PersistableBundle b) {
231         super(b);
232         mFlags = FLAG_HAS_FDS_KNOWN | FLAG_HAS_BINDERS_KNOWN | FLAG_ALLOW_FDS;
233     }
234 
235     /**
236      * Make a Bundle for a single key/value pair.
237      *
238      * @hide
239      */
240     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
forPair(String key, String value)241     public static Bundle forPair(String key, String value) {
242         Bundle b = new Bundle(1);
243         b.putString(key, value);
244         return b;
245     }
246 
247     /**
248      * Changes the ClassLoader this Bundle uses when instantiating objects.
249      *
250      * @param loader An explicit ClassLoader to use when instantiating objects
251      * inside of the Bundle.
252      */
253     @Override
setClassLoader(ClassLoader loader)254     public void setClassLoader(ClassLoader loader) {
255         super.setClassLoader(loader);
256     }
257 
258     /**
259      * Return the ClassLoader currently associated with this Bundle.
260      */
261     @Override
getClassLoader()262     public ClassLoader getClassLoader() {
263         return super.getClassLoader();
264     }
265 
266     /** {@hide} */
setAllowFds(boolean allowFds)267     public boolean setAllowFds(boolean allowFds) {
268         final boolean orig = (mFlags & FLAG_ALLOW_FDS) != 0;
269         if (allowFds) {
270             mFlags |= FLAG_ALLOW_FDS;
271         } else {
272             mFlags &= ~FLAG_ALLOW_FDS;
273         }
274         return orig;
275     }
276 
277     /**
278      * Mark if this Bundle is okay to "defuse." That is, it's okay for system
279      * processes to ignore any {@link BadParcelableException} encountered when
280      * unparceling it, leaving an empty bundle in its place.
281      * <p>
282      * This should <em>only</em> be set when the Bundle reaches its final
283      * destination, otherwise a system process may clobber contents that were
284      * destined for an app that could have unparceled them.
285      *
286      * @hide
287      */
setDefusable(boolean defusable)288     public void setDefusable(boolean defusable) {
289         if (defusable) {
290             mFlags |= FLAG_DEFUSABLE;
291         } else {
292             mFlags &= ~FLAG_DEFUSABLE;
293         }
294     }
295 
296     /** {@hide} */
297     @UnsupportedAppUsage
setDefusable(Bundle bundle, boolean defusable)298     public static Bundle setDefusable(Bundle bundle, boolean defusable) {
299         if (bundle != null) {
300             bundle.setDefusable(defusable);
301         }
302         return bundle;
303     }
304 
305     /**
306      * Clones the current Bundle. The internal map is cloned, but the keys and
307      * values to which it refers are copied by reference.
308      */
309     @Override
clone()310     public Object clone() {
311         return new Bundle(this);
312     }
313 
314     /**
315      * Make a deep copy of the given bundle.  Traverses into inner containers and copies
316      * them as well, so they are not shared across bundles.  Will traverse in to
317      * {@link Bundle}, {@link PersistableBundle}, {@link ArrayList}, and all types of
318      * primitive arrays.  Other types of objects (such as Parcelable or Serializable)
319      * are referenced as-is and not copied in any way.
320      */
deepCopy()321     public Bundle deepCopy() {
322         return new Bundle(this, /* deep */ true);
323     }
324 
325     /**
326      * Removes all elements from the mapping of this Bundle.
327      */
328     @Override
clear()329     public void clear() {
330         super.clear();
331         mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
332     }
333 
334     /**
335      * Removes any entry with the given key from the mapping of this Bundle.
336      *
337      * @param key a String key
338      */
remove(String key)339     public void remove(String key) {
340         super.remove(key);
341         if ((mFlags & FLAG_HAS_FDS) != 0) {
342             mFlags &= ~FLAG_HAS_FDS_KNOWN;
343         }
344         if ((mFlags & FLAG_HAS_BINDERS) != 0) {
345             mFlags &= ~FLAG_HAS_BINDERS_KNOWN;
346         }
347     }
348 
349     /**
350      * Inserts all mappings from the given Bundle into this Bundle.
351      *
352      * @param bundle a Bundle
353      */
putAll(Bundle bundle)354     public void putAll(Bundle bundle) {
355         unparcel();
356         bundle.unparcel();
357         mOwnsLazyValues = false;
358         bundle.mOwnsLazyValues = false;
359         mMap.putAll(bundle.mMap);
360 
361         // FD and Binders state is now known if and only if both bundles already knew
362         if ((bundle.mFlags & FLAG_HAS_FDS) != 0) {
363             mFlags |= FLAG_HAS_FDS;
364         }
365         if ((bundle.mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
366             mFlags &= ~FLAG_HAS_FDS_KNOWN;
367         }
368 
369         if ((bundle.mFlags & FLAG_HAS_BINDERS) != 0) {
370             mFlags |= FLAG_HAS_BINDERS;
371         }
372         if ((bundle.mFlags & FLAG_HAS_BINDERS_KNOWN) == 0) {
373             mFlags &= ~FLAG_HAS_BINDERS_KNOWN;
374         }
375     }
376 
377     /**
378      * Return the size of {@link #mParcelledData} in bytes if available, otherwise {@code 0}.
379      *
380      * @hide
381      */
382     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getSize()383     public int getSize() {
384         if (mParcelledData != null) {
385             return mParcelledData.dataSize();
386         } else {
387             return 0;
388         }
389     }
390 
391     /**
392      * Reports whether the bundle contains any parcelled file descriptors.
393      */
hasFileDescriptors()394     public boolean hasFileDescriptors() {
395         if ((mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
396             Parcel p = mParcelledData;
397             mFlags = (Parcel.hasFileDescriptors((p != null) ? p : mMap))
398                     ? mFlags | FLAG_HAS_FDS
399                     : mFlags & ~FLAG_HAS_FDS;
400             mFlags |= FLAG_HAS_FDS_KNOWN;
401         }
402         return (mFlags & FLAG_HAS_FDS) != 0;
403     }
404 
405     /**
406      * Returns a status indicating whether the bundle contains any parcelled Binder objects.
407      * @hide
408      */
hasBinders()409     public @HasBinderStatus int hasBinders() {
410         if ((mFlags & FLAG_HAS_BINDERS_KNOWN) != 0) {
411             if ((mFlags & FLAG_HAS_BINDERS) != 0) {
412                 return STATUS_BINDERS_PRESENT;
413             } else {
414                 return STATUS_BINDERS_NOT_PRESENT;
415             }
416         }
417 
418         final Parcel p = mParcelledData;
419         if (p == null) {
420             return STATUS_BINDERS_UNKNOWN;
421         }
422         if (p.hasBinders()) {
423             mFlags = mFlags | FLAG_HAS_BINDERS | FLAG_HAS_BINDERS_KNOWN;
424             return STATUS_BINDERS_PRESENT;
425         } else {
426             mFlags = mFlags & ~FLAG_HAS_BINDERS;
427             mFlags |= FLAG_HAS_BINDERS_KNOWN;
428             return STATUS_BINDERS_NOT_PRESENT;
429         }
430     }
431 
432     /** {@hide} */
433     @Override
putObject(@ullable String key, @Nullable Object value)434     public void putObject(@Nullable String key, @Nullable Object value) {
435         if (value instanceof Byte) {
436             putByte(key, (Byte) value);
437         } else if (value instanceof Character) {
438             putChar(key, (Character) value);
439         } else if (value instanceof Short) {
440             putShort(key, (Short) value);
441         } else if (value instanceof Float) {
442             putFloat(key, (Float) value);
443         } else if (value instanceof CharSequence) {
444             putCharSequence(key, (CharSequence) value);
445         } else if (value instanceof Parcelable) {
446             putParcelable(key, (Parcelable) value);
447         } else if (value instanceof Size) {
448             putSize(key, (Size) value);
449         } else if (value instanceof SizeF) {
450             putSizeF(key, (SizeF) value);
451         } else if (value instanceof Parcelable[]) {
452             putParcelableArray(key, (Parcelable[]) value);
453         } else if (value instanceof ArrayList) {
454             putParcelableArrayList(key, (ArrayList) value);
455         } else if (value instanceof List) {
456             putParcelableList(key, (List) value);
457         } else if (value instanceof SparseArray) {
458             putSparseParcelableArray(key, (SparseArray) value);
459         } else if (value instanceof Serializable) {
460             putSerializable(key, (Serializable) value);
461         } else if (value instanceof byte[]) {
462             putByteArray(key, (byte[]) value);
463         } else if (value instanceof short[]) {
464             putShortArray(key, (short[]) value);
465         } else if (value instanceof char[]) {
466             putCharArray(key, (char[]) value);
467         } else if (value instanceof float[]) {
468             putFloatArray(key, (float[]) value);
469         } else if (value instanceof CharSequence[]) {
470             putCharSequenceArray(key, (CharSequence[]) value);
471         } else if (value instanceof Bundle) {
472             putBundle(key, (Bundle) value);
473         } else if (value instanceof Binder) {
474             putBinder(key, (Binder) value);
475         } else if (value instanceof IBinder) {
476             putIBinder(key, (IBinder) value);
477         } else {
478             super.putObject(key, value);
479         }
480     }
481 
482     /**
483      * Inserts a byte value into the mapping of this Bundle, replacing
484      * any existing value for the given key.
485      *
486      * @param key a String, or null
487      * @param value a byte
488      */
489     @Override
putByte(@ullable String key, byte value)490     public void putByte(@Nullable String key, byte value) {
491         super.putByte(key, value);
492     }
493 
494     /**
495      * Inserts a char value into the mapping of this Bundle, replacing
496      * any existing value for the given key.
497      *
498      * @param key a String, or null
499      * @param value a char
500      */
501     @Override
putChar(@ullable String key, char value)502     public void putChar(@Nullable String key, char value) {
503         super.putChar(key, value);
504     }
505 
506     /**
507      * Inserts a short value into the mapping of this Bundle, replacing
508      * any existing value for the given key.
509      *
510      * @param key a String, or null
511      * @param value a short
512      */
513     @Override
putShort(@ullable String key, short value)514     public void putShort(@Nullable String key, short value) {
515         super.putShort(key, value);
516     }
517 
518     /**
519      * Inserts a float value into the mapping of this Bundle, replacing
520      * any existing value for the given key.
521      *
522      * @param key a String, or null
523      * @param value a float
524      */
525     @Override
putFloat(@ullable String key, float value)526     public void putFloat(@Nullable String key, float value) {
527         super.putFloat(key, value);
528     }
529 
530     /**
531      * Inserts a CharSequence value into the mapping of this Bundle, replacing
532      * any existing value for the given key.  Either key or value may be null.
533      *
534      * @param key a String, or null
535      * @param value a CharSequence, or null
536      */
537     @Override
putCharSequence(@ullable String key, @Nullable CharSequence value)538     public void putCharSequence(@Nullable String key, @Nullable CharSequence value) {
539         super.putCharSequence(key, value);
540     }
541 
542     /**
543      * Inserts a Parcelable value into the mapping of this Bundle, replacing
544      * any existing value for the given key.  Either key or value may be null.
545      *
546      * @param key a String, or null
547      * @param value a Parcelable object, or null
548      */
putParcelable(@ullable String key, @Nullable Parcelable value)549     public void putParcelable(@Nullable String key, @Nullable Parcelable value) {
550         unparcel();
551         mMap.put(key, value);
552         mFlags &= ~FLAG_HAS_FDS_KNOWN;
553         mFlags &= ~FLAG_HAS_BINDERS_KNOWN;
554     }
555 
556     /**
557      * Inserts a Size value into the mapping of this Bundle, replacing
558      * any existing value for the given key.  Either key or value may be null.
559      *
560      * @param key a String, or null
561      * @param value a Size object, or null
562      */
putSize(@ullable String key, @Nullable Size value)563     public void putSize(@Nullable String key, @Nullable Size value) {
564         unparcel();
565         mMap.put(key, value);
566     }
567 
568     /**
569      * Inserts a SizeF value into the mapping of this Bundle, replacing
570      * any existing value for the given key.  Either key or value may be null.
571      *
572      * @param key a String, or null
573      * @param value a SizeF object, or null
574      */
putSizeF(@ullable String key, @Nullable SizeF value)575     public void putSizeF(@Nullable String key, @Nullable SizeF value) {
576         unparcel();
577         mMap.put(key, value);
578     }
579 
580     /**
581      * Inserts an array of Parcelable values into the mapping of this Bundle,
582      * replacing any existing value for the given key.  Either key or value may
583      * be null.
584      *
585      * @param key a String, or null
586      * @param value an array of Parcelable objects, or null
587      */
putParcelableArray(@ullable String key, @Nullable Parcelable[] value)588     public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) {
589         unparcel();
590         mMap.put(key, value);
591         mFlags &= ~FLAG_HAS_FDS_KNOWN;
592         mFlags &= ~FLAG_HAS_BINDERS_KNOWN;
593     }
594 
595     /**
596      * Inserts a List of Parcelable values into the mapping of this Bundle,
597      * replacing any existing value for the given key.  Either key or value may
598      * be null.
599      *
600      * @param key a String, or null
601      * @param value an ArrayList of Parcelable objects, or null
602      */
putParcelableArrayList(@ullable String key, @Nullable ArrayList<? extends Parcelable> value)603     public void putParcelableArrayList(@Nullable String key,
604             @Nullable ArrayList<? extends Parcelable> value) {
605         unparcel();
606         mMap.put(key, value);
607         mFlags &= ~FLAG_HAS_FDS_KNOWN;
608         mFlags &= ~FLAG_HAS_BINDERS_KNOWN;
609     }
610 
611     /** {@hide} */
612     @UnsupportedAppUsage
putParcelableList(String key, List<? extends Parcelable> value)613     public void putParcelableList(String key, List<? extends Parcelable> value) {
614         unparcel();
615         mMap.put(key, value);
616         mFlags &= ~FLAG_HAS_FDS_KNOWN;
617         mFlags &= ~FLAG_HAS_BINDERS_KNOWN;
618     }
619 
620     /**
621      * Inserts a SparceArray of Parcelable values into the mapping of this
622      * Bundle, replacing any existing value for the given key.  Either key
623      * or value may be null.
624      *
625      * @param key a String, or null
626      * @param value a SparseArray of Parcelable objects, or null
627      */
putSparseParcelableArray(@ullable String key, @Nullable SparseArray<? extends Parcelable> value)628     public void putSparseParcelableArray(@Nullable String key,
629             @Nullable SparseArray<? extends Parcelable> value) {
630         unparcel();
631         mMap.put(key, value);
632         mFlags &= ~FLAG_HAS_FDS_KNOWN;
633         mFlags &= ~FLAG_HAS_BINDERS_KNOWN;
634     }
635 
636     /**
637      * Inserts an ArrayList<Integer> value into the mapping of this Bundle, replacing
638      * any existing value for the given key.  Either key or value may be null.
639      *
640      * @param key a String, or null
641      * @param value an ArrayList<Integer> object, or null
642      */
643     @Override
putIntegerArrayList(@ullable String key, @Nullable ArrayList<Integer> value)644     public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) {
645         super.putIntegerArrayList(key, value);
646     }
647 
648     /**
649      * Inserts an ArrayList<String> value into the mapping of this Bundle, replacing
650      * any existing value for the given key.  Either key or value may be null.
651      *
652      * @param key a String, or null
653      * @param value an ArrayList<String> object, or null
654      */
655     @Override
putStringArrayList(@ullable String key, @Nullable ArrayList<String> value)656     public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) {
657         super.putStringArrayList(key, value);
658     }
659 
660     /**
661      * Inserts an ArrayList<CharSequence> value into the mapping of this Bundle, replacing
662      * any existing value for the given key.  Either key or value may be null.
663      *
664      * @param key a String, or null
665      * @param value an ArrayList<CharSequence> object, or null
666      */
667     @Override
putCharSequenceArrayList(@ullable String key, @Nullable ArrayList<CharSequence> value)668     public void putCharSequenceArrayList(@Nullable String key,
669             @Nullable ArrayList<CharSequence> value) {
670         super.putCharSequenceArrayList(key, value);
671     }
672 
673     /**
674      * Inserts a Serializable value into the mapping of this Bundle, replacing
675      * any existing value for the given key.  Either key or value may be null.
676      *
677      * @param key a String, or null
678      * @param value a Serializable object, or null
679      */
680     @Override
putSerializable(@ullable String key, @Nullable Serializable value)681     public void putSerializable(@Nullable String key, @Nullable Serializable value) {
682         super.putSerializable(key, value);
683     }
684 
685     /**
686      * Inserts a byte array value into the mapping of this Bundle, replacing
687      * any existing value for the given key.  Either key or value may be null.
688      *
689      * @param key a String, or null
690      * @param value a byte array object, or null
691      */
692     @Override
putByteArray(@ullable String key, @Nullable byte[] value)693     public void putByteArray(@Nullable String key, @Nullable byte[] value) {
694         super.putByteArray(key, value);
695     }
696 
697     /**
698      * Inserts a short array value into the mapping of this Bundle, replacing
699      * any existing value for the given key.  Either key or value may be null.
700      *
701      * @param key a String, or null
702      * @param value a short array object, or null
703      */
704     @Override
putShortArray(@ullable String key, @Nullable short[] value)705     public void putShortArray(@Nullable String key, @Nullable short[] value) {
706         super.putShortArray(key, value);
707     }
708 
709     /**
710      * Inserts a char array value into the mapping of this Bundle, replacing
711      * any existing value for the given key.  Either key or value may be null.
712      *
713      * @param key a String, or null
714      * @param value a char array object, or null
715      */
716     @Override
putCharArray(@ullable String key, @Nullable char[] value)717     public void putCharArray(@Nullable String key, @Nullable char[] value) {
718         super.putCharArray(key, value);
719     }
720 
721     /**
722      * Inserts a float array value into the mapping of this Bundle, replacing
723      * any existing value for the given key.  Either key or value may be null.
724      *
725      * @param key a String, or null
726      * @param value a float array object, or null
727      */
728     @Override
putFloatArray(@ullable String key, @Nullable float[] value)729     public void putFloatArray(@Nullable String key, @Nullable float[] value) {
730         super.putFloatArray(key, value);
731     }
732 
733     /**
734      * Inserts a CharSequence array value into the mapping of this Bundle, replacing
735      * any existing value for the given key.  Either key or value may be null.
736      *
737      * @param key a String, or null
738      * @param value a CharSequence array object, or null
739      */
740     @Override
putCharSequenceArray(@ullable String key, @Nullable CharSequence[] value)741     public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) {
742         super.putCharSequenceArray(key, value);
743     }
744 
745     /**
746      * Inserts a Bundle value into the mapping of this Bundle, replacing
747      * any existing value for the given key.  Either key or value may be null.
748      *
749      * @param key a String, or null
750      * @param value a Bundle object, or null
751      */
putBundle(@ullable String key, @Nullable Bundle value)752     public void putBundle(@Nullable String key, @Nullable Bundle value) {
753         unparcel();
754         mMap.put(key, value);
755     }
756 
757     /**
758      * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing
759      * any existing value for the given key.  Either key or value may be null.
760      *
761      * <p class="note">You should be very careful when using this function.  In many
762      * places where Bundles are used (such as inside of Intent objects), the Bundle
763      * can live longer inside of another process than the process that had originally
764      * created it.  In that case, the IBinder you supply here will become invalid
765      * when your process goes away, and no longer usable, even if a new process is
766      * created for you later on.</p>
767      *
768      * @param key a String, or null
769      * @param value an IBinder object, or null
770      */
putBinder(@ullable String key, @Nullable IBinder value)771     public void putBinder(@Nullable String key, @Nullable IBinder value) {
772         unparcel();
773         mMap.put(key, value);
774         mFlags &= ~FLAG_HAS_BINDERS_KNOWN;
775     }
776 
777     /**
778      * Inserts an IBinder value into the mapping of this Bundle, replacing
779      * any existing value for the given key.  Either key or value may be null.
780      *
781      * @param key a String, or null
782      * @param value an IBinder object, or null
783      *
784      * @deprecated
785      * @hide This is the old name of the function.
786      */
787     @UnsupportedAppUsage
788     @Deprecated
putIBinder(@ullable String key, @Nullable IBinder value)789     public void putIBinder(@Nullable String key, @Nullable IBinder value) {
790         unparcel();
791         mMap.put(key, value);
792         mFlags &= ~FLAG_HAS_BINDERS_KNOWN;
793     }
794 
795     /**
796      * Returns the value associated with the given key, or (byte) 0 if
797      * no mapping of the desired type exists for the given key.
798      *
799      * @param key a String
800      * @return a byte value
801      */
802     @Override
getByte(String key)803     public byte getByte(String key) {
804         return super.getByte(key);
805     }
806 
807     /**
808      * Returns the value associated with the given key, or defaultValue if
809      * no mapping of the desired type exists for the given key.
810      *
811      * @param key a String
812      * @param defaultValue Value to return if key does not exist
813      * @return a byte value
814      */
815     @Override
getByte(String key, byte defaultValue)816     public Byte getByte(String key, byte defaultValue) {
817         return super.getByte(key, defaultValue);
818     }
819 
820     /**
821      * Returns the value associated with the given key, or (char) 0 if
822      * no mapping of the desired type exists for the given key.
823      *
824      * @param key a String
825      * @return a char value
826      */
827     @Override
getChar(String key)828     public char getChar(String key) {
829         return super.getChar(key);
830     }
831 
832     /**
833      * Returns the value associated with the given key, or defaultValue if
834      * no mapping of the desired type exists for the given key.
835      *
836      * @param key a String
837      * @param defaultValue Value to return if key does not exist
838      * @return a char value
839      */
840     @Override
getChar(String key, char defaultValue)841     public char getChar(String key, char defaultValue) {
842         return super.getChar(key, defaultValue);
843     }
844 
845     /**
846      * Returns the value associated with the given key, or (short) 0 if
847      * no mapping of the desired type exists for the given key.
848      *
849      * @param key a String
850      * @return a short value
851      */
852     @Override
getShort(String key)853     public short getShort(String key) {
854         return super.getShort(key);
855     }
856 
857     /**
858      * Returns the value associated with the given key, or defaultValue if
859      * no mapping of the desired type exists for the given key.
860      *
861      * @param key a String
862      * @param defaultValue Value to return if key does not exist
863      * @return a short value
864      */
865     @Override
getShort(String key, short defaultValue)866     public short getShort(String key, short defaultValue) {
867         return super.getShort(key, defaultValue);
868     }
869 
870     /**
871      * Returns the value associated with the given key, or 0.0f if
872      * no mapping of the desired type exists for the given key.
873      *
874      * @param key a String
875      * @return a float value
876      */
877     @Override
getFloat(String key)878     public float getFloat(String key) {
879         return super.getFloat(key);
880     }
881 
882     /**
883      * Returns the value associated with the given key, or defaultValue if
884      * no mapping of the desired type exists for the given key.
885      *
886      * @param key a String
887      * @param defaultValue Value to return if key does not exist
888      * @return a float value
889      */
890     @Override
getFloat(String key, float defaultValue)891     public float getFloat(String key, float defaultValue) {
892         return super.getFloat(key, defaultValue);
893     }
894 
895     /**
896      * Returns the value associated with the given key, or null if
897      * no mapping of the desired type exists for the given key or a null
898      * value is explicitly associated with the key.
899      *
900      * @param key a String, or null
901      * @return a CharSequence value, or null
902      */
903     @Override
904     @Nullable
getCharSequence(@ullable String key)905     public CharSequence getCharSequence(@Nullable String key) {
906         return super.getCharSequence(key);
907     }
908 
909     /**
910      * Returns the value associated with the given key, or defaultValue if
911      * no mapping of the desired type exists for the given key or if a null
912      * value is explicitly associatd with the given key.
913      *
914      * @param key a String, or null
915      * @param defaultValue Value to return if key does not exist or if a null
916      *     value is associated with the given key.
917      * @return the CharSequence value associated with the given key, or defaultValue
918      *     if no valid CharSequence object is currently mapped to that key.
919      */
920     @Override
getCharSequence(@ullable String key, CharSequence defaultValue)921     public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) {
922         return super.getCharSequence(key, defaultValue);
923     }
924 
925     /**
926      * Returns the value associated with the given key, or null if
927      * no mapping of the desired type exists for the given key or a null
928      * value is explicitly associated with the key.
929      *
930      * @param key a String, or null
931      * @return a Size value, or null
932      */
933     @Nullable
getSize(@ullable String key)934     public Size getSize(@Nullable String key) {
935         unparcel();
936         final Object o = mMap.get(key);
937         try {
938             return (Size) o;
939         } catch (ClassCastException e) {
940             typeWarning(key, o, "Size", e);
941             return null;
942         }
943     }
944 
945     /**
946      * Returns the value associated with the given key, or null if
947      * no mapping of the desired type exists for the given key or a null
948      * value is explicitly associated with the key.
949      *
950      * @param key a String, or null
951      * @return a Size value, or null
952      */
953     @Nullable
getSizeF(@ullable String key)954     public SizeF getSizeF(@Nullable String key) {
955         unparcel();
956         final Object o = mMap.get(key);
957         try {
958             return (SizeF) o;
959         } catch (ClassCastException e) {
960             typeWarning(key, o, "SizeF", e);
961             return null;
962         }
963     }
964 
965     /**
966      * Returns the value associated with the given key, or null if
967      * no mapping of the desired type exists for the given key or a null
968      * value is explicitly associated with the key.
969      *
970      * @param key a String, or null
971      * @return a Bundle value, or null
972      */
973     @Nullable
getBundle(@ullable String key)974     public Bundle getBundle(@Nullable String key) {
975         unparcel();
976         Object o = mMap.get(key);
977         if (o == null) {
978             return null;
979         }
980         try {
981             return (Bundle) o;
982         } catch (ClassCastException e) {
983             typeWarning(key, o, "Bundle", e);
984             return null;
985         }
986     }
987 
988     /**
989      * Returns the value associated with the given key, or {@code null} if
990      * no mapping of the desired type exists for the given key or a {@code null}
991      * value is explicitly associated with the key.
992      *
993      * <p><b>Note: </b> if the expected value is not a class provided by the Android platform,
994      * you must call {@link #setClassLoader(ClassLoader)} with the proper {@link ClassLoader} first.
995      * Otherwise, this method might throw an exception or return {@code null}.
996      *
997      * @param key a String, or {@code null}
998      * @return a Parcelable value, or {@code null}
999      *
1000      * @deprecated Use the type-safer {@link #getParcelable(String, Class)} starting from Android
1001      *      {@link Build.VERSION_CODES#TIRAMISU}.
1002      */
1003     @Deprecated
1004     @Nullable
getParcelable(@ullable String key)1005     public <T extends Parcelable> T getParcelable(@Nullable String key) {
1006         unparcel();
1007         Object o = getValue(key);
1008         if (o == null) {
1009             return null;
1010         }
1011         try {
1012             return (T) o;
1013         } catch (ClassCastException e) {
1014             typeWarning(key, o, "Parcelable", e);
1015             return null;
1016         }
1017     }
1018 
1019     /**
1020      * Returns the value associated with the given key or {@code null} if:
1021      * <ul>
1022      *     <li>No mapping of the desired type exists for the given key.
1023      *     <li>A {@code null} value is explicitly associated with the key.
1024      *     <li>The object is not of type {@code clazz}.
1025      * </ul>
1026      *
1027      * <p><b>Note: </b> if the expected value is not a class provided by the Android platform,
1028      * you must call {@link #setClassLoader(ClassLoader)} with the proper {@link ClassLoader} first.
1029      * Otherwise, this method might throw an exception or return {@code null}.
1030      *
1031      * <p><b>Warning: </b> the class that implements {@link Parcelable} has to be the immediately
1032      * enclosing class of the runtime type of its CREATOR field (that is,
1033      * {@link Class#getEnclosingClass()} has to return the parcelable implementing class),
1034      * otherwise this method might throw an exception. If the Parcelable class does not enclose the
1035      * CREATOR, use the deprecated {@link #getParcelable(String)} instead.
1036      *
1037      * @param key a String, or {@code null}
1038      * @param clazz The type of the object expected
1039      * @return a Parcelable value, or {@code null}
1040      */
1041     @SuppressWarnings("unchecked")
1042     @Nullable
getParcelable(@ullable String key, @NonNull Class<T> clazz)1043     public <T> T getParcelable(@Nullable String key, @NonNull Class<T> clazz) {
1044         // The reason for not using <T extends Parcelable> is because the caller could provide a
1045         // super class to restrict the children that doesn't implement Parcelable itself while the
1046         // children do, more details at b/210800751 (same reasoning applies here).
1047         return get(key, clazz);
1048     }
1049 
1050     /**
1051      * Returns the value associated with the given key, or {@code null} if
1052      * no mapping of the desired type exists for the given key or a null
1053      * value is explicitly associated with the key.
1054      *
1055      * <p><b>Note: </b> if the expected value is not a class provided by the Android platform,
1056      * you must call {@link #setClassLoader(ClassLoader)} with the proper {@link ClassLoader} first.
1057      * Otherwise, this method might throw an exception or return {@code null}.
1058      *
1059      * @param key a String, or {@code null}
1060      * @return a Parcelable[] value, or {@code null}
1061      *
1062      * @deprecated Use the type-safer {@link #getParcelableArray(String, Class)} starting from
1063      *      Android {@link Build.VERSION_CODES#TIRAMISU}.
1064      */
1065     @Deprecated
1066     @Nullable
getParcelableArray(@ullable String key)1067     public Parcelable[] getParcelableArray(@Nullable String key) {
1068         unparcel();
1069         Object o = getValue(key);
1070         if (o == null) {
1071             return null;
1072         }
1073         try {
1074             return (Parcelable[]) o;
1075         } catch (ClassCastException e) {
1076             typeWarning(key, o, "Parcelable[]", e);
1077             return null;
1078         }
1079     }
1080 
1081     /**
1082      * Returns the value associated with the given key, or {@code null} if:
1083      * <ul>
1084      *     <li>No mapping of the desired type exists for the given key.
1085      *     <li>A {@code null} value is explicitly associated with the key.
1086      *     <li>The object is not of type {@code clazz}.
1087      * </ul>
1088      *
1089      * <p><b>Note: </b> if the expected value is not a class provided by the Android platform,
1090      * you must call {@link #setClassLoader(ClassLoader)} with the proper {@link ClassLoader} first.
1091      * Otherwise, this method might throw an exception or return {@code null}.
1092      *
1093      * <p><b>Warning: </b> if the list contains items implementing the {@link Parcelable} interface,
1094      * the class that implements {@link Parcelable} has to be the immediately
1095      * enclosing class of the runtime type of its CREATOR field (that is,
1096      * {@link Class#getEnclosingClass()} has to return the parcelable implementing class),
1097      * otherwise this method might throw an exception. If the Parcelable class does not enclose the
1098      * CREATOR, use the deprecated {@link #getParcelableArray(String)} instead.
1099      *
1100      * @param key a String, or {@code null}
1101      * @param clazz The type of the items inside the array. This is only verified when unparceling.
1102      * @return a Parcelable[] value, or {@code null}
1103      */
1104     @SuppressLint({"ArrayReturn", "NullableCollection"})
1105     @SuppressWarnings("unchecked")
1106     @Nullable
getParcelableArray(@ullable String key, @NonNull Class<T> clazz)1107     public <T> T[] getParcelableArray(@Nullable String key, @NonNull Class<T> clazz) {
1108         // The reason for not using <T extends Parcelable> is because the caller could provide a
1109         // super class to restrict the children that doesn't implement Parcelable itself while the
1110         // children do, more details at b/210800751 (same reasoning applies here).
1111         unparcel();
1112         try {
1113             // In Java 12, we can pass clazz.arrayType() instead of Parcelable[] and later casting.
1114             return (T[]) getValue(key, Parcelable[].class, requireNonNull(clazz));
1115         } catch (ClassCastException | BadTypeParcelableException e) {
1116             typeWarning(key, clazz.getCanonicalName() + "[]", e);
1117             return null;
1118         }
1119     }
1120 
1121     /**
1122      * Returns the value associated with the given key, or {@code null} if
1123      * no mapping of the desired type exists for the given key or a {@code null}
1124      * value is explicitly associated with the key.
1125      *
1126      * <p><b>Note: </b> if the expected value is not a class provided by the Android platform,
1127      * you must call {@link #setClassLoader(ClassLoader)} with the proper {@link ClassLoader} first.
1128      * Otherwise, this method might throw an exception or return {@code null}.
1129      *
1130      * @param key a String, or {@code null}
1131      * @return an ArrayList<T> value, or {@code null}
1132      *
1133      * @deprecated Use the type-safer {@link #getParcelable(String, Class)} starting from Android
1134      *      {@link Build.VERSION_CODES#TIRAMISU}.
1135      */
1136     @Deprecated
1137     @Nullable
getParcelableArrayList(@ullable String key)1138     public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) {
1139         unparcel();
1140         Object o = getValue(key);
1141         if (o == null) {
1142             return null;
1143         }
1144         try {
1145             return (ArrayList<T>) o;
1146         } catch (ClassCastException e) {
1147             typeWarning(key, o, "ArrayList", e);
1148             return null;
1149         }
1150     }
1151 
1152     /**
1153      * Returns the value associated with the given key, or {@code null} if:
1154      * <ul>
1155      *     <li>No mapping of the desired type exists for the given key.
1156      *     <li>A {@code null} value is explicitly associated with the key.
1157      *     <li>The object is not of type {@code clazz}.
1158      * </ul>
1159      *
1160      * <p><b>Note: </b> if the expected value is not a class provided by the Android platform,
1161      * you must call {@link #setClassLoader(ClassLoader)} with the proper {@link ClassLoader} first.
1162      * Otherwise, this method might throw an exception or return {@code null}.
1163      *
1164      * <p><b>Warning: </b> if the list contains items implementing the {@link Parcelable} interface,
1165      * the class that implements {@link Parcelable} has to be the immediately
1166      * enclosing class of the runtime type of its CREATOR field (that is,
1167      * {@link Class#getEnclosingClass()} has to return the parcelable implementing class),
1168      * otherwise this method might throw an exception. If the Parcelable class does not enclose the
1169      * CREATOR, use the deprecated {@link #getParcelableArrayList(String)} instead.
1170      *
1171      * @param key   a String, or {@code null}
1172      * @param clazz The type of the items inside the array list. This is only verified when
1173      *     unparceling.
1174      * @return an ArrayList<T> value, or {@code null}
1175      */
1176     @SuppressLint("NullableCollection")
1177     @SuppressWarnings("unchecked")
1178     @Nullable
getParcelableArrayList(@ullable String key, @NonNull Class<? extends T> clazz)1179     public <T> ArrayList<T> getParcelableArrayList(@Nullable String key,
1180             @NonNull Class<? extends T> clazz) {
1181         // The reason for not using <T extends Parcelable> is because the caller could provide a
1182         // super class to restrict the children that doesn't implement Parcelable itself while the
1183         // children do, more details at b/210800751 (same reasoning applies here).
1184         return getArrayList(key, clazz);
1185     }
1186 
1187     /**
1188      * Returns the value associated with the given key, or null if
1189      * no mapping of the desired type exists for the given key or a null
1190      * value is explicitly associated with the key.
1191      *
1192      * @param key a String, or null
1193      * @return a SparseArray of T values, or null
1194      *
1195      * @deprecated Use the type-safer {@link #getSparseParcelableArray(String, Class)} starting from
1196      *      Android {@link Build.VERSION_CODES#TIRAMISU}.
1197      */
1198     @Deprecated
1199     @Nullable
getSparseParcelableArray(@ullable String key)1200     public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) {
1201         unparcel();
1202         Object o = getValue(key);
1203         if (o == null) {
1204             return null;
1205         }
1206         try {
1207             return (SparseArray<T>) o;
1208         } catch (ClassCastException e) {
1209             typeWarning(key, o, "SparseArray", e);
1210             return null;
1211         }
1212     }
1213 
1214     /**
1215      * Returns the value associated with the given key, or {@code null} if:
1216      * <ul>
1217      *     <li>No mapping of the desired type exists for the given key.
1218      *     <li>A {@code null} value is explicitly associated with the key.
1219      *     <li>The object is not of type {@code clazz}.
1220      * </ul>
1221      *
1222      * <p><b>Warning: </b> if the list contains items implementing the {@link Parcelable} interface,
1223      * the class that implements {@link Parcelable} has to be the immediately
1224      * enclosing class of the runtime type of its CREATOR field (that is,
1225      * {@link Class#getEnclosingClass()} has to return the parcelable implementing class),
1226      * otherwise this method might throw an exception. If the Parcelable class does not enclose the
1227      * CREATOR, use the deprecated {@link #getSparseParcelableArray(String)} instead.
1228      *
1229      * @param key a String, or null
1230      * @param clazz The type of the items inside the sparse array. This is only verified when
1231      *     unparceling.
1232      * @return a SparseArray of T values, or null
1233      */
1234     @SuppressWarnings("unchecked")
1235     @Nullable
getSparseParcelableArray(@ullable String key, @NonNull Class<? extends T> clazz)1236     public <T> SparseArray<T> getSparseParcelableArray(@Nullable String key,
1237             @NonNull Class<? extends T> clazz) {
1238         // The reason for not using <T extends Parcelable> is because the caller could provide a
1239         // super class to restrict the children that doesn't implement Parcelable itself while the
1240         // children do, more details at b/210800751 (same reasoning applies here).
1241         unparcel();
1242         try {
1243             return (SparseArray<T>) getValue(key, SparseArray.class, requireNonNull(clazz));
1244         } catch (ClassCastException | BadTypeParcelableException e) {
1245             typeWarning(key, "SparseArray<" + clazz.getCanonicalName() + ">", e);
1246             return null;
1247         }
1248     }
1249 
1250     /**
1251      * Returns the value associated with the given key, or null if
1252      * no mapping of the desired type exists for the given key or a null
1253      * value is explicitly associated with the key.
1254      *
1255      * @param key a String, or null
1256      * @return a Serializable value, or null
1257      *
1258      * @deprecated Use the type-safer {@link #getSerializable(String, Class)} starting from Android
1259      *      {@link Build.VERSION_CODES#TIRAMISU}.
1260      */
1261     @Deprecated
1262     @Override
1263     @Nullable
getSerializable(@ullable String key)1264     public Serializable getSerializable(@Nullable String key) {
1265         return super.getSerializable(key);
1266     }
1267 
1268     /**
1269      * Returns the value associated with the given key, or {@code null} if:
1270      * <ul>
1271      *     <li>No mapping of the desired type exists for the given key.
1272      *     <li>A {@code null} value is explicitly associated with the key.
1273      *     <li>The object is not of type {@code clazz}.
1274      * </ul>
1275      *
1276      * @param key   a String, or null
1277      * @param clazz The expected class of the returned type
1278      * @return a Serializable value, or null
1279      */
1280     @Nullable
getSerializable(@ullable String key, @NonNull Class<T> clazz)1281     public <T extends Serializable> T getSerializable(@Nullable String key,
1282             @NonNull Class<T> clazz) {
1283         return super.getSerializable(key, requireNonNull(clazz));
1284     }
1285 
1286     /**
1287      * Returns the value associated with the given key, or null if
1288      * no mapping of the desired type exists for the given key or a null
1289      * value is explicitly associated with the key.
1290      *
1291      * @param key a String, or null
1292      * @return an ArrayList<String> value, or null
1293      */
1294     @Override
1295     @Nullable
getIntegerArrayList(@ullable String key)1296     public ArrayList<Integer> getIntegerArrayList(@Nullable String key) {
1297         return super.getIntegerArrayList(key);
1298     }
1299 
1300     /**
1301      * Returns the value associated with the given key, or null if
1302      * no mapping of the desired type exists for the given key or a null
1303      * value is explicitly associated with the key.
1304      *
1305      * @param key a String, or null
1306      * @return an ArrayList<String> value, or null
1307      */
1308     @Override
1309     @Nullable
getStringArrayList(@ullable String key)1310     public ArrayList<String> getStringArrayList(@Nullable String key) {
1311         return super.getStringArrayList(key);
1312     }
1313 
1314     /**
1315      * Returns the value associated with the given key, or null if
1316      * no mapping of the desired type exists for the given key or a null
1317      * value is explicitly associated with the key.
1318      *
1319      * @param key a String, or null
1320      * @return an ArrayList<CharSequence> value, or null
1321      */
1322     @Override
1323     @Nullable
getCharSequenceArrayList(@ullable String key)1324     public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) {
1325         return super.getCharSequenceArrayList(key);
1326     }
1327 
1328     /**
1329      * Returns the value associated with the given key, or null if
1330      * no mapping of the desired type exists for the given key or a null
1331      * value is explicitly associated with the key.
1332      *
1333      * @param key a String, or null
1334      * @return a byte[] value, or null
1335      */
1336     @Override
1337     @Nullable
getByteArray(@ullable String key)1338     public byte[] getByteArray(@Nullable String key) {
1339         return super.getByteArray(key);
1340     }
1341 
1342     /**
1343      * Returns the value associated with the given key, or null if
1344      * no mapping of the desired type exists for the given key or a null
1345      * value is explicitly associated with the key.
1346      *
1347      * @param key a String, or null
1348      * @return a short[] value, or null
1349      */
1350     @Override
1351     @Nullable
getShortArray(@ullable String key)1352     public short[] getShortArray(@Nullable String key) {
1353         return super.getShortArray(key);
1354     }
1355 
1356     /**
1357      * Returns the value associated with the given key, or null if
1358      * no mapping of the desired type exists for the given key or a null
1359      * value is explicitly associated with the key.
1360      *
1361      * @param key a String, or null
1362      * @return a char[] value, or null
1363      */
1364     @Override
1365     @Nullable
getCharArray(@ullable String key)1366     public char[] getCharArray(@Nullable String key) {
1367         return super.getCharArray(key);
1368     }
1369 
1370     /**
1371      * Returns the value associated with the given key, or null if
1372      * no mapping of the desired type exists for the given key or a null
1373      * value is explicitly associated with the key.
1374      *
1375      * @param key a String, or null
1376      * @return a float[] value, or null
1377      */
1378     @Override
1379     @Nullable
getFloatArray(@ullable String key)1380     public float[] getFloatArray(@Nullable String key) {
1381         return super.getFloatArray(key);
1382     }
1383 
1384     /**
1385      * Returns the value associated with the given key, or null if
1386      * no mapping of the desired type exists for the given key or a null
1387      * value is explicitly associated with the key.
1388      *
1389      * @param key a String, or null
1390      * @return a CharSequence[] value, or null
1391      */
1392     @Override
1393     @Nullable
getCharSequenceArray(@ullable String key)1394     public CharSequence[] getCharSequenceArray(@Nullable String key) {
1395         return super.getCharSequenceArray(key);
1396     }
1397 
1398     /**
1399      * Returns the value associated with the given key, or null if
1400      * no mapping of the desired type exists for the given key or a null
1401      * value is explicitly associated with the key.
1402      *
1403      * @param key a String, or null
1404      * @return an IBinder value, or null
1405      */
1406     @Nullable
getBinder(@ullable String key)1407     public IBinder getBinder(@Nullable String key) {
1408         unparcel();
1409         Object o = mMap.get(key);
1410         if (o == null) {
1411             return null;
1412         }
1413         try {
1414             return (IBinder) o;
1415         } catch (ClassCastException e) {
1416             typeWarning(key, o, "IBinder", e);
1417             return null;
1418         }
1419     }
1420 
1421     /**
1422      * Returns the value associated with the given key, or null if
1423      * no mapping of the desired type exists for the given key or a null
1424      * value is explicitly associated with the key.
1425      *
1426      * @param key a String, or null
1427      * @return an IBinder value, or null
1428      *
1429      * @deprecated
1430      * @hide This is the old name of the function.
1431      */
1432     @UnsupportedAppUsage
1433     @Deprecated
1434     @Nullable
getIBinder(@ullable String key)1435     public IBinder getIBinder(@Nullable String key) {
1436         unparcel();
1437         Object o = mMap.get(key);
1438         if (o == null) {
1439             return null;
1440         }
1441         try {
1442             return (IBinder) o;
1443         } catch (ClassCastException e) {
1444             typeWarning(key, o, "IBinder", e);
1445             return null;
1446         }
1447     }
1448 
1449     public static final @android.annotation.NonNull Parcelable.Creator<Bundle> CREATOR =
1450         new Parcelable.Creator<Bundle>() {
1451         @Override
1452         public Bundle createFromParcel(Parcel in) {
1453             return in.readBundle();
1454         }
1455 
1456         @Override
1457         public Bundle[] newArray(int size) {
1458             return new Bundle[size];
1459         }
1460     };
1461 
1462     /**
1463      * Report the nature of this Parcelable's contents
1464      */
1465     @Override
describeContents()1466     public int describeContents() {
1467         int mask = 0;
1468         if (hasFileDescriptors()) {
1469             mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR;
1470         }
1471         return mask;
1472     }
1473 
1474     /**
1475      * Writes the Bundle contents to a Parcel, typically in order for
1476      * it to be passed through an IBinder connection.
1477      * @param parcel The parcel to copy this bundle to.
1478      */
1479     @Override
writeToParcel(Parcel parcel, int flags)1480     public void writeToParcel(Parcel parcel, int flags) {
1481         final boolean oldAllowFds = parcel.pushAllowFds((mFlags & FLAG_ALLOW_FDS) != 0);
1482         try {
1483             writeToParcelInner(parcel, flags);
1484         } finally {
1485             parcel.restoreAllowFds(oldAllowFds);
1486         }
1487     }
1488 
1489     /**
1490      * Reads the Parcel contents into this Bundle, typically in order for
1491      * it to be passed through an IBinder connection.
1492      * @param parcel The parcel to overwrite this bundle from.
1493      */
readFromParcel(Parcel parcel)1494     public void readFromParcel(Parcel parcel) {
1495         readFromParcelInner(parcel);
1496         mFlags = FLAG_ALLOW_FDS;
1497         maybePrefillHasFds();
1498     }
1499 
1500     /**
1501      * Returns a string representation of the {@link Bundle} that may be suitable for debugging. It
1502      * won't print the internal map if its content hasn't been unparcelled.
1503      */
1504     @Override
toString()1505     public synchronized String toString() {
1506         if (mParcelledData != null) {
1507             if (isEmptyParcel()) {
1508                 return "Bundle[EMPTY_PARCEL]";
1509             } else {
1510                 return "Bundle[mParcelledData.dataSize=" +
1511                         mParcelledData.dataSize() + "]";
1512             }
1513         }
1514         return "Bundle[" + mMap.toString() + "]";
1515     }
1516 
1517     /**
1518      * @hide
1519      */
toShortString()1520     public synchronized String toShortString() {
1521         if (mParcelledData != null) {
1522             if (isEmptyParcel()) {
1523                 return "EMPTY_PARCEL";
1524             } else {
1525                 return "mParcelledData.dataSize=" + mParcelledData.dataSize();
1526             }
1527         }
1528         return mMap.toString();
1529     }
1530 
1531     /** @hide */
dumpDebug(ProtoOutputStream proto, long fieldId)1532     public void dumpDebug(ProtoOutputStream proto, long fieldId) {
1533         final long token = proto.start(fieldId);
1534 
1535         if (mParcelledData != null) {
1536             if (isEmptyParcel()) {
1537                 proto.write(BundleProto.PARCELLED_DATA_SIZE, 0);
1538             } else {
1539                 proto.write(BundleProto.PARCELLED_DATA_SIZE, mParcelledData.dataSize());
1540             }
1541         } else {
1542             proto.write(BundleProto.MAP_DATA, mMap.toString());
1543         }
1544 
1545         proto.end(token);
1546     }
1547 }
1548