1 /*
2  * Copyright 2020 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.media;
18 
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21 import android.os.Build;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import androidx.annotation.RequiresApi;
26 
27 import java.util.Collections;
28 import java.util.List;
29 
30 /**
31  * This is a copied version of MediaParceledListSlice in framework with hidden API usages removed,
32  * and also with some lint error fixed.
33  *
34  * Transfer a large list of Parcelable objects across an IPC.  Splits into
35  * multiple transactions if needed.
36  *
37  * TODO: Remove this from @SystemApi once all the MediaSession related classes are moved
38  *       to apex (or ParceledListSlice moved to apex). This class is temporaily added to system API
39  *       for moving classes step by step.
40  *
41  * @param <T> The type of the elements in the list.
42  * @see BaseMediaParceledListSlice
43  * @deprecated This is temporary marked as @SystemApi. Should be removed from the API surface.
44  * @hide
45  */
46 @Deprecated
47 @RequiresApi(Build.VERSION_CODES.S)
48 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
49 public final class MediaParceledListSlice<T extends Parcelable>
50         extends BaseMediaParceledListSlice<T> {
MediaParceledListSlice(@onNull List<T> list)51     public MediaParceledListSlice(@NonNull List<T> list) {
52         super(list);
53     }
54 
MediaParceledListSlice(Parcel in, ClassLoader loader)55     private MediaParceledListSlice(Parcel in, ClassLoader loader) {
56         super(in, loader);
57     }
58 
59     @NonNull
emptyList()60     public static <T extends Parcelable> MediaParceledListSlice<T> emptyList() {
61         return new MediaParceledListSlice<T>(Collections.<T> emptyList());
62     }
63 
64     @Override
describeContents()65     public int describeContents() {
66         int contents = 0;
67         final List<T> list = getList();
68         for (int i=0; i<list.size(); i++) {
69             contents |= list.get(i).describeContents();
70         }
71         return contents;
72     }
73 
74     @Override
writeElement(T parcelable, Parcel dest, int callFlags)75     void writeElement(T parcelable, Parcel dest, int callFlags) {
76         parcelable.writeToParcel(dest, callFlags);
77     }
78 
79     @Override
writeParcelableCreator(T parcelable, Parcel dest)80     void writeParcelableCreator(T parcelable, Parcel dest) {
81         dest.writeParcelableCreator((Parcelable) parcelable);
82     }
83 
84     @Override
readParcelableCreator(Parcel from, ClassLoader loader)85     Parcelable.Creator<?> readParcelableCreator(Parcel from, ClassLoader loader) {
86         return from.readParcelableCreator(loader);
87     }
88 
89     @NonNull
90     @SuppressWarnings("unchecked")
91     public static final Parcelable.ClassLoaderCreator<MediaParceledListSlice> CREATOR =
92             new Parcelable.ClassLoaderCreator<MediaParceledListSlice>() {
93         public MediaParceledListSlice createFromParcel(Parcel in) {
94             return new MediaParceledListSlice(in, null);
95         }
96 
97         @Override
98         public MediaParceledListSlice createFromParcel(Parcel in, ClassLoader loader) {
99             return new MediaParceledListSlice(in, loader);
100         }
101 
102         @Override
103         public MediaParceledListSlice[] newArray(int size) {
104             return new MediaParceledListSlice[size];
105         }
106     };
107 }
108