• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.parsing.component;
18 
19 import static android.content.pm.parsing.ParsingPackageImpl.sForInternedString;
20 
21 import android.annotation.IntDef;
22 import android.annotation.NonNull;
23 import android.content.pm.PackageInfo;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 
30 /**
31  * A {@link android.R.styleable#AndroidManifestUsesPermission
32  * <uses-permission>} tag parsed from the manifest.
33  *
34  * @hide
35  */
36 public class ParsedUsesPermission implements Parcelable {
37     /** Name of the permission requested */
38     public @NonNull String name;
39 
40     /** Set of flags that should apply to this permission request. */
41     public @UsesPermissionFlags int usesPermissionFlags;
42 
43     /**
44      * Strong assertion by a developer that they will never use this permission
45      * to derive the physical location of the device, regardless of
46      * ACCESS_FINE_LOCATION and/or ACCESS_COARSE_LOCATION being granted.
47      */
48     public static final int FLAG_NEVER_FOR_LOCATION =
49             PackageInfo.REQUESTED_PERMISSION_NEVER_FOR_LOCATION;
50 
51     /** @hide */
52     @Retention(RetentionPolicy.SOURCE)
53     @IntDef(flag = true, prefix = { "FLAG_" }, value = {
54             FLAG_NEVER_FOR_LOCATION
55     })
56     public @interface UsesPermissionFlags {}
57 
ParsedUsesPermission(@onNull String name, @UsesPermissionFlags int usesPermissionFlags)58     public ParsedUsesPermission(@NonNull String name,
59             @UsesPermissionFlags int usesPermissionFlags) {
60         this.name = name.intern();
61         this.usesPermissionFlags = usesPermissionFlags;
62     }
63 
64     @Override
writeToParcel(@onNull Parcel dest, int flags)65     public void writeToParcel(@NonNull Parcel dest, int flags) {
66         sForInternedString.parcel(this.name, dest, flags);
67         dest.writeInt(usesPermissionFlags);
68     }
69 
70     @Override
describeContents()71     public int describeContents() {
72         return 0;
73     }
74 
ParsedUsesPermission(@onNull Parcel in)75     protected ParsedUsesPermission(@NonNull Parcel in) {
76         this.name = sForInternedString.unparcel(in);
77         this.usesPermissionFlags = in.readInt();
78     }
79 
80     public static final @NonNull Parcelable.Creator<ParsedUsesPermission> CREATOR
81             = new Parcelable.Creator<ParsedUsesPermission>() {
82         @Override
83         public ParsedUsesPermission[] newArray(int size) {
84             return new ParsedUsesPermission[size];
85         }
86 
87         @Override
88         public ParsedUsesPermission createFromParcel(@NonNull Parcel in) {
89             return new ParsedUsesPermission(in);
90         }
91     };
92 }
93