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 public final class PermissionGroup implements Comparable<PermissionGroup> {
22     private final String mName;
23     private final String mDeclaringPackage;
24     private final CharSequence mLabel;
25     private final Drawable mIcon;
26 
PermissionGroup(String name, String declaringPackage, CharSequence label, Drawable icon)27     PermissionGroup(String name, String declaringPackage,
28             CharSequence label, Drawable icon) {
29         mDeclaringPackage = declaringPackage;
30         mName = name;
31         mLabel = label;
32         mIcon = icon;
33     }
34 
getName()35     public String getName() {
36         return mName;
37     }
38 
getDeclaringPackage()39     public String getDeclaringPackage() {
40         return mDeclaringPackage;
41     }
42 
getLabel()43     public CharSequence getLabel() {
44         return mLabel;
45     }
46 
getIcon()47     public Drawable getIcon() {
48         return mIcon;
49     }
50 
51     @Override
compareTo(PermissionGroup another)52     public int compareTo(PermissionGroup another) {
53         return mLabel.toString().compareTo(another.mLabel.toString());
54     }
55 
56     @Override
equals(Object obj)57     public boolean equals(Object obj) {
58         if (this == obj) {
59             return true;
60         }
61 
62         if (obj == null) {
63             return false;
64         }
65 
66         if (getClass() != obj.getClass()) {
67             return false;
68         }
69 
70         PermissionGroup other = (PermissionGroup) obj;
71 
72         if (mName == null) {
73             if (other.mName != null) {
74                 return false;
75             }
76         } else if (!mName.equals(other.mName)) {
77             return false;
78         }
79 
80         return true;
81     }
82 
83     @Override
hashCode()84     public int hashCode() {
85         return mName != null ? mName.hashCode() : 0;
86     }
87 }
88