• 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.packageinstaller.permission.model;
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 public final class PermissionGroup implements Comparable<PermissionGroup> {
29     private final String mName;
30     private final String mDeclaringPackage;
31     private final CharSequence mLabel;
32     private final Drawable mIcon;
33     private final int mTotal;
34     private final int mGranted;
35     private final PermissionApps mPermApps;
36 
PermissionGroup(String name, String declaringPackage, CharSequence label, Drawable icon, int total, int granted, PermissionApps permApps)37     PermissionGroup(String name, String declaringPackage, CharSequence label, Drawable icon,
38             int total, int granted, PermissionApps permApps) {
39         mDeclaringPackage = declaringPackage;
40         mName = name;
41         mLabel = label;
42         mIcon = icon;
43         mTotal = total;
44         mGranted = granted;
45         mPermApps = permApps;
46     }
47 
getName()48     public String getName() {
49         return mName;
50     }
51 
getDeclaringPackage()52     public String getDeclaringPackage() {
53         return mDeclaringPackage;
54     }
55 
getLabel()56     public CharSequence getLabel() {
57         return mLabel;
58     }
59 
getIcon()60     public Drawable getIcon() {
61         return mIcon;
62     }
63 
64     /**
65      * @return The number of apps that might request permissions of this group
66      */
getTotal()67     public int getTotal() {
68         return mTotal;
69     }
70 
71     /**
72      * @return The number of apps that were granted permissions of this group
73      */
getGranted()74     public int getGranted() {
75         return mGranted;
76     }
77 
78     /**
79      * @return The PermissionApps object for this permission group.
80      */
getPermissionApps()81     public PermissionApps getPermissionApps() {
82         return mPermApps;
83     }
84 
85     @Override
compareTo(PermissionGroup another)86     public int compareTo(PermissionGroup another) {
87         return mLabel.toString().compareTo(another.mLabel.toString());
88     }
89 
90     @Override
equals(Object obj)91     public boolean equals(Object obj) {
92         if (this == obj) {
93             return true;
94         }
95 
96         if (obj == null) {
97             return false;
98         }
99 
100         if (getClass() != obj.getClass()) {
101             return false;
102         }
103 
104         PermissionGroup other = (PermissionGroup) obj;
105 
106         if (mName == null) {
107             if (other.mName != null) {
108                 return false;
109             }
110         } else if (!mName.equals(other.mName)) {
111             return false;
112         }
113 
114         if (mTotal != other.mTotal) {
115             return false;
116         }
117 
118         if (mGranted != other.mGranted) {
119             return false;
120         }
121 
122         return true;
123     }
124 
125     @Override
hashCode()126     public int hashCode() {
127         return mName != null ? mName.hashCode() + mTotal + mGranted : mTotal + mGranted;
128     }
129 }
130