blob: 97312c44a9958b7c9ebbe2d7cebd7f53007d7942 [file] [log] [blame]
Svet Ganovae0e03a2016-02-25 18:22:10 -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.content.pm.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
Philip P. Moltmanndbf78b82018-12-04 13:44:27 -080032 *
33 * @deprecated Not used anymore. Use {@link android.permission.RuntimePermissionPresentationInfo}
34 * instead
Svet Ganovae0e03a2016-02-25 18:22:10 -080035 */
Philip P. Moltmanndbf78b82018-12-04 13:44:27 -080036@Deprecated
Svet Ganovae0e03a2016-02-25 18:22:10 -080037@SystemApi
38public 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 */
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
65 private RuntimePermissionPresentationInfo(Parcel parcel) {
66 mLabel = parcel.readCharSequence();
67 mFlags = parcel.readInt();
68 }
69
70 /**
71 * @return Whether the permission is granted.
72 */
73 public boolean isGranted() {
74 return (mFlags & FLAG_GRANTED) != 0;
75 }
76
77 /**
78 * @return Whether the permission is platform-defined.
79 */
80 public boolean isStandard() {
81 return (mFlags & FLAG_STANDARD) != 0;
82 }
83
84 /**
85 * Gets the permission label.
86 *
87 * @return The label.
88 */
89 public @NonNull CharSequence getLabel() {
90 return mLabel;
91 }
92
93 @Override
94 public int describeContents() {
95 return 0;
96 }
97
98 @Override
99 public void writeToParcel(Parcel parcel, int flags) {
100 parcel.writeCharSequence(mLabel);
101 parcel.writeInt(mFlags);
102 }
103
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700104 public static final @android.annotation.NonNull Creator<RuntimePermissionPresentationInfo> CREATOR =
Svet Ganovae0e03a2016-02-25 18:22:10 -0800105 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}