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
17package com.android.packageinstaller.permission.model;
18
19import android.graphics.drawable.Drawable;
20
21public 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
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
35    public String getName() {
36        return mName;
37    }
38
39    public String getDeclaringPackage() {
40        return mDeclaringPackage;
41    }
42
43    public CharSequence getLabel() {
44        return mLabel;
45    }
46
47    public Drawable getIcon() {
48        return mIcon;
49    }
50
51    @Override
52    public int compareTo(PermissionGroup another) {
53        return mLabel.toString().compareTo(another.mLabel.toString());
54    }
55
56    @Override
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
84    public int hashCode() {
85        return mName != null ? mName.hashCode() : 0;
86    }
87}
88