blob: 05dd48b12e55ccd74ecc394293a2c2834103bc54 [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
Dianne Hackborn8aee64d2013-10-25 10:41:50 -070041 static final Parcel EMPTY_PARCEL;
Dianne Hackborne784d1e2013-09-20 18:13:52 -070042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 static {
44 EMPTY = new Bundle();
Dianne Hackbornb87655b2013-07-17 19:06:22 -070045 EMPTY.mMap = ArrayMap.EMPTY;
Craig Mautner0a8e160e2014-05-29 10:27:32 -070046 EMPTY_PARCEL = BaseBundle.EMPTY_PARCEL;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 }
48
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 * Constructs a new, empty Bundle.
51 */
52 public Bundle() {
Craig Mautner719e6b12014-04-04 20:29:41 -070053 super();
Jeff Sharkey7410fb42016-03-16 21:23:29 -060054 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 }
56
57 /**
58 * Constructs a Bundle whose data is stored as a Parcel. The data
59 * will be unparcelled on first contact, using the assigned ClassLoader.
60 *
61 * @param parcelledData a Parcel containing a Bundle
62 */
63 Bundle(Parcel parcelledData) {
Craig Mautner719e6b12014-04-04 20:29:41 -070064 super(parcelledData);
Jeff Sharkey7410fb42016-03-16 21:23:29 -060065 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070066 if (mParcelledData.hasFileDescriptors()) {
67 mFlags |= FLAG_HAS_FDS;
68 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 }
70
Dianne Hackborn6aff9052009-05-22 13:20:23 -070071 /* package */ Bundle(Parcel parcelledData, int length) {
Craig Mautner719e6b12014-04-04 20:29:41 -070072 super(parcelledData, length);
Jeff Sharkey7410fb42016-03-16 21:23:29 -060073 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -070074 if (mParcelledData.hasFileDescriptors()) {
75 mFlags |= FLAG_HAS_FDS;
76 }
Dianne Hackborn6aff9052009-05-22 13:20:23 -070077 }
78
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 /**
80 * Constructs a new, empty Bundle that uses a specific ClassLoader for
81 * instantiating Parcelable and Serializable objects.
82 *
83 * @param loader An explicit ClassLoader to use when instantiating objects
84 * inside of the Bundle.
85 */
86 public Bundle(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -070087 super(loader);
Jeff Sharkey7410fb42016-03-16 21:23:29 -060088 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 }
90
91 /**
92 * Constructs a new, empty Bundle sized to hold the given number of
93 * elements. The Bundle will grow as needed.
94 *
95 * @param capacity the initial capacity of the Bundle
96 */
97 public Bundle(int capacity) {
Craig Mautner719e6b12014-04-04 20:29:41 -070098 super(capacity);
Jeff Sharkey7410fb42016-03-16 21:23:29 -060099 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 }
101
102 /**
103 * Constructs a Bundle containing a copy of the mappings from the given
104 * Bundle.
105 *
106 * @param b a Bundle to be copied.
107 */
108 public Bundle(Bundle b) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700109 super(b);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700110 mFlags = b.mFlags;
Craig Mautner719e6b12014-04-04 20:29:41 -0700111 }
112
113 /**
114 * Constructs a Bundle containing a copy of the mappings from the given
115 * PersistableBundle.
116 *
117 * @param b a Bundle to be copied.
118 */
119 public Bundle(PersistableBundle b) {
120 super(b);
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600121 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 }
123
124 /**
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800125 * Make a Bundle for a single key/value pair.
126 *
127 * @hide
128 */
129 public static Bundle forPair(String key, String value) {
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800130 Bundle b = new Bundle(1);
131 b.putString(key, value);
132 return b;
133 }
134
135 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 * Changes the ClassLoader this Bundle uses when instantiating objects.
137 *
138 * @param loader An explicit ClassLoader to use when instantiating objects
139 * inside of the Bundle.
140 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700141 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 public void setClassLoader(ClassLoader loader) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700143 super.setClassLoader(loader);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 }
145
146 /**
Dianne Hackborn51642462010-10-28 10:32:37 -0700147 * Return the ClassLoader currently associated with this Bundle.
148 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700149 @Override
Dianne Hackborn51642462010-10-28 10:32:37 -0700150 public ClassLoader getClassLoader() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700151 return super.getClassLoader();
Dianne Hackborn51642462010-10-28 10:32:37 -0700152 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400153
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700154 /** {@hide} */
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400155 public boolean setAllowFds(boolean allowFds) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700156 final boolean orig = (mFlags & FLAG_ALLOW_FDS) != 0;
157 if (allowFds) {
158 mFlags |= FLAG_ALLOW_FDS;
159 } else {
160 mFlags &= ~FLAG_ALLOW_FDS;
161 }
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -0400162 return orig;
163 }
164
Dianne Hackborn51642462010-10-28 10:32:37 -0700165 /**
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700166 * Mark if this Bundle is okay to "defuse." That is, it's okay for system
167 * processes to ignore any {@link BadParcelableException} encountered when
168 * unparceling it, leaving an empty bundle in its place.
169 * <p>
170 * This should <em>only</em> be set when the Bundle reaches its final
171 * destination, otherwise a system process may clobber contents that were
172 * destined for an app that could have unparceled them.
173 *
174 * @hide
175 */
176 public void setDefusable(boolean defusable) {
177 if (defusable) {
178 mFlags |= FLAG_DEFUSABLE;
179 } else {
180 mFlags &= ~FLAG_DEFUSABLE;
181 }
182 }
183
Jeff Sharkeya04c7a72016-03-18 12:20:36 -0600184 /** {@hide} */
185 public static Bundle setDefusable(Bundle bundle, boolean defusable) {
186 if (bundle != null) {
187 bundle.setDefusable(defusable);
188 }
189 return bundle;
190 }
191
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700192 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 * Clones the current Bundle. The internal map is cloned, but the keys and
194 * values to which it refers are copied by reference.
195 */
196 @Override
197 public Object clone() {
198 return new Bundle(this);
199 }
200
201 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 * Removes all elements from the mapping of this Bundle.
203 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700204 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 public void clear() {
Craig Mautner719e6b12014-04-04 20:29:41 -0700206 super.clear();
Jeff Sharkey7410fb42016-03-16 21:23:29 -0600207 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 }
209
210 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 * Inserts all mappings from the given Bundle into this Bundle.
212 *
Craig Mautner719e6b12014-04-04 20:29:41 -0700213 * @param bundle a Bundle
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700215 public void putAll(Bundle bundle) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 unparcel();
Craig Mautner719e6b12014-04-04 20:29:41 -0700217 bundle.unparcel();
218 mMap.putAll(bundle.mMap);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700220 // FD state is now known if and only if both bundles already knew
221 if ((bundle.mFlags & FLAG_HAS_FDS) != 0) {
222 mFlags |= FLAG_HAS_FDS;
223 }
224 if ((bundle.mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
225 mFlags &= ~FLAG_HAS_FDS_KNOWN;
226 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700227 }
228
229 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 * Reports whether the bundle contains any parcelled file descriptors.
231 */
232 public boolean hasFileDescriptors() {
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700233 if ((mFlags & FLAG_HAS_FDS_KNOWN) == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 boolean fdFound = false; // keep going until we find one or run out of data
Craig Mautner719e6b12014-04-04 20:29:41 -0700235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 if (mParcelledData != null) {
237 if (mParcelledData.hasFileDescriptors()) {
238 fdFound = true;
239 }
240 } else {
241 // It's been unparcelled, so we need to walk the map
Dianne Hackbornb87655b2013-07-17 19:06:22 -0700242 for (int i=mMap.size()-1; i>=0; i--) {
243 Object obj = mMap.valueAt(i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 if (obj instanceof Parcelable) {
245 if ((((Parcelable)obj).describeContents()
246 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
247 fdFound = true;
248 break;
249 }
250 } else if (obj instanceof Parcelable[]) {
251 Parcelable[] array = (Parcelable[]) obj;
252 for (int n = array.length - 1; n >= 0; n--) {
Taiju Tsuikie58c7852015-04-22 16:59:00 +0900253 Parcelable p = array[n];
254 if (p != null && ((p.describeContents()
255 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 fdFound = true;
257 break;
258 }
259 }
260 } else if (obj instanceof SparseArray) {
261 SparseArray<? extends Parcelable> array =
262 (SparseArray<? extends Parcelable>) obj;
263 for (int n = array.size() - 1; n >= 0; n--) {
Taiju Tsuikiecd21842015-04-28 13:36:15 +0900264 Parcelable p = array.valueAt(n);
265 if (p != null && (p.describeContents()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
267 fdFound = true;
268 break;
269 }
270 }
271 } else if (obj instanceof ArrayList) {
272 ArrayList array = (ArrayList) obj;
273 // an ArrayList here might contain either Strings or
274 // Parcelables; only look inside for Parcelables
Craig Mautner719e6b12014-04-04 20:29:41 -0700275 if (!array.isEmpty() && (array.get(0) instanceof Parcelable)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 for (int n = array.size() - 1; n >= 0; n--) {
277 Parcelable p = (Parcelable) array.get(n);
278 if (p != null && ((p.describeContents()
279 & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
280 fdFound = true;
281 break;
282 }
283 }
284 }
285 }
286 }
287 }
288
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700289 if (fdFound) {
290 mFlags |= FLAG_HAS_FDS;
291 }
292 mFlags |= FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 }
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700294 return (mFlags & FLAG_HAS_FDS) != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 }
Craig Mautner719e6b12014-04-04 20:29:41 -0700296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 /**
Dianne Hackborna83ce1d2015-03-11 15:16:13 -0700298 * Filter values in Bundle to only basic types.
299 * @hide
300 */
301 public void filterValues() {
302 unparcel();
303 if (mMap != null) {
304 for (int i = mMap.size() - 1; i >= 0; i--) {
305 Object value = mMap.valueAt(i);
306 if (PersistableBundle.isValidType(value)) {
307 continue;
308 }
309 if (value instanceof Bundle) {
310 ((Bundle)value).filterValues();
311 }
312 if (value.getClass().getName().startsWith("android.")) {
313 continue;
314 }
315 mMap.removeAt(i);
316 }
317 }
318 }
319
320 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 * Inserts a byte value into the mapping of this Bundle, replacing
322 * any existing value for the given key.
323 *
324 * @param key a String, or null
325 * @param value a byte
326 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700327 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800328 public void putByte(@Nullable String key, byte value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700329 super.putByte(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 }
331
332 /**
333 * Inserts a char value into the mapping of this Bundle, replacing
334 * any existing value for the given key.
335 *
336 * @param key a String, or null
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800337 * @param value a char
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700339 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800340 public void putChar(@Nullable String key, char value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700341 super.putChar(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 }
343
344 /**
345 * Inserts a short value into the mapping of this Bundle, replacing
346 * any existing value for the given key.
347 *
348 * @param key a String, or null
349 * @param value a short
350 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700351 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800352 public void putShort(@Nullable String key, short value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700353 super.putShort(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 }
355
356 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 * Inserts a float value into the mapping of this Bundle, replacing
358 * any existing value for the given key.
359 *
360 * @param key a String, or null
361 * @param value a float
362 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700363 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800364 public void putFloat(@Nullable String key, float value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700365 super.putFloat(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 }
367
368 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 * Inserts a CharSequence value into the mapping of this Bundle, replacing
370 * any existing value for the given key. Either key or value may be null.
371 *
372 * @param key a String, or null
373 * @param value a CharSequence, or null
374 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700375 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800376 public void putCharSequence(@Nullable String key, @Nullable CharSequence value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700377 super.putCharSequence(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 }
379
380 /**
381 * Inserts a Parcelable value into the mapping of this Bundle, replacing
382 * any existing value for the given key. Either key or value may be null.
383 *
384 * @param key a String, or null
385 * @param value a Parcelable object, or null
386 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800387 public void putParcelable(@Nullable String key, @Nullable Parcelable value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 unparcel();
389 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700390 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 }
392
393 /**
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700394 * Inserts a Size value into the mapping of this Bundle, replacing
395 * any existing value for the given key. Either key or value may be null.
396 *
397 * @param key a String, or null
398 * @param value a Size object, or null
399 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800400 public void putSize(@Nullable String key, @Nullable Size value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700401 unparcel();
402 mMap.put(key, value);
403 }
404
405 /**
406 * Inserts a SizeF value into the mapping of this Bundle, replacing
407 * any existing value for the given key. Either key or value may be null.
408 *
409 * @param key a String, or null
410 * @param value a SizeF object, or null
411 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800412 public void putSizeF(@Nullable String key, @Nullable SizeF value) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700413 unparcel();
414 mMap.put(key, value);
415 }
416
417 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 * Inserts an array of Parcelable values into the mapping of this Bundle,
419 * replacing any existing value for the given key. Either key or value may
420 * be null.
421 *
422 * @param key a String, or null
423 * @param value an array of Parcelable objects, or null
424 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800425 public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 unparcel();
427 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700428 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 }
430
431 /**
432 * Inserts a List of Parcelable values into the mapping of this Bundle,
433 * replacing any existing value for the given key. Either key or value may
434 * be null.
435 *
436 * @param key a String, or null
437 * @param value an ArrayList of Parcelable objects, or null
438 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800439 public void putParcelableArrayList(@Nullable String key,
440 @Nullable ArrayList<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 unparcel();
442 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700443 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 }
445
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700446 /** {@hide} */
447 public void putParcelableList(String key, List<? extends Parcelable> value) {
448 unparcel();
449 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700450 mFlags &= ~FLAG_HAS_FDS_KNOWN;
Jeff Sharkeyaeb16e22013-08-27 18:26:48 -0700451 }
452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 /**
454 * Inserts a SparceArray of Parcelable values into the mapping of this
455 * Bundle, replacing any existing value for the given key. Either key
456 * or value may be null.
457 *
458 * @param key a String, or null
459 * @param value a SparseArray of Parcelable objects, or null
460 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800461 public void putSparseParcelableArray(@Nullable String key,
462 @Nullable SparseArray<? extends Parcelable> value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 unparcel();
464 mMap.put(key, value);
Jeff Sharkeyd136e512016-03-09 22:30:56 -0700465 mFlags &= ~FLAG_HAS_FDS_KNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 }
467
468 /**
469 * Inserts an ArrayList<Integer> value into the mapping of this Bundle, replacing
470 * any existing value for the given key. Either key or value may be null.
471 *
472 * @param key a String, or null
473 * @param value an ArrayList<Integer> object, or null
474 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700475 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800476 public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700477 super.putIntegerArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 }
479
480 /**
481 * Inserts an ArrayList<String> 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 an ArrayList<String> object, or null
486 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700487 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800488 public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700489 super.putStringArrayList(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 }
491
492 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000493 * Inserts an ArrayList<CharSequence> 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 an ArrayList<CharSequence> object, or null
498 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700499 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800500 public void putCharSequenceArrayList(@Nullable String key,
501 @Nullable ArrayList<CharSequence> value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700502 super.putCharSequenceArrayList(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000503 }
504
505 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 * Inserts a Serializable 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 Serializable object, or null
511 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700512 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800513 public void putSerializable(@Nullable String key, @Nullable Serializable value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700514 super.putSerializable(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 }
516
517 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 * Inserts a byte array 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 byte array object, or null
523 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700524 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800525 public void putByteArray(@Nullable String key, @Nullable byte[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700526 super.putByteArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800527 }
528
529 /**
530 * Inserts a short array value into the mapping of this Bundle, replacing
531 * any existing value for the given key. Either key or value may be null.
532 *
533 * @param key a String, or null
534 * @param value a short array object, or null
535 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700536 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800537 public void putShortArray(@Nullable String key, @Nullable short[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700538 super.putShortArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 }
540
541 /**
542 * Inserts a char array value into the mapping of this Bundle, replacing
543 * any existing value for the given key. Either key or value may be null.
544 *
545 * @param key a String, or null
546 * @param value a char array object, or null
547 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700548 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800549 public void putCharArray(@Nullable String key, @Nullable char[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700550 super.putCharArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 }
552
553 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 * Inserts a float array value into the mapping of this Bundle, replacing
555 * any existing value for the given key. Either key or value may be null.
556 *
557 * @param key a String, or null
558 * @param value a float array object, or null
559 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700560 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800561 public void putFloatArray(@Nullable String key, @Nullable float[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700562 super.putFloatArray(key, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 }
564
565 /**
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000566 * Inserts a CharSequence array value into the mapping of this Bundle, replacing
567 * any existing value for the given key. Either key or value may be null.
568 *
569 * @param key a String, or null
570 * @param value a CharSequence array object, or null
571 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700572 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800573 public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700574 super.putCharSequenceArray(key, value);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000575 }
576
577 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 * Inserts a Bundle value into the mapping of this Bundle, replacing
579 * any existing value for the given key. Either key or value may be null.
580 *
581 * @param key a String, or null
582 * @param value a Bundle object, or null
583 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800584 public void putBundle(@Nullable String key, @Nullable Bundle value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 unparcel();
586 mMap.put(key, value);
587 }
588
589 /**
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800590 * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing
591 * any existing value for the given key. Either key or value may be null.
592 *
593 * <p class="note">You should be very careful when using this function. In many
594 * places where Bundles are used (such as inside of Intent objects), the Bundle
595 * can live longer inside of another process than the process that had originally
596 * created it. In that case, the IBinder you supply here will become invalid
597 * when your process goes away, and no longer usable, even if a new process is
598 * created for you later on.</p>
599 *
600 * @param key a String, or null
601 * @param value an IBinder object, or null
602 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800603 public void putBinder(@Nullable String key, @Nullable IBinder value) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800604 unparcel();
605 mMap.put(key, value);
606 }
607
608 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 * Inserts an IBinder value into the mapping of this Bundle, replacing
610 * any existing value for the given key. Either key or value may be null.
611 *
612 * @param key a String, or null
613 * @param value an IBinder object, or null
614 *
615 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -0800616 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 */
618 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800619 public void putIBinder(@Nullable String key, @Nullable IBinder value) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 unparcel();
621 mMap.put(key, value);
622 }
623
624 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 * Returns the value associated with the given key, or (byte) 0 if
626 * no mapping of the desired type exists for the given key.
627 *
628 * @param key a String
629 * @return a byte value
630 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700631 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 public byte getByte(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700633 return super.getByte(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 }
635
636 /**
637 * Returns the value associated with the given key, or defaultValue if
638 * no mapping of the desired type exists for the given key.
639 *
640 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800641 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 * @return a byte value
643 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700644 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 public Byte getByte(String key, byte defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700646 return super.getByte(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 }
648
649 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800650 * Returns the value associated with the given key, or (char) 0 if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 * no mapping of the desired type exists for the given key.
652 *
653 * @param key a String
654 * @return a char value
655 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700656 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 public char getChar(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700658 return super.getChar(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 }
660
661 /**
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800662 * Returns the value associated with the given key, or defaultValue if
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 * no mapping of the desired type exists for the given key.
664 *
665 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800666 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 * @return a char value
668 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700669 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 public char getChar(String key, char defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700671 return super.getChar(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 }
673
674 /**
675 * Returns the value associated with the given key, or (short) 0 if
676 * no mapping of the desired type exists for the given key.
677 *
678 * @param key a String
679 * @return a short value
680 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700681 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 public short getShort(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700683 return super.getShort(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 }
685
686 /**
687 * Returns the value associated with the given key, or defaultValue if
688 * no mapping of the desired type exists for the given key.
689 *
690 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800691 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 * @return a short value
693 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700694 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 public short getShort(String key, short defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700696 return super.getShort(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697 }
698
699 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 * Returns the value associated with the given key, or 0.0f if
701 * no mapping of the desired type exists for the given key.
702 *
703 * @param key a String
704 * @return a float value
705 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700706 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 public float getFloat(String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700708 return super.getFloat(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 }
710
711 /**
712 * Returns the value associated with the given key, or defaultValue if
713 * no mapping of the desired type exists for the given key.
714 *
715 * @param key a String
Nicolas Klein9f6cb872012-11-30 14:41:46 -0800716 * @param defaultValue Value to return if key does not exist
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 * @return a float value
718 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700719 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 public float getFloat(String key, float defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700721 return super.getFloat(key, defaultValue);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 }
723
724 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 * Returns the value associated with the given key, or null if
726 * no mapping of the desired type exists for the given key or a null
727 * value is explicitly associated with the key.
728 *
729 * @param key a String, or null
730 * @return a CharSequence value, or null
731 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700732 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800733 @Nullable
734 public CharSequence getCharSequence(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700735 return super.getCharSequence(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 }
737
738 /**
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800739 * Returns the value associated with the given key, or defaultValue if
Narayan Kamathca2197b2014-06-19 10:46:00 +0100740 * no mapping of the desired type exists for the given key or if a null
741 * value is explicitly associatd with the given key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800742 *
743 * @param key a String, or null
Narayan Kamathca2197b2014-06-19 10:46:00 +0100744 * @param defaultValue Value to return if key does not exist or if a null
745 * value is associated with the given key.
Christopher Tate116751d2012-12-20 18:57:09 -0800746 * @return the CharSequence value associated with the given key, or defaultValue
747 * if no valid CharSequence object is currently mapped to that key.
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800748 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700749 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800750 public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700751 return super.getCharSequence(key, defaultValue);
Dianne Hackborne3a7f622011-03-03 21:48:24 -0800752 }
753
754 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 * Returns the value associated with the given key, or null if
756 * no mapping of the desired type exists for the given key or a null
757 * value is explicitly associated with the key.
758 *
759 * @param key a String, or null
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700760 * @return a Size value, or null
761 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800762 @Nullable
763 public Size getSize(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700764 unparcel();
765 final Object o = mMap.get(key);
766 try {
767 return (Size) o;
768 } catch (ClassCastException e) {
769 typeWarning(key, o, "Size", e);
770 return null;
771 }
772 }
773
774 /**
775 * Returns the value associated with the given key, or null if
776 * no mapping of the desired type exists for the given key or a null
777 * value is explicitly associated with the key.
778 *
779 * @param key a String, or null
780 * @return a Size value, or null
781 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800782 @Nullable
783 public SizeF getSizeF(@Nullable String key) {
Jeff Sharkey5ef33982014-09-04 18:13:39 -0700784 unparcel();
785 final Object o = mMap.get(key);
786 try {
787 return (SizeF) o;
788 } catch (ClassCastException e) {
789 typeWarning(key, o, "SizeF", e);
790 return null;
791 }
792 }
793
794 /**
795 * Returns the value associated with the given key, or null if
796 * no mapping of the desired type exists for the given key or a null
797 * value is explicitly associated with the key.
798 *
799 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 * @return a Bundle value, or null
801 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800802 @Nullable
803 public Bundle getBundle(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 unparcel();
805 Object o = mMap.get(key);
806 if (o == null) {
807 return null;
808 }
809 try {
810 return (Bundle) o;
811 } catch (ClassCastException e) {
812 typeWarning(key, o, "Bundle", e);
813 return null;
814 }
815 }
816
817 /**
818 * Returns the value associated with the given key, or null if
819 * no mapping of the desired type exists for the given key or a null
820 * value is explicitly associated with the key.
821 *
822 * @param key a String, or null
823 * @return a Parcelable value, or null
824 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800825 @Nullable
826 public <T extends Parcelable> T getParcelable(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 unparcel();
828 Object o = mMap.get(key);
829 if (o == null) {
830 return null;
831 }
832 try {
833 return (T) o;
834 } catch (ClassCastException e) {
835 typeWarning(key, o, "Parcelable", e);
836 return null;
837 }
838 }
839
840 /**
841 * Returns the value associated with the given key, or null if
842 * no mapping of the desired type exists for the given key or a null
843 * value is explicitly associated with the key.
844 *
845 * @param key a String, or null
846 * @return a Parcelable[] value, or null
847 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800848 @Nullable
849 public Parcelable[] getParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 unparcel();
851 Object o = mMap.get(key);
852 if (o == null) {
853 return null;
854 }
855 try {
856 return (Parcelable[]) o;
857 } catch (ClassCastException e) {
858 typeWarning(key, o, "Parcelable[]", e);
859 return null;
860 }
861 }
862
863 /**
864 * Returns the value associated with the given key, or null if
865 * no mapping of the desired type exists for the given key or a null
866 * value is explicitly associated with the key.
867 *
868 * @param key a String, or null
869 * @return an ArrayList<T> value, or null
870 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800871 @Nullable
872 public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 unparcel();
874 Object o = mMap.get(key);
875 if (o == null) {
876 return null;
877 }
878 try {
879 return (ArrayList<T>) o;
880 } catch (ClassCastException e) {
881 typeWarning(key, o, "ArrayList", 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 *
893 * @return a SparseArray of T values, or null
894 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800895 @Nullable
896 public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 unparcel();
898 Object o = mMap.get(key);
899 if (o == null) {
900 return null;
901 }
902 try {
903 return (SparseArray<T>) o;
904 } catch (ClassCastException e) {
905 typeWarning(key, o, "SparseArray", e);
906 return null;
907 }
908 }
909
910 /**
911 * Returns the value associated with the given key, or null if
912 * no mapping of the desired type exists for the given key or a null
913 * value is explicitly associated with the key.
914 *
915 * @param key a String, or null
916 * @return a Serializable value, or null
917 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700918 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800919 @Nullable
920 public Serializable getSerializable(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700921 return super.getSerializable(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922 }
923
924 /**
925 * Returns the value associated with the given key, or null if
926 * no mapping of the desired type exists for the given key or a null
927 * value is explicitly associated with the key.
928 *
929 * @param key a String, or null
930 * @return an ArrayList<String> value, or null
931 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700932 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800933 @Nullable
934 public ArrayList<Integer> getIntegerArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700935 return super.getIntegerArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 }
937
938 /**
939 * Returns the value associated with the given key, or null if
940 * no mapping of the desired type exists for the given key or a null
941 * value is explicitly associated with the key.
942 *
943 * @param key a String, or null
944 * @return an ArrayList<String> value, or null
945 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700946 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800947 @Nullable
948 public ArrayList<String> getStringArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700949 return super.getStringArrayList(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 }
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
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000958 * @return an ArrayList<CharSequence> value, or null
959 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700960 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800961 @Nullable
962 public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700963 return super.getCharSequenceArrayList(key);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +0000964 }
965
966 /**
967 * Returns the value associated with the given key, or null if
968 * no mapping of the desired type exists for the given key or a null
969 * value is explicitly associated with the key.
970 *
971 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800972 * @return a byte[] value, or null
973 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700974 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800975 @Nullable
976 public byte[] getByteArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700977 return super.getByteArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800978 }
979
980 /**
981 * Returns the value associated with the given key, or null if
982 * no mapping of the desired type exists for the given key or a null
983 * value is explicitly associated with the key.
984 *
985 * @param key a String, or null
986 * @return a short[] value, or null
987 */
Craig Mautner719e6b12014-04-04 20:29:41 -0700988 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -0800989 @Nullable
990 public short[] getShortArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -0700991 return super.getShortArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 }
993
994 /**
995 * Returns the value associated with the given key, or null if
996 * no mapping of the desired type exists for the given key or a null
997 * value is explicitly associated with the key.
998 *
999 * @param key a String, or null
1000 * @return a char[] value, or null
1001 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001002 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001003 @Nullable
1004 public char[] getCharArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001005 return super.getCharArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 }
1007
1008 /**
1009 * Returns the value associated with the given key, or null if
1010 * no mapping of the desired type exists for the given key or a null
1011 * value is explicitly associated with the key.
1012 *
1013 * @param key a String, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 * @return a float[] value, or null
1015 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001016 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001017 @Nullable
1018 public float[] getFloatArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001019 return super.getFloatArray(key);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001020 }
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
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001028 * @return a CharSequence[] value, or null
1029 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001030 @Override
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001031 @Nullable
1032 public CharSequence[] getCharSequenceArray(@Nullable String key) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001033 return super.getCharSequenceArray(key);
Bjorn Bringert08bbffb2010-02-25 11:16:22 +00001034 }
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001042 * @return an IBinder value, or null
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001043 */
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001044 @Nullable
1045 public IBinder getBinder(@Nullable String key) {
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001046 unparcel();
1047 Object o = mMap.get(key);
1048 if (o == null) {
1049 return null;
1050 }
1051 try {
1052 return (IBinder) o;
1053 } catch (ClassCastException e) {
1054 typeWarning(key, o, "IBinder", e);
1055 return null;
1056 }
1057 }
1058
1059 /**
1060 * Returns the value associated with the given key, or null if
1061 * no mapping of the desired type exists for the given key or a null
1062 * value is explicitly associated with the key.
1063 *
1064 * @param key a String, or null
1065 * @return an IBinder value, or null
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 *
1067 * @deprecated
Dianne Hackborn3cbdddb2013-02-25 18:37:18 -08001068 * @hide This is the old name of the function.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001069 */
1070 @Deprecated
Scott Kennedyc6a65dff2015-03-01 17:10:10 -08001071 @Nullable
1072 public IBinder getIBinder(@Nullable String key) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073 unparcel();
1074 Object o = mMap.get(key);
1075 if (o == null) {
1076 return null;
1077 }
1078 try {
1079 return (IBinder) o;
1080 } catch (ClassCastException e) {
1081 typeWarning(key, o, "IBinder", e);
1082 return null;
1083 }
1084 }
1085
1086 public static final Parcelable.Creator<Bundle> CREATOR =
1087 new Parcelable.Creator<Bundle>() {
Craig Mautner719e6b12014-04-04 20:29:41 -07001088 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001089 public Bundle createFromParcel(Parcel in) {
1090 return in.readBundle();
1091 }
1092
Craig Mautner719e6b12014-04-04 20:29:41 -07001093 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 public Bundle[] newArray(int size) {
1095 return new Bundle[size];
1096 }
1097 };
1098
1099 /**
1100 * Report the nature of this Parcelable's contents
1101 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001102 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 public int describeContents() {
1104 int mask = 0;
1105 if (hasFileDescriptors()) {
1106 mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR;
1107 }
1108 return mask;
1109 }
Craig Mautner719e6b12014-04-04 20:29:41 -07001110
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001111 /**
1112 * Writes the Bundle contents to a Parcel, typically in order for
1113 * it to be passed through an IBinder connection.
1114 * @param parcel The parcel to copy this bundle to.
1115 */
Craig Mautner719e6b12014-04-04 20:29:41 -07001116 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 public void writeToParcel(Parcel parcel, int flags) {
Jeff Sharkeyd136e512016-03-09 22:30:56 -07001118 final boolean oldAllowFds = parcel.pushAllowFds((mFlags & FLAG_ALLOW_FDS) != 0);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001119 try {
Craig Mautner719e6b12014-04-04 20:29:41 -07001120 super.writeToParcelInner(parcel, flags);
Dianne Hackborn9ecebbf2011-09-28 23:19:47 -04001121 } finally {
Dianne Hackbornc04db7e2011-10-03 21:09:35 -07001122 parcel.restoreAllowFds(oldAllowFds);
Dianne Hackborn6aff9052009-05-22 13:20:23 -07001123 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 }
1125
1126 /**
1127 * Reads the Parcel contents into this Bundle, typically in order for
1128 * it to be passed through an IBinder connection.
1129 * @param parcel The parcel to overwrite this bundle from.
1130 */
1131 public void readFromParcel(Parcel parcel) {
Craig Mautner719e6b12014-04-04 20:29:41 -07001132 super.readFromParcelInner(parcel);
Jeff Sharkey7410fb42016-03-16 21:23:29 -06001133 mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS;
Jeff Sharkeyd136e512016-03-09 22:30:56 -07001134 if (mParcelledData.hasFileDescriptors()) {
1135 mFlags |= FLAG_HAS_FDS;
1136 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 }
1138
1139 @Override
1140 public synchronized String toString() {
1141 if (mParcelledData != null) {
Dianne Hackborn8aee64d2013-10-25 10:41:50 -07001142 if (mParcelledData == EMPTY_PARCEL) {
1143 return "Bundle[EMPTY_PARCEL]";
1144 } else {
1145 return "Bundle[mParcelledData.dataSize=" +
1146 mParcelledData.dataSize() + "]";
1147 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 }
1149 return "Bundle[" + mMap.toString() + "]";
1150 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151}