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     @Override
compareTo(PermissionGroup another)82     public int compareTo(PermissionGroup another) {
83         return mLabel.toString().compareTo(another.mLabel.toString());
84     }
85 
86     @Override
equals(Object obj)87     public boolean equals(Object obj) {
88         if (this == obj) {
89             return true;
90         }
91 
92         if (obj == null) {
93             return false;
94         }
95 
96         if (getClass() != obj.getClass()) {
97             return false;
98         }
99 
100         PermissionGroup other = (PermissionGroup) obj;
101 
102         if (mName == null) {
103             if (other.mName != null) {
104                 return false;
105             }
106         } else if (!mName.equals(other.mName)) {
107             return false;
108         }
109 
110         if (mTotal != other.mTotal) {
111             return false;
112         }
113 
114         if (mGranted != other.mGranted) {
115             return false;
116         }
117 
118         return true;
119     }
120 
121     @Override
hashCode()122     public int hashCode() {
123         return mName != null ? mName.hashCode() + mTotal + mGranted : mTotal + mGranted;
124     }
125 }
126