blob: c58153aa34d1aace4cb0e7f3e145dadad112981f [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;
24
Makoto Onuki4501c61d2017-07-27 15:56:40 -070025import com.android.internal.annotations.VisibleForTesting;
26
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import java.io.Serializable;
28import java.util.ArrayList;
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -070029import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
31/**
Jeff Sharkeyd136e512016-03-09 22:30:56 -070032 * A mapping from String keys to various {@link Parcelable} values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 *
Jeff Sharkeyd136e512016-03-09 22:30:56 -070034 * @see PersistableBundle
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 */
Craig Mautner0a8e160e2014-05-29 10:27:32 -070036public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
Makoto Onuki4501c61d2017-07-27 15:56:40 -070037 @VisibleForTesting
38 static final int FLAG_HAS_FDS = 1 << 8;
39
40 @VisibleForTesting
41 static final int FLAG_HAS_FDS_KNOWN = 1 << 9;
42
43 @VisibleForTesting
44 static final int FLAG_ALLOW_FDS = 1 << 10;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 public static final Bundle EMPTY;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070047
Makoto Onuki97f82f22017-05-31 16:20:21 -070048 /**
49 * Special extras used to denote extras have been stripped off.
50 * @hide
51 */
52 public static final Bundle STRIPPED;
53
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 static {
55 EMPTY = new Bundle();
Dianne Hackbornb87655b2013-07-17 19:06:22 -070056 EMPTY.mMap = ArrayMap.EMPTY;
Makoto Onuki97f82f22017-05-31 16:20:21 -070057
58 STRIPPED = new Bundle();
59 STRIPPED.putInt("STRIPPED", 1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 }
61
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 * Constructs a new, empty Bundle.
64 */
65 public Bundle() {
Craig Mautner719e6b12014-04-04 20:29:41 -070066 super();
Jeff Sharkey7410fb42016-03-16 21:23:29 -060067 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 }
69
70 /**
71 * Constructs a Bundle whose data is stored as a Parcel. The data
72 * will be unparcelled on first contact, using the assigned ClassLoader.
73 *
74 * @param parcelledData a Parcel containing a Bundle
Makoto Onuki4501c61d2017-07-27 15:56:40 -070075 *
76 * @hide
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 */
Makoto Onuki4501c61d2017-07-27 15:56:40 -070078 @VisibleForTesting
79 public Bundle(Parcel parcelledData) {
Craig Mautner719e6b12014-04-04 20:29:41 -070080 super(parcelledData);
Makoto Onuki4501c61d2017-07-27 15:56:40 -070081 mFlags = FLAG_ALLOW_FDS;
82 maybePrefillHasFds();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 }
84
Makoto Onuki4501c61d2017-07-27 15:56:40 -070085 /**
86 * Constructor from a parcel for when the length is known *and is not stored in the parcel.*
87 * The other constructor that takes a parcel assumes the length is in the parcel.
88 *
89 * @hide
90 */
91 @VisibleForTesting
92 public Bundle(Parcel parcelledData, int length) {
Craig Mautner719e6b12014-04-04 20:29:41 -070093 super(parcelledData, length);
Makoto Onuki4501c61d2017-07-27 15:56:40 -070094 mFlags = FLAG_ALLOW_FDS;
95 maybePrefillHasFds();
96 }
97
98 /**
99 * If {@link #mParcelledData} is not null, copy the HAS FDS bit from it because it's fast.
100 * Otherwise (if {@link #mParcelledData} is already null), leave {@link #FLAG_HAS_FDS_KNOWN}
101 * unset, because scanning a map is slower. We'll do it lazily in
102 * {@link #hasFileDescriptors()}.
103 */
104 private void maybePrefillHasFds() {
105 if (mParcelledData != null) {
106 if (mParcelledData.hasFileDescriptors()) {
107 mFlags |= FLAG_HAS_FDS | FLAG_HAS_FDS_KNOWN;
108 } else {
109 mFlags |= FLAG_HAS_FDS_KNOWN;
110 }
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700111 }
Dianne Hackborn6aff9052009-05-22 13:20:23 -0700112 }
113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 /**
115 * Constructs a new, empty Bundle that uses a specific ClassLoader for
116 * instantiating Parcelable and Serializable objects.
117 *
118 * @param loader An explicit ClassLoader to use when instantiating objects
119 * inside of the Bundle.
120 */
121 public Bundle(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700122 super(loader);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600123 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 }
125
126 /**
127 * Constructs a new, empty Bundle sized to hold the given number of
128 * elements. The Bundle will grow as needed.
129 *
130 * @param capacity the initial capacity of the Bundle
131 */
132 public Bundle(int capacity) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700133 super(capacity);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600134 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 }
136
137 /**
138 * Constructs a Bundle containing a copy of the mappings from the given
Dianne Hackborn2510b372017-03-03 17:01:38 -0800139 * Bundle. Does only a shallow copy of the original Bundle -- see
140 * {@link #deepCopy()} if that is not what you want.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 *
142 * @param b a Bundle to be copied.
Dianne Hackborn2510b372017-03-03 17:01:38 -0800143 *
144 * @see #deepCopy()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 */
146 public Bundle(Bundle b) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700147 super(b);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700148 mFlags = b.mFlags;
Craig Mautner719e6b12014-04-04 20:29:41 -0700149 }
150
151 /**
152 * Constructs a Bundle containing a copy of the mappings from the given
Dianne Hackborn2510b372017-03-03 17:01:38 -0800153 * PersistableBundle. Does only a shallow copy of the PersistableBundle -- see
154 * {@link PersistableBundle#deepCopy()} if you don't want that.
Craig Mautner719e6b12014-04-04 20:29:41 -0700155 *
Dianne Hackborn2510b372017-03-03 17:01:38 -0800156 * @param b a PersistableBundle to be copied.
Craig Mautner719e6b12014-04-04 20:29:41 -0700157 */
158 public Bundle(PersistableBundle b) {
159 super(b);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600160 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 }
162
163 /**
Dianne Hackbornba604732016-02-10 17:05:10 -0800164 * Constructs a Bundle without initializing it.
165 */
166 Bundle(boolean doInit) {
167 super(doInit);
168 }
169
170 /**
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800171 * Make a Bundle for a single key/value pair.
172 *
173 * @hide
174 */
175 public static Bundle forPair(String key, String value) {
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800176 Bundle b = new Bundle(1);
177 b.putString(key, value);
178 return b;
179 }
180
181 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 * Changes the ClassLoader this Bundle uses when instantiating objects.
183 *
184 * @param loader An explicit ClassLoader to use when instantiating objects
185 * inside of the Bundle.
186 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700187 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 public void setClassLoader(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700189 super.setClassLoader(loader);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 }
191
192 /**
Dianne Hackborn51642462010-10-28 10:32:37 -0700193 * Return the ClassLoader currently associated with this Bundle.
194 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700195 @Override
Dianne Hackborn51642462010-10-28 10:32:37 -0700196 public ClassLoader getClassLoader() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700197 return super.getClassLoader();
Dianne Hackborn51642462010-10-28 10:32:37 -0700198 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400199
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700200 /** {@hide} */
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400201 public boolean setAllowFds(boolean allowFds) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700202 final boolean orig = (mFlags & FLAG_ALLOW_FDS) != 0;
203 if (allowFds) {
204 mFlags |= FLAG_ALLOW_FDS;
205 } else {
206 mFlags &= ~FLAG_ALLOW_FDS;
207 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400208 return orig;
209 }
210
Dianne Hackborn51642462010-10-28 10:32:37 -0700211 /**
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700212 * Mark if this Bundle is okay to "defuse." That is, it's okay for system
213 * processes to ignore any {@link BadParcelableException} encountered when
214 * unparceling it, leaving an empty bundle in its place.
215 * <p>
216 * This should <em>only</em> be set when the Bundle reaches its final
217 * destination, otherwise a system process may clobber contents that were
218 * destined for an app that could have unparceled them.
219 *
220 * @hide
221 */
222 public void setDefusable(boolean defusable) {
223 if (defusable) {
224 mFlags |= FLAG_DEFUSABLE;
225 } else {
226 mFlags &= ~FLAG_DEFUSABLE;
227 }
228 }
229
Jeff Sharkeya04c7a72016-03-18 12:20:36 -0600230 /** {@hide} */
231 public static Bundle setDefusable(Bundle bundle, boolean defusable) {
232 if (bundle != null) {
233 bundle.setDefusable(defusable);
234 }
235 return bundle;
236 }
237
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700238 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 * Clones the current Bundle. The internal map is cloned, but the keys and
240 * values to which it refers are copied by reference.
241 */
242 @Override
243 public Object clone() {
244 return new Bundle(this);
245 }
246
247 /**
Dianne Hackbornba604732016-02-10 17:05:10 -0800248 * Make a deep copy of the given bundle. Traverses into inner containers and copies
249 * them as well, so they are not shared across bundles. Will traverse in to
250 * {@link Bundle}, {@link PersistableBundle}, {@link ArrayList}, and all types of
251 * primitive arrays. Other types of objects (such as Parcelable or Serializable)
252 * are referenced as-is and not copied in any way.
253 */
Dianne Hackborn2510b372017-03-03 17:01:38 -0800254 public Bundle deepCopy() {
Dianne Hackbornba604732016-02-10 17:05:10 -0800255 Bundle b = new Bundle(false);
256 b.copyInternal(this, true);
257 return b;
258 }
259
260 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 * Removes all elements from the mapping of this Bundle.
262 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700263 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 public void clear() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700265 super.clear();
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600266 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 }
268
269 /**
Christopher Tate250985f2016-03-31 13:57:42 -0700270 * Removes any entry with the given key from the mapping of this Bundle.
271 *
272 * @param key a String key
273 */
274 public void remove(String key) {
275 super.remove(key);
276 if ((mFlags & FLAG_HAS_FDS) != 0) {
277 mFlags &= ~FLAG_HAS_FDS_KNOWN;
278 }
279 }
280
281 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 * Inserts all mappings from the given Bundle into this Bundle.
283 *
Craig Mautner719e6b12014-04-04 20:29:41 -0700284 * @param bundle a Bundle
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700286 public void putAll(Bundle bundle) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 unparcel();
Craig Mautner719e6b12014-04-04 20:29:41 -0700288 bundle.unparcel();
289 mMap.putAll(bundle.mMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700291 // FD state is now known if and only if both bundles already knew
292 if ((bundle.mFlags & FLAG_HAS_FDS) != 0) {
293 mFlags |= FLAG_HAS_FDS;
294 }
295 if ((bundle.mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
296 mFlags &= ~FLAG_HAS_FDS_KNOWN;
297 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700298 }
299
300 /**
Sudheer Shankafab200f2017-05-17 20:41:53 -0700301 * Return the size of {@link #mParcelledData} in bytes if available, otherwise {@code 0}.
302 *
303 * @hide
304 */
305 public int getSize() {
306 if (mParcelledData != null) {
307 return mParcelledData.dataSize();
308 } else {
309 return 0;
310 }
311 }
312
313 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 * Reports whether the bundle contains any parcelled file descriptors.
315 */
316 public boolean hasFileDescriptors() {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700317 if ((mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 boolean fdFound = false; // keep going until we find one or run out of data
Craig Mautner719e6b12014-04-04 20:29:41 -0700319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320 if (mParcelledData != null) {
321 if (mParcelledData.hasFileDescriptors()) {
322 fdFound = true;
323 }
324 } else {
325 // It's been unparcelled, so we need to walk the map
Dianne Hackbornb87655b2013-07-17 19:06:22 -0700326 for (int i=mMap.size()-1; i>=0; i--) {
327 Object obj = mMap.valueAt(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 if (obj instanceof Parcelable) {
329 if ((((Parcelable)obj).describeContents()
330 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
331 fdFound = true;
332 break;
333 }
334 } else if (obj instanceof Parcelable[]) {
335 Parcelable[] array = (Parcelable[]) obj;
336 for (int n = array.length - 1; n >= 0; n--) {
Taiju Tsuikie58c7852015-04-22 16:59:00 +0900337 Parcelable p = array[n];
338 if (p != null && ((p.describeContents()
339 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 fdFound = true;
341 break;
342 }
343 }
344 } else if (obj instanceof SparseArray) {
345 SparseArray<? extends Parcelable> array =
346 (SparseArray<? extends Parcelable>) obj;
347 for (int n = array.size() - 1; n >= 0; n--) {
Taiju Tsuikiecd21842015-04-28 13:36:15 +0900348 Parcelable p = array.valueAt(n);
349 if (p != null && (p.describeContents()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800350 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
351 fdFound = true;
352 break;
353 }
354 }
355 } else if (obj instanceof ArrayList) {
356 ArrayList array = (ArrayList) obj;
357 // an ArrayList here might contain either Strings or
358 // Parcelables; only look inside for Parcelables
Craig Mautner719e6b12014-04-04 20:29:41 -0700359 if (!array.isEmpty() && (array.get(0) instanceof Parcelable)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 for (int n = array.size() - 1; n >= 0; n--) {
361 Parcelable p = (Parcelable) array.get(n);
362 if (p != null && ((p.describeContents()
363 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
364 fdFound = true;
365 break;
366 }
367 }
368 }
369 }
370 }
371 }
372
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700373 if (fdFound) {
374 mFlags |= FLAG_HAS_FDS;
Christopher Tate250985f2016-03-31 13:57:42 -0700375 } else {
376 mFlags &= ~FLAG_HAS_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700377 }
378 mFlags |= FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 }
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700380 return (mFlags & FLAG_HAS_FDS) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700382
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 /**
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700384 * Filter values in Bundle to only basic types.
385 * @hide
386 */
Dianne Hackborn851ec492016-10-12 17:20:07 -0700387 public Bundle filterValues() {
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700388 unparcel();
Dianne Hackborn851ec492016-10-12 17:20:07 -0700389 Bundle bundle = this;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700390 if (mMap != null) {
Dianne Hackborn851ec492016-10-12 17:20:07 -0700391 ArrayMap<String, Object> map = mMap;
392 for (int i = map.size() - 1; i >= 0; i--) {
393 Object value = map.valueAt(i);
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700394 if (PersistableBundle.isValidType(value)) {
395 continue;
396 }
397 if (value instanceof Bundle) {
Dianne Hackborn851ec492016-10-12 17:20:07 -0700398 Bundle newBundle = ((Bundle)value).filterValues();
399 if (newBundle != value) {
400 if (map == mMap) {
401 // The filter had to generate a new bundle, but we have not yet
402 // created a new one here. Do that now.
403 bundle = new Bundle(this);
404 // Note the ArrayMap<> constructor is guaranteed to generate
405 // a new object with items in the same order as the original.
406 map = bundle.mMap;
407 }
408 // Replace this current entry with the new child bundle.
409 map.setValueAt(i, newBundle);
410 }
411 continue;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700412 }
413 if (value.getClass().getName().startsWith("android.")) {
414 continue;
415 }
Dianne Hackborn851ec492016-10-12 17:20:07 -0700416 if (map == mMap) {
417 // This is the first time we have had to remove something, that means we
418 // need to switch to a new Bundle.
419 bundle = new Bundle(this);
420 // Note the ArrayMap<> constructor is guaranteed to generate
421 // a new object with items in the same order as the original.
422 map = bundle.mMap;
423 }
424 map.removeAt(i);
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700425 }
426 }
Christopher Tate250985f2016-03-31 13:57:42 -0700427 mFlags |= FLAG_HAS_FDS_KNOWN;
428 mFlags &= ~FLAG_HAS_FDS;
Dianne Hackborn851ec492016-10-12 17:20:07 -0700429 return bundle;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700430 }
431
432 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800433 * Inserts a byte value into the mapping of this Bundle, replacing
434 * any existing value for the given key.
435 *
436 * @param key a String, or null
437 * @param value a byte
438 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700439 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800440 public void putByte(@Nullable String key, byte value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700441 super.putByte(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 }
443
444 /**
445 * Inserts a char value into the mapping of this Bundle, replacing
446 * any existing value for the given key.
447 *
448 * @param key a String, or null
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800449 * @param value a char
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700451 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800452 public void putChar(@Nullable String key, char value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700453 super.putChar(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 }
455
456 /**
457 * Inserts a short value into the mapping of this Bundle, replacing
458 * any existing value for the given key.
459 *
460 * @param key a String, or null
461 * @param value a short
462 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700463 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800464 public void putShort(@Nullable String key, short value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700465 super.putShort(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 }
467
468 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 * Inserts a float value into the mapping of this Bundle, replacing
470 * any existing value for the given key.
471 *
472 * @param key a String, or null
473 * @param value a float
474 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700475 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800476 public void putFloat(@Nullable String key, float value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700477 super.putFloat(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 }
479
480 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 * Inserts a CharSequence value into the mapping of this Bundle, replacing
482 * any existing value for the given key. Either key or value may be null.
483 *
484 * @param key a String, or null
485 * @param value a CharSequence, or null
486 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700487 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800488 public void putCharSequence(@Nullable String key, @Nullable CharSequence value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700489 super.putCharSequence(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 }
491
492 /**
493 * Inserts a Parcelable value into the mapping of this Bundle, replacing
494 * any existing value for the given key. Either key or value may be null.
495 *
496 * @param key a String, or null
497 * @param value a Parcelable object, or null
498 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800499 public void putParcelable(@Nullable String key, @Nullable Parcelable value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 unparcel();
501 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700502 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 }
504
505 /**
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700506 * Inserts a Size value into the mapping of this Bundle, replacing
507 * any existing value for the given key. Either key or value may be null.
508 *
509 * @param key a String, or null
510 * @param value a Size object, or null
511 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800512 public void putSize(@Nullable String key, @Nullable Size value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700513 unparcel();
514 mMap.put(key, value);
515 }
516
517 /**
518 * Inserts a SizeF value into the mapping of this Bundle, replacing
519 * any existing value for the given key. Either key or value may be null.
520 *
521 * @param key a String, or null
522 * @param value a SizeF object, or null
523 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800524 public void putSizeF(@Nullable String key, @Nullable SizeF value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700525 unparcel();
526 mMap.put(key, value);
527 }
528
529 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 * Inserts an array of Parcelable values into the mapping of this Bundle,
531 * replacing any existing value for the given key. Either key or value may
532 * be null.
533 *
534 * @param key a String, or null
535 * @param value an array of Parcelable objects, or null
536 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800537 public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 unparcel();
539 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700540 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 }
542
543 /**
544 * Inserts a List of Parcelable values into the mapping of this Bundle,
545 * replacing any existing value for the given key. Either key or value may
546 * be null.
547 *
548 * @param key a String, or null
549 * @param value an ArrayList of Parcelable objects, or null
550 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800551 public void putParcelableArrayList(@Nullable String key,
552 @Nullable ArrayList<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 unparcel();
554 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700555 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 }
557
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700558 /** {@hide} */
559 public void putParcelableList(String key, List<? extends Parcelable> value) {
560 unparcel();
561 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700562 mFlags &= ~FLAG_HAS_FDS_KNOWN;
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700563 }
564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 /**
566 * Inserts a SparceArray of Parcelable values into the mapping of this
567 * Bundle, replacing any existing value for the given key. Either key
568 * or value may be null.
569 *
570 * @param key a String, or null
571 * @param value a SparseArray of Parcelable objects, or null
572 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800573 public void putSparseParcelableArray(@Nullable String key,
574 @Nullable SparseArray<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 unparcel();
576 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700577 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 }
579
580 /**
581 * Inserts an ArrayList<Integer> value into the mapping of this Bundle, replacing
582 * any existing value for the given key. Either key or value may be null.
583 *
584 * @param key a String, or null
585 * @param value an ArrayList<Integer> object, or null
586 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700587 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800588 public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700589 super.putIntegerArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 }
591
592 /**
593 * Inserts an ArrayList<String> value into the mapping of this Bundle, replacing
594 * any existing value for the given key. Either key or value may be null.
595 *
596 * @param key a String, or null
597 * @param value an ArrayList<String> object, or null
598 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700599 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800600 public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700601 super.putStringArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 }
603
604 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000605 * Inserts an ArrayList<CharSequence> value into the mapping of this Bundle, replacing
606 * any existing value for the given key. Either key or value may be null.
607 *
608 * @param key a String, or null
609 * @param value an ArrayList<CharSequence> object, or null
610 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700611 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800612 public void putCharSequenceArrayList(@Nullable String key,
613 @Nullable ArrayList<CharSequence> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700614 super.putCharSequenceArrayList(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000615 }
616
617 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 * Inserts a Serializable value into the mapping of this Bundle, replacing
619 * any existing value for the given key. Either key or value may be null.
620 *
621 * @param key a String, or null
622 * @param value a Serializable object, or null
623 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700624 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800625 public void putSerializable(@Nullable String key, @Nullable Serializable value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700626 super.putSerializable(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 }
628
629 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 * Inserts a byte array value into the mapping of this Bundle, replacing
631 * any existing value for the given key. Either key or value may be null.
632 *
633 * @param key a String, or null
634 * @param value a byte array object, or null
635 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700636 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800637 public void putByteArray(@Nullable String key, @Nullable byte[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700638 super.putByteArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 }
640
641 /**
642 * Inserts a short array value into the mapping of this Bundle, replacing
643 * any existing value for the given key. Either key or value may be null.
644 *
645 * @param key a String, or null
646 * @param value a short array object, or null
647 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700648 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800649 public void putShortArray(@Nullable String key, @Nullable short[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700650 super.putShortArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 }
652
653 /**
654 * Inserts a char array value into the mapping of this Bundle, replacing
655 * any existing value for the given key. Either key or value may be null.
656 *
657 * @param key a String, or null
658 * @param value a char array object, or null
659 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700660 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800661 public void putCharArray(@Nullable String key, @Nullable char[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700662 super.putCharArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 }
664
665 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 * Inserts a float array value into the mapping of this Bundle, replacing
667 * any existing value for the given key. Either key or value may be null.
668 *
669 * @param key a String, or null
670 * @param value a float array object, or null
671 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700672 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800673 public void putFloatArray(@Nullable String key, @Nullable float[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700674 super.putFloatArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 }
676
677 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000678 * Inserts a CharSequence array value into the mapping of this Bundle, replacing
679 * any existing value for the given key. Either key or value may be null.
680 *
681 * @param key a String, or null
682 * @param value a CharSequence array object, or null
683 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700684 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800685 public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700686 super.putCharSequenceArray(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000687 }
688
689 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 * Inserts a Bundle value into the mapping of this Bundle, replacing
691 * any existing value for the given key. Either key or value may be null.
692 *
693 * @param key a String, or null
694 * @param value a Bundle object, or null
695 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800696 public void putBundle(@Nullable String key, @Nullable Bundle value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 unparcel();
698 mMap.put(key, value);
699 }
700
701 /**
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800702 * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing
703 * any existing value for the given key. Either key or value may be null.
704 *
705 * <p class="note">You should be very careful when using this function. In many
706 * places where Bundles are used (such as inside of Intent objects), the Bundle
707 * can live longer inside of another process than the process that had originally
708 * created it. In that case, the IBinder you supply here will become invalid
709 * when your process goes away, and no longer usable, even if a new process is
710 * created for you later on.</p>
711 *
712 * @param key a String, or null
713 * @param value an IBinder object, or null
714 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800715 public void putBinder(@Nullable String key, @Nullable IBinder value) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800716 unparcel();
717 mMap.put(key, value);
718 }
719
720 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 * Inserts an IBinder value into the mapping of this Bundle, replacing
722 * any existing value for the given key. Either key or value may be null.
723 *
724 * @param key a String, or null
725 * @param value an IBinder object, or null
726 *
727 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800728 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 */
730 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800731 public void putIBinder(@Nullable String key, @Nullable IBinder value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 unparcel();
733 mMap.put(key, value);
734 }
735
736 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 * Returns the value associated with the given key, or (byte) 0 if
738 * no mapping of the desired type exists for the given key.
739 *
740 * @param key a String
741 * @return a byte value
742 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700743 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800744 public byte getByte(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700745 return super.getByte(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 }
747
748 /**
749 * Returns the value associated with the given key, or defaultValue if
750 * no mapping of the desired type exists for the given key.
751 *
752 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800753 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 * @return a byte value
755 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700756 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 public Byte getByte(String key, byte defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700758 return super.getByte(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 }
760
761 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800762 * Returns the value associated with the given key, or (char) 0 if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 * no mapping of the desired type exists for the given key.
764 *
765 * @param key a String
766 * @return a char value
767 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700768 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 public char getChar(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700770 return super.getChar(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 }
772
773 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800774 * Returns the value associated with the given key, or defaultValue if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 * no mapping of the desired type exists for the given key.
776 *
777 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800778 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 * @return a char value
780 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700781 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 public char getChar(String key, char defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700783 return super.getChar(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 }
785
786 /**
787 * Returns the value associated with the given key, or (short) 0 if
788 * no mapping of the desired type exists for the given key.
789 *
790 * @param key a String
791 * @return a short value
792 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700793 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 public short getShort(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700795 return super.getShort(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 }
797
798 /**
799 * Returns the value associated with the given key, or defaultValue if
800 * no mapping of the desired type exists for the given key.
801 *
802 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800803 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 * @return a short value
805 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700806 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 public short getShort(String key, short defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700808 return super.getShort(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809 }
810
811 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 * Returns the value associated with the given key, or 0.0f if
813 * no mapping of the desired type exists for the given key.
814 *
815 * @param key a String
816 * @return a float value
817 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700818 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800819 public float getFloat(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700820 return super.getFloat(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 }
822
823 /**
824 * Returns the value associated with the given key, or defaultValue if
825 * no mapping of the desired type exists for the given key.
826 *
827 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800828 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 * @return a float value
830 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700831 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 public float getFloat(String key, float defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700833 return super.getFloat(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 }
835
836 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 * Returns the value associated with the given key, or null if
838 * no mapping of the desired type exists for the given key or a null
839 * value is explicitly associated with the key.
840 *
841 * @param key a String, or null
842 * @return a CharSequence value, or null
843 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700844 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800845 @Nullable
846 public CharSequence getCharSequence(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700847 return super.getCharSequence(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 }
849
850 /**
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800851 * Returns the value associated with the given key, or defaultValue if
Narayan Kamathca2197b2014-06-19 10:46:00 +0100852 * no mapping of the desired type exists for the given key or if a null
853 * value is explicitly associatd with the given key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800854 *
855 * @param key a String, or null
Narayan Kamathca2197b2014-06-19 10:46:00 +0100856 * @param defaultValue Value to return if key does not exist or if a null
857 * value is associated with the given key.
Christopher Tate116751d2012-12-20 18:57:09 -0800858 * @return the CharSequence value associated with the given key, or defaultValue
859 * if no valid CharSequence object is currently mapped to that key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800860 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700861 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800862 public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700863 return super.getCharSequence(key, defaultValue);
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800864 }
865
866 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 * Returns the value associated with the given key, or null if
868 * no mapping of the desired type exists for the given key or a null
869 * value is explicitly associated with the key.
870 *
871 * @param key a String, or null
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700872 * @return a Size value, or null
873 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800874 @Nullable
875 public Size getSize(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700876 unparcel();
877 final Object o = mMap.get(key);
878 try {
879 return (Size) o;
880 } catch (ClassCastException e) {
881 typeWarning(key, o, "Size", e);
882 return null;
883 }
884 }
885
886 /**
887 * Returns the value associated with the given key, or null if
888 * no mapping of the desired type exists for the given key or a null
889 * value is explicitly associated with the key.
890 *
891 * @param key a String, or null
892 * @return a Size value, or null
893 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800894 @Nullable
895 public SizeF getSizeF(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700896 unparcel();
897 final Object o = mMap.get(key);
898 try {
899 return (SizeF) o;
900 } catch (ClassCastException e) {
901 typeWarning(key, o, "SizeF", e);
902 return null;
903 }
904 }
905
906 /**
907 * Returns the value associated with the given key, or null if
908 * no mapping of the desired type exists for the given key or a null
909 * value is explicitly associated with the key.
910 *
911 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 * @return a Bundle value, or null
913 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800914 @Nullable
915 public Bundle getBundle(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 unparcel();
917 Object o = mMap.get(key);
918 if (o == null) {
919 return null;
920 }
921 try {
922 return (Bundle) o;
923 } catch (ClassCastException e) {
924 typeWarning(key, o, "Bundle", e);
925 return null;
926 }
927 }
928
929 /**
930 * Returns the value associated with the given key, or null if
931 * no mapping of the desired type exists for the given key or a null
932 * value is explicitly associated with the key.
933 *
934 * @param key a String, or null
935 * @return a Parcelable value, or null
936 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800937 @Nullable
938 public <T extends Parcelable> T getParcelable(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800939 unparcel();
940 Object o = mMap.get(key);
941 if (o == null) {
942 return null;
943 }
944 try {
945 return (T) o;
946 } catch (ClassCastException e) {
947 typeWarning(key, o, "Parcelable", e);
948 return null;
949 }
950 }
951
952 /**
953 * Returns the value associated with the given key, or null if
954 * no mapping of the desired type exists for the given key or a null
955 * value is explicitly associated with the key.
956 *
957 * @param key a String, or null
958 * @return a Parcelable[] value, or null
959 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800960 @Nullable
961 public Parcelable[] getParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800962 unparcel();
963 Object o = mMap.get(key);
964 if (o == null) {
965 return null;
966 }
967 try {
968 return (Parcelable[]) o;
969 } catch (ClassCastException e) {
970 typeWarning(key, o, "Parcelable[]", e);
971 return null;
972 }
973 }
974
975 /**
976 * Returns the value associated with the given key, or null if
977 * no mapping of the desired type exists for the given key or a null
978 * value is explicitly associated with the key.
979 *
980 * @param key a String, or null
981 * @return an ArrayList<T> value, or null
982 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800983 @Nullable
984 public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 unparcel();
986 Object o = mMap.get(key);
987 if (o == null) {
988 return null;
989 }
990 try {
991 return (ArrayList<T>) o;
992 } catch (ClassCastException e) {
993 typeWarning(key, o, "ArrayList", e);
994 return null;
995 }
996 }
997
998 /**
999 * Returns the value associated with the given key, or null if
1000 * no mapping of the desired type exists for the given key or a null
1001 * value is explicitly associated with the key.
1002 *
1003 * @param key a String, or null
1004 *
1005 * @return a SparseArray of T values, or null
1006 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001007 @Nullable
1008 public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001009 unparcel();
1010 Object o = mMap.get(key);
1011 if (o == null) {
1012 return null;
1013 }
1014 try {
1015 return (SparseArray<T>) o;
1016 } catch (ClassCastException e) {
1017 typeWarning(key, o, "SparseArray", e);
1018 return null;
1019 }
1020 }
1021
1022 /**
1023 * Returns the value associated with the given key, or null if
1024 * no mapping of the desired type exists for the given key or a null
1025 * value is explicitly associated with the key.
1026 *
1027 * @param key a String, or null
1028 * @return a Serializable value, or null
1029 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001030 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001031 @Nullable
1032 public Serializable getSerializable(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001033 return super.getSerializable(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 }
1035
1036 /**
1037 * Returns the value associated with the given key, or null if
1038 * no mapping of the desired type exists for the given key or a null
1039 * value is explicitly associated with the key.
1040 *
1041 * @param key a String, or null
1042 * @return an ArrayList<String> value, or null
1043 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001044 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001045 @Nullable
1046 public ArrayList<Integer> getIntegerArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001047 return super.getIntegerArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 }
1049
1050 /**
1051 * Returns the value associated with the given key, or null if
1052 * no mapping of the desired type exists for the given key or a null
1053 * value is explicitly associated with the key.
1054 *
1055 * @param key a String, or null
1056 * @return an ArrayList<String> value, or null
1057 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001058 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001059 @Nullable
1060 public ArrayList<String> getStringArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001061 return super.getStringArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 }
1063
1064 /**
1065 * Returns the value associated with the given key, or null if
1066 * no mapping of the desired type exists for the given key or a null
1067 * value is explicitly associated with the key.
1068 *
1069 * @param key a String, or null
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001070 * @return an ArrayList<CharSequence> value, or null
1071 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001072 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001073 @Nullable
1074 public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001075 return super.getCharSequenceArrayList(key);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001076 }
1077
1078 /**
1079 * Returns the value associated with the given key, or null if
1080 * no mapping of the desired type exists for the given key or a null
1081 * value is explicitly associated with the key.
1082 *
1083 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084 * @return a byte[] value, or null
1085 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001086 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001087 @Nullable
1088 public byte[] getByteArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001089 return super.getByteArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 }
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 short[] value, or null
1099 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001100 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001101 @Nullable
1102 public short[] getShortArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001103 return super.getShortArray(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 a char[] value, or null
1113 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001114 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001115 @Nullable
1116 public char[] getCharArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001117 return super.getCharArray(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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001126 * @return a float[] value, or null
1127 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001128 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001129 @Nullable
1130 public float[] getFloatArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001131 return super.getFloatArray(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 a 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 CharSequence[] getCharSequenceArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001145 return super.getCharSequenceArray(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 an IBinder value, or null
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001155 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001156 @Nullable
1157 public IBinder getBinder(@Nullable String key) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001158 unparcel();
1159 Object o = mMap.get(key);
1160 if (o == null) {
1161 return null;
1162 }
1163 try {
1164 return (IBinder) o;
1165 } catch (ClassCastException e) {
1166 typeWarning(key, o, "IBinder", e);
1167 return null;
1168 }
1169 }
1170
1171 /**
1172 * Returns the value associated with the given key, or null if
1173 * no mapping of the desired type exists for the given key or a null
1174 * value is explicitly associated with the key.
1175 *
1176 * @param key a String, or null
1177 * @return an IBinder value, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 *
1179 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001180 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 */
1182 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001183 @Nullable
1184 public IBinder getIBinder(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 unparcel();
1186 Object o = mMap.get(key);
1187 if (o == null) {
1188 return null;
1189 }
1190 try {
1191 return (IBinder) o;
1192 } catch (ClassCastException e) {
1193 typeWarning(key, o, "IBinder", e);
1194 return null;
1195 }
1196 }
1197
1198 public static final Parcelable.Creator<Bundle> CREATOR =
1199 new Parcelable.Creator<Bundle>() {
Craig Mautner719e6b12014-04-04 20:29:41 -07001200 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001201 public Bundle createFromParcel(Parcel in) {
1202 return in.readBundle();
1203 }
1204
Craig Mautner719e6b12014-04-04 20:29:41 -07001205 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 public Bundle[] newArray(int size) {
1207 return new Bundle[size];
1208 }
1209 };
1210
1211 /**
1212 * Report the nature of this Parcelable's contents
1213 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001214 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 public int describeContents() {
1216 int mask = 0;
1217 if (hasFileDescriptors()) {
1218 mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR;
1219 }
1220 return mask;
1221 }
Craig Mautner719e6b12014-04-04 20:29:41 -07001222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 /**
1224 * Writes the Bundle contents to a Parcel, typically in order for
1225 * it to be passed through an IBinder connection.
1226 * @param parcel The parcel to copy this bundle to.
1227 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001228 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 public void writeToParcel(Parcel parcel, int flags) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -07001230 final boolean oldAllowFds = parcel.pushAllowFds((mFlags & FLAG_ALLOW_FDS) != 0);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001231 try {
Craig Mautner719e6b12014-04-04 20:29:41 -07001232 super.writeToParcelInner(parcel, flags);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001233 } finally {
Dianne Hackbornc04db7e2011-10-03 21:09:35 -07001234 parcel.restoreAllowFds(oldAllowFds);
Dianne Hackborn6aff9052009-05-22 13:20:23 -07001235 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001236 }
1237
1238 /**
1239 * Reads the Parcel contents into this Bundle, typically in order for
1240 * it to be passed through an IBinder connection.
1241 * @param parcel The parcel to overwrite this bundle from.
1242 */
1243 public void readFromParcel(Parcel parcel) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001244 super.readFromParcelInner(parcel);
Makoto Onuki4501c61d2017-07-27 15:56:40 -07001245 mFlags = FLAG_ALLOW_FDS;
1246 maybePrefillHasFds();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 }
1248
1249 @Override
1250 public synchronized String toString() {
1251 if (mParcelledData != null) {
Andreas Gampe52764cb2016-04-19 20:46:43 -07001252 if (isEmptyParcel()) {
Dianne Hackborn8aee64d2013-10-25 10:41:50 -07001253 return "Bundle[EMPTY_PARCEL]";
1254 } else {
1255 return "Bundle[mParcelledData.dataSize=" +
1256 mParcelledData.dataSize() + "]";
1257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001258 }
1259 return "Bundle[" + mMap.toString() + "]";
1260 }
Dianne Hackborna47223f2017-03-30 13:49:13 -07001261
1262 /**
1263 * @hide
1264 */
1265 public synchronized String toShortString() {
1266 if (mParcelledData != null) {
1267 if (isEmptyParcel()) {
1268 return "EMPTY_PARCEL";
1269 } else {
1270 return "mParcelledData.dataSize=" + mParcelledData.dataSize();
1271 }
1272 }
1273 return mMap.toString();
1274 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275}