2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 import android.annotation.Nullable;
20 import android.util.ArrayMap;
21 import android.util.Size;
22 import android.util.SizeF;
23 import android.util.SparseArray;
25 import java.io.Serializable;
26 import java.util.ArrayList;
27 import java.util.List;
30 * A mapping from String keys to various {@link Parcelable} values.
32 * @see PersistableBundle
34 public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
35 private static final int FLAG_HAS_FDS = 1 << 8;
36 private static final int FLAG_HAS_FDS_KNOWN = 1 << 9;
37 private static final int FLAG_ALLOW_FDS = 1 << 10;
39 public static final Bundle EMPTY;
41 static final Parcel EMPTY_PARCEL;
45 EMPTY.mMap = ArrayMap.EMPTY;
46 EMPTY_PARCEL = BaseBundle.EMPTY_PARCEL;
50 * Constructs a new, empty Bundle.
54 mFlags = FLAG_HAS_FDS_KNOWN;
58 * Constructs a Bundle whose data is stored as a Parcel. The data
59 * will be unparcelled on first contact, using the assigned ClassLoader.
61 * @param parcelledData a Parcel containing a Bundle
63 Bundle(Parcel parcelledData) {
65 mFlags = FLAG_HAS_FDS_KNOWN;
66 if (mParcelledData.hasFileDescriptors()) {
67 mFlags |= FLAG_HAS_FDS;
71 /* package */ Bundle(Parcel parcelledData, int length) {
72 super(parcelledData, length);
73 mFlags = FLAG_HAS_FDS_KNOWN;
74 if (mParcelledData.hasFileDescriptors()) {
75 mFlags |= FLAG_HAS_FDS;
80 * Constructs a new, empty Bundle that uses a specific ClassLoader for
81 * instantiating Parcelable and Serializable objects.
83 * @param loader An explicit ClassLoader to use when instantiating objects
84 * inside of the Bundle.
86 public Bundle(ClassLoader loader) {
88 mFlags = FLAG_HAS_FDS_KNOWN;
92 * Constructs a new, empty Bundle sized to hold the given number of
93 * elements. The Bundle will grow as needed.
95 * @param capacity the initial capacity of the Bundle
97 public Bundle(int capacity) {
99 mFlags = FLAG_HAS_FDS_KNOWN;
103 * Constructs a Bundle containing a copy of the mappings from the given
106 * @param b a Bundle to be copied.
108 public Bundle(Bundle b) {
114 * Constructs a Bundle containing a copy of the mappings from the given
117 * @param b a Bundle to be copied.
119 public Bundle(PersistableBundle b) {
121 mFlags = FLAG_HAS_FDS_KNOWN;
125 * Make a Bundle for a single key/value pair.
129 public static Bundle forPair(String key, String value) {
130 Bundle b = new Bundle(1);
131 b.putString(key, value);
136 * Changes the ClassLoader this Bundle uses when instantiating objects.
138 * @param loader An explicit ClassLoader to use when instantiating objects
139 * inside of the Bundle.
142 public void setClassLoader(ClassLoader loader) {
143 super.setClassLoader(loader);
147 * Return the ClassLoader currently associated with this Bundle.
150 public ClassLoader getClassLoader() {
151 return super.getClassLoader();
155 public boolean setAllowFds(boolean allowFds) {
156 final boolean orig = (mFlags & FLAG_ALLOW_FDS) != 0;
158 mFlags |= FLAG_ALLOW_FDS;
160 mFlags &= ~FLAG_ALLOW_FDS;
166 * Mark if this Bundle is okay to "defuse." That is, it's okay for system
167 * processes to ignore any {@link BadParcelableException} encountered when
168 * unparceling it, leaving an empty bundle in its place.
170 * This should <em>only</em> be set when the Bundle reaches its final
171 * destination, otherwise a system process may clobber contents that were
172 * destined for an app that could have unparceled them.
176 public void setDefusable(boolean defusable) {
178 mFlags |= FLAG_DEFUSABLE;
180 mFlags &= ~FLAG_DEFUSABLE;
185 * Clones the current Bundle. The internal map is cloned, but the keys and
186 * values to which it refers are copied by reference.
189 public Object clone() {
190 return new Bundle(this);
194 * Removes all elements from the mapping of this Bundle.
197 public void clear() {
199 mFlags = FLAG_HAS_FDS_KNOWN;
203 * Inserts all mappings from the given Bundle into this Bundle.
205 * @param bundle a Bundle
207 public void putAll(Bundle bundle) {
210 mMap.putAll(bundle.mMap);
212 // FD state is now known if and only if both bundles already knew
213 if ((bundle.mFlags & FLAG_HAS_FDS) != 0) {
214 mFlags |= FLAG_HAS_FDS;
216 if ((bundle.mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
217 mFlags &= ~FLAG_HAS_FDS_KNOWN;
222 * Reports whether the bundle contains any parcelled file descriptors.
224 public boolean hasFileDescriptors() {
225 if ((mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
226 boolean fdFound = false; // keep going until we find one or run out of data
228 if (mParcelledData != null) {
229 if (mParcelledData.hasFileDescriptors()) {
233 // It's been unparcelled, so we need to walk the map
234 for (int i=mMap.size()-1; i>=0; i--) {
235 Object obj = mMap.valueAt(i);
236 if (obj instanceof Parcelable) {
237 if ((((Parcelable)obj).describeContents()
238 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
242 } else if (obj instanceof Parcelable[]) {
243 Parcelable[] array = (Parcelable[]) obj;
244 for (int n = array.length - 1; n >= 0; n--) {
245 Parcelable p = array[n];
246 if (p != null && ((p.describeContents()
247 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
252 } else if (obj instanceof SparseArray) {
253 SparseArray<? extends Parcelable> array =
254 (SparseArray<? extends Parcelable>) obj;
255 for (int n = array.size() - 1; n >= 0; n--) {
256 Parcelable p = array.valueAt(n);
257 if (p != null && (p.describeContents()
258 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
263 } else if (obj instanceof ArrayList) {
264 ArrayList array = (ArrayList) obj;
265 // an ArrayList here might contain either Strings or
266 // Parcelables; only look inside for Parcelables
267 if (!array.isEmpty() && (array.get(0) instanceof Parcelable)) {
268 for (int n = array.size() - 1; n >= 0; n--) {
269 Parcelable p = (Parcelable) array.get(n);
270 if (p != null && ((p.describeContents()
271 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
282 mFlags |= FLAG_HAS_FDS;
284 mFlags |= FLAG_HAS_FDS_KNOWN;
286 return (mFlags & FLAG_HAS_FDS) != 0;
290 * Filter values in Bundle to only basic types.
293 public void filterValues() {
296 for (int i = mMap.size() - 1; i >= 0; i--) {
297 Object value = mMap.valueAt(i);
298 if (PersistableBundle.isValidType(value)) {
301 if (value instanceof Bundle) {
302 ((Bundle)value).filterValues();
304 if (value.getClass().getName().startsWith("android.")) {
313 * Inserts a byte value into the mapping of this Bundle, replacing
314 * any existing value for the given key.
316 * @param key a String, or null
317 * @param value a byte
320 public void putByte(@Nullable String key, byte value) {
321 super.putByte(key, value);
325 * Inserts a char value into the mapping of this Bundle, replacing
326 * any existing value for the given key.
328 * @param key a String, or null
329 * @param value a char
332 public void putChar(@Nullable String key, char value) {
333 super.putChar(key, value);
337 * Inserts a short value into the mapping of this Bundle, replacing
338 * any existing value for the given key.
340 * @param key a String, or null
341 * @param value a short
344 public void putShort(@Nullable String key, short value) {
345 super.putShort(key, value);
349 * Inserts a float value into the mapping of this Bundle, replacing
350 * any existing value for the given key.
352 * @param key a String, or null
353 * @param value a float
356 public void putFloat(@Nullable String key, float value) {
357 super.putFloat(key, value);
361 * Inserts a CharSequence value into the mapping of this Bundle, replacing
362 * any existing value for the given key. Either key or value may be null.
364 * @param key a String, or null
365 * @param value a CharSequence, or null
368 public void putCharSequence(@Nullable String key, @Nullable CharSequence value) {
369 super.putCharSequence(key, value);
373 * Inserts a Parcelable value into the mapping of this Bundle, replacing
374 * any existing value for the given key. Either key or value may be null.
376 * @param key a String, or null
377 * @param value a Parcelable object, or null
379 public void putParcelable(@Nullable String key, @Nullable Parcelable value) {
381 mMap.put(key, value);
382 mFlags &= ~FLAG_HAS_FDS_KNOWN;
386 * Inserts a Size value into the mapping of this Bundle, replacing
387 * any existing value for the given key. Either key or value may be null.
389 * @param key a String, or null
390 * @param value a Size object, or null
392 public void putSize(@Nullable String key, @Nullable Size value) {
394 mMap.put(key, value);
398 * Inserts a SizeF value into the mapping of this Bundle, replacing
399 * any existing value for the given key. Either key or value may be null.
401 * @param key a String, or null
402 * @param value a SizeF object, or null
404 public void putSizeF(@Nullable String key, @Nullable SizeF value) {
406 mMap.put(key, value);
410 * Inserts an array of Parcelable values into the mapping of this Bundle,
411 * replacing any existing value for the given key. Either key or value may
414 * @param key a String, or null
415 * @param value an array of Parcelable objects, or null
417 public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) {
419 mMap.put(key, value);
420 mFlags &= ~FLAG_HAS_FDS_KNOWN;
424 * Inserts a List of Parcelable values into the mapping of this Bundle,
425 * replacing any existing value for the given key. Either key or value may
428 * @param key a String, or null
429 * @param value an ArrayList of Parcelable objects, or null
431 public void putParcelableArrayList(@Nullable String key,
432 @Nullable ArrayList<? extends Parcelable> value) {
434 mMap.put(key, value);
435 mFlags &= ~FLAG_HAS_FDS_KNOWN;
439 public void putParcelableList(String key, List<? extends Parcelable> value) {
441 mMap.put(key, value);
442 mFlags &= ~FLAG_HAS_FDS_KNOWN;
446 * Inserts a SparceArray of Parcelable values into the mapping of this
447 * Bundle, replacing any existing value for the given key. Either key
448 * or value may be null.
450 * @param key a String, or null
451 * @param value a SparseArray of Parcelable objects, or null
453 public void putSparseParcelableArray(@Nullable String key,
454 @Nullable SparseArray<? extends Parcelable> value) {
456 mMap.put(key, value);
457 mFlags &= ~FLAG_HAS_FDS_KNOWN;
461 * Inserts an ArrayList<Integer> value into the mapping of this Bundle, replacing
462 * any existing value for the given key. Either key or value may be null.
464 * @param key a String, or null
465 * @param value an ArrayList<Integer> object, or null
468 public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) {
469 super.putIntegerArrayList(key, value);
473 * Inserts an ArrayList<String> value into the mapping of this Bundle, replacing
474 * any existing value for the given key. Either key or value may be null.
476 * @param key a String, or null
477 * @param value an ArrayList<String> object, or null
480 public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) {
481 super.putStringArrayList(key, value);
485 * Inserts an ArrayList<CharSequence> value into the mapping of this Bundle, replacing
486 * any existing value for the given key. Either key or value may be null.
488 * @param key a String, or null
489 * @param value an ArrayList<CharSequence> object, or null
492 public void putCharSequenceArrayList(@Nullable String key,
493 @Nullable ArrayList<CharSequence> value) {
494 super.putCharSequenceArrayList(key, value);
498 * Inserts a Serializable value into the mapping of this Bundle, replacing
499 * any existing value for the given key. Either key or value may be null.
501 * @param key a String, or null
502 * @param value a Serializable object, or null
505 public void putSerializable(@Nullable String key, @Nullable Serializable value) {
506 super.putSerializable(key, value);
510 * Inserts a byte array value into the mapping of this Bundle, replacing
511 * any existing value for the given key. Either key or value may be null.
513 * @param key a String, or null
514 * @param value a byte array object, or null
517 public void putByteArray(@Nullable String key, @Nullable byte[] value) {
518 super.putByteArray(key, value);
522 * Inserts a short array value into the mapping of this Bundle, replacing
523 * any existing value for the given key. Either key or value may be null.
525 * @param key a String, or null
526 * @param value a short array object, or null
529 public void putShortArray(@Nullable String key, @Nullable short[] value) {
530 super.putShortArray(key, value);
534 * Inserts a char array value into the mapping of this Bundle, replacing
535 * any existing value for the given key. Either key or value may be null.
537 * @param key a String, or null
538 * @param value a char array object, or null
541 public void putCharArray(@Nullable String key, @Nullable char[] value) {
542 super.putCharArray(key, value);
546 * Inserts a float array value into the mapping of this Bundle, replacing
547 * any existing value for the given key. Either key or value may be null.
549 * @param key a String, or null
550 * @param value a float array object, or null
553 public void putFloatArray(@Nullable String key, @Nullable float[] value) {
554 super.putFloatArray(key, value);
558 * Inserts a CharSequence array value into the mapping of this Bundle, replacing
559 * any existing value for the given key. Either key or value may be null.
561 * @param key a String, or null
562 * @param value a CharSequence array object, or null
565 public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) {
566 super.putCharSequenceArray(key, value);
570 * Inserts a Bundle value into the mapping of this Bundle, replacing
571 * any existing value for the given key. Either key or value may be null.
573 * @param key a String, or null
574 * @param value a Bundle object, or null
576 public void putBundle(@Nullable String key, @Nullable Bundle value) {
578 mMap.put(key, value);
582 * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing
583 * any existing value for the given key. Either key or value may be null.
585 * <p class="note">You should be very careful when using this function. In many
586 * places where Bundles are used (such as inside of Intent objects), the Bundle
587 * can live longer inside of another process than the process that had originally
588 * created it. In that case, the IBinder you supply here will become invalid
589 * when your process goes away, and no longer usable, even if a new process is
590 * created for you later on.</p>
592 * @param key a String, or null
593 * @param value an IBinder object, or null
595 public void putBinder(@Nullable String key, @Nullable IBinder value) {
597 mMap.put(key, value);
601 * Inserts an IBinder value into the mapping of this Bundle, replacing
602 * any existing value for the given key. Either key or value may be null.
604 * @param key a String, or null
605 * @param value an IBinder object, or null
608 * @hide This is the old name of the function.
611 public void putIBinder(@Nullable String key, @Nullable IBinder value) {
613 mMap.put(key, value);
617 * Returns the value associated with the given key, or (byte) 0 if
618 * no mapping of the desired type exists for the given key.
620 * @param key a String
621 * @return a byte value
624 public byte getByte(String key) {
625 return super.getByte(key);
629 * Returns the value associated with the given key, or defaultValue if
630 * no mapping of the desired type exists for the given key.
632 * @param key a String
633 * @param defaultValue Value to return if key does not exist
634 * @return a byte value
637 public Byte getByte(String key, byte defaultValue) {
638 return super.getByte(key, defaultValue);
642 * Returns the value associated with the given key, or (char) 0 if
643 * no mapping of the desired type exists for the given key.
645 * @param key a String
646 * @return a char value
649 public char getChar(String key) {
650 return super.getChar(key);
654 * Returns the value associated with the given key, or defaultValue if
655 * no mapping of the desired type exists for the given key.
657 * @param key a String
658 * @param defaultValue Value to return if key does not exist
659 * @return a char value
662 public char getChar(String key, char defaultValue) {
663 return super.getChar(key, defaultValue);
667 * Returns the value associated with the given key, or (short) 0 if
668 * no mapping of the desired type exists for the given key.
670 * @param key a String
671 * @return a short value
674 public short getShort(String key) {
675 return super.getShort(key);
679 * Returns the value associated with the given key, or defaultValue if
680 * no mapping of the desired type exists for the given key.
682 * @param key a String
683 * @param defaultValue Value to return if key does not exist
684 * @return a short value
687 public short getShort(String key, short defaultValue) {
688 return super.getShort(key, defaultValue);
692 * Returns the value associated with the given key, or 0.0f if
693 * no mapping of the desired type exists for the given key.
695 * @param key a String
696 * @return a float value
699 public float getFloat(String key) {
700 return super.getFloat(key);
704 * Returns the value associated with the given key, or defaultValue if
705 * no mapping of the desired type exists for the given key.
707 * @param key a String
708 * @param defaultValue Value to return if key does not exist
709 * @return a float value
712 public float getFloat(String key, float defaultValue) {
713 return super.getFloat(key, defaultValue);
717 * Returns the value associated with the given key, or null if
718 * no mapping of the desired type exists for the given key or a null
719 * value is explicitly associated with the key.
721 * @param key a String, or null
722 * @return a CharSequence value, or null
726 public CharSequence getCharSequence(@Nullable String key) {
727 return super.getCharSequence(key);
731 * Returns the value associated with the given key, or defaultValue if
732 * no mapping of the desired type exists for the given key or if a null
733 * value is explicitly associatd with the given key.
735 * @param key a String, or null
736 * @param defaultValue Value to return if key does not exist or if a null
737 * value is associated with the given key.
738 * @return the CharSequence value associated with the given key, or defaultValue
739 * if no valid CharSequence object is currently mapped to that key.
742 public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) {
743 return super.getCharSequence(key, defaultValue);
747 * Returns the value associated with the given key, or null if
748 * no mapping of the desired type exists for the given key or a null
749 * value is explicitly associated with the key.
751 * @param key a String, or null
752 * @return a Size value, or null
755 public Size getSize(@Nullable String key) {
757 final Object o = mMap.get(key);
760 } catch (ClassCastException e) {
761 typeWarning(key, o, "Size", e);
767 * Returns the value associated with the given key, or null if
768 * no mapping of the desired type exists for the given key or a null
769 * value is explicitly associated with the key.
771 * @param key a String, or null
772 * @return a Size value, or null
775 public SizeF getSizeF(@Nullable String key) {
777 final Object o = mMap.get(key);
780 } catch (ClassCastException e) {
781 typeWarning(key, o, "SizeF", e);
787 * Returns the value associated with the given key, or null if
788 * no mapping of the desired type exists for the given key or a null
789 * value is explicitly associated with the key.
791 * @param key a String, or null
792 * @return a Bundle value, or null
795 public Bundle getBundle(@Nullable String key) {
797 Object o = mMap.get(key);
803 } catch (ClassCastException e) {
804 typeWarning(key, o, "Bundle", e);
810 * Returns the value associated with the given key, or null if
811 * no mapping of the desired type exists for the given key or a null
812 * value is explicitly associated with the key.
814 * @param key a String, or null
815 * @return a Parcelable value, or null
818 public <T extends Parcelable> T getParcelable(@Nullable String key) {
820 Object o = mMap.get(key);
826 } catch (ClassCastException e) {
827 typeWarning(key, o, "Parcelable", e);
833 * Returns the value associated with the given key, or null if
834 * no mapping of the desired type exists for the given key or a null
835 * value is explicitly associated with the key.
837 * @param key a String, or null
838 * @return a Parcelable[] value, or null
841 public Parcelable[] getParcelableArray(@Nullable String key) {
843 Object o = mMap.get(key);
848 return (Parcelable[]) o;
849 } catch (ClassCastException e) {
850 typeWarning(key, o, "Parcelable[]", e);
856 * Returns the value associated with the given key, or null if
857 * no mapping of the desired type exists for the given key or a null
858 * value is explicitly associated with the key.
860 * @param key a String, or null
861 * @return an ArrayList<T> value, or null
864 public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) {
866 Object o = mMap.get(key);
871 return (ArrayList<T>) o;
872 } catch (ClassCastException e) {
873 typeWarning(key, o, "ArrayList", e);
879 * Returns the value associated with the given key, or null if
880 * no mapping of the desired type exists for the given key or a null
881 * value is explicitly associated with the key.
883 * @param key a String, or null
885 * @return a SparseArray of T values, or null
888 public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) {
890 Object o = mMap.get(key);
895 return (SparseArray<T>) o;
896 } catch (ClassCastException e) {
897 typeWarning(key, o, "SparseArray", e);
903 * Returns the value associated with the given key, or null if
904 * no mapping of the desired type exists for the given key or a null
905 * value is explicitly associated with the key.
907 * @param key a String, or null
908 * @return a Serializable value, or null
912 public Serializable getSerializable(@Nullable String key) {
913 return super.getSerializable(key);
917 * Returns the value associated with the given key, or null if
918 * no mapping of the desired type exists for the given key or a null
919 * value is explicitly associated with the key.
921 * @param key a String, or null
922 * @return an ArrayList<String> value, or null
926 public ArrayList<Integer> getIntegerArrayList(@Nullable String key) {
927 return super.getIntegerArrayList(key);
931 * Returns the value associated with the given key, or null if
932 * no mapping of the desired type exists for the given key or a null
933 * value is explicitly associated with the key.
935 * @param key a String, or null
936 * @return an ArrayList<String> value, or null
940 public ArrayList<String> getStringArrayList(@Nullable String key) {
941 return super.getStringArrayList(key);
945 * Returns the value associated with the given key, or null if
946 * no mapping of the desired type exists for the given key or a null
947 * value is explicitly associated with the key.
949 * @param key a String, or null
950 * @return an ArrayList<CharSequence> value, or null
954 public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) {
955 return super.getCharSequenceArrayList(key);
959 * Returns the value associated with the given key, or null if
960 * no mapping of the desired type exists for the given key or a null
961 * value is explicitly associated with the key.
963 * @param key a String, or null
964 * @return a byte[] value, or null
968 public byte[] getByteArray(@Nullable String key) {
969 return super.getByteArray(key);
973 * Returns the value associated with the given key, or null if
974 * no mapping of the desired type exists for the given key or a null
975 * value is explicitly associated with the key.
977 * @param key a String, or null
978 * @return a short[] value, or null
982 public short[] getShortArray(@Nullable String key) {
983 return super.getShortArray(key);
987 * Returns the value associated with the given key, or null if
988 * no mapping of the desired type exists for the given key or a null
989 * value is explicitly associated with the key.
991 * @param key a String, or null
992 * @return a char[] value, or null
996 public char[] getCharArray(@Nullable String key) {
997 return super.getCharArray(key);
1001 * Returns the value associated with the given key, or null if
1002 * no mapping of the desired type exists for the given key or a null
1003 * value is explicitly associated with the key.
1005 * @param key a String, or null
1006 * @return a float[] value, or null
1010 public float[] getFloatArray(@Nullable String key) {
1011 return super.getFloatArray(key);
1015 * Returns the value associated with the given key, or null if
1016 * no mapping of the desired type exists for the given key or a null
1017 * value is explicitly associated with the key.
1019 * @param key a String, or null
1020 * @return a CharSequence[] value, or null
1024 public CharSequence[] getCharSequenceArray(@Nullable String key) {
1025 return super.getCharSequenceArray(key);
1029 * Returns the value associated with the given key, or null if
1030 * no mapping of the desired type exists for the given key or a null
1031 * value is explicitly associated with the key.
1033 * @param key a String, or null
1034 * @return an IBinder value, or null
1037 public IBinder getBinder(@Nullable String key) {
1039 Object o = mMap.get(key);
1045 } catch (ClassCastException e) {
1046 typeWarning(key, o, "IBinder", e);
1052 * Returns the value associated with the given key, or null if
1053 * no mapping of the desired type exists for the given key or a null
1054 * value is explicitly associated with the key.
1056 * @param key a String, or null
1057 * @return an IBinder value, or null
1060 * @hide This is the old name of the function.
1064 public IBinder getIBinder(@Nullable String key) {
1066 Object o = mMap.get(key);
1072 } catch (ClassCastException e) {
1073 typeWarning(key, o, "IBinder", e);
1078 public static final Parcelable.Creator<Bundle> CREATOR =
1079 new Parcelable.Creator<Bundle>() {
1081 public Bundle createFromParcel(Parcel in) {
1082 return in.readBundle();
1086 public Bundle[] newArray(int size) {
1087 return new Bundle[size];
1092 * Report the nature of this Parcelable's contents
1095 public int describeContents() {
1097 if (hasFileDescriptors()) {
1098 mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR;
1104 * Writes the Bundle contents to a Parcel, typically in order for
1105 * it to be passed through an IBinder connection.
1106 * @param parcel The parcel to copy this bundle to.
1109 public void writeToParcel(Parcel parcel, int flags) {
1110 final boolean oldAllowFds = parcel.pushAllowFds((mFlags & FLAG_ALLOW_FDS) != 0);
1112 super.writeToParcelInner(parcel, flags);
1114 parcel.restoreAllowFds(oldAllowFds);
1119 * Reads the Parcel contents into this Bundle, typically in order for
1120 * it to be passed through an IBinder connection.
1121 * @param parcel The parcel to overwrite this bundle from.
1123 public void readFromParcel(Parcel parcel) {
1124 super.readFromParcelInner(parcel);
1125 mFlags = FLAG_HAS_FDS_KNOWN;
1126 if (mParcelledData.hasFileDescriptors()) {
1127 mFlags |= FLAG_HAS_FDS;
1132 public synchronized String toString() {
1133 if (mParcelledData != null) {
1134 if (mParcelledData == EMPTY_PARCEL) {
1135 return "Bundle[EMPTY_PARCEL]";
1137 return "Bundle[mParcelledData.dataSize=" +
1138 mParcelledData.dataSize() + "]";
1141 return "Bundle[" + mMap.toString() + "]";