Debian Codegraph @

core/java/android/app/admin/ParcelableGranteeMap.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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.app.admin;
18
19 import android.annotation.NonNull;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.util.ArrayMap;
23 import android.util.ArraySet;
24
25 import java.util.Map;
26 import java.util.Set;
27
28 /**
29 * Class for marshalling keypair grantees for a given KeyChain key via Binder.
30 *
31 * @hide
32 */
33 public class ParcelableGranteeMap implements Parcelable {
34
35 private final Map<Integer, Set<String>> mPackagesByUid;
36
37 @Override
38 public int describeContents() {
39 return 0;
40 }
41
42 @Override
43 public void writeToParcel(Parcel dest, int flags) {
44 dest.writeInt(mPackagesByUid.size());
45 for (final Map.Entry<Integer, Set<String>> uidEntry : mPackagesByUid.entrySet()) {
46 dest.writeInt(uidEntry.getKey());
47 dest.writeStringArray(uidEntry.getValue().toArray(new String[0]));
48 }
49 }
50
51 public static final @NonNull Parcelable.Creator<ParcelableGranteeMap> CREATOR =
52 new Parcelable.Creator<ParcelableGranteeMap>() {
53 @Override
54 public ParcelableGranteeMap createFromParcel(Parcel source) {
55 final Map<Integer, Set<String>> packagesByUid = new ArrayMap<>();
56 final int numUids = source.readInt();
57 for (int i = 0; i < numUids; i++) {
58 final int uid = source.readInt();
59 final String[] pkgs = source.readStringArray();
60 packagesByUid.put(uid, new ArraySet<>(pkgs));
61 }
62 return new ParcelableGranteeMap(packagesByUid);
63 }
64
65 @Override
66 public ParcelableGranteeMap[] newArray(int size) {
67 return new ParcelableGranteeMap[size];
68 }
69 };
70
71 /**
72 * Creates an instance holding a reference (not a copy) to the given map.
73 */
74 public ParcelableGranteeMap(@NonNull Map<Integer, Set<String>> packagesByUid) {
75 mPackagesByUid = packagesByUid;
76 }
77
78 /**
79 * Returns a reference (not a copy) to the stored map.
80 */
81 @NonNull
82 public Map<Integer, Set<String>> getPackagesByUid() {
83 return mPackagesByUid;
84 }
85 }