The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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; |
| 18 | |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 19 | import static android.content.res.Resources.ID_NULL; |
| 20 | |
| 21 | import android.annotation.IntDef; |
| 22 | import android.annotation.NonNull; |
| 23 | import android.annotation.Nullable; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 24 | import android.annotation.StringRes; |
| 25 | import android.annotation.SystemApi; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.os.Parcel; |
| 27 | import android.os.Parcelable; |
| 28 | import android.text.TextUtils; |
| 29 | |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 30 | import java.lang.annotation.Retention; |
| 31 | import java.lang.annotation.RetentionPolicy; |
| 32 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | /** |
| 34 | * Information you can retrieve about a particular security permission |
| 35 | * group known to the system. This corresponds to information collected from the |
| 36 | * AndroidManifest.xml's <permission-group> tags. |
| 37 | */ |
| 38 | public class PermissionGroupInfo extends PackageItemInfo implements Parcelable { |
| 39 | /** |
| 40 | * A string resource identifier (in the package's resources) of this |
| 41 | * permission's description. From the "description" attribute or, |
| 42 | * if not set, 0. |
| 43 | */ |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 44 | public @StringRes int descriptionRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 47 | * A string resource identifier (in the package's resources) used to request the permissions. |
| 48 | * From the "request" attribute or, if not set, 0. |
| 49 | * |
| 50 | * @hide |
| 51 | */ |
| 52 | @SystemApi |
| 53 | public @StringRes int requestRes; |
| 54 | |
| 55 | /** |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 56 | * A string resource identifier (in the package's resources) used as subtitle when requesting |
| 57 | * only access while in the foreground. |
| 58 | * |
| 59 | * From the "requestDetail" attribute or, if not set, {@link |
Aurimas Liutikas | d8ebfef | 2019-01-16 12:46:42 -0800 | [diff] [blame] | 60 | * android.content.res.Resources#ID_NULL}. |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 61 | * |
| 62 | * @hide |
| 63 | */ |
| 64 | @SystemApi |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 65 | public final @StringRes int requestDetailResourceId; |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * A string resource identifier (in the package's resources) used when requesting background |
| 69 | * access. Also used when requesting both foreground and background access. |
| 70 | * |
| 71 | * From the "backgroundRequest" attribute or, if not set, {@link |
Aurimas Liutikas | d8ebfef | 2019-01-16 12:46:42 -0800 | [diff] [blame] | 72 | * android.content.res.Resources#ID_NULL}. |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 73 | * |
| 74 | * @hide |
| 75 | */ |
| 76 | @SystemApi |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 77 | public final @StringRes int backgroundRequestResourceId; |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * A string resource identifier (in the package's resources) used as subtitle when requesting |
| 81 | * background access. |
| 82 | * |
| 83 | * From the "backgroundRequestDetail" attribute or, if not set, {@link |
Aurimas Liutikas | d8ebfef | 2019-01-16 12:46:42 -0800 | [diff] [blame] | 84 | * android.content.res.Resources#ID_NULL}. |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 85 | * |
| 86 | * @hide |
| 87 | */ |
| 88 | @SystemApi |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 89 | public final @StringRes int backgroundRequestDetailResourceId; |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | * The description string provided in the AndroidManifest file, if any. You |
| 93 | * probably don't want to use this, since it will be null if the description |
| 94 | * is in a resource. You probably want |
| 95 | * {@link PermissionInfo#loadDescription} instead. |
| 96 | */ |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 97 | public @Nullable CharSequence nonLocalizedDescription; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Flag for {@link #flags}, corresponding to <code>personalInfo</code> |
| 101 | * value of {@link android.R.attr#permissionGroupFlags}. |
| 102 | */ |
| 103 | public static final int FLAG_PERSONAL_INFO = 1<<0; |
| 104 | |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 105 | /** @hide */ |
| 106 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 107 | FLAG_PERSONAL_INFO, |
| 108 | }) |
| 109 | @Retention(RetentionPolicy.SOURCE) |
| 110 | public @interface Flags {} |
| 111 | |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 112 | /** |
| 113 | * Additional flags about this group as given by |
| 114 | * {@link android.R.attr#permissionGroupFlags}. |
| 115 | */ |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 116 | public @Flags int flags; |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * Prioritization of this group, for visually sorting with other groups. |
| 120 | */ |
| 121 | public int priority; |
| 122 | |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 123 | /** |
| 124 | * @hide |
| 125 | */ |
| 126 | public PermissionGroupInfo(@StringRes int requestDetailResourceId, |
| 127 | @StringRes int backgroundRequestResourceId, |
| 128 | @StringRes int backgroundRequestDetailResourceId) { |
| 129 | this.requestDetailResourceId = requestDetailResourceId; |
| 130 | this.backgroundRequestResourceId = backgroundRequestResourceId; |
| 131 | this.backgroundRequestDetailResourceId = backgroundRequestDetailResourceId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 134 | /** |
| 135 | * @deprecated Should only be created by the system. |
| 136 | */ |
| 137 | @Deprecated |
| 138 | public PermissionGroupInfo() { |
| 139 | this(ID_NULL, ID_NULL, ID_NULL); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @deprecated Should only be created by the system. |
| 144 | */ |
| 145 | @Deprecated |
| 146 | public PermissionGroupInfo(@NonNull PermissionGroupInfo orig) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | super(orig); |
| 148 | descriptionRes = orig.descriptionRes; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 149 | requestRes = orig.requestRes; |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 150 | requestDetailResourceId = orig.requestDetailResourceId; |
| 151 | backgroundRequestResourceId = orig.backgroundRequestResourceId; |
| 152 | backgroundRequestDetailResourceId = orig.backgroundRequestDetailResourceId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | nonLocalizedDescription = orig.nonLocalizedDescription; |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 154 | flags = orig.flags; |
| 155 | priority = orig.priority; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Retrieve the textual description of this permission. This |
| 160 | * will call back on the given PackageManager to load the description from |
| 161 | * the application. |
| 162 | * |
| 163 | * @param pm A PackageManager from which the label can be loaded; usually |
| 164 | * the PackageManager from which you originally retrieved this item. |
| 165 | * |
| 166 | * @return Returns a CharSequence containing the permission's description. |
| 167 | * If there is no description, null is returned. |
| 168 | */ |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 169 | public @Nullable CharSequence loadDescription(@NonNull PackageManager pm) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | if (nonLocalizedDescription != null) { |
| 171 | return nonLocalizedDescription; |
| 172 | } |
| 173 | if (descriptionRes != 0) { |
| 174 | CharSequence label = pm.getText(packageName, descriptionRes, null); |
| 175 | if (label != null) { |
| 176 | return label; |
| 177 | } |
| 178 | } |
| 179 | return null; |
| 180 | } |
| 181 | |
| 182 | public String toString() { |
| 183 | return "PermissionGroupInfo{" |
| 184 | + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 185 | + " " + name + " flgs=0x" + Integer.toHexString(flags) + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | public int describeContents() { |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 193 | super.writeToParcel(dest, parcelableFlags); |
| 194 | dest.writeInt(descriptionRes); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 195 | dest.writeInt(requestRes); |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 196 | dest.writeInt(requestDetailResourceId); |
| 197 | dest.writeInt(backgroundRequestResourceId); |
| 198 | dest.writeInt(backgroundRequestDetailResourceId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags); |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 200 | dest.writeInt(flags); |
| 201 | dest.writeInt(priority); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Philip P. Moltmann | 0635dab | 2019-03-02 11:19:03 -0800 | [diff] [blame] | 204 | public static final @NonNull Creator<PermissionGroupInfo> CREATOR = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | new Creator<PermissionGroupInfo>() { |
| 206 | public PermissionGroupInfo createFromParcel(Parcel source) { |
| 207 | return new PermissionGroupInfo(source); |
| 208 | } |
| 209 | public PermissionGroupInfo[] newArray(int size) { |
| 210 | return new PermissionGroupInfo[size]; |
| 211 | } |
| 212 | }; |
| 213 | |
| 214 | private PermissionGroupInfo(Parcel source) { |
| 215 | super(source); |
| 216 | descriptionRes = source.readInt(); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 217 | requestRes = source.readInt(); |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 218 | requestDetailResourceId = source.readInt(); |
| 219 | backgroundRequestResourceId = source.readInt(); |
| 220 | backgroundRequestDetailResourceId = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
Dianne Hackborn | fd5015b | 2012-04-30 16:33:56 -0700 | [diff] [blame] | 222 | flags = source.readInt(); |
| 223 | priority = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | } |
| 225 | } |