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