Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
| 19 | import android.annotation.IntDef; |
| 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | import java.lang.annotation.RetentionPolicy; |
| 24 | /** |
| 25 | * Information you can retrive about a particular application requested permission. This |
| 26 | * corresponds to information collected from the AndroidManifest.xml's <uses-permission> |
| 27 | * tags. |
| 28 | */ |
| 29 | public final class UsesPermissionInfo extends PackageItemInfo implements Parcelable { |
| 30 | |
| 31 | /** |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 32 | * Flag for {@link #getFlags()}: the requested permission is currently granted to the |
| 33 | * application. |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 34 | */ |
| 35 | public static final int FLAG_REQUESTED_PERMISSION_GRANTED = 1 << 1; |
| 36 | |
| 37 | /** @hide */ |
| 38 | @IntDef(flag = true, prefix = {"FLAG_"}, value = {FLAG_REQUESTED_PERMISSION_GRANTED}) |
| 39 | @java.lang.annotation.Retention(RetentionPolicy.SOURCE) |
| 40 | public @interface Flags {} |
| 41 | |
| 42 | /** An unset value for {@link #getDataSentOffDevice()}, |
| 43 | * {@link #getDataSharedWithThirdParty()}, and {@link #getDataUsedForMonetization()} |
| 44 | */ |
| 45 | public static final int USAGE_UNDEFINED = 0; |
| 46 | |
| 47 | /** |
| 48 | * A yes value for {@link #getDataSentOffDevice()}, {@link #getDataSharedWithThirdParty()}, |
| 49 | * and {@link #getDataUsedForMonetization()} corresponding to the <code>yes</code> value of |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 50 | * {@link android.R.attr#dataSentOffDevice}, {@link android.R.attr#dataSharedWithThirdParty}, |
| 51 | * and {@link android.R.attr#dataUsedForMonetization} attributes. |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 52 | */ |
| 53 | public static final int USAGE_YES = 1; |
| 54 | |
| 55 | /** |
| 56 | * A user triggered only value for {@link #getDataSentOffDevice()}, |
| 57 | * {@link #getDataSharedWithThirdParty()}, and {@link #getDataUsedForMonetization()} |
| 58 | * corresponding to the <code>userTriggered</code> value of |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 59 | * {@link android.R.attr#dataSentOffDevice}, {@link android.R.attr#dataSharedWithThirdParty}, |
| 60 | * and {@link android.R.attr#dataUsedForMonetization} attributes. |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 61 | */ |
| 62 | public static final int USAGE_USER_TRIGGERED = 2; |
| 63 | |
| 64 | /** |
| 65 | * A no value for {@link #getDataSentOffDevice()}, {@link #getDataSharedWithThirdParty()}, |
| 66 | * and {@link #getDataUsedForMonetization()} corresponding to the <code>no</code> value of |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 67 | * {@link android.R.attr#dataSentOffDevice}, {@link android.R.attr#dataSharedWithThirdParty}, |
| 68 | * and {@link android.R.attr#dataUsedForMonetization} attributes. |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 69 | */ |
| 70 | public static final int USAGE_NO = 3; |
| 71 | |
| 72 | /** @hide */ |
| 73 | @IntDef(prefix = {"USAGE_"}, value = { |
| 74 | USAGE_UNDEFINED, |
| 75 | USAGE_YES, |
| 76 | USAGE_USER_TRIGGERED, |
| 77 | USAGE_NO}) |
| 78 | @java.lang.annotation.Retention(RetentionPolicy.SOURCE) |
| 79 | public @interface Usage {} |
| 80 | |
| 81 | /** |
| 82 | * An unset value for {@link #getDataRetention}. |
| 83 | */ |
| 84 | public static final int RETENTION_UNDEFINED = 0; |
| 85 | |
| 86 | /** |
| 87 | * A data not retained value for {@link #getDataRetention()} corresponding to the |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 88 | * <code>notRetained</code> value of {@link android.R.attr#dataRetentionTime}. |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 89 | */ |
| 90 | public static final int RETENTION_NOT_RETAINED = 1; |
| 91 | |
| 92 | /** |
| 93 | * A user selected value for {@link #getDataRetention()} corresponding to the |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 94 | * <code>userSelected</code> value of {@link android.R.attr#dataRetentionTime}. |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 95 | */ |
| 96 | public static final int RETENTION_USER_SELECTED = 2; |
| 97 | |
| 98 | /** |
| 99 | * An unlimited value for {@link #getDataRetention()} corresponding to the |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 100 | * <code>unlimited</code> value of {@link android.R.attr#dataRetentionTime}. |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 101 | */ |
| 102 | public static final int RETENTION_UNLIMITED = 3; |
| 103 | |
| 104 | /** |
| 105 | * A specified value for {@link #getDataRetention()} corresponding to providing the number of |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 106 | * weeks data is retained in {@link android.R.attr#dataRetentionTime}. The number of weeks |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 107 | * is available in {@link #getDataRetentionWeeks()}. |
| 108 | */ |
| 109 | public static final int RETENTION_SPECIFIED = 4; |
| 110 | |
| 111 | /** @hide */ |
| 112 | @IntDef(prefix = {"RETENTION_"}, value = { |
| 113 | RETENTION_UNDEFINED, |
| 114 | RETENTION_NOT_RETAINED, |
| 115 | RETENTION_USER_SELECTED, |
| 116 | RETENTION_UNLIMITED, |
| 117 | RETENTION_SPECIFIED}) |
| 118 | @java.lang.annotation.Retention(RetentionPolicy.SOURCE) |
| 119 | public @interface Retention {} |
| 120 | |
| 121 | private final String mPermission; |
| 122 | private final @Flags int mFlags; |
| 123 | private final @Usage int mDataSentOffDevice; |
| 124 | private final @Usage int mDataSharedWithThirdParty; |
| 125 | private final @Usage int mDataUsedForMonetization; |
| 126 | private final @Retention int mDataRetention; |
| 127 | private final int mDataRetentionWeeks; |
| 128 | |
| 129 | /** @hide */ |
| 130 | public UsesPermissionInfo(String permission) { |
| 131 | mPermission = permission; |
| 132 | mDataSentOffDevice = USAGE_UNDEFINED; |
| 133 | mDataSharedWithThirdParty = USAGE_UNDEFINED; |
| 134 | mDataUsedForMonetization = USAGE_UNDEFINED; |
| 135 | mDataRetention = RETENTION_UNDEFINED; |
| 136 | mDataRetentionWeeks = -1; |
| 137 | mFlags = 0; |
| 138 | } |
| 139 | |
| 140 | /** @hide */ |
| 141 | public UsesPermissionInfo(String permission, |
| 142 | @Usage int dataSentOffDevice, @Usage int dataSharedWithThirdParty, |
| 143 | @Usage int dataUsedForMonetization, @Retention int dataRetention, |
| 144 | int dataRetentionWeeks) { |
| 145 | mPermission = permission; |
| 146 | mDataSentOffDevice = dataSentOffDevice; |
| 147 | mDataSharedWithThirdParty = dataSharedWithThirdParty; |
| 148 | mDataUsedForMonetization = dataUsedForMonetization; |
| 149 | mDataRetention = dataRetention; |
| 150 | mDataRetentionWeeks = dataRetentionWeeks; |
| 151 | mFlags = 0; |
| 152 | } |
| 153 | |
| 154 | /** @hide */ |
| 155 | public UsesPermissionInfo(UsesPermissionInfo orig) { |
| 156 | this(orig, orig.mFlags); |
| 157 | } |
| 158 | |
| 159 | /** @hide */ |
| 160 | public UsesPermissionInfo(UsesPermissionInfo orig, int flags) { |
| 161 | super(orig); |
| 162 | mPermission = orig.mPermission; |
| 163 | mFlags = flags; |
| 164 | mDataSentOffDevice = orig.mDataSentOffDevice; |
| 165 | mDataSharedWithThirdParty = orig.mDataSharedWithThirdParty; |
| 166 | mDataUsedForMonetization = orig.mDataUsedForMonetization; |
| 167 | mDataRetention = orig.mDataRetention; |
| 168 | mDataRetentionWeeks = orig.mDataRetentionWeeks; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * The name of the requested permission. |
| 173 | */ |
| 174 | public String getPermission() { |
| 175 | return mPermission; |
| 176 | } |
| 177 | |
| 178 | public @Flags int getFlags() { |
| 179 | return mFlags; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * If the application sends the data guarded by this permission off the device. |
| 184 | * |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 185 | * See {@link android.R.attr#dataSentOffDevice} |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 186 | */ |
| 187 | public @Usage int getDataSentOffDevice() { |
| 188 | return mDataSentOffDevice; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * If the application or its services shares the data guarded by this permission with third |
| 193 | * parties. |
| 194 | * |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 195 | * See {@link android.R.attr#dataSharedWithThirdParty} |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 196 | */ |
| 197 | public @Usage int getDataSharedWithThirdParty() { |
| 198 | return mDataSharedWithThirdParty; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * If the application or its services use the data guarded by this permission for monetization |
| 203 | * purposes. |
| 204 | * |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 205 | * See {@link android.R.attr#dataUsedForMonetization} |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 206 | */ |
| 207 | public @Usage int getDataUsedForMonetization() { |
| 208 | return mDataUsedForMonetization; |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * How long the application or its services store the data guarded by this permission. |
| 213 | * If set to {@link #RETENTION_SPECIFIED} {@link #getDataRetentionWeeks()} will contain the |
| 214 | * number of weeks the data is stored. |
| 215 | * |
Chad Brubaker | 125970d | 2018-11-29 13:30:09 -0800 | [diff] [blame] | 216 | * See {@link android.R.attr#dataRetentionTime} |
Chad Brubaker | a58ce39 | 2018-10-29 14:14:22 -0700 | [diff] [blame] | 217 | */ |
| 218 | public @Retention int getDataRetention() { |
| 219 | return mDataRetention; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * If {@link #getDataRetention()} is {@link #RETENTION_SPECIFIED} the number of weeks the |
| 224 | * application or its services store data guarded by this permission. |
| 225 | * |
| 226 | * @throws IllegalStateException if {@link #getDataRetention} is not |
| 227 | * {@link #RETENTION_SPECIFIED}. |
| 228 | */ |
| 229 | public int getDataRetentionWeeks() { |
| 230 | if (mDataRetention != RETENTION_SPECIFIED) { |
| 231 | throw new IllegalStateException("Data retention weeks not specified"); |
| 232 | } |
| 233 | return mDataRetentionWeeks; |
| 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public int describeContents() { |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public void writeToParcel(Parcel dest, int flags) { |
| 243 | super.writeToParcel(dest, flags); |
| 244 | dest.writeString(mPermission); |
| 245 | dest.writeInt(mFlags); |
| 246 | dest.writeInt(mDataSentOffDevice); |
| 247 | dest.writeInt(mDataSharedWithThirdParty); |
| 248 | dest.writeInt(mDataUsedForMonetization); |
| 249 | dest.writeInt(mDataRetention); |
| 250 | dest.writeInt(mDataRetentionWeeks); |
| 251 | } |
| 252 | |
| 253 | private UsesPermissionInfo(Parcel source) { |
| 254 | super(source); |
| 255 | mPermission = source.readString(); |
| 256 | mFlags = source.readInt(); |
| 257 | mDataSentOffDevice = source.readInt(); |
| 258 | mDataSharedWithThirdParty = source.readInt(); |
| 259 | mDataUsedForMonetization = source.readInt(); |
| 260 | mDataRetention = source.readInt(); |
| 261 | mDataRetentionWeeks = source.readInt(); |
| 262 | } |
| 263 | |
| 264 | public static final Creator<UsesPermissionInfo> CREATOR = |
| 265 | new Creator<UsesPermissionInfo>() { |
| 266 | @Override |
| 267 | public UsesPermissionInfo createFromParcel(Parcel source) { |
| 268 | return new UsesPermissionInfo(source); |
| 269 | } |
| 270 | @Override |
| 271 | public UsesPermissionInfo[] newArray(int size) { |
| 272 | return new UsesPermissionInfo[size]; |
| 273 | } |
| 274 | }; |
| 275 | } |