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