Joel Galenson | 5f63b83 | 2018-12-19 15:38:04 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.permission; |
| 18 | |
| 19 | import static com.android.internal.util.Preconditions.checkArgumentNonnegative; |
| 20 | import static com.android.internal.util.Preconditions.checkNotNull; |
| 21 | |
| 22 | import android.annotation.NonNull; |
| 23 | import android.annotation.SystemApi; |
| 24 | import android.os.Parcel; |
| 25 | import 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 |
| 37 | public 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 Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 86 | public static final @android.annotation.NonNull Creator<RuntimePermissionUsageInfo> CREATOR = |
Joel Galenson | 5f63b83 | 2018-12-19 15:38:04 -0800 | [diff] [blame] | 87 | 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 | } |