The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.os; |
| 18 | |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Dianne Hackborn | b87655b | 2013-07-17 19:06:22 -0700 | [diff] [blame] | 20 | import android.util.ArrayMap; |
Jeff Sharkey | 5ef3398 | 2014-09-04 18:13:39 -0700 | [diff] [blame] | 21 | import android.util.Size; |
| 22 | import android.util.SizeF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.util.SparseArray; |
| 24 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 25 | import com.android.internal.annotations.VisibleForTesting; |
| 26 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import java.io.Serializable; |
| 28 | import java.util.ArrayList; |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 29 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | /** |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 32 | * A mapping from String keys to various {@link Parcelable} values. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | * |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 34 | * @see PersistableBundle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | */ |
Craig Mautner | 0a8e160e | 2014-05-29 10:27:32 -0700 | [diff] [blame] | 36 | public final class Bundle extends BaseBundle implements Cloneable, Parcelable { |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 37 | @VisibleForTesting |
| 38 | static final int FLAG_HAS_FDS = 1 << 8; |
| 39 | |
| 40 | @VisibleForTesting |
| 41 | static final int FLAG_HAS_FDS_KNOWN = 1 << 9; |
| 42 | |
| 43 | @VisibleForTesting |
| 44 | static final int FLAG_ALLOW_FDS = 1 << 10; |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 45 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | public static final Bundle EMPTY; |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 47 | |
Makoto Onuki | 97f82f2 | 2017-05-31 16:20:21 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Special extras used to denote extras have been stripped off. |
| 50 | * @hide |
| 51 | */ |
| 52 | public static final Bundle STRIPPED; |
| 53 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | static { |
| 55 | EMPTY = new Bundle(); |
Dianne Hackborn | b87655b | 2013-07-17 19:06:22 -0700 | [diff] [blame] | 56 | EMPTY.mMap = ArrayMap.EMPTY; |
Makoto Onuki | 97f82f2 | 2017-05-31 16:20:21 -0700 | [diff] [blame] | 57 | |
| 58 | STRIPPED = new Bundle(); |
| 59 | STRIPPED.putInt("STRIPPED", 1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | } |
| 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | * Constructs a new, empty Bundle. |
| 64 | */ |
| 65 | public Bundle() { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 66 | super(); |
Jeff Sharkey | 7410fb4 | 2016-03-16 21:23:29 -0600 | [diff] [blame] | 67 | mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Constructs a Bundle whose data is stored as a Parcel. The data |
| 72 | * will be unparcelled on first contact, using the assigned ClassLoader. |
| 73 | * |
| 74 | * @param parcelledData a Parcel containing a Bundle |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 75 | * |
| 76 | * @hide |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | */ |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 78 | @VisibleForTesting |
| 79 | public Bundle(Parcel parcelledData) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 80 | super(parcelledData); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 81 | mFlags = FLAG_ALLOW_FDS; |
| 82 | maybePrefillHasFds(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Constructor from a parcel for when the length is known *and is not stored in the parcel.* |
| 87 | * The other constructor that takes a parcel assumes the length is in the parcel. |
| 88 | * |
| 89 | * @hide |
| 90 | */ |
| 91 | @VisibleForTesting |
| 92 | public Bundle(Parcel parcelledData, int length) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 93 | super(parcelledData, length); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 94 | mFlags = FLAG_ALLOW_FDS; |
| 95 | maybePrefillHasFds(); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * If {@link #mParcelledData} is not null, copy the HAS FDS bit from it because it's fast. |
| 100 | * Otherwise (if {@link #mParcelledData} is already null), leave {@link #FLAG_HAS_FDS_KNOWN} |
| 101 | * unset, because scanning a map is slower. We'll do it lazily in |
| 102 | * {@link #hasFileDescriptors()}. |
| 103 | */ |
| 104 | private void maybePrefillHasFds() { |
| 105 | if (mParcelledData != null) { |
| 106 | if (mParcelledData.hasFileDescriptors()) { |
| 107 | mFlags |= FLAG_HAS_FDS | FLAG_HAS_FDS_KNOWN; |
| 108 | } else { |
| 109 | mFlags |= FLAG_HAS_FDS_KNOWN; |
| 110 | } |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 111 | } |
Dianne Hackborn | 6aff905 | 2009-05-22 13:20:23 -0700 | [diff] [blame] | 112 | } |
| 113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | /** |
| 115 | * Constructs a new, empty Bundle that uses a specific ClassLoader for |
| 116 | * instantiating Parcelable and Serializable objects. |
| 117 | * |
| 118 | * @param loader An explicit ClassLoader to use when instantiating objects |
| 119 | * inside of the Bundle. |
| 120 | */ |
| 121 | public Bundle(ClassLoader loader) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 122 | super(loader); |
Jeff Sharkey | 7410fb4 | 2016-03-16 21:23:29 -0600 | [diff] [blame] | 123 | mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Constructs a new, empty Bundle sized to hold the given number of |
| 128 | * elements. The Bundle will grow as needed. |
| 129 | * |
| 130 | * @param capacity the initial capacity of the Bundle |
| 131 | */ |
| 132 | public Bundle(int capacity) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 133 | super(capacity); |
Jeff Sharkey | 7410fb4 | 2016-03-16 21:23:29 -0600 | [diff] [blame] | 134 | mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Constructs a Bundle containing a copy of the mappings from the given |
Dianne Hackborn | 2510b37 | 2017-03-03 17:01:38 -0800 | [diff] [blame] | 139 | * Bundle. Does only a shallow copy of the original Bundle -- see |
| 140 | * {@link #deepCopy()} if that is not what you want. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | * |
| 142 | * @param b a Bundle to be copied. |
Dianne Hackborn | 2510b37 | 2017-03-03 17:01:38 -0800 | [diff] [blame] | 143 | * |
| 144 | * @see #deepCopy() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | */ |
| 146 | public Bundle(Bundle b) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 147 | super(b); |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 148 | mFlags = b.mFlags; |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Constructs a Bundle containing a copy of the mappings from the given |
Dianne Hackborn | 2510b37 | 2017-03-03 17:01:38 -0800 | [diff] [blame] | 153 | * PersistableBundle. Does only a shallow copy of the PersistableBundle -- see |
| 154 | * {@link PersistableBundle#deepCopy()} if you don't want that. |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 155 | * |
Dianne Hackborn | 2510b37 | 2017-03-03 17:01:38 -0800 | [diff] [blame] | 156 | * @param b a PersistableBundle to be copied. |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 157 | */ |
| 158 | public Bundle(PersistableBundle b) { |
| 159 | super(b); |
Jeff Sharkey | 7410fb4 | 2016-03-16 21:23:29 -0600 | [diff] [blame] | 160 | mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /** |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 164 | * Constructs a Bundle without initializing it. |
| 165 | */ |
| 166 | Bundle(boolean doInit) { |
| 167 | super(doInit); |
| 168 | } |
| 169 | |
| 170 | /** |
Brad Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 171 | * Make a Bundle for a single key/value pair. |
| 172 | * |
| 173 | * @hide |
| 174 | */ |
| 175 | public static Bundle forPair(String key, String value) { |
Brad Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 176 | Bundle b = new Bundle(1); |
| 177 | b.putString(key, value); |
| 178 | return b; |
| 179 | } |
| 180 | |
| 181 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | * Changes the ClassLoader this Bundle uses when instantiating objects. |
| 183 | * |
| 184 | * @param loader An explicit ClassLoader to use when instantiating objects |
| 185 | * inside of the Bundle. |
| 186 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 187 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | public void setClassLoader(ClassLoader loader) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 189 | super.setClassLoader(loader); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /** |
Dianne Hackborn | 5164246 | 2010-10-28 10:32:37 -0700 | [diff] [blame] | 193 | * Return the ClassLoader currently associated with this Bundle. |
| 194 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 195 | @Override |
Dianne Hackborn | 5164246 | 2010-10-28 10:32:37 -0700 | [diff] [blame] | 196 | public ClassLoader getClassLoader() { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 197 | return super.getClassLoader(); |
Dianne Hackborn | 5164246 | 2010-10-28 10:32:37 -0700 | [diff] [blame] | 198 | } |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 199 | |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 200 | /** {@hide} */ |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 201 | public boolean setAllowFds(boolean allowFds) { |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 202 | final boolean orig = (mFlags & FLAG_ALLOW_FDS) != 0; |
| 203 | if (allowFds) { |
| 204 | mFlags |= FLAG_ALLOW_FDS; |
| 205 | } else { |
| 206 | mFlags &= ~FLAG_ALLOW_FDS; |
| 207 | } |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 208 | return orig; |
| 209 | } |
| 210 | |
Dianne Hackborn | 5164246 | 2010-10-28 10:32:37 -0700 | [diff] [blame] | 211 | /** |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 212 | * Mark if this Bundle is okay to "defuse." That is, it's okay for system |
| 213 | * processes to ignore any {@link BadParcelableException} encountered when |
| 214 | * unparceling it, leaving an empty bundle in its place. |
| 215 | * <p> |
| 216 | * This should <em>only</em> be set when the Bundle reaches its final |
| 217 | * destination, otherwise a system process may clobber contents that were |
| 218 | * destined for an app that could have unparceled them. |
| 219 | * |
| 220 | * @hide |
| 221 | */ |
| 222 | public void setDefusable(boolean defusable) { |
| 223 | if (defusable) { |
| 224 | mFlags |= FLAG_DEFUSABLE; |
| 225 | } else { |
| 226 | mFlags &= ~FLAG_DEFUSABLE; |
| 227 | } |
| 228 | } |
| 229 | |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 230 | /** {@hide} */ |
| 231 | public static Bundle setDefusable(Bundle bundle, boolean defusable) { |
| 232 | if (bundle != null) { |
| 233 | bundle.setDefusable(defusable); |
| 234 | } |
| 235 | return bundle; |
| 236 | } |
| 237 | |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 238 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | * Clones the current Bundle. The internal map is cloned, but the keys and |
| 240 | * values to which it refers are copied by reference. |
| 241 | */ |
| 242 | @Override |
| 243 | public Object clone() { |
| 244 | return new Bundle(this); |
| 245 | } |
| 246 | |
| 247 | /** |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 248 | * Make a deep copy of the given bundle. Traverses into inner containers and copies |
| 249 | * them as well, so they are not shared across bundles. Will traverse in to |
| 250 | * {@link Bundle}, {@link PersistableBundle}, {@link ArrayList}, and all types of |
| 251 | * primitive arrays. Other types of objects (such as Parcelable or Serializable) |
| 252 | * are referenced as-is and not copied in any way. |
| 253 | */ |
Dianne Hackborn | 2510b37 | 2017-03-03 17:01:38 -0800 | [diff] [blame] | 254 | public Bundle deepCopy() { |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 255 | Bundle b = new Bundle(false); |
| 256 | b.copyInternal(this, true); |
| 257 | return b; |
| 258 | } |
| 259 | |
| 260 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | * Removes all elements from the mapping of this Bundle. |
| 262 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 263 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 | public void clear() { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 265 | super.clear(); |
Jeff Sharkey | 7410fb4 | 2016-03-16 21:23:29 -0600 | [diff] [blame] | 266 | mFlags = FLAG_HAS_FDS_KNOWN | FLAG_ALLOW_FDS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /** |
Christopher Tate | 250985f | 2016-03-31 13:57:42 -0700 | [diff] [blame] | 270 | * Removes any entry with the given key from the mapping of this Bundle. |
| 271 | * |
| 272 | * @param key a String key |
| 273 | */ |
| 274 | public void remove(String key) { |
| 275 | super.remove(key); |
| 276 | if ((mFlags & FLAG_HAS_FDS) != 0) { |
| 277 | mFlags &= ~FLAG_HAS_FDS_KNOWN; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | * Inserts all mappings from the given Bundle into this Bundle. |
| 283 | * |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 284 | * @param bundle a Bundle |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 286 | public void putAll(Bundle bundle) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | unparcel(); |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 288 | bundle.unparcel(); |
| 289 | mMap.putAll(bundle.mMap); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 291 | // FD state is now known if and only if both bundles already knew |
| 292 | if ((bundle.mFlags & FLAG_HAS_FDS) != 0) { |
| 293 | mFlags |= FLAG_HAS_FDS; |
| 294 | } |
| 295 | if ((bundle.mFlags & FLAG_HAS_FDS_KNOWN) == 0) { |
| 296 | mFlags &= ~FLAG_HAS_FDS_KNOWN; |
| 297 | } |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
Sudheer Shanka | fab200f | 2017-05-17 20:41:53 -0700 | [diff] [blame] | 301 | * Return the size of {@link #mParcelledData} in bytes if available, otherwise {@code 0}. |
| 302 | * |
| 303 | * @hide |
| 304 | */ |
| 305 | public int getSize() { |
| 306 | if (mParcelledData != null) { |
| 307 | return mParcelledData.dataSize(); |
| 308 | } else { |
| 309 | return 0; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | * Reports whether the bundle contains any parcelled file descriptors. |
| 315 | */ |
| 316 | public boolean hasFileDescriptors() { |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 317 | if ((mFlags & FLAG_HAS_FDS_KNOWN) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | boolean fdFound = false; // keep going until we find one or run out of data |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 319 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | if (mParcelledData != null) { |
| 321 | if (mParcelledData.hasFileDescriptors()) { |
| 322 | fdFound = true; |
| 323 | } |
| 324 | } else { |
| 325 | // It's been unparcelled, so we need to walk the map |
Dianne Hackborn | b87655b | 2013-07-17 19:06:22 -0700 | [diff] [blame] | 326 | for (int i=mMap.size()-1; i>=0; i--) { |
| 327 | Object obj = mMap.valueAt(i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | if (obj instanceof Parcelable) { |
| 329 | if ((((Parcelable)obj).describeContents() |
| 330 | & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) { |
| 331 | fdFound = true; |
| 332 | break; |
| 333 | } |
| 334 | } else if (obj instanceof Parcelable[]) { |
| 335 | Parcelable[] array = (Parcelable[]) obj; |
| 336 | for (int n = array.length - 1; n >= 0; n--) { |
Taiju Tsuiki | e58c785 | 2015-04-22 16:59:00 +0900 | [diff] [blame] | 337 | Parcelable p = array[n]; |
| 338 | if (p != null && ((p.describeContents() |
| 339 | & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | fdFound = true; |
| 341 | break; |
| 342 | } |
| 343 | } |
| 344 | } else if (obj instanceof SparseArray) { |
| 345 | SparseArray<? extends Parcelable> array = |
| 346 | (SparseArray<? extends Parcelable>) obj; |
| 347 | for (int n = array.size() - 1; n >= 0; n--) { |
Taiju Tsuiki | ecd2184 | 2015-04-28 13:36:15 +0900 | [diff] [blame] | 348 | Parcelable p = array.valueAt(n); |
| 349 | if (p != null && (p.describeContents() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) { |
| 351 | fdFound = true; |
| 352 | break; |
| 353 | } |
| 354 | } |
| 355 | } else if (obj instanceof ArrayList) { |
| 356 | ArrayList array = (ArrayList) obj; |
| 357 | // an ArrayList here might contain either Strings or |
| 358 | // Parcelables; only look inside for Parcelables |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 359 | if (!array.isEmpty() && (array.get(0) instanceof Parcelable)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | for (int n = array.size() - 1; n >= 0; n--) { |
| 361 | Parcelable p = (Parcelable) array.get(n); |
| 362 | if (p != null && ((p.describeContents() |
| 363 | & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) { |
| 364 | fdFound = true; |
| 365 | break; |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 373 | if (fdFound) { |
| 374 | mFlags |= FLAG_HAS_FDS; |
Christopher Tate | 250985f | 2016-03-31 13:57:42 -0700 | [diff] [blame] | 375 | } else { |
| 376 | mFlags &= ~FLAG_HAS_FDS; |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 377 | } |
| 378 | mFlags |= FLAG_HAS_FDS_KNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | } |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 380 | return (mFlags & FLAG_HAS_FDS) != 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | } |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | /** |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 384 | * Filter values in Bundle to only basic types. |
| 385 | * @hide |
| 386 | */ |
Dianne Hackborn | 851ec49 | 2016-10-12 17:20:07 -0700 | [diff] [blame] | 387 | public Bundle filterValues() { |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 388 | unparcel(); |
Dianne Hackborn | 851ec49 | 2016-10-12 17:20:07 -0700 | [diff] [blame] | 389 | Bundle bundle = this; |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 390 | if (mMap != null) { |
Dianne Hackborn | 851ec49 | 2016-10-12 17:20:07 -0700 | [diff] [blame] | 391 | ArrayMap<String, Object> map = mMap; |
| 392 | for (int i = map.size() - 1; i >= 0; i--) { |
| 393 | Object value = map.valueAt(i); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 394 | if (PersistableBundle.isValidType(value)) { |
| 395 | continue; |
| 396 | } |
| 397 | if (value instanceof Bundle) { |
Dianne Hackborn | 851ec49 | 2016-10-12 17:20:07 -0700 | [diff] [blame] | 398 | Bundle newBundle = ((Bundle)value).filterValues(); |
| 399 | if (newBundle != value) { |
| 400 | if (map == mMap) { |
| 401 | // The filter had to generate a new bundle, but we have not yet |
| 402 | // created a new one here. Do that now. |
| 403 | bundle = new Bundle(this); |
| 404 | // Note the ArrayMap<> constructor is guaranteed to generate |
| 405 | // a new object with items in the same order as the original. |
| 406 | map = bundle.mMap; |
| 407 | } |
| 408 | // Replace this current entry with the new child bundle. |
| 409 | map.setValueAt(i, newBundle); |
| 410 | } |
| 411 | continue; |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 412 | } |
| 413 | if (value.getClass().getName().startsWith("android.")) { |
| 414 | continue; |
| 415 | } |
Dianne Hackborn | 851ec49 | 2016-10-12 17:20:07 -0700 | [diff] [blame] | 416 | if (map == mMap) { |
| 417 | // This is the first time we have had to remove something, that means we |
| 418 | // need to switch to a new Bundle. |
| 419 | bundle = new Bundle(this); |
| 420 | // Note the ArrayMap<> constructor is guaranteed to generate |
| 421 | // a new object with items in the same order as the original. |
| 422 | map = bundle.mMap; |
| 423 | } |
| 424 | map.removeAt(i); |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
Christopher Tate | 250985f | 2016-03-31 13:57:42 -0700 | [diff] [blame] | 427 | mFlags |= FLAG_HAS_FDS_KNOWN; |
| 428 | mFlags &= ~FLAG_HAS_FDS; |
Dianne Hackborn | 851ec49 | 2016-10-12 17:20:07 -0700 | [diff] [blame] | 429 | return bundle; |
Dianne Hackborn | a83ce1d | 2015-03-11 15:16:13 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 433 | * Inserts a byte value into the mapping of this Bundle, replacing |
| 434 | * any existing value for the given key. |
| 435 | * |
| 436 | * @param key a String, or null |
| 437 | * @param value a byte |
| 438 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 439 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 440 | public void putByte(@Nullable String key, byte value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 441 | super.putByte(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Inserts a char value into the mapping of this Bundle, replacing |
| 446 | * any existing value for the given key. |
| 447 | * |
| 448 | * @param key a String, or null |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 449 | * @param value a char |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 451 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 452 | public void putChar(@Nullable String key, char value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 453 | super.putChar(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Inserts a short value into the mapping of this Bundle, replacing |
| 458 | * any existing value for the given key. |
| 459 | * |
| 460 | * @param key a String, or null |
| 461 | * @param value a short |
| 462 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 463 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 464 | public void putShort(@Nullable String key, short value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 465 | super.putShort(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | * Inserts a float value into the mapping of this Bundle, replacing |
| 470 | * any existing value for the given key. |
| 471 | * |
| 472 | * @param key a String, or null |
| 473 | * @param value a float |
| 474 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 475 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 476 | public void putFloat(@Nullable String key, float value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 477 | super.putFloat(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | * Inserts a CharSequence value into the mapping of this Bundle, replacing |
| 482 | * any existing value for the given key. Either key or value may be null. |
| 483 | * |
| 484 | * @param key a String, or null |
| 485 | * @param value a CharSequence, or null |
| 486 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 487 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 488 | public void putCharSequence(@Nullable String key, @Nullable CharSequence value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 489 | super.putCharSequence(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Inserts a Parcelable value into the mapping of this Bundle, replacing |
| 494 | * any existing value for the given key. Either key or value may be null. |
| 495 | * |
| 496 | * @param key a String, or null |
| 497 | * @param value a Parcelable object, or null |
| 498 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 499 | public void putParcelable(@Nullable String key, @Nullable Parcelable value) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | unparcel(); |
| 501 | mMap.put(key, value); |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 502 | mFlags &= ~FLAG_HAS_FDS_KNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /** |
Jeff Sharkey | 5ef3398 | 2014-09-04 18:13:39 -0700 | [diff] [blame] | 506 | * Inserts a Size value into the mapping of this Bundle, replacing |
| 507 | * any existing value for the given key. Either key or value may be null. |
| 508 | * |
| 509 | * @param key a String, or null |
| 510 | * @param value a Size object, or null |
| 511 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 512 | public void putSize(@Nullable String key, @Nullable Size value) { |
Jeff Sharkey | 5ef3398 | 2014-09-04 18:13:39 -0700 | [diff] [blame] | 513 | unparcel(); |
| 514 | mMap.put(key, value); |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * Inserts a SizeF value into the mapping of this Bundle, replacing |
| 519 | * any existing value for the given key. Either key or value may be null. |
| 520 | * |
| 521 | * @param key a String, or null |
| 522 | * @param value a SizeF object, or null |
| 523 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 524 | public void putSizeF(@Nullable String key, @Nullable SizeF value) { |
Jeff Sharkey | 5ef3398 | 2014-09-04 18:13:39 -0700 | [diff] [blame] | 525 | unparcel(); |
| 526 | mMap.put(key, value); |
| 527 | } |
| 528 | |
| 529 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | * Inserts an array of Parcelable values into the mapping of this Bundle, |
| 531 | * replacing any existing value for the given key. Either key or value may |
| 532 | * be null. |
| 533 | * |
| 534 | * @param key a String, or null |
| 535 | * @param value an array of Parcelable objects, or null |
| 536 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 537 | public void putParcelableArray(@Nullable String key, @Nullable Parcelable[] value) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 538 | unparcel(); |
| 539 | mMap.put(key, value); |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 540 | mFlags &= ~FLAG_HAS_FDS_KNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
| 544 | * Inserts a List of Parcelable values into the mapping of this Bundle, |
| 545 | * replacing any existing value for the given key. Either key or value may |
| 546 | * be null. |
| 547 | * |
| 548 | * @param key a String, or null |
| 549 | * @param value an ArrayList of Parcelable objects, or null |
| 550 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 551 | public void putParcelableArrayList(@Nullable String key, |
| 552 | @Nullable ArrayList<? extends Parcelable> value) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 553 | unparcel(); |
| 554 | mMap.put(key, value); |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 555 | mFlags &= ~FLAG_HAS_FDS_KNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 556 | } |
| 557 | |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 558 | /** {@hide} */ |
| 559 | public void putParcelableList(String key, List<? extends Parcelable> value) { |
| 560 | unparcel(); |
| 561 | mMap.put(key, value); |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 562 | mFlags &= ~FLAG_HAS_FDS_KNOWN; |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 563 | } |
| 564 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | /** |
| 566 | * Inserts a SparceArray of Parcelable values into the mapping of this |
| 567 | * Bundle, replacing any existing value for the given key. Either key |
| 568 | * or value may be null. |
| 569 | * |
| 570 | * @param key a String, or null |
| 571 | * @param value a SparseArray of Parcelable objects, or null |
| 572 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 573 | public void putSparseParcelableArray(@Nullable String key, |
| 574 | @Nullable SparseArray<? extends Parcelable> value) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | unparcel(); |
| 576 | mMap.put(key, value); |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 577 | mFlags &= ~FLAG_HAS_FDS_KNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Inserts an ArrayList<Integer> value into the mapping of this Bundle, replacing |
| 582 | * any existing value for the given key. Either key or value may be null. |
| 583 | * |
| 584 | * @param key a String, or null |
| 585 | * @param value an ArrayList<Integer> object, or null |
| 586 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 587 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 588 | public void putIntegerArrayList(@Nullable String key, @Nullable ArrayList<Integer> value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 589 | super.putIntegerArrayList(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Inserts an ArrayList<String> value into the mapping of this Bundle, replacing |
| 594 | * any existing value for the given key. Either key or value may be null. |
| 595 | * |
| 596 | * @param key a String, or null |
| 597 | * @param value an ArrayList<String> object, or null |
| 598 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 599 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 600 | public void putStringArrayList(@Nullable String key, @Nullable ArrayList<String> value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 601 | super.putStringArrayList(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /** |
Bjorn Bringert | 08bbffb | 2010-02-25 11:16:22 +0000 | [diff] [blame] | 605 | * Inserts an ArrayList<CharSequence> value into the mapping of this Bundle, replacing |
| 606 | * any existing value for the given key. Either key or value may be null. |
| 607 | * |
| 608 | * @param key a String, or null |
| 609 | * @param value an ArrayList<CharSequence> object, or null |
| 610 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 611 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 612 | public void putCharSequenceArrayList(@Nullable String key, |
| 613 | @Nullable ArrayList<CharSequence> value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 614 | super.putCharSequenceArrayList(key, value); |
Bjorn Bringert | 08bbffb | 2010-02-25 11:16:22 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | * Inserts a Serializable value into the mapping of this Bundle, replacing |
| 619 | * any existing value for the given key. Either key or value may be null. |
| 620 | * |
| 621 | * @param key a String, or null |
| 622 | * @param value a Serializable object, or null |
| 623 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 624 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 625 | public void putSerializable(@Nullable String key, @Nullable Serializable value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 626 | super.putSerializable(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | * Inserts a byte array value into the mapping of this Bundle, replacing |
| 631 | * any existing value for the given key. Either key or value may be null. |
| 632 | * |
| 633 | * @param key a String, or null |
| 634 | * @param value a byte array object, or null |
| 635 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 636 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 637 | public void putByteArray(@Nullable String key, @Nullable byte[] value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 638 | super.putByteArray(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Inserts a short array value into the mapping of this Bundle, replacing |
| 643 | * any existing value for the given key. Either key or value may be null. |
| 644 | * |
| 645 | * @param key a String, or null |
| 646 | * @param value a short array object, or null |
| 647 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 648 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 649 | public void putShortArray(@Nullable String key, @Nullable short[] value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 650 | super.putShortArray(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Inserts a char array value into the mapping of this Bundle, replacing |
| 655 | * any existing value for the given key. Either key or value may be null. |
| 656 | * |
| 657 | * @param key a String, or null |
| 658 | * @param value a char array object, or null |
| 659 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 660 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 661 | public void putCharArray(@Nullable String key, @Nullable char[] value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 662 | super.putCharArray(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | * Inserts a float array value into the mapping of this Bundle, replacing |
| 667 | * any existing value for the given key. Either key or value may be null. |
| 668 | * |
| 669 | * @param key a String, or null |
| 670 | * @param value a float array object, or null |
| 671 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 672 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 673 | public void putFloatArray(@Nullable String key, @Nullable float[] value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 674 | super.putFloatArray(key, value); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /** |
Bjorn Bringert | 08bbffb | 2010-02-25 11:16:22 +0000 | [diff] [blame] | 678 | * Inserts a CharSequence array value into the mapping of this Bundle, replacing |
| 679 | * any existing value for the given key. Either key or value may be null. |
| 680 | * |
| 681 | * @param key a String, or null |
| 682 | * @param value a CharSequence array object, or null |
| 683 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 684 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 685 | public void putCharSequenceArray(@Nullable String key, @Nullable CharSequence[] value) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 686 | super.putCharSequenceArray(key, value); |
Bjorn Bringert | 08bbffb | 2010-02-25 11:16:22 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | * Inserts a Bundle value into the mapping of this Bundle, replacing |
| 691 | * any existing value for the given key. Either key or value may be null. |
| 692 | * |
| 693 | * @param key a String, or null |
| 694 | * @param value a Bundle object, or null |
| 695 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 696 | public void putBundle(@Nullable String key, @Nullable Bundle value) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | unparcel(); |
| 698 | mMap.put(key, value); |
| 699 | } |
| 700 | |
| 701 | /** |
Dianne Hackborn | 3cbdddb | 2013-02-25 18:37:18 -0800 | [diff] [blame] | 702 | * Inserts an {@link IBinder} value into the mapping of this Bundle, replacing |
| 703 | * any existing value for the given key. Either key or value may be null. |
| 704 | * |
| 705 | * <p class="note">You should be very careful when using this function. In many |
| 706 | * places where Bundles are used (such as inside of Intent objects), the Bundle |
| 707 | * can live longer inside of another process than the process that had originally |
| 708 | * created it. In that case, the IBinder you supply here will become invalid |
| 709 | * when your process goes away, and no longer usable, even if a new process is |
| 710 | * created for you later on.</p> |
| 711 | * |
| 712 | * @param key a String, or null |
| 713 | * @param value an IBinder object, or null |
| 714 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 715 | public void putBinder(@Nullable String key, @Nullable IBinder value) { |
Dianne Hackborn | 3cbdddb | 2013-02-25 18:37:18 -0800 | [diff] [blame] | 716 | unparcel(); |
| 717 | mMap.put(key, value); |
| 718 | } |
| 719 | |
| 720 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 721 | * Inserts an IBinder value into the mapping of this Bundle, replacing |
| 722 | * any existing value for the given key. Either key or value may be null. |
| 723 | * |
| 724 | * @param key a String, or null |
| 725 | * @param value an IBinder object, or null |
| 726 | * |
| 727 | * @deprecated |
Dianne Hackborn | 3cbdddb | 2013-02-25 18:37:18 -0800 | [diff] [blame] | 728 | * @hide This is the old name of the function. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | */ |
| 730 | @Deprecated |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 731 | public void putIBinder(@Nullable String key, @Nullable IBinder value) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 732 | unparcel(); |
| 733 | mMap.put(key, value); |
| 734 | } |
| 735 | |
| 736 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | * Returns the value associated with the given key, or (byte) 0 if |
| 738 | * no mapping of the desired type exists for the given key. |
| 739 | * |
| 740 | * @param key a String |
| 741 | * @return a byte value |
| 742 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 743 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | public byte getByte(String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 745 | return super.getByte(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /** |
| 749 | * Returns the value associated with the given key, or defaultValue if |
| 750 | * no mapping of the desired type exists for the given key. |
| 751 | * |
| 752 | * @param key a String |
Nicolas Klein | 9f6cb87 | 2012-11-30 14:41:46 -0800 | [diff] [blame] | 753 | * @param defaultValue Value to return if key does not exist |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | * @return a byte value |
| 755 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 756 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | public Byte getByte(String key, byte defaultValue) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 758 | return super.getByte(key, defaultValue); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | /** |
Nicolas Klein | 9f6cb87 | 2012-11-30 14:41:46 -0800 | [diff] [blame] | 762 | * Returns the value associated with the given key, or (char) 0 if |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 763 | * no mapping of the desired type exists for the given key. |
| 764 | * |
| 765 | * @param key a String |
| 766 | * @return a char value |
| 767 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 768 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | public char getChar(String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 770 | return super.getChar(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | /** |
Nicolas Klein | 9f6cb87 | 2012-11-30 14:41:46 -0800 | [diff] [blame] | 774 | * Returns the value associated with the given key, or defaultValue if |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | * no mapping of the desired type exists for the given key. |
| 776 | * |
| 777 | * @param key a String |
Nicolas Klein | 9f6cb87 | 2012-11-30 14:41:46 -0800 | [diff] [blame] | 778 | * @param defaultValue Value to return if key does not exist |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 779 | * @return a char value |
| 780 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 781 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | public char getChar(String key, char defaultValue) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 783 | return super.getChar(key, defaultValue); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /** |
| 787 | * Returns the value associated with the given key, or (short) 0 if |
| 788 | * no mapping of the desired type exists for the given key. |
| 789 | * |
| 790 | * @param key a String |
| 791 | * @return a short value |
| 792 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 793 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | public short getShort(String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 795 | return super.getShort(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Returns the value associated with the given key, or defaultValue if |
| 800 | * no mapping of the desired type exists for the given key. |
| 801 | * |
| 802 | * @param key a String |
Nicolas Klein | 9f6cb87 | 2012-11-30 14:41:46 -0800 | [diff] [blame] | 803 | * @param defaultValue Value to return if key does not exist |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | * @return a short value |
| 805 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 806 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | public short getShort(String key, short defaultValue) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 808 | return super.getShort(key, defaultValue); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | * Returns the value associated with the given key, or 0.0f if |
| 813 | * no mapping of the desired type exists for the given key. |
| 814 | * |
| 815 | * @param key a String |
| 816 | * @return a float value |
| 817 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 818 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | public float getFloat(String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 820 | return super.getFloat(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | /** |
| 824 | * Returns the value associated with the given key, or defaultValue if |
| 825 | * no mapping of the desired type exists for the given key. |
| 826 | * |
| 827 | * @param key a String |
Nicolas Klein | 9f6cb87 | 2012-11-30 14:41:46 -0800 | [diff] [blame] | 828 | * @param defaultValue Value to return if key does not exist |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | * @return a float value |
| 830 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 831 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | public float getFloat(String key, float defaultValue) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 833 | return super.getFloat(key, defaultValue); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 837 | * Returns the value associated with the given key, or null if |
| 838 | * no mapping of the desired type exists for the given key or a null |
| 839 | * value is explicitly associated with the key. |
| 840 | * |
| 841 | * @param key a String, or null |
| 842 | * @return a CharSequence value, or null |
| 843 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 844 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 845 | @Nullable |
| 846 | public CharSequence getCharSequence(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 847 | return super.getCharSequence(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | /** |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 851 | * Returns the value associated with the given key, or defaultValue if |
Narayan Kamath | ca2197b | 2014-06-19 10:46:00 +0100 | [diff] [blame] | 852 | * no mapping of the desired type exists for the given key or if a null |
| 853 | * value is explicitly associatd with the given key. |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 854 | * |
| 855 | * @param key a String, or null |
Narayan Kamath | ca2197b | 2014-06-19 10:46:00 +0100 | [diff] [blame] | 856 | * @param defaultValue Value to return if key does not exist or if a null |
| 857 | * value is associated with the given key. |
Christopher Tate | 116751d | 2012-12-20 18:57:09 -0800 | [diff] [blame] | 858 | * @return the CharSequence value associated with the given key, or defaultValue |
| 859 | * if no valid CharSequence object is currently mapped to that key. |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 860 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 861 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 862 | public CharSequence getCharSequence(@Nullable String key, CharSequence defaultValue) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 863 | return super.getCharSequence(key, defaultValue); |
Dianne Hackborn | e3a7f62 | 2011-03-03 21:48:24 -0800 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | * Returns the value associated with the given key, or null if |
| 868 | * no mapping of the desired type exists for the given key or a null |
| 869 | * value is explicitly associated with the key. |
| 870 | * |
| 871 | * @param key a String, or null |
Jeff Sharkey | 5ef3398 | 2014-09-04 18:13:39 -0700 | [diff] [blame] | 872 | * @return a Size value, or null |
| 873 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 874 | @Nullable |
| 875 | public Size getSize(@Nullable String key) { |
Jeff Sharkey | 5ef3398 | 2014-09-04 18:13:39 -0700 | [diff] [blame] | 876 | unparcel(); |
| 877 | final Object o = mMap.get(key); |
| 878 | try { |
| 879 | return (Size) o; |
| 880 | } catch (ClassCastException e) { |
| 881 | typeWarning(key, o, "Size", e); |
| 882 | return null; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * Returns the value associated with the given key, or null if |
| 888 | * no mapping of the desired type exists for the given key or a null |
| 889 | * value is explicitly associated with the key. |
| 890 | * |
| 891 | * @param key a String, or null |
| 892 | * @return a Size value, or null |
| 893 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 894 | @Nullable |
| 895 | public SizeF getSizeF(@Nullable String key) { |
Jeff Sharkey | 5ef3398 | 2014-09-04 18:13:39 -0700 | [diff] [blame] | 896 | unparcel(); |
| 897 | final Object o = mMap.get(key); |
| 898 | try { |
| 899 | return (SizeF) o; |
| 900 | } catch (ClassCastException e) { |
| 901 | typeWarning(key, o, "SizeF", e); |
| 902 | return null; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * Returns the value associated with the given key, or null if |
| 908 | * no mapping of the desired type exists for the given key or a null |
| 909 | * value is explicitly associated with the key. |
| 910 | * |
| 911 | * @param key a String, or null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | * @return a Bundle value, or null |
| 913 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 914 | @Nullable |
| 915 | public Bundle getBundle(@Nullable String key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | unparcel(); |
| 917 | Object o = mMap.get(key); |
| 918 | if (o == null) { |
| 919 | return null; |
| 920 | } |
| 921 | try { |
| 922 | return (Bundle) o; |
| 923 | } catch (ClassCastException e) { |
| 924 | typeWarning(key, o, "Bundle", e); |
| 925 | return null; |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * Returns the value associated with the given key, or null if |
| 931 | * no mapping of the desired type exists for the given key or a null |
| 932 | * value is explicitly associated with the key. |
| 933 | * |
| 934 | * @param key a String, or null |
| 935 | * @return a Parcelable value, or null |
| 936 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 937 | @Nullable |
| 938 | public <T extends Parcelable> T getParcelable(@Nullable String key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 939 | unparcel(); |
| 940 | Object o = mMap.get(key); |
| 941 | if (o == null) { |
| 942 | return null; |
| 943 | } |
| 944 | try { |
| 945 | return (T) o; |
| 946 | } catch (ClassCastException e) { |
| 947 | typeWarning(key, o, "Parcelable", e); |
| 948 | return null; |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | /** |
| 953 | * Returns the value associated with the given key, or null if |
| 954 | * no mapping of the desired type exists for the given key or a null |
| 955 | * value is explicitly associated with the key. |
| 956 | * |
| 957 | * @param key a String, or null |
| 958 | * @return a Parcelable[] value, or null |
| 959 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 960 | @Nullable |
| 961 | public Parcelable[] getParcelableArray(@Nullable String key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | unparcel(); |
| 963 | Object o = mMap.get(key); |
| 964 | if (o == null) { |
| 965 | return null; |
| 966 | } |
| 967 | try { |
| 968 | return (Parcelable[]) o; |
| 969 | } catch (ClassCastException e) { |
| 970 | typeWarning(key, o, "Parcelable[]", e); |
| 971 | return null; |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * Returns the value associated with the given key, or null if |
| 977 | * no mapping of the desired type exists for the given key or a null |
| 978 | * value is explicitly associated with the key. |
| 979 | * |
| 980 | * @param key a String, or null |
| 981 | * @return an ArrayList<T> value, or null |
| 982 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 983 | @Nullable |
| 984 | public <T extends Parcelable> ArrayList<T> getParcelableArrayList(@Nullable String key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | unparcel(); |
| 986 | Object o = mMap.get(key); |
| 987 | if (o == null) { |
| 988 | return null; |
| 989 | } |
| 990 | try { |
| 991 | return (ArrayList<T>) o; |
| 992 | } catch (ClassCastException e) { |
| 993 | typeWarning(key, o, "ArrayList", e); |
| 994 | return null; |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * Returns the value associated with the given key, or null if |
| 1000 | * no mapping of the desired type exists for the given key or a null |
| 1001 | * value is explicitly associated with the key. |
| 1002 | * |
| 1003 | * @param key a String, or null |
| 1004 | * |
| 1005 | * @return a SparseArray of T values, or null |
| 1006 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1007 | @Nullable |
| 1008 | public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@Nullable String key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1009 | unparcel(); |
| 1010 | Object o = mMap.get(key); |
| 1011 | if (o == null) { |
| 1012 | return null; |
| 1013 | } |
| 1014 | try { |
| 1015 | return (SparseArray<T>) o; |
| 1016 | } catch (ClassCastException e) { |
| 1017 | typeWarning(key, o, "SparseArray", e); |
| 1018 | return null; |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | /** |
| 1023 | * Returns the value associated with the given key, or null if |
| 1024 | * no mapping of the desired type exists for the given key or a null |
| 1025 | * value is explicitly associated with the key. |
| 1026 | * |
| 1027 | * @param key a String, or null |
| 1028 | * @return a Serializable value, or null |
| 1029 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1030 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1031 | @Nullable |
| 1032 | public Serializable getSerializable(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1033 | return super.getSerializable(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | /** |
| 1037 | * Returns the value associated with the given key, or null if |
| 1038 | * no mapping of the desired type exists for the given key or a null |
| 1039 | * value is explicitly associated with the key. |
| 1040 | * |
| 1041 | * @param key a String, or null |
| 1042 | * @return an ArrayList<String> value, or null |
| 1043 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1044 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1045 | @Nullable |
| 1046 | public ArrayList<Integer> getIntegerArrayList(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1047 | return super.getIntegerArrayList(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * Returns the value associated with the given key, or null if |
| 1052 | * no mapping of the desired type exists for the given key or a null |
| 1053 | * value is explicitly associated with the key. |
| 1054 | * |
| 1055 | * @param key a String, or null |
| 1056 | * @return an ArrayList<String> value, or null |
| 1057 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1058 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1059 | @Nullable |
| 1060 | public ArrayList<String> getStringArrayList(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1061 | return super.getStringArrayList(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | /** |
| 1065 | * Returns the value associated with the given key, or null if |
| 1066 | * no mapping of the desired type exists for the given key or a null |
| 1067 | * value is explicitly associated with the key. |
| 1068 | * |
| 1069 | * @param key a String, or null |
Bjorn Bringert | 08bbffb | 2010-02-25 11:16:22 +0000 | [diff] [blame] | 1070 | * @return an ArrayList<CharSequence> value, or null |
| 1071 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1072 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1073 | @Nullable |
| 1074 | public ArrayList<CharSequence> getCharSequenceArrayList(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1075 | return super.getCharSequenceArrayList(key); |
Bjorn Bringert | 08bbffb | 2010-02-25 11:16:22 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * Returns the value associated with the given key, or null if |
| 1080 | * no mapping of the desired type exists for the given key or a null |
| 1081 | * value is explicitly associated with the key. |
| 1082 | * |
| 1083 | * @param key a String, or null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | * @return a byte[] value, or null |
| 1085 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1086 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1087 | @Nullable |
| 1088 | public byte[] getByteArray(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1089 | return super.getByteArray(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * Returns the value associated with the given key, or null if |
| 1094 | * no mapping of the desired type exists for the given key or a null |
| 1095 | * value is explicitly associated with the key. |
| 1096 | * |
| 1097 | * @param key a String, or null |
| 1098 | * @return a short[] value, or null |
| 1099 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1100 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1101 | @Nullable |
| 1102 | public short[] getShortArray(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1103 | return super.getShortArray(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * Returns the value associated with the given key, or null if |
| 1108 | * no mapping of the desired type exists for the given key or a null |
| 1109 | * value is explicitly associated with the key. |
| 1110 | * |
| 1111 | * @param key a String, or null |
| 1112 | * @return a char[] value, or null |
| 1113 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1114 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1115 | @Nullable |
| 1116 | public char[] getCharArray(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1117 | return super.getCharArray(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * Returns the value associated with the given key, or null if |
| 1122 | * no mapping of the desired type exists for the given key or a null |
| 1123 | * value is explicitly associated with the key. |
| 1124 | * |
| 1125 | * @param key a String, or null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1126 | * @return a float[] value, or null |
| 1127 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1128 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1129 | @Nullable |
| 1130 | public float[] getFloatArray(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1131 | return super.getFloatArray(key); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | /** |
| 1135 | * Returns the value associated with the given key, or null if |
| 1136 | * no mapping of the desired type exists for the given key or a null |
| 1137 | * value is explicitly associated with the key. |
| 1138 | * |
| 1139 | * @param key a String, or null |
Bjorn Bringert | 08bbffb | 2010-02-25 11:16:22 +0000 | [diff] [blame] | 1140 | * @return a CharSequence[] value, or null |
| 1141 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1142 | @Override |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1143 | @Nullable |
| 1144 | public CharSequence[] getCharSequenceArray(@Nullable String key) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1145 | return super.getCharSequenceArray(key); |
Bjorn Bringert | 08bbffb | 2010-02-25 11:16:22 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | /** |
| 1149 | * Returns the value associated with the given key, or null if |
| 1150 | * no mapping of the desired type exists for the given key or a null |
| 1151 | * value is explicitly associated with the key. |
| 1152 | * |
| 1153 | * @param key a String, or null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1154 | * @return an IBinder value, or null |
Dianne Hackborn | 3cbdddb | 2013-02-25 18:37:18 -0800 | [diff] [blame] | 1155 | */ |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1156 | @Nullable |
| 1157 | public IBinder getBinder(@Nullable String key) { |
Dianne Hackborn | 3cbdddb | 2013-02-25 18:37:18 -0800 | [diff] [blame] | 1158 | unparcel(); |
| 1159 | Object o = mMap.get(key); |
| 1160 | if (o == null) { |
| 1161 | return null; |
| 1162 | } |
| 1163 | try { |
| 1164 | return (IBinder) o; |
| 1165 | } catch (ClassCastException e) { |
| 1166 | typeWarning(key, o, "IBinder", e); |
| 1167 | return null; |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | /** |
| 1172 | * Returns the value associated with the given key, or null if |
| 1173 | * no mapping of the desired type exists for the given key or a null |
| 1174 | * value is explicitly associated with the key. |
| 1175 | * |
| 1176 | * @param key a String, or null |
| 1177 | * @return an IBinder value, or null |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1178 | * |
| 1179 | * @deprecated |
Dianne Hackborn | 3cbdddb | 2013-02-25 18:37:18 -0800 | [diff] [blame] | 1180 | * @hide This is the old name of the function. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1181 | */ |
| 1182 | @Deprecated |
Scott Kennedy | c6a65dff | 2015-03-01 17:10:10 -0800 | [diff] [blame] | 1183 | @Nullable |
| 1184 | public IBinder getIBinder(@Nullable String key) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | unparcel(); |
| 1186 | Object o = mMap.get(key); |
| 1187 | if (o == null) { |
| 1188 | return null; |
| 1189 | } |
| 1190 | try { |
| 1191 | return (IBinder) o; |
| 1192 | } catch (ClassCastException e) { |
| 1193 | typeWarning(key, o, "IBinder", e); |
| 1194 | return null; |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | public static final Parcelable.Creator<Bundle> CREATOR = |
| 1199 | new Parcelable.Creator<Bundle>() { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1200 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | public Bundle createFromParcel(Parcel in) { |
| 1202 | return in.readBundle(); |
| 1203 | } |
| 1204 | |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1205 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1206 | public Bundle[] newArray(int size) { |
| 1207 | return new Bundle[size]; |
| 1208 | } |
| 1209 | }; |
| 1210 | |
| 1211 | /** |
| 1212 | * Report the nature of this Parcelable's contents |
| 1213 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1214 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1215 | public int describeContents() { |
| 1216 | int mask = 0; |
| 1217 | if (hasFileDescriptors()) { |
| 1218 | mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR; |
| 1219 | } |
| 1220 | return mask; |
| 1221 | } |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1222 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1223 | /** |
| 1224 | * Writes the Bundle contents to a Parcel, typically in order for |
| 1225 | * it to be passed through an IBinder connection. |
| 1226 | * @param parcel The parcel to copy this bundle to. |
| 1227 | */ |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1228 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | public void writeToParcel(Parcel parcel, int flags) { |
Jeff Sharkey | d136e51 | 2016-03-09 22:30:56 -0700 | [diff] [blame] | 1230 | final boolean oldAllowFds = parcel.pushAllowFds((mFlags & FLAG_ALLOW_FDS) != 0); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 1231 | try { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1232 | super.writeToParcelInner(parcel, flags); |
Dianne Hackborn | 9ecebbf | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 1233 | } finally { |
Dianne Hackborn | c04db7e | 2011-10-03 21:09:35 -0700 | [diff] [blame] | 1234 | parcel.restoreAllowFds(oldAllowFds); |
Dianne Hackborn | 6aff905 | 2009-05-22 13:20:23 -0700 | [diff] [blame] | 1235 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | /** |
| 1239 | * Reads the Parcel contents into this Bundle, typically in order for |
| 1240 | * it to be passed through an IBinder connection. |
| 1241 | * @param parcel The parcel to overwrite this bundle from. |
| 1242 | */ |
| 1243 | public void readFromParcel(Parcel parcel) { |
Craig Mautner | 719e6b1 | 2014-04-04 20:29:41 -0700 | [diff] [blame] | 1244 | super.readFromParcelInner(parcel); |
Makoto Onuki | 4501c61d | 2017-07-27 15:56:40 -0700 | [diff] [blame] | 1245 | mFlags = FLAG_ALLOW_FDS; |
| 1246 | maybePrefillHasFds(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | @Override |
| 1250 | public synchronized String toString() { |
| 1251 | if (mParcelledData != null) { |
Andreas Gampe | 52764cb | 2016-04-19 20:46:43 -0700 | [diff] [blame] | 1252 | if (isEmptyParcel()) { |
Dianne Hackborn | 8aee64d | 2013-10-25 10:41:50 -0700 | [diff] [blame] | 1253 | return "Bundle[EMPTY_PARCEL]"; |
| 1254 | } else { |
| 1255 | return "Bundle[mParcelledData.dataSize=" + |
| 1256 | mParcelledData.dataSize() + "]"; |
| 1257 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | } |
| 1259 | return "Bundle[" + mMap.toString() + "]"; |
| 1260 | } |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 1261 | |
| 1262 | /** |
| 1263 | * @hide |
| 1264 | */ |
| 1265 | public synchronized String toShortString() { |
| 1266 | if (mParcelledData != null) { |
| 1267 | if (isEmptyParcel()) { |
| 1268 | return "EMPTY_PARCEL"; |
| 1269 | } else { |
| 1270 | return "mParcelledData.dataSize=" + mParcelledData.dataSize(); |
| 1271 | } |
| 1272 | } |
| 1273 | return mMap.toString(); |
| 1274 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | } |