blob: 9f954f7dcbe92bb81010333e8e48717104da00af [file] [log] [blame]
Joel Galenson5f63b832018-12-19 15:38:04 -08001/*
2 * Copyright (C) 2019 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.permission;
18
19import static com.android.internal.util.Preconditions.checkArgumentNonnegative;
20import static com.android.internal.util.Preconditions.checkNotNull;
21
22import android.annotation.NonNull;
23import android.annotation.SystemApi;
24import android.os.Parcel;
25import android.os.Parcelable;
26
27/**
28 * This class contains information about how a runtime permission
29 * is used. A single runtime permission presented to the user may
30 * correspond to multiple platform defined permissions, e.g. the
31 * location permission may control both the coarse and fine platform
32 * permissions.
33 *
34 * @hide
35 */
36@SystemApi
37public final class RuntimePermissionUsageInfo implements Parcelable {
38 private final @NonNull CharSequence mName;
39 private final int mNumUsers;
40
41 /**
42 * Creates a new instance.
43 *
44 * @param name The permission group name.
45 * @param numUsers The number of apps that have used this permission.
46 */
47 public RuntimePermissionUsageInfo(@NonNull CharSequence name, int numUsers) {
48 checkNotNull(name);
49 checkArgumentNonnegative(numUsers);
50
51 mName = name;
52 mNumUsers = numUsers;
53 }
54
55 private RuntimePermissionUsageInfo(Parcel parcel) {
56 this(parcel.readCharSequence(), parcel.readInt());
57 }
58
59 /**
60 * @return The number of apps that accessed this permission
61 */
62 public int getAppAccessCount() {
63 return mNumUsers;
64 }
65
66 /**
67 * Gets the permission group name.
68 *
69 * @return The name.
70 */
71 public @NonNull CharSequence getName() {
72 return mName;
73 }
74
75 @Override
76 public int describeContents() {
77 return 0;
78 }
79
80 @Override
81 public void writeToParcel(Parcel parcel, int flags) {
82 parcel.writeCharSequence(mName);
83 parcel.writeInt(mNumUsers);
84 }
85
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070086 public static final @android.annotation.NonNull Creator<RuntimePermissionUsageInfo> CREATOR =
Joel Galenson5f63b832018-12-19 15:38:04 -080087 new Creator<RuntimePermissionUsageInfo>() {
88 public RuntimePermissionUsageInfo createFromParcel(Parcel source) {
89 return new RuntimePermissionUsageInfo(source);
90 }
91
92 public RuntimePermissionUsageInfo[] newArray(int size) {
93 return new RuntimePermissionUsageInfo[size];
94 }
95 };
96}