• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 com.android.permissioncontroller.permission.model.legacy;
18 
19 import android.graphics.drawable.Drawable;
20 
21 /**
22  * A permission group with runtime permission as defined in an app's manifest as
23  * {@code android:permission-group}.
24  *
25  * <p>For individual permissions that are not part of any group a {@link PermissionGroup} is created
26  * dynamically with the name and icon of the individual permission.
27  *
28  * @deprecated Use classes from permission.ui.model instead
29  */
30 @Deprecated
31 public final class PermissionGroup implements Comparable<PermissionGroup> {
32     private final String mName;
33     private final String mDeclaringPackage;
34     private final CharSequence mLabel;
35     private final Drawable mIcon;
36     private final int mTotal;
37     private final int mGranted;
38     private final PermissionApps mPermApps;
39 
PermissionGroup(String name, String declaringPackage, CharSequence label, Drawable icon, int total, int granted, PermissionApps permApps)40     PermissionGroup(String name, String declaringPackage, CharSequence label, Drawable icon,
41             int total, int granted, PermissionApps permApps) {
42         mDeclaringPackage = declaringPackage;
43         mName = name;
44         mLabel = label;
45         mIcon = icon;
46         mTotal = total;
47         mGranted = granted;
48         mPermApps = permApps;
49     }
50 
getName()51     public String getName() {
52         return mName;
53     }
54 
getDeclaringPackage()55     public String getDeclaringPackage() {
56         return mDeclaringPackage;
57     }
58 
getLabel()59     public CharSequence getLabel() {
60         return mLabel;
61     }
62 
getIcon()63     public Drawable getIcon() {
64         return mIcon;
65     }
66 
67     /**
68      * @return The number of apps that might request permissions of this group
69      */
getTotal()70     public int getTotal() {
71         return mTotal;
72     }
73 
74     /**
75      * @return The number of apps that were granted permissions of this group
76      */
getGranted()77     public int getGranted() {
78         return mGranted;
79     }
80 
81     /**
82      * @return The PermissionApps object for this permission group.
83      */
getPermissionApps()84     public PermissionApps getPermissionApps() {
85         return mPermApps;
86     }
87 
88     @Override
compareTo(PermissionGroup another)89     public int compareTo(PermissionGroup another) {
90         return mLabel.toString().compareTo(another.mLabel.toString());
91     }
92 
93     @Override
equals(Object obj)94     public boolean equals(Object obj) {
95         if (this == obj) {
96             return true;
97         }
98 
99         if (obj == null) {
100             return false;
101         }
102 
103         if (getClass() != obj.getClass()) {
104             return false;
105         }
106 
107         PermissionGroup other = (PermissionGroup) obj;
108 
109         if (mName == null) {
110             if (other.mName != null) {
111                 return false;
112             }
113         } else if (!mName.equals(other.mName)) {
114             return false;
115         }
116 
117         if (mTotal != other.mTotal) {
118             return false;
119         }
120 
121         if (mGranted != other.mGranted) {
122             return false;
123         }
124 
125         return true;
126     }
127 
128     @Override
hashCode()129     public int hashCode() {
130         return mName != null ? mName.hashCode() + mTotal + mGranted : mTotal + mGranted;
131     }
132 }
133