blob: 7e118406f1d38ef6d1d794242d8482331373a6b1 [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;
Andrei Onea24ec3212019-03-15 17:35:05 +000020import android.annotation.UnsupportedAppUsage;
Dianne Hackbornb87655b2013-07-17 19:06:22 -070021import android.util.ArrayMap;
Jeff Sharkey5ef33982014-09-04 18:13:39 -070022import android.util.Size;
23import android.util.SizeF;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.util.SparseArray;
Kweku Adams85f2fbc2017-12-18 12:04:12 -080025import android.util.proto.ProtoOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026
Makoto Onuki4501c61d2017-07-27 15:56:40 -070027import com.android.internal.annotations.VisibleForTesting;
28
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import java.io.Serializable;
30import java.util.ArrayList;
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -070031import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
33/**
Jeff Sharkeyd136e512016-03-09 22:30:56 -070034 * A mapping from String keys to various {@link Parcelable} values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 *
Jeff Sharkeyd136e512016-03-09 22:30:56 -070036 * @see PersistableBundle
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 */
Craig Mautner0a8e160e2014-05-29 10:27:32 -070038public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
Makoto Onuki4501c61d2017-07-27 15:56:40 -070039 @VisibleForTesting
40 static final int FLAG_HAS_FDS = 1 << 8;
41
42 @VisibleForTesting
43 static final int FLAG_HAS_FDS_KNOWN = 1 << 9;
44
45 @VisibleForTesting
46 static final int FLAG_ALLOW_FDS = 1 << 10;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070047
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 public static final Bundle EMPTY;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070049
Makoto Onuki97f82f22017-05-31 16:20:21 -070050 /**
51 * Special extras used to denote extras have been stripped off.
52 * @hide
53 */
54 public static final Bundle STRIPPED;
55
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056 static {
57 EMPTY = new Bundle();
Dianne Hackbornb87655b2013-07-17 19:06:22 -070058 EMPTY.mMap = ArrayMap.EMPTY;
Makoto Onuki97f82f22017-05-31 16:20:21 -070059
60 STRIPPED = new Bundle();
61 STRIPPED.putInt("STRIPPED", 1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 }
63
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 * Constructs a new, empty Bundle.
66 */
67 public Bundle() {
Craig Mautner719e6b12014-04-04 20:29:41 -070068 super();
Jeff Sharkey7410fb42016-03-16 21:23:29 -060069 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070 }
71
72 /**
73 * Constructs a Bundle whose data is stored as a Parcel. The data
74 * will be unparcelled on first contact, using the assigned ClassLoader.
75 *
76 * @param parcelledData a Parcel containing a Bundle
Makoto Onuki4501c61d2017-07-27 15:56:40 -070077 *
78 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 */
Makoto Onuki4501c61d2017-07-27 15:56:40 -070080 @VisibleForTesting
81 public Bundle(Parcel parcelledData) {
Craig Mautner719e6b12014-04-04 20:29:41 -070082 super(parcelledData);
Makoto Onuki4501c61d2017-07-27 15:56:40 -070083 mFlags = FLAG_ALLOW_FDS;
84 maybePrefillHasFds();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 }
86
Makoto Onuki4501c61d2017-07-27 15:56:40 -070087 /**
88 * Constructor from a parcel for when the length is known *and is not stored in the parcel.*
89 * The other constructor that takes a parcel assumes the length is in the parcel.
90 *
91 * @hide
92 */
93 @VisibleForTesting
94 public Bundle(Parcel parcelledData, int length) {
Craig Mautner719e6b12014-04-04 20:29:41 -070095 super(parcelledData, length);
Makoto Onuki4501c61d2017-07-27 15:56:40 -070096 mFlags = FLAG_ALLOW_FDS;
97 maybePrefillHasFds();
98 }
99
100 /**
101 * If {@link #mParcelledData} is not null, copy the HAS FDS bit from it because it's fast.
102 * Otherwise (if {@link #mParcelledData} is already null), leave {@link #FLAG_HAS_FDS_KNOWN}
103 * unset, because scanning a map is slower. We'll do it lazily in
104 * {@link #hasFileDescriptors()}.
105 */
106 private void maybePrefillHasFds() {
107 if (mParcelledData != null) {
108 if (mParcelledData.hasFileDescriptors()) {
109 mFlags |= FLAG_HAS_FDS | FLAG_HAS_FDS_KNOWN;
110 } else {
111 mFlags |= FLAG_HAS_FDS_KNOWN;
112 }
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700113 }
Dianne Hackborn6aff9052009-05-22 13:20:23 -0700114 }
115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800116 /**
117 * Constructs a new, empty Bundle that uses a specific ClassLoader for
118 * instantiating Parcelable and Serializable objects.
119 *
120 * @param loader An explicit ClassLoader to use when instantiating objects
121 * inside of the Bundle.
122 */
123 public Bundle(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700124 super(loader);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600125 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 }
127
128 /**
129 * Constructs a new, empty Bundle sized to hold the given number of
130 * elements. The Bundle will grow as needed.
131 *
132 * @param capacity the initial capacity of the Bundle
133 */
134 public Bundle(int capacity) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700135 super(capacity);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600136 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 }
138
139 /**
140 * Constructs a Bundle containing a copy of the mappings from the given
Dianne Hackborn2510b372017-03-03 17:01:38 -0800141 * Bundle. Does only a shallow copy of the original Bundle -- see
142 * {@link #deepCopy()} if that is not what you want.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 *
144 * @param b a Bundle to be copied.
Dianne Hackborn2510b372017-03-03 17:01:38 -0800145 *
146 * @see #deepCopy()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 */
148 public Bundle(Bundle b) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700149 super(b);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700150 mFlags = b.mFlags;
Craig Mautner719e6b12014-04-04 20:29:41 -0700151 }
152
153 /**
154 * Constructs a Bundle containing a copy of the mappings from the given
Dianne Hackborn2510b372017-03-03 17:01:38 -0800155 * PersistableBundle. Does only a shallow copy of the PersistableBundle -- see
156 * {@link PersistableBundle#deepCopy()} if you don't want that.
Craig Mautner719e6b12014-04-04 20:29:41 -0700157 *
Dianne Hackborn2510b372017-03-03 17:01:38 -0800158 * @param b a PersistableBundle to be copied.
Craig Mautner719e6b12014-04-04 20:29:41 -0700159 */
160 public Bundle(PersistableBundle b) {
161 super(b);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600162 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 }
164
165 /**
Dianne Hackbornba604732016-02-10 17:05:10 -0800166 * Constructs a Bundle without initializing it.
167 */
168 Bundle(boolean doInit) {
169 super(doInit);
170 }
171
172 /**
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800173 * Make a Bundle for a single key/value pair.
174 *
175 * @hide
176 */
Andrei Onea24ec3212019-03-15 17:35:05 +0000177 @UnsupportedAppUsage
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800178 public static Bundle forPair(String key, String value) {
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800179 Bundle b = new Bundle(1);
180 b.putString(key, value);
181 return b;
182 }
183
184 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 * Changes the ClassLoader this Bundle uses when instantiating objects.
186 *
187 * @param loader An explicit ClassLoader to use when instantiating objects
188 * inside of the Bundle.
189 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700190 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 public void setClassLoader(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700192 super.setClassLoader(loader);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 }
194
195 /**
Dianne Hackborn51642462010-10-28 10:32:37 -0700196 * Return the ClassLoader currently associated with this Bundle.
197 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700198 @Override
Dianne Hackborn51642462010-10-28 10:32:37 -0700199 public ClassLoader getClassLoader() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700200 return super.getClassLoader();
Dianne Hackborn51642462010-10-28 10:32:37 -0700201 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400202
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700203 /** {@hide} */
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400204 public boolean setAllowFds(boolean allowFds) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700205 final boolean orig = (mFlags & FLAG_ALLOW_FDS) != 0;
206 if (allowFds) {
207 mFlags |= FLAG_ALLOW_FDS;
208 } else {
209 mFlags &= ~FLAG_ALLOW_FDS;
210 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400211 return orig;
212 }
213
Dianne Hackborn51642462010-10-28 10:32:37 -0700214 /**
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700215 * Mark if this Bundle is okay to "defuse." That is, it's okay for system
216 * processes to ignore any {@link BadParcelableException} encountered when
217 * unparceling it, leaving an empty bundle in its place.
218 * <p>
219 * This should <em>only</em> be set when the Bundle reaches its final
220 * destination, otherwise a system process may clobber contents that were
221 * destined for an app that could have unparceled them.
222 *
223 * @hide
224 */
225 public void setDefusable(boolean defusable) {
226 if (defusable) {
227 mFlags |= FLAG_DEFUSABLE;
228 } else {
229 mFlags &= ~FLAG_DEFUSABLE;
230 }
231 }
232
Jeff Sharkeya04c7a72016-03-18 12:20:36 -0600233 /** {@hide} */
Andrei Onea24ec3212019-03-15 17:35:05 +0000234 @UnsupportedAppUsage
Jeff Sharkeya04c7a72016-03-18 12:20:36 -0600235 public static Bundle setDefusable(Bundle bundle, boolean defusable) {
236 if (bundle != null) {
237 bundle.setDefusable(defusable);
238 }
239 return bundle;
240 }
241
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700242 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 * Clones the current Bundle. The internal map is cloned, but the keys and
244 * values to which it refers are copied by reference.
245 */
246 @Override
247 public Object clone() {
248 return new Bundle(this);
249 }
250
251 /**
Dianne Hackbornba604732016-02-10 17:05:10 -0800252 * Make a deep copy of the given bundle. Traverses into inner containers and copies
253 * them as well, so they are not shared across bundles. Will traverse in to
254 * {@link Bundle}, {@link PersistableBundle}, {@link ArrayList}, and all types of
255 * primitive arrays. Other types of objects (such as Parcelable or Serializable)
256 * are referenced as-is and not copied in any way.
257 */
Dianne Hackborn2510b372017-03-03 17:01:38 -0800258 public Bundle deepCopy() {
Dianne Hackbornba604732016-02-10 17:05:10 -0800259 Bundle b = new Bundle(false);
260 b.copyInternal(this, true);
261 return b;
262 }
263
264 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 * Removes all elements from the mapping of this Bundle.
266 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700267 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 public void clear() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700269 super.clear();
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600270 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 }
272
273 /**
Christopher Tate250985f2016-03-31 13:57:42 -0700274 * Removes any entry with the given key from the mapping of this Bundle.
275 *
276 * @param key a String key
277 */
278 public void remove(String key) {
279 super.remove(key);
280 if ((mFlags & FLAG_HAS_FDS) != 0) {
281 mFlags &= ~FLAG_HAS_FDS_KNOWN;
282 }
283 }
284
285 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 * Inserts all mappings from the given Bundle into this Bundle.
287 *
Craig Mautner719e6b12014-04-04 20:29:41 -0700288 * @param bundle a Bundle
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700290 public void putAll(Bundle bundle) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 unparcel();
Craig Mautner719e6b12014-04-04 20:29:41 -0700292 bundle.unparcel();
293 mMap.putAll(bundle.mMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700295 // FD state is now known if and only if both bundles already knew
296 if ((bundle.mFlags & FLAG_HAS_FDS) != 0) {
297 mFlags |= FLAG_HAS_FDS;
298 }
299 if ((bundle.mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
300 mFlags &= ~FLAG_HAS_FDS_KNOWN;
301 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700302 }
303
304 /**
Sudheer Shankafab200f2017-05-17 20:41:53 -0700305 * Return the size of {@link #mParcelledData} in bytes if available, otherwise {@code 0}.
306 *
307 * @hide
308 */
Andrei Onea24ec3212019-03-15 17:35:05 +0000309 @UnsupportedAppUsage
Sudheer Shankafab200f2017-05-17 20:41:53 -0700310 public int getSize() {
311 if (mParcelledData != null) {
312 return mParcelledData.dataSize();
313 } else {
314 return 0;
315 }
316 }
317
318 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 * Reports whether the bundle contains any parcelled file descriptors.
320 */
321 public boolean hasFileDescriptors() {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700322 if ((mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 boolean fdFound = false; // keep going until we find one or run out of data
Craig Mautner719e6b12014-04-04 20:29:41 -0700324
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 if (mParcelledData != null) {
326 if (mParcelledData.hasFileDescriptors()) {
327 fdFound = true;
328 }
329 } else {
330 // It's been unparcelled, so we need to walk the map
Dianne Hackbornb87655b2013-07-17 19:06:22 -0700331 for (int i=mMap.size()-1; i>=0; i--) {
332 Object obj = mMap.valueAt(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 if (obj instanceof Parcelable) {
334 if ((((Parcelable)obj).describeContents()
335 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
336 fdFound = true;
337 break;
338 }
339 } else if (obj instanceof Parcelable[]) {
340 Parcelable[] array = (Parcelable[]) obj;
341 for (int n = array.length - 1; n >= 0; n--) {
Taiju Tsuikie58c7852015-04-22 16:59:00 +0900342 Parcelable p = array[n];
343 if (p != null && ((p.describeContents()
344 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 fdFound = true;
346 break;
347 }
348 }
349 } else if (obj instanceof SparseArray) {
350 SparseArray<? extends Parcelable> array =
351 (SparseArray<? extends Parcelable>) obj;
352 for (int n = array.size() - 1; n >= 0; n--) {
Taiju Tsuikiecd21842015-04-28 13:36:15 +0900353 Parcelable p = array.valueAt(n);
354 if (p != null && (p.describeContents()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800355 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
356 fdFound = true;
357 break;
358 }
359 }
360 } else if (obj instanceof ArrayList) {
361 ArrayList array = (ArrayList) obj;
362 // an ArrayList here might contain either Strings or
363 // Parcelables; only look inside for Parcelables
Craig Mautner719e6b12014-04-04 20:29:41 -0700364 if (!array.isEmpty() && (array.get(0) instanceof Parcelable)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 for (int n = array.size() - 1; n >= 0; n--) {
366 Parcelable p = (Parcelable) array.get(n);
367 if (p != null && ((p.describeContents()
368 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
369 fdFound = true;
370 break;
371 }
372 }
373 }
374 }
375 }
376 }
377
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700378 if (fdFound) {
379 mFlags |= FLAG_HAS_FDS;
Christopher Tate250985f2016-03-31 13:57:42 -0700380 } else {
381 mFlags &= ~FLAG_HAS_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700382 }
383 mFlags |= FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 }
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700385 return (mFlags & FLAG_HAS_FDS) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700387
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 /**
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700389 * Filter values in Bundle to only basic types.
390 * @hide
391 */
Andrei Onea24ec3212019-03-15 17:35:05 +0000392 @UnsupportedAppUsage
Dianne Hackborn851ec492016-10-12 17:20:07 -0700393 public Bundle filterValues() {
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700394 unparcel();
Dianne Hackborn851ec492016-10-12 17:20:07 -0700395 Bundle bundle = this;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700396 if (mMap != null) {
Dianne Hackborn851ec492016-10-12 17:20:07 -0700397 ArrayMap<String, Object> map = mMap;
398 for (int i = map.size() - 1; i >= 0; i--) {
399 Object value = map.valueAt(i);
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700400 if (PersistableBundle.isValidType(value)) {
401 continue;
402 }
403 if (value instanceof Bundle) {
Dianne Hackborn851ec492016-10-12 17:20:07 -0700404 Bundle newBundle = ((Bundle)value).filterValues();
405 if (newBundle != value) {
406 if (map == mMap) {
407 // The filter had to generate a new bundle, but we have not yet
408 // created a new one here. Do that now.
409 bundle = new Bundle(this);
410 // Note the ArrayMap<> constructor is guaranteed to generate
411 // a new object with items in the same order as the original.
412 map = bundle.mMap;
413 }
414 // Replace this current entry with the new child bundle.
415 map.setValueAt(i, newBundle);
416 }
417 continue;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700418 }
419 if (value.getClass().getName().startsWith("android.")) {
420 continue;
421 }
Dianne Hackborn851ec492016-10-12 17:20:07 -0700422 if (map == mMap) {
423 // This is the first time we have had to remove something, that means we
424 // need to switch to a new Bundle.
425 bundle = new Bundle(this);
426 // Note the ArrayMap<> constructor is guaranteed to generate
427 // a new object with items in the same order as the original.
428 map = bundle.mMap;
429 }
430 map.removeAt(i);
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700431 }
432 }
Christopher Tate250985f2016-03-31 13:57:42 -0700433 mFlags |= FLAG_HAS_FDS_KNOWN;
434 mFlags &= ~FLAG_HAS_FDS;
Dianne Hackborn851ec492016-10-12 17:20:07 -0700435 return bundle;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700436 }
437
Jeff Sharkey7d6fd4b2019-08-07 18:12:00 -0600438 /** {@hide} */
439 @Override
440 public void putObject(@Nullable String key, @Nullable Object value) {
441 if (value instanceof Byte) {
442 putByte(key, (Byte) value);
443 } else if (value instanceof Character) {
444 putChar(key, (Character) value);
445 } else if (value instanceof Short) {
446 putShort(key, (Short) value);
447 } else if (value instanceof Float) {
448 putFloat(key, (Float) value);
449 } else if (value instanceof CharSequence) {
450 putCharSequence(key, (CharSequence) value);
451 } else if (value instanceof Parcelable) {
452 putParcelable(key, (Parcelable) value);
453 } else if (value instanceof Size) {
454 putSize(key, (Size) value);
455 } else if (value instanceof SizeF) {
456 putSizeF(key, (SizeF) value);
457 } else if (value instanceof Parcelable[]) {
458 putParcelableArray(key, (Parcelable[]) value);
459 } else if (value instanceof ArrayList) {
460 putParcelableArrayList(key, (ArrayList) value);
461 } else if (value instanceof List) {
462 putParcelableList(key, (List) value);
463 } else if (value instanceof SparseArray) {
464 putSparseParcelableArray(key, (SparseArray) value);
465 } else if (value instanceof Serializable) {
466 putSerializable(key, (Serializable) value);
467 } else if (value instanceof byte[]) {
468 putByteArray(key, (byte[]) value);
469 } else if (value instanceof short[]) {
470 putShortArray(key, (short[]) value);
471 } else if (value instanceof char[]) {
472 putCharArray(key, (char[]) value);
473 } else if (value instanceof float[]) {
474 putFloatArray(key, (float[]) value);
475 } else if (value instanceof CharSequence[]) {
476 putCharSequenceArray(key, (CharSequence[]) value);
477 } else if (value instanceof Bundle) {
478 putBundle(key, (Bundle) value);
479 } else if (value instanceof Binder) {
480 putBinder(key, (Binder) value);
481 } else if (value instanceof IBinder) {
482 putIBinder(key, (IBinder) value);
483 } else {
484 super.putObject(key, value);
485 }
486 }
487
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700488 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 * Inserts a byte value into the mapping of this Bundle, replacing
490 * any existing value for the given key.
491 *
492 * @param key a String, or null
493 * @param value a byte
494 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700495 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800496 public void putByte(@Nullable String key, byte value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700497 super.putByte(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 }
499
500 /**
501 * Inserts a char value into the mapping of this Bundle, replacing
502 * any existing value for the given key.
503 *
504 * @param key a String, or null
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800505 * @param value a char
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700507 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800508 public void putChar(@Nullable String key, char value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700509 super.putChar(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 }
511
512 /**
513 * Inserts a short value into the mapping of this Bundle, replacing
514 * any existing value for the given key.
515 *
516 * @param key a String, or null
517 * @param value a short
518 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700519 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800520 public void putShort(@Nullable String key, short value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700521 super.putShort(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 }
523
524 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800525 * Inserts a float value into the mapping of this Bundle, replacing
526 * any existing value for the given key.
527 *
528 * @param key a String, or null
529 * @param value a float
530 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700531 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800532 public void putFloat(@Nullable String key, float value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700533 super.putFloat(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 }
535
536 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 * Inserts a CharSequence value into the mapping of this Bundle, replacing
538 * any existing value for the given key. Either key or value may be null.
539 *
540 * @param key a String, or null
541 * @param value a CharSequence, or null
542 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700543 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800544 public void putCharSequence(@Nullable String key, @Nullable CharSequence value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700545 super.putCharSequence(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 }
547
548 /**
549 * Inserts a Parcelable value into the mapping of this Bundle, replacing
550 * any existing value for the given key. Either key or value may be null.
551 *
552 * @param key a String, or null
553 * @param value a Parcelable object, or null
554 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800555 public void putParcelable(@Nullable String key, @Nullable Parcelable value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 unparcel();
557 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700558 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 }
560
561 /**
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700562 * Inserts a Size value into the mapping of this Bundle, replacing
563 * any existing value for the given key. Either key or value may be null.
564 *
565 * @param key a String, or null
566 * @param value a Size object, or null
567 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800568 public void putSize(@Nullable String key, @Nullable Size value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700569 unparcel();
570 mMap.put(key, value);
571 }
572
573 /**
574 * Inserts a SizeF value into the mapping of this Bundle, replacing
575 * any existing value for the given key. Either key or value may be null.
576 *
577 * @param key a String, or null
578 * @param value a SizeF object, or null
579 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800580 public void putSizeF(@Nullable String key, @Nullable SizeF value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700581 unparcel();
582 mMap.put(key, value);
583 }
584
585 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 * Inserts an array of Parcelable values into the mapping of this Bundle,
587 * replacing any existing value for the given key. Either key or value may
588 * be null.
589 *
590 * @param key a String, or null
591 * @param value an array of Parcelable objects, or null
592 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800593 public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 unparcel();
595 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700596 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800597 }
598
599 /**
600 * Inserts a List of Parcelable values into the mapping of this Bundle,
601 * replacing any existing value for the given key. Either key or value may
602 * be null.
603 *
604 * @param key a String, or null
605 * @param value an ArrayList of Parcelable objects, or null
606 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800607 public void putParcelableArrayList(@Nullable String key,
608 @Nullable ArrayList<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 unparcel();
610 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700611 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 }
613
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700614 /** {@hide} */
Andrei Onea24ec3212019-03-15 17:35:05 +0000615 @UnsupportedAppUsage
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700616 public void putParcelableList(String key, List<? extends Parcelable> value) {
617 unparcel();
618 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700619 mFlags &= ~FLAG_HAS_FDS_KNOWN;
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700620 }
621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 /**
623 * Inserts a SparceArray of Parcelable values into the mapping of this
624 * Bundle, replacing any existing value for the given key. Either key
625 * or value may be null.
626 *
627 * @param key a String, or null
628 * @param value a SparseArray of Parcelable objects, or null
629 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800630 public void putSparseParcelableArray(@Nullable String key,
631 @Nullable SparseArray<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 unparcel();
633 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700634 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 }
636
637 /**
638 * Inserts an ArrayList<Integer> value into the mapping of this Bundle, replacing
639 * any existing value for the given key. Either key or value may be null.
640 *
641 * @param key a String, or null
642 * @param value an ArrayList<Integer> object, or null
643 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700644 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800645 public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700646 super.putIntegerArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 }
648
649 /**
650 * Inserts an ArrayList<String> value into the mapping of this Bundle, replacing
651 * any existing value for the given key. Either key or value may be null.
652 *
653 * @param key a String, or null
654 * @param value an ArrayList<String> object, or null
655 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700656 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800657 public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700658 super.putStringArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 }
660
661 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000662 * Inserts an ArrayList<CharSequence> value into the mapping of this Bundle, replacing
663 * any existing value for the given key. Either key or value may be null.
664 *
665 * @param key a String, or null
666 * @param value an ArrayList<CharSequence> object, or null
667 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700668 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800669 public void putCharSequenceArrayList(@Nullable String key,
670 @Nullable ArrayList<CharSequence> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700671 super.putCharSequenceArrayList(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000672 }
673
674 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 * Inserts a Serializable value into the mapping of this Bundle, replacing
676 * any existing value for the given key. Either key or value may be null.
677 *
678 * @param key a String, or null
679 * @param value a Serializable object, or null
680 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700681 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800682 public void putSerializable(@Nullable String key, @Nullable Serializable value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700683 super.putSerializable(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 }
685
686 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 * Inserts a byte array value into the mapping of this Bundle, replacing
688 * any existing value for the given key. Either key or value may be null.
689 *
690 * @param key a String, or null
691 * @param value a byte array object, or null
692 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700693 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800694 public void putByteArray(@Nullable String key, @Nullable byte[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700695 super.putByteArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 }
697
698 /**
699 * Inserts a short array value into the mapping of this Bundle, replacing
700 * any existing value for the given key. Either key or value may be null.
701 *
702 * @param key a String, or null
703 * @param value a short array object, or null
704 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700705 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800706 public void putShortArray(@Nullable String key, @Nullable short[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700707 super.putShortArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 }
709
710 /**
711 * Inserts a char array value into the mapping of this Bundle, replacing
712 * any existing value for the given key. Either key or value may be null.
713 *
714 * @param key a String, or null
715 * @param value a char array object, or null
716 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700717 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800718 public void putCharArray(@Nullable String key, @Nullable char[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700719 super.putCharArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 }
721
722 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 * Inserts a float array value into the mapping of this Bundle, replacing
724 * any existing value for the given key. Either key or value may be null.
725 *
726 * @param key a String, or null
727 * @param value a float array object, or null
728 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700729 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800730 public void putFloatArray(@Nullable String key, @Nullable float[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700731 super.putFloatArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 }
733
734 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000735 * Inserts a CharSequence array value into the mapping of this Bundle, replacing
736 * any existing value for the given key. Either key or value may be null.
737 *
738 * @param key a String, or null
739 * @param value a CharSequence array object, or null
740 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700741 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800742 public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700743 super.putCharSequenceArray(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000744 }
745
746 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 * Inserts a Bundle value into the mapping of this Bundle, replacing
748 * any existing value for the given key. Either key or value may be null.
749 *
750 * @param key a String, or null
751 * @param value a Bundle object, or null
752 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800753 public void putBundle(@Nullable String key, @Nullable Bundle value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 unparcel();
755 mMap.put(key, value);
756 }
757
758 /**
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800759 * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing
760 * any existing value for the given key. Either key or value may be null.
761 *
762 * <p class="note">You should be very careful when using this function. In many
763 * places where Bundles are used (such as inside of Intent objects), the Bundle
764 * can live longer inside of another process than the process that had originally
765 * created it. In that case, the IBinder you supply here will become invalid
766 * when your process goes away, and no longer usable, even if a new process is
767 * created for you later on.</p>
768 *
769 * @param key a String, or null
770 * @param value an IBinder object, or null
771 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800772 public void putBinder(@Nullable String key, @Nullable IBinder value) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800773 unparcel();
774 mMap.put(key, value);
775 }
776
777 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 * Inserts an IBinder value into the mapping of this Bundle, replacing
779 * any existing value for the given key. Either key or value may be null.
780 *
781 * @param key a String, or null
782 * @param value an IBinder object, or null
783 *
784 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800785 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 */
Andrei Onea24ec3212019-03-15 17:35:05 +0000787 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800789 public void putIBinder(@Nullable String key, @Nullable IBinder value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 unparcel();
791 mMap.put(key, value);
792 }
793
794 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800795 * Returns the value associated with the given key, or (byte) 0 if
796 * no mapping of the desired type exists for the given key.
797 *
798 * @param key a String
799 * @return a byte value
800 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700801 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 public byte getByte(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700803 return super.getByte(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 }
805
806 /**
807 * Returns the value associated with the given key, or defaultValue if
808 * no mapping of the desired type exists for the given key.
809 *
810 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800811 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 * @return a byte value
813 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700814 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800815 public Byte getByte(String key, byte defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700816 return super.getByte(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 }
818
819 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800820 * Returns the value associated with the given key, or (char) 0 if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 * no mapping of the desired type exists for the given key.
822 *
823 * @param key a String
824 * @return a char value
825 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700826 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 public char getChar(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700828 return super.getChar(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 }
830
831 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800832 * Returns the value associated with the given key, or defaultValue if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 * no mapping of the desired type exists for the given key.
834 *
835 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800836 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 * @return a char value
838 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700839 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 public char getChar(String key, char defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700841 return super.getChar(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800842 }
843
844 /**
845 * Returns the value associated with the given key, or (short) 0 if
846 * no mapping of the desired type exists for the given key.
847 *
848 * @param key a String
849 * @return a short value
850 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700851 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 public short getShort(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700853 return super.getShort(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 }
855
856 /**
857 * Returns the value associated with the given key, or defaultValue if
858 * no mapping of the desired type exists for the given key.
859 *
860 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800861 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 * @return a short value
863 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700864 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 public short getShort(String key, short defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700866 return super.getShort(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 }
868
869 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 * Returns the value associated with the given key, or 0.0f if
871 * no mapping of the desired type exists for the given key.
872 *
873 * @param key a String
874 * @return a float value
875 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700876 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 public float getFloat(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700878 return super.getFloat(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 }
880
881 /**
882 * Returns the value associated with the given key, or defaultValue if
883 * no mapping of the desired type exists for the given key.
884 *
885 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800886 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 * @return a float value
888 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700889 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 public float getFloat(String key, float defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700891 return super.getFloat(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892 }
893
894 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 * Returns the value associated with the given key, or null if
896 * no mapping of the desired type exists for the given key or a null
897 * value is explicitly associated with the key.
898 *
899 * @param key a String, or null
900 * @return a CharSequence value, or null
901 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700902 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800903 @Nullable
904 public CharSequence getCharSequence(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700905 return super.getCharSequence(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 }
907
908 /**
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800909 * Returns the value associated with the given key, or defaultValue if
Narayan Kamathca2197b2014-06-19 10:46:00 +0100910 * no mapping of the desired type exists for the given key or if a null
911 * value is explicitly associatd with the given key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800912 *
913 * @param key a String, or null
Narayan Kamathca2197b2014-06-19 10:46:00 +0100914 * @param defaultValue Value to return if key does not exist or if a null
915 * value is associated with the given key.
Christopher Tate116751d2012-12-20 18:57:09 -0800916 * @return the CharSequence value associated with the given key, or defaultValue
917 * if no valid CharSequence object is currently mapped to that key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800918 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700919 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800920 public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700921 return super.getCharSequence(key, defaultValue);
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800922 }
923
924 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 * Returns the value associated with the given key, or null if
926 * no mapping of the desired type exists for the given key or a null
927 * value is explicitly associated with the key.
928 *
929 * @param key a String, or null
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700930 * @return a Size value, or null
931 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800932 @Nullable
933 public Size getSize(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700934 unparcel();
935 final Object o = mMap.get(key);
936 try {
937 return (Size) o;
938 } catch (ClassCastException e) {
939 typeWarning(key, o, "Size", e);
940 return null;
941 }
942 }
943
944 /**
945 * Returns the value associated with the given key, or null if
946 * no mapping of the desired type exists for the given key or a null
947 * value is explicitly associated with the key.
948 *
949 * @param key a String, or null
950 * @return a Size value, or null
951 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800952 @Nullable
953 public SizeF getSizeF(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700954 unparcel();
955 final Object o = mMap.get(key);
956 try {
957 return (SizeF) o;
958 } catch (ClassCastException e) {
959 typeWarning(key, o, "SizeF", e);
960 return null;
961 }
962 }
963
964 /**
965 * Returns the value associated with the given key, or null if
966 * no mapping of the desired type exists for the given key or a null
967 * value is explicitly associated with the key.
968 *
969 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 * @return a Bundle value, or null
971 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800972 @Nullable
973 public Bundle getBundle(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800974 unparcel();
975 Object o = mMap.get(key);
976 if (o == null) {
977 return null;
978 }
979 try {
980 return (Bundle) o;
981 } catch (ClassCastException e) {
982 typeWarning(key, o, "Bundle", e);
983 return null;
984 }
985 }
986
987 /**
Felipe Leme45d3bfc2019-03-19 13:51:38 -0700988 * Returns the value associated with the given key, or {@code null} if
989 * no mapping of the desired type exists for the given key or a {@code null}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 * value is explicitly associated with the key.
991 *
Felipe Leme45d3bfc2019-03-19 13:51:38 -0700992 * <p><b>Note: </b> if the expected value is not a class provided by the Android platform,
993 * you must call {@link #setClassLoader(ClassLoader)} with the proper {@link ClassLoader} first.
994 * Otherwise, this method might throw an exception or return {@code null}.
995 *
996 * @param key a String, or {@code null}
997 * @return a Parcelable value, or {@code null}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800999 @Nullable
1000 public <T extends Parcelable> T getParcelable(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 unparcel();
1002 Object o = mMap.get(key);
1003 if (o == null) {
1004 return null;
1005 }
1006 try {
1007 return (T) o;
1008 } catch (ClassCastException e) {
1009 typeWarning(key, o, "Parcelable", e);
1010 return null;
1011 }
1012 }
1013
1014 /**
Felipe Leme45d3bfc2019-03-19 13:51:38 -07001015 * Returns the value associated with the given key, or {@code null} if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001016 * no mapping of the desired type exists for the given key or a null
1017 * value is explicitly associated with the key.
1018 *
Felipe Leme45d3bfc2019-03-19 13:51:38 -07001019 * <p><b>Note: </b> if the expected value is not a class provided by the Android platform,
1020 * you must call {@link #setClassLoader(ClassLoader)} with the proper {@link ClassLoader} first.
1021 * Otherwise, this method might throw an exception or return {@code null}.
1022 *
1023 * @param key a String, or {@code null}
1024 * @return a Parcelable[] value, or {@code null}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001026 @Nullable
1027 public Parcelable[] getParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 unparcel();
1029 Object o = mMap.get(key);
1030 if (o == null) {
1031 return null;
1032 }
1033 try {
1034 return (Parcelable[]) o;
1035 } catch (ClassCastException e) {
1036 typeWarning(key, o, "Parcelable[]", e);
1037 return null;
1038 }
1039 }
1040
1041 /**
Felipe Leme45d3bfc2019-03-19 13:51:38 -07001042 * Returns the value associated with the given key, or {@code null} if
1043 * no mapping of the desired type exists for the given key or a {@code null}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 * value is explicitly associated with the key.
1045 *
Felipe Leme45d3bfc2019-03-19 13:51:38 -07001046 * <p><b>Note: </b> if the expected value is not a class provided by the Android platform,
1047 * you must call {@link #setClassLoader(ClassLoader)} with the proper {@link ClassLoader} first.
1048 * Otherwise, this method might throw an exception or return {@code null}.
1049 *
1050 * @param key a String, or {@code null}
1051 * @return an ArrayList<T> value, or {@code null}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001052 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001053 @Nullable
1054 public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 unparcel();
1056 Object o = mMap.get(key);
1057 if (o == null) {
1058 return null;
1059 }
1060 try {
1061 return (ArrayList<T>) o;
1062 } catch (ClassCastException e) {
1063 typeWarning(key, o, "ArrayList", e);
1064 return null;
1065 }
1066 }
1067
1068 /**
1069 * Returns the value associated with the given key, or null if
1070 * no mapping of the desired type exists for the given key or a null
1071 * value is explicitly associated with the key.
1072 *
1073 * @param key a String, or null
1074 *
1075 * @return a SparseArray of T values, or null
1076 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001077 @Nullable
1078 public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 unparcel();
1080 Object o = mMap.get(key);
1081 if (o == null) {
1082 return null;
1083 }
1084 try {
1085 return (SparseArray<T>) o;
1086 } catch (ClassCastException e) {
1087 typeWarning(key, o, "SparseArray", e);
1088 return null;
1089 }
1090 }
1091
1092 /**
1093 * Returns the value associated with the given key, or null if
1094 * no mapping of the desired type exists for the given key or a null
1095 * value is explicitly associated with the key.
1096 *
1097 * @param key a String, or null
1098 * @return a Serializable value, or null
1099 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001100 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001101 @Nullable
1102 public Serializable getSerializable(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001103 return super.getSerializable(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001104 }
1105
1106 /**
1107 * Returns the value associated with the given key, or null if
1108 * no mapping of the desired type exists for the given key or a null
1109 * value is explicitly associated with the key.
1110 *
1111 * @param key a String, or null
1112 * @return an ArrayList<String> value, or null
1113 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001114 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001115 @Nullable
1116 public ArrayList<Integer> getIntegerArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001117 return super.getIntegerArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001118 }
1119
1120 /**
1121 * Returns the value associated with the given key, or null if
1122 * no mapping of the desired type exists for the given key or a null
1123 * value is explicitly associated with the key.
1124 *
1125 * @param key a String, or null
1126 * @return an ArrayList<String> value, or null
1127 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001128 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001129 @Nullable
1130 public ArrayList<String> getStringArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001131 return super.getStringArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 }
1133
1134 /**
1135 * Returns the value associated with the given key, or null if
1136 * no mapping of the desired type exists for the given key or a null
1137 * value is explicitly associated with the key.
1138 *
1139 * @param key a String, or null
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001140 * @return an ArrayList<CharSequence> value, or null
1141 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001142 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001143 @Nullable
1144 public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001145 return super.getCharSequenceArrayList(key);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001146 }
1147
1148 /**
1149 * Returns the value associated with the given key, or null if
1150 * no mapping of the desired type exists for the given key or a null
1151 * value is explicitly associated with the key.
1152 *
1153 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 * @return a byte[] value, or null
1155 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001156 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001157 @Nullable
1158 public byte[] getByteArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001159 return super.getByteArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 }
1161
1162 /**
1163 * Returns the value associated with the given key, or null if
1164 * no mapping of the desired type exists for the given key or a null
1165 * value is explicitly associated with the key.
1166 *
1167 * @param key a String, or null
1168 * @return a short[] value, or null
1169 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001170 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001171 @Nullable
1172 public short[] getShortArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001173 return super.getShortArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001174 }
1175
1176 /**
1177 * Returns the value associated with the given key, or null if
1178 * no mapping of the desired type exists for the given key or a null
1179 * value is explicitly associated with the key.
1180 *
1181 * @param key a String, or null
1182 * @return a char[] value, or null
1183 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001184 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001185 @Nullable
1186 public char[] getCharArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001187 return super.getCharArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 }
1189
1190 /**
1191 * Returns the value associated with the given key, or null if
1192 * no mapping of the desired type exists for the given key or a null
1193 * value is explicitly associated with the key.
1194 *
1195 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 * @return a float[] value, or null
1197 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001198 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001199 @Nullable
1200 public float[] getFloatArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001201 return super.getFloatArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001202 }
1203
1204 /**
1205 * Returns the value associated with the given key, or null if
1206 * no mapping of the desired type exists for the given key or a null
1207 * value is explicitly associated with the key.
1208 *
1209 * @param key a String, or null
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001210 * @return a CharSequence[] value, or null
1211 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001212 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001213 @Nullable
1214 public CharSequence[] getCharSequenceArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001215 return super.getCharSequenceArray(key);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001216 }
1217
1218 /**
1219 * Returns the value associated with the given key, or null if
1220 * no mapping of the desired type exists for the given key or a null
1221 * value is explicitly associated with the key.
1222 *
1223 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 * @return an IBinder value, or null
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001225 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001226 @Nullable
1227 public IBinder getBinder(@Nullable String key) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001228 unparcel();
1229 Object o = mMap.get(key);
1230 if (o == null) {
1231 return null;
1232 }
1233 try {
1234 return (IBinder) o;
1235 } catch (ClassCastException e) {
1236 typeWarning(key, o, "IBinder", e);
1237 return null;
1238 }
1239 }
1240
1241 /**
1242 * Returns the value associated with the given key, or null if
1243 * no mapping of the desired type exists for the given key or a null
1244 * value is explicitly associated with the key.
1245 *
1246 * @param key a String, or null
1247 * @return an IBinder value, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001248 *
1249 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001250 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 */
Andrei Onea24ec3212019-03-15 17:35:05 +00001252 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001254 @Nullable
1255 public IBinder getIBinder(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 unparcel();
1257 Object o = mMap.get(key);
1258 if (o == null) {
1259 return null;
1260 }
1261 try {
1262 return (IBinder) o;
1263 } catch (ClassCastException e) {
1264 typeWarning(key, o, "IBinder", e);
1265 return null;
1266 }
1267 }
1268
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07001269 public static final @android.annotation.NonNull Parcelable.Creator<Bundle> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 new Parcelable.Creator<Bundle>() {
Craig Mautner719e6b12014-04-04 20:29:41 -07001271 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001272 public Bundle createFromParcel(Parcel in) {
1273 return in.readBundle();
1274 }
1275
Craig Mautner719e6b12014-04-04 20:29:41 -07001276 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 public Bundle[] newArray(int size) {
1278 return new Bundle[size];
1279 }
1280 };
1281
1282 /**
1283 * Report the nature of this Parcelable's contents
1284 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001285 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 public int describeContents() {
1287 int mask = 0;
1288 if (hasFileDescriptors()) {
1289 mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR;
1290 }
1291 return mask;
1292 }
Craig Mautner719e6b12014-04-04 20:29:41 -07001293
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 /**
1295 * Writes the Bundle contents to a Parcel, typically in order for
1296 * it to be passed through an IBinder connection.
1297 * @param parcel The parcel to copy this bundle to.
1298 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001299 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 public void writeToParcel(Parcel parcel, int flags) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -07001301 final boolean oldAllowFds = parcel.pushAllowFds((mFlags & FLAG_ALLOW_FDS) != 0);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001302 try {
Craig Mautner719e6b12014-04-04 20:29:41 -07001303 super.writeToParcelInner(parcel, flags);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001304 } finally {
Dianne Hackbornc04db7e2011-10-03 21:09:35 -07001305 parcel.restoreAllowFds(oldAllowFds);
Dianne Hackborn6aff9052009-05-22 13:20:23 -07001306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 }
1308
1309 /**
1310 * Reads the Parcel contents into this Bundle, typically in order for
1311 * it to be passed through an IBinder connection.
1312 * @param parcel The parcel to overwrite this bundle from.
1313 */
1314 public void readFromParcel(Parcel parcel) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001315 super.readFromParcelInner(parcel);
Makoto Onuki4501c61d2017-07-27 15:56:40 -07001316 mFlags = FLAG_ALLOW_FDS;
1317 maybePrefillHasFds();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 }
1319
1320 @Override
1321 public synchronized String toString() {
1322 if (mParcelledData != null) {
Andreas Gampe52764cb2016-04-19 20:46:43 -07001323 if (isEmptyParcel()) {
Dianne Hackborn8aee64d2013-10-25 10:41:50 -07001324 return "Bundle[EMPTY_PARCEL]";
1325 } else {
1326 return "Bundle[mParcelledData.dataSize=" +
1327 mParcelledData.dataSize() + "]";
1328 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 }
1330 return "Bundle[" + mMap.toString() + "]";
1331 }
Dianne Hackborna47223f2017-03-30 13:49:13 -07001332
1333 /**
1334 * @hide
1335 */
1336 public synchronized String toShortString() {
1337 if (mParcelledData != null) {
1338 if (isEmptyParcel()) {
1339 return "EMPTY_PARCEL";
1340 } else {
1341 return "mParcelledData.dataSize=" + mParcelledData.dataSize();
1342 }
1343 }
1344 return mMap.toString();
1345 }
Kweku Adams85f2fbc2017-12-18 12:04:12 -08001346
1347 /** @hide */
1348 public void writeToProto(ProtoOutputStream proto, long fieldId) {
1349 final long token = proto.start(fieldId);
1350
1351 if (mParcelledData != null) {
1352 if (isEmptyParcel()) {
1353 proto.write(BundleProto.PARCELLED_DATA_SIZE, 0);
1354 } else {
1355 proto.write(BundleProto.PARCELLED_DATA_SIZE, mParcelledData.dataSize());
1356 }
1357 } else {
1358 proto.write(BundleProto.MAP_DATA, mMap.toString());
1359 }
1360
1361 proto.end(token);
1362 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001363}