Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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.content.pm; |
| 18 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 20 | import android.os.Build; |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | |
Jeff Sharkey | 2f3e353 | 2015-12-21 14:16:43 -0700 | [diff] [blame] | 24 | import java.util.Collections; |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 25 | import java.util.List; |
| 26 | |
| 27 | /** |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 28 | * Transfer a large list of Parcelable objects across an IPC. Splits into |
| 29 | * multiple transactions if needed. |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 30 | * |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 31 | * @see BaseParceledListSlice |
Adam Lesinski | 3df1c38 | 2014-11-07 11:26:14 -0800 | [diff] [blame] | 32 | * |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 33 | * @hide |
| 34 | */ |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 35 | public class ParceledListSlice<T extends Parcelable> extends BaseParceledListSlice<T> { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 36 | @UnsupportedAppUsage |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 37 | public ParceledListSlice(List<T> list) { |
| 38 | super(list); |
| 39 | } |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 40 | |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 41 | private ParceledListSlice(Parcel in, ClassLoader loader) { |
| 42 | super(in, loader); |
| 43 | } |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 44 | |
Jeff Sharkey | 2f3e353 | 2015-12-21 14:16:43 -0700 | [diff] [blame] | 45 | public static <T extends Parcelable> ParceledListSlice<T> emptyList() { |
| 46 | return new ParceledListSlice<T>(Collections.<T> emptyList()); |
| 47 | } |
| 48 | |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 49 | @Override |
| 50 | public int describeContents() { |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 51 | int contents = 0; |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 52 | final List<T> list = getList(); |
| 53 | for (int i=0; i<list.size(); i++) { |
| 54 | contents |= list.get(i).describeContents(); |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 55 | } |
| 56 | return contents; |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 59 | @Override |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 60 | protected void writeElement(T parcelable, Parcel dest, int callFlags) { |
| 61 | parcelable.writeToParcel(dest, callFlags); |
| 62 | } |
Adam Lesinski | 3df1c38 | 2014-11-07 11:26:14 -0800 | [diff] [blame] | 63 | |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 64 | @Override |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 65 | @UnsupportedAppUsage |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 66 | protected void writeParcelableCreator(T parcelable, Parcel dest) { |
| 67 | dest.writeParcelableCreator((Parcelable) parcelable); |
| 68 | } |
Adam Lesinski | 3df1c38 | 2014-11-07 11:26:14 -0800 | [diff] [blame] | 69 | |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 70 | @Override |
| 71 | protected Parcelable.Creator<?> readParcelableCreator(Parcel from, ClassLoader loader) { |
| 72 | return from.readParcelableCreator(loader); |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @SuppressWarnings("unchecked") |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 76 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 77 | public static final Parcelable.ClassLoaderCreator<ParceledListSlice> CREATOR = |
| 78 | new Parcelable.ClassLoaderCreator<ParceledListSlice>() { |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 79 | public ParceledListSlice createFromParcel(Parcel in) { |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 80 | return new ParceledListSlice(in, null); |
| 81 | } |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 82 | |
Dianne Hackborn | d8e1dbb | 2013-01-17 17:47:37 -0800 | [diff] [blame] | 83 | @Override |
| 84 | public ParceledListSlice createFromParcel(Parcel in, ClassLoader loader) { |
| 85 | return new ParceledListSlice(in, loader); |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Robin Lee | abaa069 | 2017-02-20 20:54:22 +0000 | [diff] [blame] | 88 | @Override |
Kenny Root | 0e2c0f3 | 2011-04-15 17:50:10 -0700 | [diff] [blame] | 89 | public ParceledListSlice[] newArray(int size) { |
| 90 | return new ParceledListSlice[size]; |
| 91 | } |
| 92 | }; |
| 93 | } |