blob: 8e6a5541941ec24a793c266cfa1f7962ee87649e [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Scott Kennedyc6a65dff2015-03-01 17:10:10 -080019import android.annotation.Nullable;
Dianne Hackbornb87655b2013-07-17 19:06:22 -070020import android.util.ArrayMap;
Jeff Sharkey5ef33982014-09-04 18:13:39 -070021import android.util.Size;
22import android.util.SizeF;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.util.SparseArray;
Kweku Adams85f2fbc2017-12-18 12:04:12 -080024import android.util.proto.ProtoOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
Makoto Onuki4501c61d2017-07-27 15:56:40 -070026import com.android.internal.annotations.VisibleForTesting;
27
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import java.io.Serializable;
29import java.util.ArrayList;
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -070030import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
32/**
Jeff Sharkeyd136e512016-03-09 22:30:56 -070033 * A mapping from String keys to various {@link Parcelable} values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 *
Jeff Sharkeyd136e512016-03-09 22:30:56 -070035 * @see PersistableBundle
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036 */
Craig Mautner0a8e160e2014-05-29 10:27:32 -070037public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
Makoto Onuki4501c61d2017-07-27 15:56:40 -070038 @VisibleForTesting
39 static final int FLAG_HAS_FDS = 1 << 8;
40
41 @VisibleForTesting
42 static final int FLAG_HAS_FDS_KNOWN = 1 << 9;
43
44 @VisibleForTesting
45 static final int FLAG_ALLOW_FDS = 1 << 10;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070046
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 public static final Bundle EMPTY;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070048
Makoto Onuki97f82f22017-05-31 16:20:21 -070049 /**
50 * Special extras used to denote extras have been stripped off.
51 * @hide
52 */
53 public static final Bundle STRIPPED;
54
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 static {
56 EMPTY = new Bundle();
Dianne Hackbornb87655b2013-07-17 19:06:22 -070057 EMPTY.mMap = ArrayMap.EMPTY;
Makoto Onuki97f82f22017-05-31 16:20:21 -070058
59 STRIPPED = new Bundle();
60 STRIPPED.putInt("STRIPPED", 1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061 }
62
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 * Constructs a new, empty Bundle.
65 */
66 public Bundle() {
Craig Mautner719e6b12014-04-04 20:29:41 -070067 super();
Jeff Sharkey7410fb42016-03-16 21:23:29 -060068 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 }
70
71 /**
72 * Constructs a Bundle whose data is stored as a Parcel. The data
73 * will be unparcelled on first contact, using the assigned ClassLoader.
74 *
75 * @param parcelledData a Parcel containing a Bundle
Makoto Onuki4501c61d2017-07-27 15:56:40 -070076 *
77 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 */
Makoto Onuki4501c61d2017-07-27 15:56:40 -070079 @VisibleForTesting
80 public Bundle(Parcel parcelledData) {
Craig Mautner719e6b12014-04-04 20:29:41 -070081 super(parcelledData);
Makoto Onuki4501c61d2017-07-27 15:56:40 -070082 mFlags = FLAG_ALLOW_FDS;
83 maybePrefillHasFds();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 }
85
Makoto Onuki4501c61d2017-07-27 15:56:40 -070086 /**
87 * Constructor from a parcel for when the length is known *and is not stored in the parcel.*
88 * The other constructor that takes a parcel assumes the length is in the parcel.
89 *
90 * @hide
91 */
92 @VisibleForTesting
93 public Bundle(Parcel parcelledData, int length) {
Craig Mautner719e6b12014-04-04 20:29:41 -070094 super(parcelledData, length);
Makoto Onuki4501c61d2017-07-27 15:56:40 -070095 mFlags = FLAG_ALLOW_FDS;
96 maybePrefillHasFds();
97 }
98
99 /**
100 * If {@link #mParcelledData} is not null, copy the HAS FDS bit from it because it's fast.
101 * Otherwise (if {@link #mParcelledData} is already null), leave {@link #FLAG_HAS_FDS_KNOWN}
102 * unset, because scanning a map is slower. We'll do it lazily in
103 * {@link #hasFileDescriptors()}.
104 */
105 private void maybePrefillHasFds() {
106 if (mParcelledData != null) {
107 if (mParcelledData.hasFileDescriptors()) {
108 mFlags |= FLAG_HAS_FDS | FLAG_HAS_FDS_KNOWN;
109 } else {
110 mFlags |= FLAG_HAS_FDS_KNOWN;
111 }
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700112 }
Dianne Hackborn6aff9052009-05-22 13:20:23 -0700113 }
114
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 /**
116 * Constructs a new, empty Bundle that uses a specific ClassLoader for
117 * instantiating Parcelable and Serializable objects.
118 *
119 * @param loader An explicit ClassLoader to use when instantiating objects
120 * inside of the Bundle.
121 */
122 public Bundle(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700123 super(loader);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600124 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 }
126
127 /**
128 * Constructs a new, empty Bundle sized to hold the given number of
129 * elements. The Bundle will grow as needed.
130 *
131 * @param capacity the initial capacity of the Bundle
132 */
133 public Bundle(int capacity) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700134 super(capacity);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600135 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 }
137
138 /**
139 * Constructs a Bundle containing a copy of the mappings from the given
Dianne Hackborn2510b372017-03-03 17:01:38 -0800140 * Bundle. Does only a shallow copy of the original Bundle -- see
141 * {@link #deepCopy()} if that is not what you want.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 *
143 * @param b a Bundle to be copied.
Dianne Hackborn2510b372017-03-03 17:01:38 -0800144 *
145 * @see #deepCopy()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 */
147 public Bundle(Bundle b) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700148 super(b);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700149 mFlags = b.mFlags;
Craig Mautner719e6b12014-04-04 20:29:41 -0700150 }
151
152 /**
153 * Constructs a Bundle containing a copy of the mappings from the given
Dianne Hackborn2510b372017-03-03 17:01:38 -0800154 * PersistableBundle. Does only a shallow copy of the PersistableBundle -- see
155 * {@link PersistableBundle#deepCopy()} if you don't want that.
Craig Mautner719e6b12014-04-04 20:29:41 -0700156 *
Dianne Hackborn2510b372017-03-03 17:01:38 -0800157 * @param b a PersistableBundle to be copied.
Craig Mautner719e6b12014-04-04 20:29:41 -0700158 */
159 public Bundle(PersistableBundle b) {
160 super(b);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600161 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 }
163
164 /**
Dianne Hackbornba604732016-02-10 17:05:10 -0800165 * Constructs a Bundle without initializing it.
166 */
167 Bundle(boolean doInit) {
168 super(doInit);
169 }
170
171 /**
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800172 * Make a Bundle for a single key/value pair.
173 *
174 * @hide
175 */
176 public static Bundle forPair(String key, String value) {
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800177 Bundle b = new Bundle(1);
178 b.putString(key, value);
179 return b;
180 }
181
182 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 * Changes the ClassLoader this Bundle uses when instantiating objects.
184 *
185 * @param loader An explicit ClassLoader to use when instantiating objects
186 * inside of the Bundle.
187 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700188 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 public void setClassLoader(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700190 super.setClassLoader(loader);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 }
192
193 /**
Dianne Hackborn51642462010-10-28 10:32:37 -0700194 * Return the ClassLoader currently associated with this Bundle.
195 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700196 @Override
Dianne Hackborn51642462010-10-28 10:32:37 -0700197 public ClassLoader getClassLoader() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700198 return super.getClassLoader();
Dianne Hackborn51642462010-10-28 10:32:37 -0700199 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400200
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700201 /** {@hide} */
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400202 public boolean setAllowFds(boolean allowFds) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700203 final boolean orig = (mFlags & FLAG_ALLOW_FDS) != 0;
204 if (allowFds) {
205 mFlags |= FLAG_ALLOW_FDS;
206 } else {
207 mFlags &= ~FLAG_ALLOW_FDS;
208 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400209 return orig;
210 }
211
Dianne Hackborn51642462010-10-28 10:32:37 -0700212 /**
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700213 * Mark if this Bundle is okay to "defuse." That is, it's okay for system
214 * processes to ignore any {@link BadParcelableException} encountered when
215 * unparceling it, leaving an empty bundle in its place.
216 * <p>
217 * This should <em>only</em> be set when the Bundle reaches its final
218 * destination, otherwise a system process may clobber contents that were
219 * destined for an app that could have unparceled them.
220 *
221 * @hide
222 */
223 public void setDefusable(boolean defusable) {
224 if (defusable) {
225 mFlags |= FLAG_DEFUSABLE;
226 } else {
227 mFlags &= ~FLAG_DEFUSABLE;
228 }
229 }
230
Jeff Sharkeya04c7a72016-03-18 12:20:36 -0600231 /** {@hide} */
232 public static Bundle setDefusable(Bundle bundle, boolean defusable) {
233 if (bundle != null) {
234 bundle.setDefusable(defusable);
235 }
236 return bundle;
237 }
238
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700239 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 * Clones the current Bundle. The internal map is cloned, but the keys and
241 * values to which it refers are copied by reference.
242 */
243 @Override
244 public Object clone() {
245 return new Bundle(this);
246 }
247
248 /**
Dianne Hackbornba604732016-02-10 17:05:10 -0800249 * Make a deep copy of the given bundle. Traverses into inner containers and copies
250 * them as well, so they are not shared across bundles. Will traverse in to
251 * {@link Bundle}, {@link PersistableBundle}, {@link ArrayList}, and all types of
252 * primitive arrays. Other types of objects (such as Parcelable or Serializable)
253 * are referenced as-is and not copied in any way.
254 */
Dianne Hackborn2510b372017-03-03 17:01:38 -0800255 public Bundle deepCopy() {
Dianne Hackbornba604732016-02-10 17:05:10 -0800256 Bundle b = new Bundle(false);
257 b.copyInternal(this, true);
258 return b;
259 }
260
261 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 * Removes all elements from the mapping of this Bundle.
263 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700264 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 public void clear() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700266 super.clear();
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600267 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 }
269
270 /**
Christopher Tate250985f2016-03-31 13:57:42 -0700271 * Removes any entry with the given key from the mapping of this Bundle.
272 *
273 * @param key a String key
274 */
275 public void remove(String key) {
276 super.remove(key);
277 if ((mFlags & FLAG_HAS_FDS) != 0) {
278 mFlags &= ~FLAG_HAS_FDS_KNOWN;
279 }
280 }
281
282 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 * Inserts all mappings from the given Bundle into this Bundle.
284 *
Craig Mautner719e6b12014-04-04 20:29:41 -0700285 * @param bundle a Bundle
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700287 public void putAll(Bundle bundle) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 unparcel();
Craig Mautner719e6b12014-04-04 20:29:41 -0700289 bundle.unparcel();
290 mMap.putAll(bundle.mMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700292 // FD state is now known if and only if both bundles already knew
293 if ((bundle.mFlags & FLAG_HAS_FDS) != 0) {
294 mFlags |= FLAG_HAS_FDS;
295 }
296 if ((bundle.mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
297 mFlags &= ~FLAG_HAS_FDS_KNOWN;
298 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700299 }
300
301 /**
Sudheer Shankafab200f2017-05-17 20:41:53 -0700302 * Return the size of {@link #mParcelledData} in bytes if available, otherwise {@code 0}.
303 *
304 * @hide
305 */
306 public int getSize() {
307 if (mParcelledData != null) {
308 return mParcelledData.dataSize();
309 } else {
310 return 0;
311 }
312 }
313
314 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 * Reports whether the bundle contains any parcelled file descriptors.
316 */
317 public boolean hasFileDescriptors() {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700318 if ((mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 boolean fdFound = false; // keep going until we find one or run out of data
Craig Mautner719e6b12014-04-04 20:29:41 -0700320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 if (mParcelledData != null) {
322 if (mParcelledData.hasFileDescriptors()) {
323 fdFound = true;
324 }
325 } else {
326 // It's been unparcelled, so we need to walk the map
Dianne Hackbornb87655b2013-07-17 19:06:22 -0700327 for (int i=mMap.size()-1; i>=0; i--) {
328 Object obj = mMap.valueAt(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 if (obj instanceof Parcelable) {
330 if ((((Parcelable)obj).describeContents()
331 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
332 fdFound = true;
333 break;
334 }
335 } else if (obj instanceof Parcelable[]) {
336 Parcelable[] array = (Parcelable[]) obj;
337 for (int n = array.length - 1; n >= 0; n--) {
Taiju Tsuikie58c7852015-04-22 16:59:00 +0900338 Parcelable p = array[n];
339 if (p != null && ((p.describeContents()
340 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 fdFound = true;
342 break;
343 }
344 }
345 } else if (obj instanceof SparseArray) {
346 SparseArray<? extends Parcelable> array =
347 (SparseArray<? extends Parcelable>) obj;
348 for (int n = array.size() - 1; n >= 0; n--) {
Taiju Tsuikiecd21842015-04-28 13:36:15 +0900349 Parcelable p = array.valueAt(n);
350 if (p != null && (p.describeContents()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
352 fdFound = true;
353 break;
354 }
355 }
356 } else if (obj instanceof ArrayList) {
357 ArrayList array = (ArrayList) obj;
358 // an ArrayList here might contain either Strings or
359 // Parcelables; only look inside for Parcelables
Craig Mautner719e6b12014-04-04 20:29:41 -0700360 if (!array.isEmpty() && (array.get(0) instanceof Parcelable)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 for (int n = array.size() - 1; n >= 0; n--) {
362 Parcelable p = (Parcelable) array.get(n);
363 if (p != null && ((p.describeContents()
364 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
365 fdFound = true;
366 break;
367 }
368 }
369 }
370 }
371 }
372 }
373
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700374 if (fdFound) {
375 mFlags |= FLAG_HAS_FDS;
Christopher Tate250985f2016-03-31 13:57:42 -0700376 } else {
377 mFlags &= ~FLAG_HAS_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700378 }
379 mFlags |= FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 }
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700381 return (mFlags & FLAG_HAS_FDS) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700383
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 /**
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700385 * Filter values in Bundle to only basic types.
386 * @hide
387 */
Dianne Hackborn851ec492016-10-12 17:20:07 -0700388 public Bundle filterValues() {
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700389 unparcel();
Dianne Hackborn851ec492016-10-12 17:20:07 -0700390 Bundle bundle = this;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700391 if (mMap != null) {
Dianne Hackborn851ec492016-10-12 17:20:07 -0700392 ArrayMap<String, Object> map = mMap;
393 for (int i = map.size() - 1; i >= 0; i--) {
394 Object value = map.valueAt(i);
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700395 if (PersistableBundle.isValidType(value)) {
396 continue;
397 }
398 if (value instanceof Bundle) {
Dianne Hackborn851ec492016-10-12 17:20:07 -0700399 Bundle newBundle = ((Bundle)value).filterValues();
400 if (newBundle != value) {
401 if (map == mMap) {
402 // The filter had to generate a new bundle, but we have not yet
403 // created a new one here. Do that now.
404 bundle = new Bundle(this);
405 // Note the ArrayMap<> constructor is guaranteed to generate
406 // a new object with items in the same order as the original.
407 map = bundle.mMap;
408 }
409 // Replace this current entry with the new child bundle.
410 map.setValueAt(i, newBundle);
411 }
412 continue;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700413 }
414 if (value.getClass().getName().startsWith("android.")) {
415 continue;
416 }
Dianne Hackborn851ec492016-10-12 17:20:07 -0700417 if (map == mMap) {
418 // This is the first time we have had to remove something, that means we
419 // need to switch to a new Bundle.
420 bundle = new Bundle(this);
421 // Note the ArrayMap<> constructor is guaranteed to generate
422 // a new object with items in the same order as the original.
423 map = bundle.mMap;
424 }
425 map.removeAt(i);
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700426 }
427 }
Christopher Tate250985f2016-03-31 13:57:42 -0700428 mFlags |= FLAG_HAS_FDS_KNOWN;
429 mFlags &= ~FLAG_HAS_FDS;
Dianne Hackborn851ec492016-10-12 17:20:07 -0700430 return bundle;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700431 }
432
433 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 * Inserts a byte value into the mapping of this Bundle, replacing
435 * any existing value for the given key.
436 *
437 * @param key a String, or null
438 * @param value a byte
439 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700440 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800441 public void putByte(@Nullable String key, byte value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700442 super.putByte(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 }
444
445 /**
446 * Inserts a char value into the mapping of this Bundle, replacing
447 * any existing value for the given key.
448 *
449 * @param key a String, or null
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800450 * @param value a char
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700452 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800453 public void putChar(@Nullable String key, char value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700454 super.putChar(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 }
456
457 /**
458 * Inserts a short value into the mapping of this Bundle, replacing
459 * any existing value for the given key.
460 *
461 * @param key a String, or null
462 * @param value a short
463 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700464 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800465 public void putShort(@Nullable String key, short value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700466 super.putShort(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 }
468
469 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 * Inserts a float value into the mapping of this Bundle, replacing
471 * any existing value for the given key.
472 *
473 * @param key a String, or null
474 * @param value a float
475 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700476 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800477 public void putFloat(@Nullable String key, float value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700478 super.putFloat(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 }
480
481 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 * Inserts a CharSequence value into the mapping of this Bundle, replacing
483 * any existing value for the given key. Either key or value may be null.
484 *
485 * @param key a String, or null
486 * @param value a CharSequence, or null
487 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700488 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800489 public void putCharSequence(@Nullable String key, @Nullable CharSequence value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700490 super.putCharSequence(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 }
492
493 /**
494 * Inserts a Parcelable value into the mapping of this Bundle, replacing
495 * any existing value for the given key. Either key or value may be null.
496 *
497 * @param key a String, or null
498 * @param value a Parcelable object, or null
499 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800500 public void putParcelable(@Nullable String key, @Nullable Parcelable value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 unparcel();
502 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700503 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
505
506 /**
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700507 * Inserts a Size value into the mapping of this Bundle, replacing
508 * any existing value for the given key. Either key or value may be null.
509 *
510 * @param key a String, or null
511 * @param value a Size object, or null
512 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800513 public void putSize(@Nullable String key, @Nullable Size value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700514 unparcel();
515 mMap.put(key, value);
516 }
517
518 /**
519 * Inserts a SizeF value into the mapping of this Bundle, replacing
520 * any existing value for the given key. Either key or value may be null.
521 *
522 * @param key a String, or null
523 * @param value a SizeF object, or null
524 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800525 public void putSizeF(@Nullable String key, @Nullable SizeF value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700526 unparcel();
527 mMap.put(key, value);
528 }
529
530 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 * Inserts an array of Parcelable values into the mapping of this Bundle,
532 * replacing any existing value for the given key. Either key or value may
533 * be null.
534 *
535 * @param key a String, or null
536 * @param value an array of Parcelable objects, or null
537 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800538 public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 unparcel();
540 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700541 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 }
543
544 /**
545 * Inserts a List of Parcelable values into the mapping of this Bundle,
546 * replacing any existing value for the given key. Either key or value may
547 * be null.
548 *
549 * @param key a String, or null
550 * @param value an ArrayList of Parcelable objects, or null
551 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800552 public void putParcelableArrayList(@Nullable String key,
553 @Nullable ArrayList<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 unparcel();
555 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700556 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 }
558
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700559 /** {@hide} */
560 public void putParcelableList(String key, List<? extends Parcelable> value) {
561 unparcel();
562 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700563 mFlags &= ~FLAG_HAS_FDS_KNOWN;
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700564 }
565
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 /**
567 * Inserts a SparceArray of Parcelable values into the mapping of this
568 * Bundle, replacing any existing value for the given key. Either key
569 * or value may be null.
570 *
571 * @param key a String, or null
572 * @param value a SparseArray of Parcelable objects, or null
573 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800574 public void putSparseParcelableArray(@Nullable String key,
575 @Nullable SparseArray<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 unparcel();
577 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700578 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 }
580
581 /**
582 * Inserts an ArrayList<Integer> value into the mapping of this Bundle, replacing
583 * any existing value for the given key. Either key or value may be null.
584 *
585 * @param key a String, or null
586 * @param value an ArrayList<Integer> object, or null
587 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700588 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800589 public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700590 super.putIntegerArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 }
592
593 /**
594 * Inserts an ArrayList<String> value into the mapping of this Bundle, replacing
595 * any existing value for the given key. Either key or value may be null.
596 *
597 * @param key a String, or null
598 * @param value an ArrayList<String> object, or null
599 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700600 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800601 public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700602 super.putStringArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 }
604
605 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000606 * Inserts an ArrayList<CharSequence> value into the mapping of this Bundle, replacing
607 * any existing value for the given key. Either key or value may be null.
608 *
609 * @param key a String, or null
610 * @param value an ArrayList<CharSequence> object, or null
611 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700612 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800613 public void putCharSequenceArrayList(@Nullable String key,
614 @Nullable ArrayList<CharSequence> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700615 super.putCharSequenceArrayList(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000616 }
617
618 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 * Inserts a Serializable value into the mapping of this Bundle, replacing
620 * any existing value for the given key. Either key or value may be null.
621 *
622 * @param key a String, or null
623 * @param value a Serializable object, or null
624 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700625 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800626 public void putSerializable(@Nullable String key, @Nullable Serializable value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700627 super.putSerializable(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 }
629
630 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 * Inserts a byte array value into the mapping of this Bundle, replacing
632 * any existing value for the given key. Either key or value may be null.
633 *
634 * @param key a String, or null
635 * @param value a byte array object, or null
636 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700637 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800638 public void putByteArray(@Nullable String key, @Nullable byte[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700639 super.putByteArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 }
641
642 /**
643 * Inserts a short array value into the mapping of this Bundle, replacing
644 * any existing value for the given key. Either key or value may be null.
645 *
646 * @param key a String, or null
647 * @param value a short array object, or null
648 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700649 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800650 public void putShortArray(@Nullable String key, @Nullable short[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700651 super.putShortArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800652 }
653
654 /**
655 * Inserts a char array value into the mapping of this Bundle, replacing
656 * any existing value for the given key. Either key or value may be null.
657 *
658 * @param key a String, or null
659 * @param value a char array object, or null
660 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700661 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800662 public void putCharArray(@Nullable String key, @Nullable char[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700663 super.putCharArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 }
665
666 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 * Inserts a float array value into the mapping of this Bundle, replacing
668 * any existing value for the given key. Either key or value may be null.
669 *
670 * @param key a String, or null
671 * @param value a float array object, or null
672 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700673 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800674 public void putFloatArray(@Nullable String key, @Nullable float[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700675 super.putFloatArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 }
677
678 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000679 * Inserts a CharSequence array value into the mapping of this Bundle, replacing
680 * any existing value for the given key. Either key or value may be null.
681 *
682 * @param key a String, or null
683 * @param value a CharSequence array object, or null
684 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700685 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800686 public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700687 super.putCharSequenceArray(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000688 }
689
690 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800691 * Inserts a Bundle value into the mapping of this Bundle, replacing
692 * any existing value for the given key. Either key or value may be null.
693 *
694 * @param key a String, or null
695 * @param value a Bundle object, or null
696 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800697 public void putBundle(@Nullable String key, @Nullable Bundle value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 unparcel();
699 mMap.put(key, value);
700 }
701
702 /**
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800703 * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing
704 * any existing value for the given key. Either key or value may be null.
705 *
706 * <p class="note">You should be very careful when using this function. In many
707 * places where Bundles are used (such as inside of Intent objects), the Bundle
708 * can live longer inside of another process than the process that had originally
709 * created it. In that case, the IBinder you supply here will become invalid
710 * when your process goes away, and no longer usable, even if a new process is
711 * created for you later on.</p>
712 *
713 * @param key a String, or null
714 * @param value an IBinder object, or null
715 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800716 public void putBinder(@Nullable String key, @Nullable IBinder value) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800717 unparcel();
718 mMap.put(key, value);
719 }
720
721 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 * Inserts an IBinder value into the mapping of this Bundle, replacing
723 * any existing value for the given key. Either key or value may be null.
724 *
725 * @param key a String, or null
726 * @param value an IBinder object, or null
727 *
728 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800729 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 */
731 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800732 public void putIBinder(@Nullable String key, @Nullable IBinder value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 unparcel();
734 mMap.put(key, value);
735 }
736
737 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 * Returns the value associated with the given key, or (byte) 0 if
739 * no mapping of the desired type exists for the given key.
740 *
741 * @param key a String
742 * @return a byte value
743 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700744 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 public byte getByte(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700746 return super.getByte(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 }
748
749 /**
750 * Returns the value associated with the given key, or defaultValue if
751 * no mapping of the desired type exists for the given key.
752 *
753 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800754 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 * @return a byte value
756 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700757 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 public Byte getByte(String key, byte defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700759 return super.getByte(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 }
761
762 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800763 * Returns the value associated with the given key, or (char) 0 if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 * no mapping of the desired type exists for the given key.
765 *
766 * @param key a String
767 * @return a char value
768 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700769 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 public char getChar(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700771 return super.getChar(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 }
773
774 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800775 * Returns the value associated with the given key, or defaultValue if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 * no mapping of the desired type exists for the given key.
777 *
778 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800779 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 * @return a char value
781 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700782 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 public char getChar(String key, char defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700784 return super.getChar(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 }
786
787 /**
788 * Returns the value associated with the given key, or (short) 0 if
789 * no mapping of the desired type exists for the given key.
790 *
791 * @param key a String
792 * @return a short value
793 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700794 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 public short getShort(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700796 return super.getShort(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 }
798
799 /**
800 * Returns the value associated with the given key, or defaultValue if
801 * no mapping of the desired type exists for the given key.
802 *
803 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800804 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 * @return a short value
806 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700807 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 public short getShort(String key, short defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700809 return super.getShort(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 }
811
812 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 * Returns the value associated with the given key, or 0.0f if
814 * no mapping of the desired type exists for the given key.
815 *
816 * @param key a String
817 * @return a float value
818 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700819 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 public float getFloat(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700821 return super.getFloat(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 }
823
824 /**
825 * Returns the value associated with the given key, or defaultValue if
826 * no mapping of the desired type exists for the given key.
827 *
828 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800829 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 * @return a float value
831 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700832 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 public float getFloat(String key, float defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700834 return super.getFloat(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 }
836
837 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 * Returns the value associated with the given key, or null if
839 * no mapping of the desired type exists for the given key or a null
840 * value is explicitly associated with the key.
841 *
842 * @param key a String, or null
843 * @return a CharSequence value, or null
844 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700845 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800846 @Nullable
847 public CharSequence getCharSequence(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700848 return super.getCharSequence(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 }
850
851 /**
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800852 * Returns the value associated with the given key, or defaultValue if
Narayan Kamathca2197b2014-06-19 10:46:00 +0100853 * no mapping of the desired type exists for the given key or if a null
854 * value is explicitly associatd with the given key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800855 *
856 * @param key a String, or null
Narayan Kamathca2197b2014-06-19 10:46:00 +0100857 * @param defaultValue Value to return if key does not exist or if a null
858 * value is associated with the given key.
Christopher Tate116751d2012-12-20 18:57:09 -0800859 * @return the CharSequence value associated with the given key, or defaultValue
860 * if no valid CharSequence object is currently mapped to that key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800861 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700862 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800863 public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700864 return super.getCharSequence(key, defaultValue);
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800865 }
866
867 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 * Returns the value associated with the given key, or null if
869 * no mapping of the desired type exists for the given key or a null
870 * value is explicitly associated with the key.
871 *
872 * @param key a String, or null
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700873 * @return a Size value, or null
874 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800875 @Nullable
876 public Size getSize(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700877 unparcel();
878 final Object o = mMap.get(key);
879 try {
880 return (Size) o;
881 } catch (ClassCastException e) {
882 typeWarning(key, o, "Size", e);
883 return null;
884 }
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 a Size value, or null
894 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800895 @Nullable
896 public SizeF getSizeF(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700897 unparcel();
898 final Object o = mMap.get(key);
899 try {
900 return (SizeF) o;
901 } catch (ClassCastException e) {
902 typeWarning(key, o, "SizeF", e);
903 return null;
904 }
905 }
906
907 /**
908 * Returns the value associated with the given key, or null if
909 * no mapping of the desired type exists for the given key or a null
910 * value is explicitly associated with the key.
911 *
912 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 * @return a Bundle value, or null
914 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800915 @Nullable
916 public Bundle getBundle(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 unparcel();
918 Object o = mMap.get(key);
919 if (o == null) {
920 return null;
921 }
922 try {
923 return (Bundle) o;
924 } catch (ClassCastException e) {
925 typeWarning(key, o, "Bundle", e);
926 return null;
927 }
928 }
929
930 /**
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.
934 *
935 * @param key a String, or null
936 * @return a Parcelable value, or null
937 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800938 @Nullable
939 public <T extends Parcelable> T getParcelable(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 unparcel();
941 Object o = mMap.get(key);
942 if (o == null) {
943 return null;
944 }
945 try {
946 return (T) o;
947 } catch (ClassCastException e) {
948 typeWarning(key, o, "Parcelable", e);
949 return null;
950 }
951 }
952
953 /**
954 * Returns the value associated with the given key, or null if
955 * no mapping of the desired type exists for the given key or a null
956 * value is explicitly associated with the key.
957 *
958 * @param key a String, or null
959 * @return a Parcelable[] value, or null
960 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800961 @Nullable
962 public Parcelable[] getParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 unparcel();
964 Object o = mMap.get(key);
965 if (o == null) {
966 return null;
967 }
968 try {
969 return (Parcelable[]) o;
970 } catch (ClassCastException e) {
971 typeWarning(key, o, "Parcelable[]", e);
972 return null;
973 }
974 }
975
976 /**
977 * Returns the value associated with the given key, or null if
978 * no mapping of the desired type exists for the given key or a null
979 * value is explicitly associated with the key.
980 *
981 * @param key a String, or null
982 * @return an ArrayList<T> value, or null
983 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800984 @Nullable
985 public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 unparcel();
987 Object o = mMap.get(key);
988 if (o == null) {
989 return null;
990 }
991 try {
992 return (ArrayList<T>) o;
993 } catch (ClassCastException e) {
994 typeWarning(key, o, "ArrayList", e);
995 return null;
996 }
997 }
998
999 /**
1000 * Returns the value associated with the given key, or null if
1001 * no mapping of the desired type exists for the given key or a null
1002 * value is explicitly associated with the key.
1003 *
1004 * @param key a String, or null
1005 *
1006 * @return a SparseArray of T values, or null
1007 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001008 @Nullable
1009 public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 unparcel();
1011 Object o = mMap.get(key);
1012 if (o == null) {
1013 return null;
1014 }
1015 try {
1016 return (SparseArray<T>) o;
1017 } catch (ClassCastException e) {
1018 typeWarning(key, o, "SparseArray", e);
1019 return null;
1020 }
1021 }
1022
1023 /**
1024 * Returns the value associated with the given key, or null if
1025 * no mapping of the desired type exists for the given key or a null
1026 * value is explicitly associated with the key.
1027 *
1028 * @param key a String, or null
1029 * @return a Serializable value, or null
1030 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001031 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001032 @Nullable
1033 public Serializable getSerializable(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001034 return super.getSerializable(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 }
1036
1037 /**
1038 * Returns the value associated with the given key, or null if
1039 * no mapping of the desired type exists for the given key or a null
1040 * value is explicitly associated with the key.
1041 *
1042 * @param key a String, or null
1043 * @return an ArrayList<String> value, or null
1044 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001045 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001046 @Nullable
1047 public ArrayList<Integer> getIntegerArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001048 return super.getIntegerArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 }
1050
1051 /**
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.
1055 *
1056 * @param key a String, or null
1057 * @return an ArrayList<String> value, or null
1058 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001059 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001060 @Nullable
1061 public ArrayList<String> getStringArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001062 return super.getStringArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 }
1064
1065 /**
1066 * Returns the value associated with the given key, or null if
1067 * no mapping of the desired type exists for the given key or a null
1068 * value is explicitly associated with the key.
1069 *
1070 * @param key a String, or null
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001071 * @return an ArrayList<CharSequence> value, or null
1072 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001073 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001074 @Nullable
1075 public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001076 return super.getCharSequenceArrayList(key);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001077 }
1078
1079 /**
1080 * Returns the value associated with the given key, or null if
1081 * no mapping of the desired type exists for the given key or a null
1082 * value is explicitly associated with the key.
1083 *
1084 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085 * @return a byte[] value, or null
1086 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001087 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001088 @Nullable
1089 public byte[] getByteArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001090 return super.getByteArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 }
1092
1093 /**
1094 * Returns the value associated with the given key, or null if
1095 * no mapping of the desired type exists for the given key or a null
1096 * value is explicitly associated with the key.
1097 *
1098 * @param key a String, or null
1099 * @return a short[] value, or null
1100 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001101 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001102 @Nullable
1103 public short[] getShortArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001104 return super.getShortArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 }
1106
1107 /**
1108 * Returns the value associated with the given key, or null if
1109 * no mapping of the desired type exists for the given key or a null
1110 * value is explicitly associated with the key.
1111 *
1112 * @param key a String, or null
1113 * @return a char[] value, or null
1114 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001115 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001116 @Nullable
1117 public char[] getCharArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001118 return super.getCharArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 }
1120
1121 /**
1122 * Returns the value associated with the given key, or null if
1123 * no mapping of the desired type exists for the given key or a null
1124 * value is explicitly associated with the key.
1125 *
1126 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 * @return a float[] value, or null
1128 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001129 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001130 @Nullable
1131 public float[] getFloatArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001132 return super.getFloatArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001133 }
1134
1135 /**
1136 * Returns the value associated with the given key, or null if
1137 * no mapping of the desired type exists for the given key or a null
1138 * value is explicitly associated with the key.
1139 *
1140 * @param key a String, or null
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001141 * @return a CharSequence[] value, or null
1142 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001143 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001144 @Nullable
1145 public CharSequence[] getCharSequenceArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001146 return super.getCharSequenceArray(key);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001147 }
1148
1149 /**
1150 * Returns the value associated with the given key, or null if
1151 * no mapping of the desired type exists for the given key or a null
1152 * value is explicitly associated with the key.
1153 *
1154 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 * @return an IBinder value, or null
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001156 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001157 @Nullable
1158 public IBinder getBinder(@Nullable String key) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001159 unparcel();
1160 Object o = mMap.get(key);
1161 if (o == null) {
1162 return null;
1163 }
1164 try {
1165 return (IBinder) o;
1166 } catch (ClassCastException e) {
1167 typeWarning(key, o, "IBinder", e);
1168 return null;
1169 }
1170 }
1171
1172 /**
1173 * Returns the value associated with the given key, or null if
1174 * no mapping of the desired type exists for the given key or a null
1175 * value is explicitly associated with the key.
1176 *
1177 * @param key a String, or null
1178 * @return an IBinder value, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 *
1180 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001181 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 */
1183 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001184 @Nullable
1185 public IBinder getIBinder(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 unparcel();
1187 Object o = mMap.get(key);
1188 if (o == null) {
1189 return null;
1190 }
1191 try {
1192 return (IBinder) o;
1193 } catch (ClassCastException e) {
1194 typeWarning(key, o, "IBinder", e);
1195 return null;
1196 }
1197 }
1198
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001199 public static final @android.annotation.NonNull Parcelable.Creator<Bundle> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 new Parcelable.Creator<Bundle>() {
Craig Mautner719e6b12014-04-04 20:29:41 -07001201 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 public Bundle createFromParcel(Parcel in) {
1203 return in.readBundle();
1204 }
1205
Craig Mautner719e6b12014-04-04 20:29:41 -07001206 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 public Bundle[] newArray(int size) {
1208 return new Bundle[size];
1209 }
1210 };
1211
1212 /**
1213 * Report the nature of this Parcelable's contents
1214 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001215 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 public int describeContents() {
1217 int mask = 0;
1218 if (hasFileDescriptors()) {
1219 mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR;
1220 }
1221 return mask;
1222 }
Craig Mautner719e6b12014-04-04 20:29:41 -07001223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 /**
1225 * Writes the Bundle contents to a Parcel, typically in order for
1226 * it to be passed through an IBinder connection.
1227 * @param parcel The parcel to copy this bundle to.
1228 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001229 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001230 public void writeToParcel(Parcel parcel, int flags) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -07001231 final boolean oldAllowFds = parcel.pushAllowFds((mFlags & FLAG_ALLOW_FDS) != 0);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001232 try {
Craig Mautner719e6b12014-04-04 20:29:41 -07001233 super.writeToParcelInner(parcel, flags);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001234 } finally {
Dianne Hackbornc04db7e2011-10-03 21:09:35 -07001235 parcel.restoreAllowFds(oldAllowFds);
Dianne Hackborn6aff9052009-05-22 13:20:23 -07001236 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 }
1238
1239 /**
1240 * Reads the Parcel contents into this Bundle, typically in order for
1241 * it to be passed through an IBinder connection.
1242 * @param parcel The parcel to overwrite this bundle from.
1243 */
1244 public void readFromParcel(Parcel parcel) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001245 super.readFromParcelInner(parcel);
Makoto Onuki4501c61d2017-07-27 15:56:40 -07001246 mFlags = FLAG_ALLOW_FDS;
1247 maybePrefillHasFds();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 }
1249
1250 @Override
1251 public synchronized String toString() {
1252 if (mParcelledData != null) {
Andreas Gampe52764cb2016-04-19 20:46:43 -07001253 if (isEmptyParcel()) {
Dianne Hackborn8aee64d2013-10-25 10:41:50 -07001254 return "Bundle[EMPTY_PARCEL]";
1255 } else {
1256 return "Bundle[mParcelledData.dataSize=" +
1257 mParcelledData.dataSize() + "]";
1258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001259 }
1260 return "Bundle[" + mMap.toString() + "]";
1261 }
Dianne Hackborna47223f2017-03-30 13:49:13 -07001262
1263 /**
1264 * @hide
1265 */
1266 public synchronized String toShortString() {
1267 if (mParcelledData != null) {
1268 if (isEmptyParcel()) {
1269 return "EMPTY_PARCEL";
1270 } else {
1271 return "mParcelledData.dataSize=" + mParcelledData.dataSize();
1272 }
1273 }
1274 return mMap.toString();
1275 }
Kweku Adams85f2fbc2017-12-18 12:04:12 -08001276
1277 /** @hide */
1278 public void writeToProto(ProtoOutputStream proto, long fieldId) {
1279 final long token = proto.start(fieldId);
1280
1281 if (mParcelledData != null) {
1282 if (isEmptyParcel()) {
1283 proto.write(BundleProto.PARCELLED_DATA_SIZE, 0);
1284 } else {
1285 proto.write(BundleProto.PARCELLED_DATA_SIZE, mParcelledData.dataSize());
1286 }
1287 } else {
1288 proto.write(BundleProto.MAP_DATA, mMap.toString());
1289 }
1290
1291 proto.end(token);
1292 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293}