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