Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | #define LOG_TAG "PersistableBundle" |
| 18 | |
| 19 | #include <binder/PersistableBundle.h> |
| 20 | |
| 21 | #include <limits> |
| 22 | |
| 23 | #include <binder/IBinder.h> |
| 24 | #include <binder/Parcel.h> |
| 25 | #include <log/log.h> |
| 26 | #include <utils/Errors.h> |
| 27 | |
| 28 | using android::BAD_TYPE; |
| 29 | using android::BAD_VALUE; |
| 30 | using android::NO_ERROR; |
| 31 | using android::Parcel; |
| 32 | using android::sp; |
| 33 | using android::status_t; |
| 34 | using android::UNEXPECTED_NULL; |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 35 | using std::map; |
| 36 | using std::set; |
| 37 | using std::vector; |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 38 | |
| 39 | enum { |
| 40 | // Keep in sync with BUNDLE_MAGIC in frameworks/base/core/java/android/os/BaseBundle.java. |
| 41 | BUNDLE_MAGIC = 0x4C444E42, |
| 42 | }; |
| 43 | |
| 44 | enum { |
| 45 | // Keep in sync with frameworks/base/core/java/android/os/Parcel.java. |
| 46 | VAL_STRING = 0, |
| 47 | VAL_INTEGER = 1, |
| 48 | VAL_LONG = 6, |
| 49 | VAL_DOUBLE = 8, |
| 50 | VAL_BOOLEAN = 9, |
| 51 | VAL_STRINGARRAY = 14, |
| 52 | VAL_INTARRAY = 18, |
| 53 | VAL_LONGARRAY = 19, |
| 54 | VAL_BOOLEANARRAY = 23, |
| 55 | VAL_PERSISTABLEBUNDLE = 25, |
| 56 | VAL_DOUBLEARRAY = 28, |
| 57 | }; |
| 58 | |
| 59 | namespace { |
| 60 | template <typename T> |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 61 | bool getValue(const android::String16& key, T* out, const map<android::String16, T>& map) { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 62 | const auto& it = map.find(key); |
| 63 | if (it == map.end()) return false; |
| 64 | *out = it->second; |
| 65 | return true; |
| 66 | } |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 67 | |
| 68 | template <typename T> |
| 69 | set<android::String16> getKeys(const map<android::String16, T>& map) { |
| 70 | if (map.empty()) return set<android::String16>(); |
| 71 | set<android::String16> keys; |
| 72 | for (const auto& key_value_pair : map) { |
| 73 | keys.emplace(key_value_pair.first); |
| 74 | } |
| 75 | return keys; |
| 76 | } |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 77 | } // namespace |
| 78 | |
| 79 | namespace android { |
| 80 | |
| 81 | namespace os { |
| 82 | |
| 83 | #define RETURN_IF_FAILED(calledOnce) \ |
| 84 | { \ |
| 85 | status_t returnStatus = calledOnce; \ |
| 86 | if (returnStatus) { \ |
| 87 | ALOGE("Failed at %s:%d (%s)", __FILE__, __LINE__, __func__); \ |
| 88 | return returnStatus; \ |
| 89 | } \ |
| 90 | } |
| 91 | |
| 92 | #define RETURN_IF_ENTRY_ERASED(map, key) \ |
| 93 | { \ |
| 94 | size_t num_erased = map.erase(key); \ |
| 95 | if (num_erased) { \ |
| 96 | ALOGE("Failed at %s:%d (%s)", __FILE__, __LINE__, __func__); \ |
| 97 | return num_erased; \ |
| 98 | } \ |
| 99 | } |
| 100 | |
| 101 | status_t PersistableBundle::writeToParcel(Parcel* parcel) const { |
| 102 | /* |
| 103 | * Keep implementation in sync with writeToParcelInner() in |
| 104 | * frameworks/base/core/java/android/os/BaseBundle.java. |
| 105 | */ |
| 106 | |
| 107 | // Special case for empty bundles. |
| 108 | if (empty()) { |
| 109 | RETURN_IF_FAILED(parcel->writeInt32(0)); |
| 110 | return NO_ERROR; |
| 111 | } |
| 112 | |
| 113 | size_t length_pos = parcel->dataPosition(); |
| 114 | RETURN_IF_FAILED(parcel->writeInt32(1)); // dummy, will hold length |
| 115 | RETURN_IF_FAILED(parcel->writeInt32(BUNDLE_MAGIC)); |
| 116 | |
| 117 | size_t start_pos = parcel->dataPosition(); |
| 118 | RETURN_IF_FAILED(writeToParcelInner(parcel)); |
| 119 | size_t end_pos = parcel->dataPosition(); |
| 120 | |
| 121 | // Backpatch length. This length value includes the length header. |
| 122 | parcel->setDataPosition(length_pos); |
| 123 | size_t length = end_pos - start_pos; |
| 124 | if (length > std::numeric_limits<int32_t>::max()) { |
Samuel Tan | 715dec7 | 2015-12-16 17:13:29 -0800 | [diff] [blame] | 125 | ALOGE("Parcel length (%zu) too large to store in 32-bit signed int", length); |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 126 | return BAD_VALUE; |
| 127 | } |
| 128 | RETURN_IF_FAILED(parcel->writeInt32(static_cast<int32_t>(length))); |
| 129 | parcel->setDataPosition(end_pos); |
| 130 | return NO_ERROR; |
| 131 | } |
| 132 | |
| 133 | status_t PersistableBundle::readFromParcel(const Parcel* parcel) { |
| 134 | /* |
| 135 | * Keep implementation in sync with readFromParcelInner() in |
| 136 | * frameworks/base/core/java/android/os/BaseBundle.java. |
| 137 | */ |
| 138 | int32_t length = parcel->readInt32(); |
| 139 | if (length < 0) { |
| 140 | ALOGE("Bad length in parcel: %d", length); |
| 141 | return UNEXPECTED_NULL; |
| 142 | } |
| 143 | |
| 144 | return readFromParcelInner(parcel, static_cast<size_t>(length)); |
| 145 | } |
| 146 | |
| 147 | bool PersistableBundle::empty() const { |
| 148 | return size() == 0u; |
| 149 | } |
| 150 | |
| 151 | size_t PersistableBundle::size() const { |
| 152 | return (mBoolMap.size() + |
| 153 | mIntMap.size() + |
| 154 | mLongMap.size() + |
| 155 | mDoubleMap.size() + |
| 156 | mStringMap.size() + |
| 157 | mBoolVectorMap.size() + |
| 158 | mIntVectorMap.size() + |
| 159 | mLongVectorMap.size() + |
| 160 | mDoubleVectorMap.size() + |
| 161 | mStringVectorMap.size() + |
| 162 | mPersistableBundleMap.size()); |
| 163 | } |
| 164 | |
| 165 | size_t PersistableBundle::erase(const String16& key) { |
| 166 | RETURN_IF_ENTRY_ERASED(mBoolMap, key); |
| 167 | RETURN_IF_ENTRY_ERASED(mIntMap, key); |
| 168 | RETURN_IF_ENTRY_ERASED(mLongMap, key); |
| 169 | RETURN_IF_ENTRY_ERASED(mDoubleMap, key); |
| 170 | RETURN_IF_ENTRY_ERASED(mStringMap, key); |
| 171 | RETURN_IF_ENTRY_ERASED(mBoolVectorMap, key); |
| 172 | RETURN_IF_ENTRY_ERASED(mIntVectorMap, key); |
| 173 | RETURN_IF_ENTRY_ERASED(mLongVectorMap, key); |
| 174 | RETURN_IF_ENTRY_ERASED(mDoubleVectorMap, key); |
| 175 | RETURN_IF_ENTRY_ERASED(mStringVectorMap, key); |
| 176 | return mPersistableBundleMap.erase(key); |
| 177 | } |
| 178 | |
| 179 | void PersistableBundle::putBoolean(const String16& key, bool value) { |
| 180 | erase(key); |
| 181 | mBoolMap[key] = value; |
| 182 | } |
| 183 | |
| 184 | void PersistableBundle::putInt(const String16& key, int32_t value) { |
| 185 | erase(key); |
| 186 | mIntMap[key] = value; |
| 187 | } |
| 188 | |
| 189 | void PersistableBundle::putLong(const String16& key, int64_t value) { |
| 190 | erase(key); |
| 191 | mLongMap[key] = value; |
| 192 | } |
| 193 | |
| 194 | void PersistableBundle::putDouble(const String16& key, double value) { |
| 195 | erase(key); |
| 196 | mDoubleMap[key] = value; |
| 197 | } |
| 198 | |
| 199 | void PersistableBundle::putString(const String16& key, const String16& value) { |
| 200 | erase(key); |
| 201 | mStringMap[key] = value; |
| 202 | } |
| 203 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 204 | void PersistableBundle::putBooleanVector(const String16& key, const vector<bool>& value) { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 205 | erase(key); |
| 206 | mBoolVectorMap[key] = value; |
| 207 | } |
| 208 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 209 | void PersistableBundle::putIntVector(const String16& key, const vector<int32_t>& value) { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 210 | erase(key); |
| 211 | mIntVectorMap[key] = value; |
| 212 | } |
| 213 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 214 | void PersistableBundle::putLongVector(const String16& key, const vector<int64_t>& value) { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 215 | erase(key); |
| 216 | mLongVectorMap[key] = value; |
| 217 | } |
| 218 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 219 | void PersistableBundle::putDoubleVector(const String16& key, const vector<double>& value) { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 220 | erase(key); |
| 221 | mDoubleVectorMap[key] = value; |
| 222 | } |
| 223 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 224 | void PersistableBundle::putStringVector(const String16& key, const vector<String16>& value) { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 225 | erase(key); |
| 226 | mStringVectorMap[key] = value; |
| 227 | } |
| 228 | |
| 229 | void PersistableBundle::putPersistableBundle(const String16& key, const PersistableBundle& value) { |
| 230 | erase(key); |
| 231 | mPersistableBundleMap[key] = value; |
| 232 | } |
| 233 | |
| 234 | bool PersistableBundle::getBoolean(const String16& key, bool* out) const { |
| 235 | return getValue(key, out, mBoolMap); |
| 236 | } |
| 237 | |
| 238 | bool PersistableBundle::getInt(const String16& key, int32_t* out) const { |
| 239 | return getValue(key, out, mIntMap); |
| 240 | } |
| 241 | |
| 242 | bool PersistableBundle::getLong(const String16& key, int64_t* out) const { |
| 243 | return getValue(key, out, mLongMap); |
| 244 | } |
| 245 | |
| 246 | bool PersistableBundle::getDouble(const String16& key, double* out) const { |
| 247 | return getValue(key, out, mDoubleMap); |
| 248 | } |
| 249 | |
| 250 | bool PersistableBundle::getString(const String16& key, String16* out) const { |
| 251 | return getValue(key, out, mStringMap); |
| 252 | } |
| 253 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 254 | bool PersistableBundle::getBooleanVector(const String16& key, vector<bool>* out) const { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 255 | return getValue(key, out, mBoolVectorMap); |
| 256 | } |
| 257 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 258 | bool PersistableBundle::getIntVector(const String16& key, vector<int32_t>* out) const { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 259 | return getValue(key, out, mIntVectorMap); |
| 260 | } |
| 261 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 262 | bool PersistableBundle::getLongVector(const String16& key, vector<int64_t>* out) const { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 263 | return getValue(key, out, mLongVectorMap); |
| 264 | } |
| 265 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 266 | bool PersistableBundle::getDoubleVector(const String16& key, vector<double>* out) const { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 267 | return getValue(key, out, mDoubleVectorMap); |
| 268 | } |
| 269 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 270 | bool PersistableBundle::getStringVector(const String16& key, vector<String16>* out) const { |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 271 | return getValue(key, out, mStringVectorMap); |
| 272 | } |
| 273 | |
| 274 | bool PersistableBundle::getPersistableBundle(const String16& key, PersistableBundle* out) const { |
| 275 | return getValue(key, out, mPersistableBundleMap); |
| 276 | } |
| 277 | |
Samuel Tan | 52545f2 | 2016-02-12 13:56:17 -0800 | [diff] [blame^] | 278 | set<String16> PersistableBundle::getBooleanKeys() const { |
| 279 | return getKeys(mBoolMap); |
| 280 | } |
| 281 | |
| 282 | set<String16> PersistableBundle::getIntKeys() const { |
| 283 | return getKeys(mIntMap); |
| 284 | } |
| 285 | |
| 286 | set<String16> PersistableBundle::getLongKeys() const { |
| 287 | return getKeys(mLongMap); |
| 288 | } |
| 289 | |
| 290 | set<String16> PersistableBundle::getDoubleKeys() const { |
| 291 | return getKeys(mDoubleMap); |
| 292 | } |
| 293 | |
| 294 | set<String16> PersistableBundle::getStringKeys() const { |
| 295 | return getKeys(mStringMap); |
| 296 | } |
| 297 | |
| 298 | set<String16> PersistableBundle::getBooleanVectorKeys() const { |
| 299 | return getKeys(mBoolVectorMap); |
| 300 | } |
| 301 | |
| 302 | set<String16> PersistableBundle::getIntVectorKeys() const { |
| 303 | return getKeys(mIntVectorMap); |
| 304 | } |
| 305 | |
| 306 | set<String16> PersistableBundle::getLongVectorKeys() const { |
| 307 | return getKeys(mLongVectorMap); |
| 308 | } |
| 309 | |
| 310 | set<String16> PersistableBundle::getDoubleVectorKeys() const { |
| 311 | return getKeys(mDoubleVectorMap); |
| 312 | } |
| 313 | |
| 314 | set<String16> PersistableBundle::getStringVectorKeys() const { |
| 315 | return getKeys(mStringVectorMap); |
| 316 | } |
| 317 | |
| 318 | set<String16> PersistableBundle::getPersistableBundleKeys() const { |
| 319 | return getKeys(mPersistableBundleMap); |
| 320 | } |
| 321 | |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 322 | status_t PersistableBundle::writeToParcelInner(Parcel* parcel) const { |
| 323 | /* |
| 324 | * To keep this implementation in sync with writeArrayMapInternal() in |
| 325 | * frameworks/base/core/java/android/os/Parcel.java, the number of key |
| 326 | * value pairs must be written into the parcel before writing the key-value |
| 327 | * pairs themselves. |
| 328 | */ |
| 329 | size_t num_entries = size(); |
| 330 | if (num_entries > std::numeric_limits<int32_t>::max()) { |
Samuel Tan | 715dec7 | 2015-12-16 17:13:29 -0800 | [diff] [blame] | 331 | ALOGE("The size of this PersistableBundle (%zu) too large to store in 32-bit signed int", |
Samuel Tan | 0a31202 | 2015-11-23 18:22:12 -0800 | [diff] [blame] | 332 | num_entries); |
| 333 | return BAD_VALUE; |
| 334 | } |
| 335 | RETURN_IF_FAILED(parcel->writeInt32(static_cast<int32_t>(num_entries))); |
| 336 | |
| 337 | for (const auto& key_val_pair : mBoolMap) { |
| 338 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 339 | RETURN_IF_FAILED(parcel->writeInt32(VAL_BOOLEAN)); |
| 340 | RETURN_IF_FAILED(parcel->writeBool(key_val_pair.second)); |
| 341 | } |
| 342 | for (const auto& key_val_pair : mIntMap) { |
| 343 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 344 | RETURN_IF_FAILED(parcel->writeInt32(VAL_INTEGER)); |
| 345 | RETURN_IF_FAILED(parcel->writeInt32(key_val_pair.second)); |
| 346 | } |
| 347 | for (const auto& key_val_pair : mLongMap) { |
| 348 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 349 | RETURN_IF_FAILED(parcel->writeInt32(VAL_LONG)); |
| 350 | RETURN_IF_FAILED(parcel->writeInt64(key_val_pair.second)); |
| 351 | } |
| 352 | for (const auto& key_val_pair : mDoubleMap) { |
| 353 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 354 | RETURN_IF_FAILED(parcel->writeInt32(VAL_DOUBLE)); |
| 355 | RETURN_IF_FAILED(parcel->writeDouble(key_val_pair.second)); |
| 356 | } |
| 357 | for (const auto& key_val_pair : mStringMap) { |
| 358 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 359 | RETURN_IF_FAILED(parcel->writeInt32(VAL_STRING)); |
| 360 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.second)); |
| 361 | } |
| 362 | for (const auto& key_val_pair : mBoolVectorMap) { |
| 363 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 364 | RETURN_IF_FAILED(parcel->writeInt32(VAL_BOOLEANARRAY)); |
| 365 | RETURN_IF_FAILED(parcel->writeBoolVector(key_val_pair.second)); |
| 366 | } |
| 367 | for (const auto& key_val_pair : mIntVectorMap) { |
| 368 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 369 | RETURN_IF_FAILED(parcel->writeInt32(VAL_INTARRAY)); |
| 370 | RETURN_IF_FAILED(parcel->writeInt32Vector(key_val_pair.second)); |
| 371 | } |
| 372 | for (const auto& key_val_pair : mLongVectorMap) { |
| 373 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 374 | RETURN_IF_FAILED(parcel->writeInt32(VAL_LONGARRAY)); |
| 375 | RETURN_IF_FAILED(parcel->writeInt64Vector(key_val_pair.second)); |
| 376 | } |
| 377 | for (const auto& key_val_pair : mDoubleVectorMap) { |
| 378 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 379 | RETURN_IF_FAILED(parcel->writeInt32(VAL_DOUBLEARRAY)); |
| 380 | RETURN_IF_FAILED(parcel->writeDoubleVector(key_val_pair.second)); |
| 381 | } |
| 382 | for (const auto& key_val_pair : mStringVectorMap) { |
| 383 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 384 | RETURN_IF_FAILED(parcel->writeInt32(VAL_STRINGARRAY)); |
| 385 | RETURN_IF_FAILED(parcel->writeString16Vector(key_val_pair.second)); |
| 386 | } |
| 387 | for (const auto& key_val_pair : mPersistableBundleMap) { |
| 388 | RETURN_IF_FAILED(parcel->writeString16(key_val_pair.first)); |
| 389 | RETURN_IF_FAILED(parcel->writeInt32(VAL_PERSISTABLEBUNDLE)); |
| 390 | RETURN_IF_FAILED(key_val_pair.second.writeToParcel(parcel)); |
| 391 | } |
| 392 | return NO_ERROR; |
| 393 | } |
| 394 | |
| 395 | status_t PersistableBundle::readFromParcelInner(const Parcel* parcel, size_t length) { |
| 396 | /* |
| 397 | * Note: we don't actually use length for anything other than an empty PersistableBundle |
| 398 | * check, since we do not actually need to copy in an entire Parcel, unlike in the Java |
| 399 | * implementation. |
| 400 | */ |
| 401 | if (length == 0) { |
| 402 | // Empty PersistableBundle or end of data. |
| 403 | return NO_ERROR; |
| 404 | } |
| 405 | |
| 406 | int32_t magic; |
| 407 | RETURN_IF_FAILED(parcel->readInt32(&magic)); |
| 408 | if (magic != BUNDLE_MAGIC) { |
| 409 | ALOGE("Bad magic number for PersistableBundle: 0x%08x", magic); |
| 410 | return BAD_VALUE; |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * To keep this implementation in sync with unparcel() in |
| 415 | * frameworks/base/core/java/android/os/BaseBundle.java, the number of |
| 416 | * key-value pairs must be read from the parcel before reading the key-value |
| 417 | * pairs themselves. |
| 418 | */ |
| 419 | int32_t num_entries; |
| 420 | RETURN_IF_FAILED(parcel->readInt32(&num_entries)); |
| 421 | |
| 422 | for (; num_entries > 0; --num_entries) { |
| 423 | size_t start_pos = parcel->dataPosition(); |
| 424 | String16 key; |
| 425 | int32_t value_type; |
| 426 | RETURN_IF_FAILED(parcel->readString16(&key)); |
| 427 | RETURN_IF_FAILED(parcel->readInt32(&value_type)); |
| 428 | |
| 429 | /* |
| 430 | * We assume that both the C++ and Java APIs ensure that all keys in a PersistableBundle |
| 431 | * are unique. |
| 432 | */ |
| 433 | switch (value_type) { |
| 434 | case VAL_STRING: { |
| 435 | RETURN_IF_FAILED(parcel->readString16(&mStringMap[key])); |
| 436 | break; |
| 437 | } |
| 438 | case VAL_INTEGER: { |
| 439 | RETURN_IF_FAILED(parcel->readInt32(&mIntMap[key])); |
| 440 | break; |
| 441 | } |
| 442 | case VAL_LONG: { |
| 443 | RETURN_IF_FAILED(parcel->readInt64(&mLongMap[key])); |
| 444 | break; |
| 445 | } |
| 446 | case VAL_DOUBLE: { |
| 447 | RETURN_IF_FAILED(parcel->readDouble(&mDoubleMap[key])); |
| 448 | break; |
| 449 | } |
| 450 | case VAL_BOOLEAN: { |
| 451 | RETURN_IF_FAILED(parcel->readBool(&mBoolMap[key])); |
| 452 | break; |
| 453 | } |
| 454 | case VAL_STRINGARRAY: { |
| 455 | RETURN_IF_FAILED(parcel->readString16Vector(&mStringVectorMap[key])); |
| 456 | break; |
| 457 | } |
| 458 | case VAL_INTARRAY: { |
| 459 | RETURN_IF_FAILED(parcel->readInt32Vector(&mIntVectorMap[key])); |
| 460 | break; |
| 461 | } |
| 462 | case VAL_LONGARRAY: { |
| 463 | RETURN_IF_FAILED(parcel->readInt64Vector(&mLongVectorMap[key])); |
| 464 | break; |
| 465 | } |
| 466 | case VAL_BOOLEANARRAY: { |
| 467 | RETURN_IF_FAILED(parcel->readBoolVector(&mBoolVectorMap[key])); |
| 468 | break; |
| 469 | } |
| 470 | case VAL_PERSISTABLEBUNDLE: { |
| 471 | RETURN_IF_FAILED(mPersistableBundleMap[key].readFromParcel(parcel)); |
| 472 | break; |
| 473 | } |
| 474 | case VAL_DOUBLEARRAY: { |
| 475 | RETURN_IF_FAILED(parcel->readDoubleVector(&mDoubleVectorMap[key])); |
| 476 | break; |
| 477 | } |
| 478 | default: { |
| 479 | ALOGE("Unrecognized type: %d", value_type); |
| 480 | return BAD_TYPE; |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | return NO_ERROR; |
| 487 | } |
| 488 | |
| 489 | } // namespace os |
| 490 | |
| 491 | } // namespace android |