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 String 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 */ RuntimePermissionUsageInfo(@onNull String name, int numUsers)47 public RuntimePermissionUsageInfo(@NonNull String name, int numUsers) { 48 checkNotNull(name); 49 checkArgumentNonnegative(numUsers); 50 51 mName = name; 52 mNumUsers = numUsers; 53 } 54 RuntimePermissionUsageInfo(Parcel parcel)55 private RuntimePermissionUsageInfo(Parcel parcel) { 56 this(parcel.readString(), parcel.readInt()); 57 } 58 59 /** 60 * @return The number of apps that accessed this permission 61 */ getAppAccessCount()62 public int getAppAccessCount() { 63 return mNumUsers; 64 } 65 66 /** 67 * Gets the permission group name. 68 * 69 * @return The name. 70 */ getName()71 public @NonNull String getName() { 72 return mName; 73 } 74 75 @Override describeContents()76 public int describeContents() { 77 return 0; 78 } 79 80 @Override writeToParcel(Parcel parcel, int flags)81 public void writeToParcel(Parcel parcel, int flags) { 82 parcel.writeString(mName); 83 parcel.writeInt(mNumUsers); 84 } 85 86 public static final @android.annotation.NonNull Creator<RuntimePermissionUsageInfo> CREATOR = 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 } 97