Bundle.java revision c6a65dff3d9ed3e75f9f4f5abbf24e3d10bdba8b
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 17package android.os; 18 19import android.annotation.Nullable; 20import android.util.ArrayMap; 21import android.util.Size; 22import android.util.SizeF; 23import android.util.SparseArray; 24 25import java.io.Serializable; 26import java.util.ArrayList; 27import java.util.List; 28import java.util.Set; 29 30/** 31 * A mapping from String values to various Parcelable types. 32 * 33 */ 34public final class Bundle extends BaseBundle implements Cloneable, Parcelable { 35 public static final Bundle EMPTY; 36 static final Parcel EMPTY_PARCEL; 37 38 static { 39 EMPTY = new Bundle(); 40 EMPTY.mMap = ArrayMap.EMPTY; 41 EMPTY_PARCEL = BaseBundle.EMPTY_PARCEL; 42 } 43 44 private boolean mHasFds = false; 45 private boolean mFdsKnown = true; 46 private boolean mAllowFds = true; 47 48 /** 49 * Constructs a new, empty Bundle. 50 */ 51 public Bundle() { 52 super(); 53 } 54 55 /** 56 * Constructs a Bundle whose data is stored as a Parcel. The data 57 * will be unparcelled on first contact, using the assigned ClassLoader. 58 * 59 * @param parcelledData a Parcel containing a Bundle 60 */ 61 Bundle(Parcel parcelledData) { 62 super(parcelledData); 63 64 mHasFds = mParcelledData.hasFileDescriptors(); 65 mFdsKnown = true; 66 } 67 68 /* package */ Bundle(Parcel parcelledData, int length) { 69 super(parcelledData, length); 70 71 mHasFds = mParcelledData.hasFileDescriptors(); 72 mFdsKnown = true; 73 } 74 75 /** 76 * Constructs a new, empty Bundle that uses a specific ClassLoader for 77 * instantiating Parcelable and Serializable objects. 78 * 79 * @param loader An explicit ClassLoader to use when instantiating objects 80 * inside of the Bundle. 81 */ 82 public Bundle(ClassLoader loader) { 83 super(loader); 84 } 85 86 /** 87 * Constructs a new, empty Bundle sized to hold the given number of 88 * elements. The Bundle will grow as needed. 89 * 90 * @param capacity the initial capacity of the Bundle 91 */ 92 public Bundle(int capacity) { 93 super(capacity); 94 } 95 96 /** 97 * Constructs a Bundle containing a copy of the mappings from the given 98 * Bundle. 99 * 100 * @param b a Bundle to be copied. 101 */ 102 public Bundle(Bundle b) { 103 super(b); 104 105 mHasFds = b.mHasFds; 106 mFdsKnown = b.mFdsKnown; 107 } 108 109 /** 110 * Constructs a Bundle containing a copy of the mappings from the given 111 * PersistableBundle. 112 * 113 * @param b a Bundle to be copied. 114 */ 115 public Bundle(PersistableBundle b) { 116 super(b); 117 } 118 119 /** 120 * Make a Bundle for a single key/value pair. 121 * 122 * @hide 123 */ 124 public static Bundle forPair(String key, String value) { 125 Bundle b = new Bundle(1); 126 b.putString(key, value); 127 return b; 128 } 129 130 /** 131 * Changes the ClassLoader this Bundle uses when instantiating objects. 132 * 133 * @param loader An explicit ClassLoader to use when instantiating objects 134 * inside of the Bundle. 135 */ 136 @Override 137 public void setClassLoader(ClassLoader loader) { 138 super.setClassLoader(loader); 139 } 140 141 /** 142 * Return the ClassLoader currently associated with this Bundle. 143 */ 144 @Override 145 public ClassLoader getClassLoader() { 146 return super.getClassLoader(); 147 } 148 149 /** @hide */ 150 public boolean setAllowFds(boolean allowFds) { 151 boolean orig = mAllowFds; 152 mAllowFds = allowFds; 153 return orig; 154 } 155 156 /** 157 * Clones the current Bundle. The internal map is cloned, but the keys and 158 * values to which it refers are copied by reference. 159 */ 160 @Override 161 public Object clone() { 162 return new Bundle(this); 163 } 164 165 /** 166 * Removes all elements from the mapping of this Bundle. 167 */ 168 @Override 169 public void clear() { 170 super.clear(); 171 172 mHasFds = false; 173 mFdsKnown = true; 174 } 175 176 /** 177 * Inserts all mappings from the given Bundle into this Bundle. 178 * 179 * @param bundle a Bundle 180 */ 181 public void putAll(Bundle bundle) { 182 unparcel(); 183 bundle.unparcel(); 184 mMap.putAll(bundle.mMap); 185 186 // fd state is now known if and only if both bundles already knew 187 mHasFds |= bundle.mHasFds; 188 mFdsKnown = mFdsKnown && bundle.mFdsKnown; 189 } 190 191 /** 192 * Reports whether the bundle contains any parcelled file descriptors. 193 */ 194 public boolean hasFileDescriptors() { 195 if (!mFdsKnown) { 196 boolean fdFound = false; // keep going until we find one or run out of data 197 198 if (mParcelledData != null) { 199 if (mParcelledData.hasFileDescriptors()) { 200 fdFound = true; 201 } 202 } else { 203 // It's been unparcelled, so we need to walk the map 204 for (int i=mMap.size()-1; i>=0; i--) { 205 Object obj = mMap.valueAt(i); 206 if (obj instanceof Parcelable) { 207 if ((((Parcelable)obj).describeContents() 208 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) { 209 fdFound = true; 210 break; 211 } 212 } else if (obj instanceof Parcelable[]) { 213 Parcelable[] array = (Parcelable[]) obj; 214 for (int n = array.length - 1; n >= 0; n--) { 215 if ((array[n].describeContents() 216 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) { 217 fdFound = true; 218 break; 219 } 220 } 221 } else if (obj instanceof SparseArray) { 222 SparseArray<? extends Parcelable> array = 223 (SparseArray<? extends Parcelable>) obj; 224 for (int n = array.size() - 1; n >= 0; n--) { 225 if ((array.valueAt(n).describeContents() 226 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) { 227 fdFound = true; 228 break; 229 } 230 } 231 } else if (obj instanceof ArrayList) { 232 ArrayList array = (ArrayList) obj; 233 // an ArrayList here might contain either Strings or 234 // Parcelables; only look inside for Parcelables 235 if (!array.isEmpty() && (array.get(0) instanceof Parcelable)) { 236 for (int n = array.size() - 1; n >= 0; n--) { 237 Parcelable p = (Parcelable) array.get(n); 238 if (p != null && ((p.describeContents() 239 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) { 240 fdFound = true; 241 break; 242 } 243 } 244 } 245 } 246 } 247 } 248 249 mHasFds = fdFound; 250 mFdsKnown = true; 251 } 252 return mHasFds; 253 } 254 255 /** 256 * Inserts a byte value into the mapping of this Bundle, replacing 257 * any existing value for the given key. 258 * 259 * @param key a String, or null 260 * @param value a byte 261 */ 262 @Override 263 public void putByte(@Nullable String key, byte value) { 264 super.putByte(key, value); 265 } 266 267 /** 268 * Inserts a char value into the mapping of this Bundle, replacing 269 * any existing value for the given key. 270 * 271 * @param key a String, or null 272 * @param value a char 273 */ 274 @Override 275 public void putChar(@Nullable String key, char value) { 276 super.putChar(key, value); 277 } 278 279 /** 280 * Inserts a short value into the mapping of this Bundle, replacing 281 * any existing value for the given key. 282 * 283 * @param key a String, or null 284 * @param value a short 285 */ 286 @Override 287 public void putShort(@Nullable String key, short value) { 288 super.putShort(key, value); 289 } 290 291 /** 292 * Inserts a float value into the mapping of this Bundle, replacing 293 * any existing value for the given key. 294 * 295 * @param key a String, or null 296 * @param value a float 297 */ 298 @Override 299 public void putFloat(@Nullable String key, float value) { 300 super.putFloat(key, value); 301 } 302 303 /** 304 * Inserts a CharSequence value into the mapping of this Bundle, replacing 305 * any existing value for the given key. Either key or value may be null. 306 * 307 * @param key a String, or null 308 * @param value a CharSequence, or null 309 */ 310 @Override 311 public void putCharSequence(@Nullable String key, @Nullable CharSequence value) { 312 super.putCharSequence(key, value); 313 } 314 315 /** 316 * Inserts a Parcelable value into the mapping of this Bundle, replacing 317 * any existing value for the given key. Either key or value may be null. 318 * 319 * @param key a String, or null 320 * @param value a Parcelable object, or null 321 */ 322 public void putParcelable(@Nullable String key, @Nullable Parcelable value) { 323 unparcel(); 324 mMap.put(key, value); 325 mFdsKnown = false; 326 } 327 328 /** 329 * Inserts a Size value into the mapping of this Bundle, replacing 330 * any existing value for the given key. Either key or value may be null. 331 * 332 * @param key a String, or null 333 * @param value a Size object, or null 334 */ 335 public void putSize(@Nullable String key, @Nullable Size value) { 336 unparcel(); 337 mMap.put(key, value); 338 } 339 340 /** 341 * Inserts a SizeF value into the mapping of this Bundle, replacing 342 * any existing value for the given key. Either key or value may be null. 343 * 344 * @param key a String, or null 345 * @param value a SizeF object, or null 346 */ 347 public void putSizeF(@Nullable String key, @Nullable SizeF value) { 348 unparcel(); 349 mMap.put(key, value); 350 } 351 352 /** 353 * Inserts an array of Parcelable values into the mapping of this Bundle, 354 * replacing any existing value for the given key. Either key or value may 355 * be null. 356 * 357 * @param key a String, or null 358 * @param value an array of Parcelable objects, or null 359 */ 360 public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) { 361 unparcel(); 362 mMap.put(key, value); 363 mFdsKnown = false; 364 } 365 366 /** 367 * Inserts a List of Parcelable values into the mapping of this Bundle, 368 * replacing any existing value for the given key. Either key or value may 369 * be null. 370 * 371 * @param key a String, or null 372 * @param value an ArrayList of Parcelable objects, or null 373 */ 374 public void putParcelableArrayList(@Nullable String key, 375 @Nullable ArrayList<? extends Parcelable> value) { 376 unparcel(); 377 mMap.put(key, value); 378 mFdsKnown = false; 379 } 380 381 /** {@hide} */ 382 public void putParcelableList(String key, List<? extends Parcelable> value) { 383 unparcel(); 384 mMap.put(key, value); 385 mFdsKnown = false; 386 } 387 388 /** 389 * Inserts a SparceArray of Parcelable values into the mapping of this 390 * Bundle, replacing any existing value for the given key. Either key 391 * or value may be null. 392 * 393 * @param key a String, or null 394 * @param value a SparseArray of Parcelable objects, or null 395 */ 396 public void putSparseParcelableArray(@Nullable String key, 397 @Nullable SparseArray<? extends Parcelable> value) { 398 unparcel(); 399 mMap.put(key, value); 400 mFdsKnown = false; 401 } 402 403 /** 404 * Inserts an ArrayList<Integer> value into the mapping of this Bundle, replacing 405 * any existing value for the given key. Either key or value may be null. 406 * 407 * @param key a String, or null 408 * @param value an ArrayList<Integer> object, or null 409 */ 410 @Override 411 public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) { 412 super.putIntegerArrayList(key, value); 413 } 414 415 /** 416 * Inserts an ArrayList<String> value into the mapping of this Bundle, replacing 417 * any existing value for the given key. Either key or value may be null. 418 * 419 * @param key a String, or null 420 * @param value an ArrayList<String> object, or null 421 */ 422 @Override 423 public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) { 424 super.putStringArrayList(key, value); 425 } 426 427 /** 428 * Inserts an ArrayList<CharSequence> value into the mapping of this Bundle, replacing 429 * any existing value for the given key. Either key or value may be null. 430 * 431 * @param key a String, or null 432 * @param value an ArrayList<CharSequence> object, or null 433 */ 434 @Override 435 public void putCharSequenceArrayList(@Nullable String key, 436 @Nullable ArrayList<CharSequence> value) { 437 super.putCharSequenceArrayList(key, value); 438 } 439 440 /** 441 * Inserts a Serializable value into the mapping of this Bundle, replacing 442 * any existing value for the given key. Either key or value may be null. 443 * 444 * @param key a String, or null 445 * @param value a Serializable object, or null 446 */ 447 @Override 448 public void putSerializable(@Nullable String key, @Nullable Serializable value) { 449 super.putSerializable(key, value); 450 } 451 452 /** 453 * Inserts a byte array value into the mapping of this Bundle, replacing 454 * any existing value for the given key. Either key or value may be null. 455 * 456 * @param key a String, or null 457 * @param value a byte array object, or null 458 */ 459 @Override 460 public void putByteArray(@Nullable String key, @Nullable byte[] value) { 461 super.putByteArray(key, value); 462 } 463 464 /** 465 * Inserts a short array value into the mapping of this Bundle, replacing 466 * any existing value for the given key. Either key or value may be null. 467 * 468 * @param key a String, or null 469 * @param value a short array object, or null 470 */ 471 @Override 472 public void putShortArray(@Nullable String key, @Nullable short[] value) { 473 super.putShortArray(key, value); 474 } 475 476 /** 477 * Inserts a char array value into the mapping of this Bundle, replacing 478 * any existing value for the given key. Either key or value may be null. 479 * 480 * @param key a String, or null 481 * @param value a char array object, or null 482 */ 483 @Override 484 public void putCharArray(@Nullable String key, @Nullable char[] value) { 485 super.putCharArray(key, value); 486 } 487 488 /** 489 * Inserts a float array value into the mapping of this Bundle, replacing 490 * any existing value for the given key. Either key or value may be null. 491 * 492 * @param key a String, or null 493 * @param value a float array object, or null 494 */ 495 @Override 496 public void putFloatArray(@Nullable String key, @Nullable float[] value) { 497 super.putFloatArray(key, value); 498 } 499 500 /** 501 * Inserts a CharSequence array value into the mapping of this Bundle, replacing 502 * any existing value for the given key. Either key or value may be null. 503 * 504 * @param key a String, or null 505 * @param value a CharSequence array object, or null 506 */ 507 @Override 508 public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) { 509 super.putCharSequenceArray(key, value); 510 } 511 512 /** 513 * Inserts a Bundle value into the mapping of this Bundle, replacing 514 * any existing value for the given key. Either key or value may be null. 515 * 516 * @param key a String, or null 517 * @param value a Bundle object, or null 518 */ 519 public void putBundle(@Nullable String key, @Nullable Bundle value) { 520 unparcel(); 521 mMap.put(key, value); 522 } 523 524 /** 525 * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing 526 * any existing value for the given key. Either key or value may be null. 527 * 528 * <p class="note">You should be very careful when using this function. In many 529 * places where Bundles are used (such as inside of Intent objects), the Bundle 530 * can live longer inside of another process than the process that had originally 531 * created it. In that case, the IBinder you supply here will become invalid 532 * when your process goes away, and no longer usable, even if a new process is 533 * created for you later on.</p> 534 * 535 * @param key a String, or null 536 * @param value an IBinder object, or null 537 */ 538 public void putBinder(@Nullable String key, @Nullable IBinder value) { 539 unparcel(); 540 mMap.put(key, value); 541 } 542 543 /** 544 * Inserts an IBinder value into the mapping of this Bundle, replacing 545 * any existing value for the given key. Either key or value may be null. 546 * 547 * @param key a String, or null 548 * @param value an IBinder object, or null 549 * 550 * @deprecated 551 * @hide This is the old name of the function. 552 */ 553 @Deprecated 554 public void putIBinder(@Nullable String key, @Nullable IBinder value) { 555 unparcel(); 556 mMap.put(key, value); 557 } 558 559 /** 560 * Returns the value associated with the given key, or (byte) 0 if 561 * no mapping of the desired type exists for the given key. 562 * 563 * @param key a String 564 * @return a byte value 565 */ 566 @Override 567 public byte getByte(String key) { 568 return super.getByte(key); 569 } 570 571 /** 572 * Returns the value associated with the given key, or defaultValue if 573 * no mapping of the desired type exists for the given key. 574 * 575 * @param key a String 576 * @param defaultValue Value to return if key does not exist 577 * @return a byte value 578 */ 579 @Override 580 public Byte getByte(String key, byte defaultValue) { 581 return super.getByte(key, defaultValue); 582 } 583 584 /** 585 * Returns the value associated with the given key, or (char) 0 if 586 * no mapping of the desired type exists for the given key. 587 * 588 * @param key a String 589 * @return a char value 590 */ 591 @Override 592 public char getChar(String key) { 593 return super.getChar(key); 594 } 595 596 /** 597 * Returns the value associated with the given key, or defaultValue if 598 * no mapping of the desired type exists for the given key. 599 * 600 * @param key a String 601 * @param defaultValue Value to return if key does not exist 602 * @return a char value 603 */ 604 @Override 605 public char getChar(String key, char defaultValue) { 606 return super.getChar(key, defaultValue); 607 } 608 609 /** 610 * Returns the value associated with the given key, or (short) 0 if 611 * no mapping of the desired type exists for the given key. 612 * 613 * @param key a String 614 * @return a short value 615 */ 616 @Override 617 public short getShort(String key) { 618 return super.getShort(key); 619 } 620 621 /** 622 * Returns the value associated with the given key, or defaultValue if 623 * no mapping of the desired type exists for the given key. 624 * 625 * @param key a String 626 * @param defaultValue Value to return if key does not exist 627 * @return a short value 628 */ 629 @Override 630 public short getShort(String key, short defaultValue) { 631 return super.getShort(key, defaultValue); 632 } 633 634 /** 635 * Returns the value associated with the given key, or 0.0f if 636 * no mapping of the desired type exists for the given key. 637 * 638 * @param key a String 639 * @return a float value 640 */ 641 @Override 642 public float getFloat(String key) { 643 return super.getFloat(key); 644 } 645 646 /** 647 * Returns the value associated with the given key, or defaultValue if 648 * no mapping of the desired type exists for the given key. 649 * 650 * @param key a String 651 * @param defaultValue Value to return if key does not exist 652 * @return a float value 653 */ 654 @Override 655 public float getFloat(String key, float defaultValue) { 656 return super.getFloat(key, defaultValue); 657 } 658 659 /** 660 * Returns the value associated with the given key, or null if 661 * no mapping of the desired type exists for the given key or a null 662 * value is explicitly associated with the key. 663 * 664 * @param key a String, or null 665 * @return a CharSequence value, or null 666 */ 667 @Override 668 @Nullable 669 public CharSequence getCharSequence(@Nullable String key) { 670 return super.getCharSequence(key); 671 } 672 673 /** 674 * Returns the value associated with the given key, or defaultValue if 675 * no mapping of the desired type exists for the given key or if a null 676 * value is explicitly associatd with the given key. 677 * 678 * @param key a String, or null 679 * @param defaultValue Value to return if key does not exist or if a null 680 * value is associated with the given key. 681 * @return the CharSequence value associated with the given key, or defaultValue 682 * if no valid CharSequence object is currently mapped to that key. 683 */ 684 @Override 685 public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) { 686 return super.getCharSequence(key, defaultValue); 687 } 688 689 /** 690 * Returns the value associated with the given key, or null if 691 * no mapping of the desired type exists for the given key or a null 692 * value is explicitly associated with the key. 693 * 694 * @param key a String, or null 695 * @return a Size value, or null 696 */ 697 @Nullable 698 public Size getSize(@Nullable String key) { 699 unparcel(); 700 final Object o = mMap.get(key); 701 try { 702 return (Size) o; 703 } catch (ClassCastException e) { 704 typeWarning(key, o, "Size", e); 705 return null; 706 } 707 } 708 709 /** 710 * Returns the value associated with the given key, or null if 711 * no mapping of the desired type exists for the given key or a null 712 * value is explicitly associated with the key. 713 * 714 * @param key a String, or null 715 * @return a Size value, or null 716 */ 717 @Nullable 718 public SizeF getSizeF(@Nullable String key) { 719 unparcel(); 720 final Object o = mMap.get(key); 721 try { 722 return (SizeF) o; 723 } catch (ClassCastException e) { 724 typeWarning(key, o, "SizeF", e); 725 return null; 726 } 727 } 728 729 /** 730 * Returns the value associated with the given key, or null if 731 * no mapping of the desired type exists for the given key or a null 732 * value is explicitly associated with the key. 733 * 734 * @param key a String, or null 735 * @return a Bundle value, or null 736 */ 737 @Nullable 738 public Bundle getBundle(@Nullable String key) { 739 unparcel(); 740 Object o = mMap.get(key); 741 if (o == null) { 742 return null; 743 } 744 try { 745 return (Bundle) o; 746 } catch (ClassCastException e) { 747 typeWarning(key, o, "Bundle", e); 748 return null; 749 } 750 } 751 752 /** 753 * Returns the value associated with the given key, or null if 754 * no mapping of the desired type exists for the given key or a null 755 * value is explicitly associated with the key. 756 * 757 * @param key a String, or null 758 * @return a Parcelable value, or null 759 */ 760 @Nullable 761 public <T extends Parcelable> T getParcelable(@Nullable String key) { 762 unparcel(); 763 Object o = mMap.get(key); 764 if (o == null) { 765 return null; 766 } 767 try { 768 return (T) o; 769 } catch (ClassCastException e) { 770 typeWarning(key, o, "Parcelable", e); 771 return null; 772 } 773 } 774 775 /** 776 * Returns the value associated with the given key, or null if 777 * no mapping of the desired type exists for the given key or a null 778 * value is explicitly associated with the key. 779 * 780 * @param key a String, or null 781 * @return a Parcelable[] value, or null 782 */ 783 @Nullable 784 public Parcelable[] getParcelableArray(@Nullable String key) { 785 unparcel(); 786 Object o = mMap.get(key); 787 if (o == null) { 788 return null; 789 } 790 try { 791 return (Parcelable[]) o; 792 } catch (ClassCastException e) { 793 typeWarning(key, o, "Parcelable[]", e); 794 return null; 795 } 796 } 797 798 /** 799 * Returns the value associated with the given key, or null if 800 * no mapping of the desired type exists for the given key or a null 801 * value is explicitly associated with the key. 802 * 803 * @param key a String, or null 804 * @return an ArrayList<T> value, or null 805 */ 806 @Nullable 807 public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) { 808 unparcel(); 809 Object o = mMap.get(key); 810 if (o == null) { 811 return null; 812 } 813 try { 814 return (ArrayList<T>) o; 815 } catch (ClassCastException e) { 816 typeWarning(key, o, "ArrayList", e); 817 return null; 818 } 819 } 820 821 /** 822 * Returns the value associated with the given key, or null if 823 * no mapping of the desired type exists for the given key or a null 824 * value is explicitly associated with the key. 825 * 826 * @param key a String, or null 827 * 828 * @return a SparseArray of T values, or null 829 */ 830 @Nullable 831 public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) { 832 unparcel(); 833 Object o = mMap.get(key); 834 if (o == null) { 835 return null; 836 } 837 try { 838 return (SparseArray<T>) o; 839 } catch (ClassCastException e) { 840 typeWarning(key, o, "SparseArray", e); 841 return null; 842 } 843 } 844 845 /** 846 * Returns the value associated with the given key, or null if 847 * no mapping of the desired type exists for the given key or a null 848 * value is explicitly associated with the key. 849 * 850 * @param key a String, or null 851 * @return a Serializable value, or null 852 */ 853 @Override 854 @Nullable 855 public Serializable getSerializable(@Nullable String key) { 856 return super.getSerializable(key); 857 } 858 859 /** 860 * Returns the value associated with the given key, or null if 861 * no mapping of the desired type exists for the given key or a null 862 * value is explicitly associated with the key. 863 * 864 * @param key a String, or null 865 * @return an ArrayList<String> value, or null 866 */ 867 @Override 868 @Nullable 869 public ArrayList<Integer> getIntegerArrayList(@Nullable String key) { 870 return super.getIntegerArrayList(key); 871 } 872 873 /** 874 * Returns the value associated with the given key, or null if 875 * no mapping of the desired type exists for the given key or a null 876 * value is explicitly associated with the key. 877 * 878 * @param key a String, or null 879 * @return an ArrayList<String> value, or null 880 */ 881 @Override 882 @Nullable 883 public ArrayList<String> getStringArrayList(@Nullable String key) { 884 return super.getStringArrayList(key); 885 } 886 887 /** 888 * Returns the value associated with the given key, or null if 889 * no mapping of the desired type exists for the given key or a null 890 * value is explicitly associated with the key. 891 * 892 * @param key a String, or null 893 * @return an ArrayList<CharSequence> value, or null 894 */ 895 @Override 896 @Nullable 897 public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) { 898 return super.getCharSequenceArrayList(key); 899 } 900 901 /** 902 * Returns the value associated with the given key, or null if 903 * no mapping of the desired type exists for the given key or a null 904 * value is explicitly associated with the key. 905 * 906 * @param key a String, or null 907 * @return a byte[] value, or null 908 */ 909 @Override 910 @Nullable 911 public byte[] getByteArray(@Nullable String key) { 912 return super.getByteArray(key); 913 } 914 915 /** 916 * Returns the value associated with the given key, or null if 917 * no mapping of the desired type exists for the given key or a null 918 * value is explicitly associated with the key. 919 * 920 * @param key a String, or null 921 * @return a short[] value, or null 922 */ 923 @Override 924 @Nullable 925 public short[] getShortArray(@Nullable String key) { 926 return super.getShortArray(key); 927 } 928 929 /** 930 * Returns the value associated with the given key, or null if 931 * no mapping of the desired type exists for the given key or a null 932 * value is explicitly associated with the key. 933 * 934 * @param key a String, or null 935 * @return a char[] value, or null 936 */ 937 @Override 938 @Nullable 939 public char[] getCharArray(@Nullable String key) { 940 return super.getCharArray(key); 941 } 942 943 /** 944 * Returns the value associated with the given key, or null if 945 * no mapping of the desired type exists for the given key or a null 946 * value is explicitly associated with the key. 947 * 948 * @param key a String, or null 949 * @return a float[] value, or null 950 */ 951 @Override 952 @Nullable 953 public float[] getFloatArray(@Nullable String key) { 954 return super.getFloatArray(key); 955 } 956 957 /** 958 * Returns the value associated with the given key, or null if 959 * no mapping of the desired type exists for the given key or a null 960 * value is explicitly associated with the key. 961 * 962 * @param key a String, or null 963 * @return a CharSequence[] value, or null 964 */ 965 @Override 966 @Nullable 967 public CharSequence[] getCharSequenceArray(@Nullable String key) { 968 return super.getCharSequenceArray(key); 969 } 970 971 /** 972 * Returns the value associated with the given key, or null if 973 * no mapping of the desired type exists for the given key or a null 974 * value is explicitly associated with the key. 975 * 976 * @param key a String, or null 977 * @return an IBinder value, or null 978 */ 979 @Nullable 980 public IBinder getBinder(@Nullable String key) { 981 unparcel(); 982 Object o = mMap.get(key); 983 if (o == null) { 984 return null; 985 } 986 try { 987 return (IBinder) o; 988 } catch (ClassCastException e) { 989 typeWarning(key, o, "IBinder", e); 990 return null; 991 } 992 } 993 994 /** 995 * Returns the value associated with the given key, or null if 996 * no mapping of the desired type exists for the given key or a null 997 * value is explicitly associated with the key. 998 * 999 * @param key a String, or null 1000 * @return an IBinder value, or null 1001 * 1002 * @deprecated 1003 * @hide This is the old name of the function. 1004 */ 1005 @Deprecated 1006 @Nullable 1007 public IBinder getIBinder(@Nullable String key) { 1008 unparcel(); 1009 Object o = mMap.get(key); 1010 if (o == null) { 1011 return null; 1012 } 1013 try { 1014 return (IBinder) o; 1015 } catch (ClassCastException e) { 1016 typeWarning(key, o, "IBinder", e); 1017 return null; 1018 } 1019 } 1020 1021 public static final Parcelable.Creator<Bundle> CREATOR = 1022 new Parcelable.Creator<Bundle>() { 1023 @Override 1024 public Bundle createFromParcel(Parcel in) { 1025 return in.readBundle(); 1026 } 1027 1028 @Override 1029 public Bundle[] newArray(int size) { 1030 return new Bundle[size]; 1031 } 1032 }; 1033 1034 /** 1035 * Report the nature of this Parcelable's contents 1036 */ 1037 @Override 1038 public int describeContents() { 1039 int mask = 0; 1040 if (hasFileDescriptors()) { 1041 mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR; 1042 } 1043 return mask; 1044 } 1045 1046 /** 1047 * Writes the Bundle contents to a Parcel, typically in order for 1048 * it to be passed through an IBinder connection. 1049 * @param parcel The parcel to copy this bundle to. 1050 */ 1051 @Override 1052 public void writeToParcel(Parcel parcel, int flags) { 1053 final boolean oldAllowFds = parcel.pushAllowFds(mAllowFds); 1054 try { 1055 super.writeToParcelInner(parcel, flags); 1056 } finally { 1057 parcel.restoreAllowFds(oldAllowFds); 1058 } 1059 } 1060 1061 /** 1062 * Reads the Parcel contents into this Bundle, typically in order for 1063 * it to be passed through an IBinder connection. 1064 * @param parcel The parcel to overwrite this bundle from. 1065 */ 1066 public void readFromParcel(Parcel parcel) { 1067 super.readFromParcelInner(parcel); 1068 mHasFds = mParcelledData.hasFileDescriptors(); 1069 mFdsKnown = true; 1070 } 1071 1072 @Override 1073 public synchronized String toString() { 1074 if (mParcelledData != null) { 1075 if (mParcelledData == EMPTY_PARCEL) { 1076 return "Bundle[EMPTY_PARCEL]"; 1077 } else { 1078 return "Bundle[mParcelledData.dataSize=" + 1079 mParcelledData.dataSize() + "]"; 1080 } 1081 } 1082 return "Bundle[" + mMap.toString() + "]"; 1083 } 1084 1085} 1086