blob: 7061589e1e23245978eb6e3d49030fd9297c0da4 [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
25import java.io.Serializable;
26import java.util.ArrayList;
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -070027import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
29/**
Jeff Sharkeyd136e512016-03-09 22:30:56 -070030 * A mapping from String keys to various {@link Parcelable} values.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031 *
Jeff Sharkeyd136e512016-03-09 22:30:56 -070032 * @see PersistableBundle
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033 */
Craig Mautner0a8e160e2014-05-29 10:27:32 -070034public final class Bundle extends BaseBundle implements Cloneable, Parcelable {
Jeff Sharkeyd136e512016-03-09 22:30:56 -070035 private static final int FLAG_HAS_FDS = 1 << 8;
36 private static final int FLAG_HAS_FDS_KNOWN = 1 << 9;
37 private static final int FLAG_ALLOW_FDS = 1 << 10;
38
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 public static final Bundle EMPTY;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041 static {
42 EMPTY = new Bundle();
Dianne Hackbornb87655b2013-07-17 19:06:22 -070043 EMPTY.mMap = ArrayMap.EMPTY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 }
45
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 * Constructs a new, empty Bundle.
48 */
49 public Bundle() {
Craig Mautner719e6b12014-04-04 20:29:41 -070050 super();
Jeff Sharkey7410fb42016-03-16 21:23:29 -060051 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 }
53
54 /**
55 * Constructs a Bundle whose data is stored as a Parcel. The data
56 * will be unparcelled on first contact, using the assigned ClassLoader.
57 *
58 * @param parcelledData a Parcel containing a Bundle
59 */
60 Bundle(Parcel parcelledData) {
Craig Mautner719e6b12014-04-04 20:29:41 -070061 super(parcelledData);
Jeff Sharkey7410fb42016-03-16 21:23:29 -060062 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070063 if (mParcelledData.hasFileDescriptors()) {
64 mFlags |= FLAG_HAS_FDS;
65 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066 }
67
Dianne Hackborn6aff9052009-05-22 13:20:23 -070068 /* package */ Bundle(Parcel parcelledData, int length) {
Craig Mautner719e6b12014-04-04 20:29:41 -070069 super(parcelledData, length);
Jeff Sharkey7410fb42016-03-16 21:23:29 -060070 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070071 if (mParcelledData.hasFileDescriptors()) {
72 mFlags |= FLAG_HAS_FDS;
73 }
Dianne Hackborn6aff9052009-05-22 13:20:23 -070074 }
75
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 /**
77 * Constructs a new, empty Bundle that uses a specific ClassLoader for
78 * instantiating Parcelable and Serializable objects.
79 *
80 * @param loader An explicit ClassLoader to use when instantiating objects
81 * inside of the Bundle.
82 */
83 public Bundle(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -070084 super(loader);
Jeff Sharkey7410fb42016-03-16 21:23:29 -060085 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 }
87
88 /**
89 * Constructs a new, empty Bundle sized to hold the given number of
90 * elements. The Bundle will grow as needed.
91 *
92 * @param capacity the initial capacity of the Bundle
93 */
94 public Bundle(int capacity) {
Craig Mautner719e6b12014-04-04 20:29:41 -070095 super(capacity);
Jeff Sharkey7410fb42016-03-16 21:23:29 -060096 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 }
98
99 /**
100 * Constructs a Bundle containing a copy of the mappings from the given
101 * Bundle.
102 *
103 * @param b a Bundle to be copied.
104 */
105 public Bundle(Bundle b) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700106 super(b);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700107 mFlags = b.mFlags;
Craig Mautner719e6b12014-04-04 20:29:41 -0700108 }
109
110 /**
111 * Constructs a Bundle containing a copy of the mappings from the given
112 * PersistableBundle.
113 *
114 * @param b a Bundle to be copied.
115 */
116 public Bundle(PersistableBundle b) {
117 super(b);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600118 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 }
120
121 /**
Dianne Hackbornba604732016-02-10 17:05:10 -0800122 * Constructs a Bundle without initializing it.
123 */
124 Bundle(boolean doInit) {
125 super(doInit);
126 }
127
128 /**
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800129 * Make a Bundle for a single key/value pair.
130 *
131 * @hide
132 */
133 public static Bundle forPair(String key, String value) {
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800134 Bundle b = new Bundle(1);
135 b.putString(key, value);
136 return b;
137 }
138
139 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 * Changes the ClassLoader this Bundle uses when instantiating objects.
141 *
142 * @param loader An explicit ClassLoader to use when instantiating objects
143 * inside of the Bundle.
144 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700145 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 public void setClassLoader(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700147 super.setClassLoader(loader);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 }
149
150 /**
Dianne Hackborn51642462010-10-28 10:32:37 -0700151 * Return the ClassLoader currently associated with this Bundle.
152 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700153 @Override
Dianne Hackborn51642462010-10-28 10:32:37 -0700154 public ClassLoader getClassLoader() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700155 return super.getClassLoader();
Dianne Hackborn51642462010-10-28 10:32:37 -0700156 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400157
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700158 /** {@hide} */
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400159 public boolean setAllowFds(boolean allowFds) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700160 final boolean orig = (mFlags & FLAG_ALLOW_FDS) != 0;
161 if (allowFds) {
162 mFlags |= FLAG_ALLOW_FDS;
163 } else {
164 mFlags &= ~FLAG_ALLOW_FDS;
165 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400166 return orig;
167 }
168
Dianne Hackborn51642462010-10-28 10:32:37 -0700169 /**
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700170 * Mark if this Bundle is okay to "defuse." That is, it's okay for system
171 * processes to ignore any {@link BadParcelableException} encountered when
172 * unparceling it, leaving an empty bundle in its place.
173 * <p>
174 * This should <em>only</em> be set when the Bundle reaches its final
175 * destination, otherwise a system process may clobber contents that were
176 * destined for an app that could have unparceled them.
177 *
178 * @hide
179 */
180 public void setDefusable(boolean defusable) {
181 if (defusable) {
182 mFlags |= FLAG_DEFUSABLE;
183 } else {
184 mFlags &= ~FLAG_DEFUSABLE;
185 }
186 }
187
Jeff Sharkeya04c7a72016-03-18 12:20:36 -0600188 /** {@hide} */
189 public static Bundle setDefusable(Bundle bundle, boolean defusable) {
190 if (bundle != null) {
191 bundle.setDefusable(defusable);
192 }
193 return bundle;
194 }
195
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700196 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 * Clones the current Bundle. The internal map is cloned, but the keys and
198 * values to which it refers are copied by reference.
199 */
200 @Override
201 public Object clone() {
202 return new Bundle(this);
203 }
204
205 /**
Dianne Hackbornba604732016-02-10 17:05:10 -0800206 * Make a deep copy of the given bundle. Traverses into inner containers and copies
207 * them as well, so they are not shared across bundles. Will traverse in to
208 * {@link Bundle}, {@link PersistableBundle}, {@link ArrayList}, and all types of
209 * primitive arrays. Other types of objects (such as Parcelable or Serializable)
210 * are referenced as-is and not copied in any way.
211 */
212 public Bundle deepcopy() {
213 Bundle b = new Bundle(false);
214 b.copyInternal(this, true);
215 return b;
216 }
217
218 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 * Removes all elements from the mapping of this Bundle.
220 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700221 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 public void clear() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700223 super.clear();
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600224 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800225 }
226
227 /**
Christopher Tate250985f2016-03-31 13:57:42 -0700228 * Removes any entry with the given key from the mapping of this Bundle.
229 *
230 * @param key a String key
231 */
232 public void remove(String key) {
233 super.remove(key);
234 if ((mFlags & FLAG_HAS_FDS) != 0) {
235 mFlags &= ~FLAG_HAS_FDS_KNOWN;
236 }
237 }
238
239 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 * Inserts all mappings from the given Bundle into this Bundle.
241 *
Craig Mautner719e6b12014-04-04 20:29:41 -0700242 * @param bundle a Bundle
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700244 public void putAll(Bundle bundle) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 unparcel();
Craig Mautner719e6b12014-04-04 20:29:41 -0700246 bundle.unparcel();
247 mMap.putAll(bundle.mMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700249 // FD state is now known if and only if both bundles already knew
250 if ((bundle.mFlags & FLAG_HAS_FDS) != 0) {
251 mFlags |= FLAG_HAS_FDS;
252 }
253 if ((bundle.mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
254 mFlags &= ~FLAG_HAS_FDS_KNOWN;
255 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700256 }
257
258 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 * Reports whether the bundle contains any parcelled file descriptors.
260 */
261 public boolean hasFileDescriptors() {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700262 if ((mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 boolean fdFound = false; // keep going until we find one or run out of data
Craig Mautner719e6b12014-04-04 20:29:41 -0700264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 if (mParcelledData != null) {
266 if (mParcelledData.hasFileDescriptors()) {
267 fdFound = true;
268 }
269 } else {
270 // It's been unparcelled, so we need to walk the map
Dianne Hackbornb87655b2013-07-17 19:06:22 -0700271 for (int i=mMap.size()-1; i>=0; i--) {
272 Object obj = mMap.valueAt(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 if (obj instanceof Parcelable) {
274 if ((((Parcelable)obj).describeContents()
275 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
276 fdFound = true;
277 break;
278 }
279 } else if (obj instanceof Parcelable[]) {
280 Parcelable[] array = (Parcelable[]) obj;
281 for (int n = array.length - 1; n >= 0; n--) {
Taiju Tsuikie58c7852015-04-22 16:59:00 +0900282 Parcelable p = array[n];
283 if (p != null && ((p.describeContents()
284 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 fdFound = true;
286 break;
287 }
288 }
289 } else if (obj instanceof SparseArray) {
290 SparseArray<? extends Parcelable> array =
291 (SparseArray<? extends Parcelable>) obj;
292 for (int n = array.size() - 1; n >= 0; n--) {
Taiju Tsuikiecd21842015-04-28 13:36:15 +0900293 Parcelable p = array.valueAt(n);
294 if (p != null && (p.describeContents()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
296 fdFound = true;
297 break;
298 }
299 }
300 } else if (obj instanceof ArrayList) {
301 ArrayList array = (ArrayList) obj;
302 // an ArrayList here might contain either Strings or
303 // Parcelables; only look inside for Parcelables
Craig Mautner719e6b12014-04-04 20:29:41 -0700304 if (!array.isEmpty() && (array.get(0) instanceof Parcelable)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 for (int n = array.size() - 1; n >= 0; n--) {
306 Parcelable p = (Parcelable) array.get(n);
307 if (p != null && ((p.describeContents()
308 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
309 fdFound = true;
310 break;
311 }
312 }
313 }
314 }
315 }
316 }
317
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700318 if (fdFound) {
319 mFlags |= FLAG_HAS_FDS;
Christopher Tate250985f2016-03-31 13:57:42 -0700320 } else {
321 mFlags &= ~FLAG_HAS_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700322 }
323 mFlags |= FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800324 }
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700325 return (mFlags & FLAG_HAS_FDS) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700327
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800328 /**
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700329 * Filter values in Bundle to only basic types.
330 * @hide
331 */
332 public void filterValues() {
333 unparcel();
334 if (mMap != null) {
335 for (int i = mMap.size() - 1; i >= 0; i--) {
336 Object value = mMap.valueAt(i);
337 if (PersistableBundle.isValidType(value)) {
338 continue;
339 }
340 if (value instanceof Bundle) {
341 ((Bundle)value).filterValues();
342 }
343 if (value.getClass().getName().startsWith("android.")) {
344 continue;
345 }
346 mMap.removeAt(i);
347 }
348 }
Christopher Tate250985f2016-03-31 13:57:42 -0700349 mFlags |= FLAG_HAS_FDS_KNOWN;
350 mFlags &= ~FLAG_HAS_FDS;
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700351 }
352
353 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 * Inserts a byte value into the mapping of this Bundle, replacing
355 * any existing value for the given key.
356 *
357 * @param key a String, or null
358 * @param value a byte
359 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700360 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800361 public void putByte(@Nullable String key, byte value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700362 super.putByte(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 }
364
365 /**
366 * Inserts a char value into the mapping of this Bundle, replacing
367 * any existing value for the given key.
368 *
369 * @param key a String, or null
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800370 * @param value a char
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700372 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800373 public void putChar(@Nullable String key, char value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700374 super.putChar(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 }
376
377 /**
378 * Inserts a short value into the mapping of this Bundle, replacing
379 * any existing value for the given key.
380 *
381 * @param key a String, or null
382 * @param value a short
383 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700384 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800385 public void putShort(@Nullable String key, short value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700386 super.putShort(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 }
388
389 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 * Inserts a float value into the mapping of this Bundle, replacing
391 * any existing value for the given key.
392 *
393 * @param key a String, or null
394 * @param value a float
395 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700396 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800397 public void putFloat(@Nullable String key, float value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700398 super.putFloat(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 }
400
401 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 * Inserts a CharSequence value into the mapping of this Bundle, replacing
403 * any existing value for the given key. Either key or value may be null.
404 *
405 * @param key a String, or null
406 * @param value a CharSequence, or null
407 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700408 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800409 public void putCharSequence(@Nullable String key, @Nullable CharSequence value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700410 super.putCharSequence(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 }
412
413 /**
414 * Inserts a Parcelable value into the mapping of this Bundle, replacing
415 * any existing value for the given key. Either key or value may be null.
416 *
417 * @param key a String, or null
418 * @param value a Parcelable object, or null
419 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800420 public void putParcelable(@Nullable String key, @Nullable Parcelable value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 unparcel();
422 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700423 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 }
425
426 /**
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700427 * Inserts a Size value into the mapping of this Bundle, replacing
428 * any existing value for the given key. Either key or value may be null.
429 *
430 * @param key a String, or null
431 * @param value a Size object, or null
432 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800433 public void putSize(@Nullable String key, @Nullable Size value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700434 unparcel();
435 mMap.put(key, value);
436 }
437
438 /**
439 * Inserts a SizeF value into the mapping of this Bundle, replacing
440 * any existing value for the given key. Either key or value may be null.
441 *
442 * @param key a String, or null
443 * @param value a SizeF object, or null
444 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800445 public void putSizeF(@Nullable String key, @Nullable SizeF value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700446 unparcel();
447 mMap.put(key, value);
448 }
449
450 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 * Inserts an array of Parcelable values into the mapping of this Bundle,
452 * replacing any existing value for the given key. Either key or value may
453 * be null.
454 *
455 * @param key a String, or null
456 * @param value an array of Parcelable objects, or null
457 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800458 public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 unparcel();
460 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700461 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 }
463
464 /**
465 * Inserts a List of Parcelable values into the mapping of this Bundle,
466 * replacing any existing value for the given key. Either key or value may
467 * be null.
468 *
469 * @param key a String, or null
470 * @param value an ArrayList of Parcelable objects, or null
471 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800472 public void putParcelableArrayList(@Nullable String key,
473 @Nullable ArrayList<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 unparcel();
475 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700476 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 }
478
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700479 /** {@hide} */
480 public void putParcelableList(String key, List<? extends Parcelable> value) {
481 unparcel();
482 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700483 mFlags &= ~FLAG_HAS_FDS_KNOWN;
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700484 }
485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 /**
487 * Inserts a SparceArray of Parcelable values into the mapping of this
488 * Bundle, replacing any existing value for the given key. Either key
489 * or value may be null.
490 *
491 * @param key a String, or null
492 * @param value a SparseArray of Parcelable objects, or null
493 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800494 public void putSparseParcelableArray(@Nullable String key,
495 @Nullable SparseArray<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 unparcel();
497 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700498 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 }
500
501 /**
502 * Inserts an ArrayList<Integer> value into the mapping of this Bundle, replacing
503 * any existing value for the given key. Either key or value may be null.
504 *
505 * @param key a String, or null
506 * @param value an ArrayList<Integer> object, or null
507 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700508 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800509 public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700510 super.putIntegerArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 }
512
513 /**
514 * Inserts an ArrayList<String> value into the mapping of this Bundle, replacing
515 * any existing value for the given key. Either key or value may be null.
516 *
517 * @param key a String, or null
518 * @param value an ArrayList<String> object, or null
519 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700520 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800521 public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700522 super.putStringArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 }
524
525 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000526 * Inserts an ArrayList<CharSequence> value into the mapping of this Bundle, replacing
527 * any existing value for the given key. Either key or value may be null.
528 *
529 * @param key a String, or null
530 * @param value an ArrayList<CharSequence> object, or null
531 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700532 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800533 public void putCharSequenceArrayList(@Nullable String key,
534 @Nullable ArrayList<CharSequence> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700535 super.putCharSequenceArrayList(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000536 }
537
538 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 * Inserts a Serializable value into the mapping of this Bundle, replacing
540 * any existing value for the given key. Either key or value may be null.
541 *
542 * @param key a String, or null
543 * @param value a Serializable object, or null
544 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700545 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800546 public void putSerializable(@Nullable String key, @Nullable Serializable value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700547 super.putSerializable(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 }
549
550 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 * Inserts a byte array value into the mapping of this Bundle, replacing
552 * any existing value for the given key. Either key or value may be null.
553 *
554 * @param key a String, or null
555 * @param value a byte array object, or null
556 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700557 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800558 public void putByteArray(@Nullable String key, @Nullable byte[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700559 super.putByteArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 }
561
562 /**
563 * Inserts a short array value into the mapping of this Bundle, replacing
564 * any existing value for the given key. Either key or value may be null.
565 *
566 * @param key a String, or null
567 * @param value a short array object, or null
568 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700569 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800570 public void putShortArray(@Nullable String key, @Nullable short[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700571 super.putShortArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 }
573
574 /**
575 * Inserts a char array value into the mapping of this Bundle, replacing
576 * any existing value for the given key. Either key or value may be null.
577 *
578 * @param key a String, or null
579 * @param value a char array object, or null
580 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700581 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800582 public void putCharArray(@Nullable String key, @Nullable char[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700583 super.putCharArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 }
585
586 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 * Inserts a float array value into the mapping of this Bundle, replacing
588 * any existing value for the given key. Either key or value may be null.
589 *
590 * @param key a String, or null
591 * @param value a float array object, or null
592 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700593 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800594 public void putFloatArray(@Nullable String key, @Nullable float[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700595 super.putFloatArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 }
597
598 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000599 * Inserts a CharSequence array value into the mapping of this Bundle, replacing
600 * any existing value for the given key. Either key or value may be null.
601 *
602 * @param key a String, or null
603 * @param value a CharSequence array object, or null
604 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700605 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800606 public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700607 super.putCharSequenceArray(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000608 }
609
610 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 * Inserts a Bundle value into the mapping of this Bundle, replacing
612 * any existing value for the given key. Either key or value may be null.
613 *
614 * @param key a String, or null
615 * @param value a Bundle object, or null
616 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800617 public void putBundle(@Nullable String key, @Nullable Bundle value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 unparcel();
619 mMap.put(key, value);
620 }
621
622 /**
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800623 * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing
624 * any existing value for the given key. Either key or value may be null.
625 *
626 * <p class="note">You should be very careful when using this function. In many
627 * places where Bundles are used (such as inside of Intent objects), the Bundle
628 * can live longer inside of another process than the process that had originally
629 * created it. In that case, the IBinder you supply here will become invalid
630 * when your process goes away, and no longer usable, even if a new process is
631 * created for you later on.</p>
632 *
633 * @param key a String, or null
634 * @param value an IBinder object, or null
635 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800636 public void putBinder(@Nullable String key, @Nullable IBinder value) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800637 unparcel();
638 mMap.put(key, value);
639 }
640
641 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 * Inserts an IBinder 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 an IBinder object, or null
647 *
648 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800649 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 */
651 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800652 public void putIBinder(@Nullable String key, @Nullable IBinder value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 unparcel();
654 mMap.put(key, value);
655 }
656
657 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 * Returns the value associated with the given key, or (byte) 0 if
659 * no mapping of the desired type exists for the given key.
660 *
661 * @param key a String
662 * @return a byte value
663 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700664 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 public byte getByte(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700666 return super.getByte(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 }
668
669 /**
670 * Returns the value associated with the given key, or defaultValue if
671 * no mapping of the desired type exists for the given key.
672 *
673 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800674 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 * @return a byte value
676 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700677 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 public Byte getByte(String key, byte defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700679 return super.getByte(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 }
681
682 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800683 * Returns the value associated with the given key, or (char) 0 if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 * no mapping of the desired type exists for the given key.
685 *
686 * @param key a String
687 * @return a char value
688 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700689 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800690 public char getChar(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700691 return super.getChar(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 }
693
694 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800695 * Returns the value associated with the given key, or defaultValue if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 * no mapping of the desired type exists for the given key.
697 *
698 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800699 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 * @return a char value
701 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700702 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800703 public char getChar(String key, char defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700704 return super.getChar(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 }
706
707 /**
708 * Returns the value associated with the given key, or (short) 0 if
709 * no mapping of the desired type exists for the given key.
710 *
711 * @param key a String
712 * @return a short value
713 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700714 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 public short getShort(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700716 return super.getShort(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 }
718
719 /**
720 * Returns the value associated with the given key, or defaultValue if
721 * no mapping of the desired type exists for the given key.
722 *
723 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800724 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 * @return a short value
726 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700727 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 public short getShort(String key, short defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700729 return super.getShort(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 }
731
732 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 * Returns the value associated with the given key, or 0.0f if
734 * no mapping of the desired type exists for the given key.
735 *
736 * @param key a String
737 * @return a float value
738 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700739 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 public float getFloat(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700741 return super.getFloat(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 }
743
744 /**
745 * Returns the value associated with the given key, or defaultValue if
746 * no mapping of the desired type exists for the given key.
747 *
748 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800749 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 * @return a float value
751 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700752 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 public float getFloat(String key, float defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700754 return super.getFloat(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 }
756
757 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800758 * Returns the value associated with the given key, or null if
759 * no mapping of the desired type exists for the given key or a null
760 * value is explicitly associated with the key.
761 *
762 * @param key a String, or null
763 * @return a CharSequence value, or null
764 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700765 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800766 @Nullable
767 public CharSequence getCharSequence(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700768 return super.getCharSequence(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 }
770
771 /**
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800772 * Returns the value associated with the given key, or defaultValue if
Narayan Kamathca2197b2014-06-19 10:46:00 +0100773 * no mapping of the desired type exists for the given key or if a null
774 * value is explicitly associatd with the given key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800775 *
776 * @param key a String, or null
Narayan Kamathca2197b2014-06-19 10:46:00 +0100777 * @param defaultValue Value to return if key does not exist or if a null
778 * value is associated with the given key.
Christopher Tate116751d2012-12-20 18:57:09 -0800779 * @return the CharSequence value associated with the given key, or defaultValue
780 * if no valid CharSequence object is currently mapped to that key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800781 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700782 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800783 public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700784 return super.getCharSequence(key, defaultValue);
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800785 }
786
787 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 * Returns the value associated with the given key, or null if
789 * no mapping of the desired type exists for the given key or a null
790 * value is explicitly associated with the key.
791 *
792 * @param key a String, or null
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700793 * @return a Size value, or null
794 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800795 @Nullable
796 public Size getSize(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700797 unparcel();
798 final Object o = mMap.get(key);
799 try {
800 return (Size) o;
801 } catch (ClassCastException e) {
802 typeWarning(key, o, "Size", e);
803 return null;
804 }
805 }
806
807 /**
808 * Returns the value associated with the given key, or null if
809 * no mapping of the desired type exists for the given key or a null
810 * value is explicitly associated with the key.
811 *
812 * @param key a String, or null
813 * @return a Size value, or null
814 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800815 @Nullable
816 public SizeF getSizeF(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700817 unparcel();
818 final Object o = mMap.get(key);
819 try {
820 return (SizeF) o;
821 } catch (ClassCastException e) {
822 typeWarning(key, o, "SizeF", e);
823 return null;
824 }
825 }
826
827 /**
828 * Returns the value associated with the given key, or null if
829 * no mapping of the desired type exists for the given key or a null
830 * value is explicitly associated with the key.
831 *
832 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 * @return a Bundle value, or null
834 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800835 @Nullable
836 public Bundle getBundle(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 unparcel();
838 Object o = mMap.get(key);
839 if (o == null) {
840 return null;
841 }
842 try {
843 return (Bundle) o;
844 } catch (ClassCastException e) {
845 typeWarning(key, o, "Bundle", e);
846 return null;
847 }
848 }
849
850 /**
851 * Returns the value associated with the given key, or null if
852 * no mapping of the desired type exists for the given key or a null
853 * value is explicitly associated with the key.
854 *
855 * @param key a String, or null
856 * @return a Parcelable value, or null
857 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800858 @Nullable
859 public <T extends Parcelable> T getParcelable(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 unparcel();
861 Object o = mMap.get(key);
862 if (o == null) {
863 return null;
864 }
865 try {
866 return (T) o;
867 } catch (ClassCastException e) {
868 typeWarning(key, o, "Parcelable", e);
869 return null;
870 }
871 }
872
873 /**
874 * Returns the value associated with the given key, or null if
875 * no mapping of the desired type exists for the given key or a null
876 * value is explicitly associated with the key.
877 *
878 * @param key a String, or null
879 * @return a Parcelable[] value, or null
880 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800881 @Nullable
882 public Parcelable[] getParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 unparcel();
884 Object o = mMap.get(key);
885 if (o == null) {
886 return null;
887 }
888 try {
889 return (Parcelable[]) o;
890 } catch (ClassCastException e) {
891 typeWarning(key, o, "Parcelable[]", e);
892 return null;
893 }
894 }
895
896 /**
897 * Returns the value associated with the given key, or null if
898 * no mapping of the desired type exists for the given key or a null
899 * value is explicitly associated with the key.
900 *
901 * @param key a String, or null
902 * @return an ArrayList<T> value, or null
903 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800904 @Nullable
905 public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 unparcel();
907 Object o = mMap.get(key);
908 if (o == null) {
909 return null;
910 }
911 try {
912 return (ArrayList<T>) o;
913 } catch (ClassCastException e) {
914 typeWarning(key, o, "ArrayList", e);
915 return null;
916 }
917 }
918
919 /**
920 * Returns the value associated with the given key, or null if
921 * no mapping of the desired type exists for the given key or a null
922 * value is explicitly associated with the key.
923 *
924 * @param key a String, or null
925 *
926 * @return a SparseArray of T values, or null
927 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800928 @Nullable
929 public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 unparcel();
931 Object o = mMap.get(key);
932 if (o == null) {
933 return null;
934 }
935 try {
936 return (SparseArray<T>) o;
937 } catch (ClassCastException e) {
938 typeWarning(key, o, "SparseArray", e);
939 return null;
940 }
941 }
942
943 /**
944 * Returns the value associated with the given key, or null if
945 * no mapping of the desired type exists for the given key or a null
946 * value is explicitly associated with the key.
947 *
948 * @param key a String, or null
949 * @return a Serializable value, or null
950 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700951 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800952 @Nullable
953 public Serializable getSerializable(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700954 return super.getSerializable(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 }
956
957 /**
958 * Returns the value associated with the given key, or null if
959 * no mapping of the desired type exists for the given key or a null
960 * value is explicitly associated with the key.
961 *
962 * @param key a String, or null
963 * @return an ArrayList<String> value, or null
964 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700965 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800966 @Nullable
967 public ArrayList<Integer> getIntegerArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700968 return super.getIntegerArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 }
970
971 /**
972 * Returns the value associated with the given key, or null if
973 * no mapping of the desired type exists for the given key or a null
974 * value is explicitly associated with the key.
975 *
976 * @param key a String, or null
977 * @return an ArrayList<String> value, or null
978 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700979 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800980 @Nullable
981 public ArrayList<String> getStringArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700982 return super.getStringArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800983 }
984
985 /**
986 * Returns the value associated with the given key, or null if
987 * no mapping of the desired type exists for the given key or a null
988 * value is explicitly associated with the key.
989 *
990 * @param key a String, or null
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000991 * @return an ArrayList<CharSequence> value, or null
992 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700993 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800994 @Nullable
995 public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700996 return super.getCharSequenceArrayList(key);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000997 }
998
999 /**
1000 * Returns the value associated with the given key, or null if
1001 * no mapping of the desired type exists for the given key or a null
1002 * value is explicitly associated with the key.
1003 *
1004 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 * @return a byte[] value, or null
1006 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001007 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001008 @Nullable
1009 public byte[] getByteArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001010 return super.getByteArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 }
1012
1013 /**
1014 * Returns the value associated with the given key, or null if
1015 * no mapping of the desired type exists for the given key or a null
1016 * value is explicitly associated with the key.
1017 *
1018 * @param key a String, or null
1019 * @return a short[] value, or null
1020 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001021 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001022 @Nullable
1023 public short[] getShortArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001024 return super.getShortArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 }
1026
1027 /**
1028 * Returns the value associated with the given key, or null if
1029 * no mapping of the desired type exists for the given key or a null
1030 * value is explicitly associated with the key.
1031 *
1032 * @param key a String, or null
1033 * @return a char[] value, or null
1034 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001035 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001036 @Nullable
1037 public char[] getCharArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001038 return super.getCharArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 }
1040
1041 /**
1042 * Returns the value associated with the given key, or null if
1043 * no mapping of the desired type exists for the given key or a null
1044 * value is explicitly associated with the key.
1045 *
1046 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 * @return a float[] value, or null
1048 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001049 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001050 @Nullable
1051 public float[] getFloatArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001052 return super.getFloatArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 }
1054
1055 /**
1056 * Returns the value associated with the given key, or null if
1057 * no mapping of the desired type exists for the given key or a null
1058 * value is explicitly associated with the key.
1059 *
1060 * @param key a String, or null
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001061 * @return a CharSequence[] value, or null
1062 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001063 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001064 @Nullable
1065 public CharSequence[] getCharSequenceArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001066 return super.getCharSequenceArray(key);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001067 }
1068
1069 /**
1070 * Returns the value associated with the given key, or null if
1071 * no mapping of the desired type exists for the given key or a null
1072 * value is explicitly associated with the key.
1073 *
1074 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001075 * @return an IBinder value, or null
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001076 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001077 @Nullable
1078 public IBinder getBinder(@Nullable String key) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001079 unparcel();
1080 Object o = mMap.get(key);
1081 if (o == null) {
1082 return null;
1083 }
1084 try {
1085 return (IBinder) o;
1086 } catch (ClassCastException e) {
1087 typeWarning(key, o, "IBinder", 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 an IBinder value, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 *
1100 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001101 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 */
1103 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001104 @Nullable
1105 public IBinder getIBinder(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 unparcel();
1107 Object o = mMap.get(key);
1108 if (o == null) {
1109 return null;
1110 }
1111 try {
1112 return (IBinder) o;
1113 } catch (ClassCastException e) {
1114 typeWarning(key, o, "IBinder", e);
1115 return null;
1116 }
1117 }
1118
1119 public static final Parcelable.Creator<Bundle> CREATOR =
1120 new Parcelable.Creator<Bundle>() {
Craig Mautner719e6b12014-04-04 20:29:41 -07001121 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 public Bundle createFromParcel(Parcel in) {
1123 return in.readBundle();
1124 }
1125
Craig Mautner719e6b12014-04-04 20:29:41 -07001126 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001127 public Bundle[] newArray(int size) {
1128 return new Bundle[size];
1129 }
1130 };
1131
1132 /**
1133 * Report the nature of this Parcelable's contents
1134 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001135 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 public int describeContents() {
1137 int mask = 0;
1138 if (hasFileDescriptors()) {
1139 mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR;
1140 }
1141 return mask;
1142 }
Craig Mautner719e6b12014-04-04 20:29:41 -07001143
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 /**
1145 * Writes the Bundle contents to a Parcel, typically in order for
1146 * it to be passed through an IBinder connection.
1147 * @param parcel The parcel to copy this bundle to.
1148 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001149 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 public void writeToParcel(Parcel parcel, int flags) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -07001151 final boolean oldAllowFds = parcel.pushAllowFds((mFlags & FLAG_ALLOW_FDS) != 0);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001152 try {
Craig Mautner719e6b12014-04-04 20:29:41 -07001153 super.writeToParcelInner(parcel, flags);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001154 } finally {
Dianne Hackbornc04db7e2011-10-03 21:09:35 -07001155 parcel.restoreAllowFds(oldAllowFds);
Dianne Hackborn6aff9052009-05-22 13:20:23 -07001156 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 }
1158
1159 /**
1160 * Reads the Parcel contents into this Bundle, typically in order for
1161 * it to be passed through an IBinder connection.
1162 * @param parcel The parcel to overwrite this bundle from.
1163 */
1164 public void readFromParcel(Parcel parcel) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001165 super.readFromParcelInner(parcel);
Jeff Sharkey7410fb42016-03-16 21:23:29 -06001166 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -07001167 if (mParcelledData.hasFileDescriptors()) {
1168 mFlags |= FLAG_HAS_FDS;
1169 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 }
1171
1172 @Override
1173 public synchronized String toString() {
1174 if (mParcelledData != null) {
Andreas Gampe52764cb2016-04-19 20:46:43 -07001175 if (isEmptyParcel()) {
Dianne Hackborn8aee64d2013-10-25 10:41:50 -07001176 return "Bundle[EMPTY_PARCEL]";
1177 } else {
1178 return "Bundle[mParcelledData.dataSize=" +
1179 mParcelledData.dataSize() + "]";
1180 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 }
1182 return "Bundle[" + mMap.toString() + "]";
1183 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184}