1 /* 2 * Copyright (C) 2016 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.content.pm.permission; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * This class contains information about how a runtime permission 26 * is to be presented in the UI. A single runtime permission 27 * presented to the user may correspond to multiple platform defined 28 * permissions, e.g. the location permission may control both the 29 * coarse and fine platform permissions. 30 * 31 * @hide 32 * 33 * @deprecated Not used anymore. Use {@link android.permission.RuntimePermissionPresentationInfo} 34 * instead 35 */ 36 @Deprecated 37 @SystemApi 38 public final class RuntimePermissionPresentationInfo implements Parcelable { 39 private static final int FLAG_GRANTED = 1 << 0; 40 private static final int FLAG_STANDARD = 1 << 1; 41 42 private final CharSequence mLabel; 43 private final int mFlags; 44 45 /** 46 * Creates a new instance. 47 * 48 * @param label The permission label. 49 * @param granted Whether the permission is granted. 50 * @param standard Whether this is a platform-defined permission. 51 */ RuntimePermissionPresentationInfo(CharSequence label, boolean granted, boolean standard)52 public RuntimePermissionPresentationInfo(CharSequence label, 53 boolean granted, boolean standard) { 54 mLabel = label; 55 int flags = 0; 56 if (granted) { 57 flags |= FLAG_GRANTED; 58 } 59 if (standard) { 60 flags |= FLAG_STANDARD; 61 } 62 mFlags = flags; 63 } 64 RuntimePermissionPresentationInfo(Parcel parcel)65 private RuntimePermissionPresentationInfo(Parcel parcel) { 66 mLabel = parcel.readCharSequence(); 67 mFlags = parcel.readInt(); 68 } 69 70 /** 71 * @return Whether the permission is granted. 72 */ isGranted()73 public boolean isGranted() { 74 return (mFlags & FLAG_GRANTED) != 0; 75 } 76 77 /** 78 * @return Whether the permission is platform-defined. 79 */ isStandard()80 public boolean isStandard() { 81 return (mFlags & FLAG_STANDARD) != 0; 82 } 83 84 /** 85 * Gets the permission label. 86 * 87 * @return The label. 88 */ getLabel()89 public @NonNull CharSequence getLabel() { 90 return mLabel; 91 } 92 93 @Override describeContents()94 public int describeContents() { 95 return 0; 96 } 97 98 @Override writeToParcel(Parcel parcel, int flags)99 public void writeToParcel(Parcel parcel, int flags) { 100 parcel.writeCharSequence(mLabel); 101 parcel.writeInt(mFlags); 102 } 103 104 public static final @android.annotation.NonNull Creator<RuntimePermissionPresentationInfo> CREATOR = 105 new Creator<RuntimePermissionPresentationInfo>() { 106 public RuntimePermissionPresentationInfo createFromParcel(Parcel source) { 107 return new RuntimePermissionPresentationInfo(source); 108 } 109 110 public RuntimePermissionPresentationInfo[] newArray(int size) { 111 return new RuntimePermissionPresentationInfo[size]; 112 } 113 }; 114 } 115