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