• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 package android.content.pm;
17 
18 import android.annotation.NonNull;
19 import android.annotation.TestApi;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 import java.util.ArrayList;
24 import java.util.List;
25 
26 /**
27  * Equivalent to List<ProviderInfo>, but it "squashes" the ApplicationInfo in the elements.
28  *
29  * @hide
30  */
31 @TestApi
32 public final class ProviderInfoList implements Parcelable {
33     private final List<ProviderInfo> mList;
34 
ProviderInfoList(Parcel source)35     private ProviderInfoList(Parcel source) {
36         final ArrayList<ProviderInfo> list = new ArrayList<>();
37         source.readTypedList(list, ProviderInfo.CREATOR);
38         mList = list;
39     }
40 
ProviderInfoList(List<ProviderInfo> list)41     private ProviderInfoList(List<ProviderInfo> list) {
42         mList = list;
43     }
44 
45     @Override
describeContents()46     public int describeContents() {
47         return 0;
48     }
49 
50     @Override
writeToParcel(@onNull Parcel dest, int flags)51     public void writeToParcel(@NonNull Parcel dest, int flags) {
52         // Allow ApplicationInfo to be squashed.
53         final boolean prevAllowSquashing = dest.allowSquashing();
54         dest.writeTypedList(mList, flags);
55         dest.restoreAllowSquashing(prevAllowSquashing);
56     }
57 
58     public static final @android.annotation.NonNull Parcelable.Creator<ProviderInfoList> CREATOR
59             = new Parcelable.Creator<ProviderInfoList>() {
60         @Override
61         public ProviderInfoList createFromParcel(@NonNull Parcel source) {
62             return new ProviderInfoList(source);
63         }
64 
65         @Override
66         public ProviderInfoList[] newArray(int size) {
67             return new ProviderInfoList[size];
68         }
69     };
70 
71     /**
72      * Return the stored list.
73      */
74     @NonNull
getList()75     public List<ProviderInfo> getList() {
76         return mList;
77     }
78 
79     /**
80      * Create a new instance with a {@code list}. The passed list will be shared with the new
81      * instance, so the caller shouldn't modify it.
82      */
83     @NonNull
fromList(@onNull List<ProviderInfo> list)84     public static ProviderInfoList fromList(@NonNull List<ProviderInfo> list) {
85         return new ProviderInfoList(list);
86     }
87 }
88