blob: ed7b05c83046b39d44b1dd48e46005219169c982 [file] [log] [blame]
Philip P. Moltmanndbf78b82018-12-04 13:44:27 -08001/*
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
17package android.permission;
18
19import android.annotation.NonNull;
20import android.annotation.SystemApi;
21import android.os.Parcel;
22import 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@SystemApi
34public final class RuntimePermissionPresentationInfo implements Parcelable {
35 private static final int FLAG_GRANTED = 1 << 0;
36 private static final int FLAG_STANDARD = 1 << 1;
37
38 private final CharSequence mLabel;
39 private final int mFlags;
40
41 /**
42 * Creates a new instance.
43 *
44 * @param label The permission label.
45 * @param granted Whether the permission is granted.
46 * @param standard Whether this is a platform-defined permission.
47 */
48 public RuntimePermissionPresentationInfo(CharSequence label,
49 boolean granted, boolean standard) {
50 mLabel = label;
51 int flags = 0;
52 if (granted) {
53 flags |= FLAG_GRANTED;
54 }
55 if (standard) {
56 flags |= FLAG_STANDARD;
57 }
58 mFlags = flags;
59 }
60
61 private RuntimePermissionPresentationInfo(Parcel parcel) {
62 mLabel = parcel.readCharSequence();
63 mFlags = parcel.readInt();
64 }
65
66 /**
67 * @return Whether the permission is granted.
68 */
69 public boolean isGranted() {
70 return (mFlags & FLAG_GRANTED) != 0;
71 }
72
73 /**
74 * @return Whether the permission is platform-defined.
75 */
76 public boolean isStandard() {
77 return (mFlags & FLAG_STANDARD) != 0;
78 }
79
80 /**
81 * Gets the permission label.
82 *
83 * @return The label.
84 */
85 public @NonNull CharSequence getLabel() {
86 return mLabel;
87 }
88
89 @Override
90 public int describeContents() {
91 return 0;
92 }
93
94 @Override
95 public void writeToParcel(Parcel parcel, int flags) {
96 parcel.writeCharSequence(mLabel);
97 parcel.writeInt(mFlags);
98 }
99
100 public static final Creator<RuntimePermissionPresentationInfo> CREATOR =
101 new Creator<RuntimePermissionPresentationInfo>() {
102 public RuntimePermissionPresentationInfo createFromParcel(Parcel source) {
103 return new RuntimePermissionPresentationInfo(source);
104 }
105
106 public RuntimePermissionPresentationInfo[] newArray(int size) {
107 return new RuntimePermissionPresentationInfo[size];
108 }
109 };
110}