• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.permission;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.TestApi;
22 
23 /**
24  * Represents the usage of a permission group by an app. Supports package name, user, permission
25  * group, whether or not the access is running or recent, whether the access is tied to a phone
26  * call, and an optional special attribution.
27  *
28  * @hide
29  */
30 @TestApi
31 public final class PermGroupUsage {
32 
33     private final String mPackageName;
34     private final int mUid;
35     private final long mLastAccess;
36     private final String mPermGroupName;
37     private final boolean mIsActive;
38     private final boolean mIsPhoneCall;
39     private final CharSequence mAttribution;
40 
41     /**
42      *
43      * @param packageName The package name of the using app
44      * @param uid The uid of the using app
45      * @param permGroupName The name of the permission group being used
46      * @param lastAccess The time of last access
47      * @param isActive Whether this is active
48      * @param isPhoneCall Whether this is a usage by the phone
49      * @param attribution An optional string attribution to show
50      * @hide
51      */
52     @TestApi
PermGroupUsage(@onNull String packageName, int uid, @NonNull String permGroupName, long lastAccess, boolean isActive, boolean isPhoneCall, @Nullable CharSequence attribution)53     public PermGroupUsage(@NonNull String packageName, int uid,
54             @NonNull String permGroupName, long lastAccess, boolean isActive, boolean isPhoneCall,
55             @Nullable CharSequence attribution) {
56         this.mPackageName = packageName;
57         this.mUid = uid;
58         this.mPermGroupName = permGroupName;
59         this.mLastAccess = lastAccess;
60         this.mIsActive = isActive;
61         this.mIsPhoneCall = isPhoneCall;
62         this.mAttribution = attribution;
63     }
64 
65     /**
66      * @hide
67      */
68     @TestApi
getPackageName()69     public @NonNull String getPackageName() {
70         return mPackageName;
71     }
72 
73     /**
74      * @hide
75      */
76     @TestApi
getUid()77     public int getUid() {
78         return mUid;
79     }
80 
81     /**
82      * @hide
83      */
84     @TestApi
getPermGroupName()85     public @NonNull String getPermGroupName() {
86         return mPermGroupName;
87     }
88 
89     /**
90      * @hide
91      */
92     @TestApi
getLastAccess()93     public long getLastAccess() {
94         return mLastAccess;
95     }
96 
97     /**
98      * @hide
99      */
100     @TestApi
isActive()101     public boolean isActive() {
102         return mIsActive;
103     }
104 
105     /**
106      * @hide
107      */
108     @TestApi
isPhoneCall()109     public boolean isPhoneCall() {
110         return mIsPhoneCall;
111     }
112 
113     /**
114      * @hide
115      */
116     @TestApi
getAttribution()117     public @Nullable CharSequence getAttribution() {
118         return mAttribution;
119     }
120 
121     @Override
toString()122     public String toString() {
123         return getClass().getSimpleName() + "@" + Integer.toHexString(System.identityHashCode(this))
124                 + " packageName: " + mPackageName + ", UID: " + mUid + ", permGroup: "
125                 + mPermGroupName + ", lastAccess: " + mLastAccess + ", isActive: " + mIsActive
126                 + ", attribution: " + mAttribution;
127     }
128 }
129