blob: dccc52494f59502f0bac46c7f7e8668ff3c761b7 [file] [log] [blame]
Kenny Root0e2c0f32011-04-15 17:50:10 -07001/*
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
17package android.content.pm;
18
Mathew Inwood5c0d3542018-08-14 13:54:31 +010019import android.annotation.UnsupportedAppUsage;
Mathew Inwood8c854f82018-09-14 12:35:36 +010020import android.os.Build;
Kenny Root0e2c0f32011-04-15 17:50:10 -070021import android.os.Parcel;
22import android.os.Parcelable;
23
Jeff Sharkey2f3e3532015-12-21 14:16:43 -070024import java.util.Collections;
Kenny Root0e2c0f32011-04-15 17:50:10 -070025import java.util.List;
26
27/**
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -080028 * Transfer a large list of Parcelable objects across an IPC. Splits into
29 * multiple transactions if needed.
Kenny Root0e2c0f32011-04-15 17:50:10 -070030 *
Robin Leeabaa0692017-02-20 20:54:22 +000031 * @see BaseParceledListSlice
Adam Lesinski3df1c382014-11-07 11:26:14 -080032 *
Kenny Root0e2c0f32011-04-15 17:50:10 -070033 * @hide
34 */
Robin Leeabaa0692017-02-20 20:54:22 +000035public class ParceledListSlice<T extends Parcelable> extends BaseParceledListSlice<T> {
Mathew Inwood5c0d3542018-08-14 13:54:31 +010036 @UnsupportedAppUsage
Robin Leeabaa0692017-02-20 20:54:22 +000037 public ParceledListSlice(List<T> list) {
38 super(list);
39 }
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -080040
Robin Leeabaa0692017-02-20 20:54:22 +000041 private ParceledListSlice(Parcel in, ClassLoader loader) {
42 super(in, loader);
43 }
Kenny Root0e2c0f32011-04-15 17:50:10 -070044
Jeff Sharkey2f3e3532015-12-21 14:16:43 -070045 public static <T extends Parcelable> ParceledListSlice<T> emptyList() {
46 return new ParceledListSlice<T>(Collections.<T> emptyList());
47 }
48
Kenny Root0e2c0f32011-04-15 17:50:10 -070049 @Override
50 public int describeContents() {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -080051 int contents = 0;
Robin Leeabaa0692017-02-20 20:54:22 +000052 final List<T> list = getList();
53 for (int i=0; i<list.size(); i++) {
54 contents |= list.get(i).describeContents();
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -080055 }
56 return contents;
Kenny Root0e2c0f32011-04-15 17:50:10 -070057 }
58
Kenny Root0e2c0f32011-04-15 17:50:10 -070059 @Override
Robin Leeabaa0692017-02-20 20:54:22 +000060 protected void writeElement(T parcelable, Parcel dest, int callFlags) {
61 parcelable.writeToParcel(dest, callFlags);
62 }
Adam Lesinski3df1c382014-11-07 11:26:14 -080063
Robin Leeabaa0692017-02-20 20:54:22 +000064 @Override
Mathew Inwood5c0d3542018-08-14 13:54:31 +010065 @UnsupportedAppUsage
Robin Leeabaa0692017-02-20 20:54:22 +000066 protected void writeParcelableCreator(T parcelable, Parcel dest) {
67 dest.writeParcelableCreator((Parcelable) parcelable);
68 }
Adam Lesinski3df1c382014-11-07 11:26:14 -080069
Robin Leeabaa0692017-02-20 20:54:22 +000070 @Override
71 protected Parcelable.Creator<?> readParcelableCreator(Parcel from, ClassLoader loader) {
72 return from.readParcelableCreator(loader);
Kenny Root0e2c0f32011-04-15 17:50:10 -070073 }
74
75 @SuppressWarnings("unchecked")
Mathew Inwood8c854f82018-09-14 12:35:36 +010076 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -080077 public static final Parcelable.ClassLoaderCreator<ParceledListSlice> CREATOR =
78 new Parcelable.ClassLoaderCreator<ParceledListSlice>() {
Kenny Root0e2c0f32011-04-15 17:50:10 -070079 public ParceledListSlice createFromParcel(Parcel in) {
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -080080 return new ParceledListSlice(in, null);
81 }
Kenny Root0e2c0f32011-04-15 17:50:10 -070082
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -080083 @Override
84 public ParceledListSlice createFromParcel(Parcel in, ClassLoader loader) {
85 return new ParceledListSlice(in, loader);
Kenny Root0e2c0f32011-04-15 17:50:10 -070086 }
87
Robin Leeabaa0692017-02-20 20:54:22 +000088 @Override
Kenny Root0e2c0f32011-04-15 17:50:10 -070089 public ParceledListSlice[] newArray(int size) {
90 return new ParceledListSlice[size];
91 }
92 };
93}