Debian Codegraph @

core/java/android/permission/RuntimePermissionPresentationInfo.java

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