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