1 /* 2 * Copyright (C) 2021 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.internal.telephony.uicc; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Used to present ADN capacity 24 * 25 * {@hide} 26 */ 27 public class AdnCapacity implements Parcelable { 28 29 private int mMaxAdnCount; 30 private int mUsedAdnCount; 31 private int mMaxEmailCount; 32 private int mUsedEmailCount; 33 private int mMaxAnrCount; 34 private int mUsedAnrCount; 35 private int mMaxNameLength; 36 private int mMaxNumberLength; 37 private int mMaxEmailLength; 38 private int mMaxAnrLength; 39 40 private int mHashCode = 0; 41 AdnCapacity(int maxAdnCount, int usedAdnCount, int maxEmailCount, int usedEmailCount, int maxAnrCount, int usedAnrCount, int maxNameLength, int maxNumberLength, int maxEmailLength, int maxAnrLength)42 public AdnCapacity(int maxAdnCount, int usedAdnCount, int maxEmailCount, 43 int usedEmailCount, int maxAnrCount, int usedAnrCount, int maxNameLength, 44 int maxNumberLength, int maxEmailLength, int maxAnrLength) { 45 mMaxAdnCount = maxAdnCount; 46 mUsedAdnCount = usedAdnCount; 47 mMaxEmailCount = maxEmailCount; 48 mUsedEmailCount = usedEmailCount; 49 mMaxAnrCount = maxAnrCount; 50 mUsedAnrCount = usedAnrCount; 51 mMaxNameLength = maxNameLength; 52 mMaxNumberLength = maxNumberLength; 53 mMaxEmailLength = maxEmailLength; 54 mMaxAnrLength = maxAnrLength; 55 } 56 AdnCapacity()57 public AdnCapacity() { 58 this(0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 59 } 60 getMaxAdnCount()61 public int getMaxAdnCount() { 62 return mMaxAdnCount; 63 } 64 getUsedAdnCount()65 public int getUsedAdnCount() { 66 return mUsedAdnCount; 67 } 68 getMaxEmailCount()69 public int getMaxEmailCount() { 70 return mMaxEmailCount; 71 } 72 getUsedEmailCount()73 public int getUsedEmailCount() { 74 return mUsedEmailCount; 75 } 76 getMaxAnrCount()77 public int getMaxAnrCount() { 78 return mMaxAnrCount; 79 } 80 getUsedAnrCount()81 public int getUsedAnrCount() { 82 return mUsedAnrCount; 83 } 84 getMaxNameLength()85 public int getMaxNameLength() { 86 return mMaxNameLength; 87 } 88 getMaxNumberLength()89 public int getMaxNumberLength() { 90 return mMaxNumberLength; 91 } 92 getMaxEmailLength()93 public int getMaxEmailLength() { 94 return mMaxEmailLength; 95 } 96 getMaxAnrLength()97 public int getMaxAnrLength() { 98 return mMaxAnrLength; 99 } 100 isSimFull()101 public boolean isSimFull() { 102 return mMaxAdnCount == mUsedAdnCount; 103 } 104 isSimEmpty()105 public boolean isSimEmpty() { 106 return mUsedAdnCount == 0; 107 } 108 isSimValid()109 public boolean isSimValid() { 110 return mMaxAdnCount > 0; 111 } 112 113 @Override toString()114 public String toString() { 115 String capacity = "getAdnRecordsCapacity : max adn=" + mMaxAdnCount 116 + ", used adn=" + mUsedAdnCount 117 + ", max email=" + mMaxEmailCount 118 + ", used email=" + mUsedEmailCount 119 + ", max anr=" + mMaxAnrCount 120 + ", used anr=" + mUsedAnrCount 121 + ", max name length=" + mMaxNameLength 122 + ", max number length =" + mMaxNumberLength 123 + ", max email length =" + mMaxEmailLength 124 + ", max anr length =" + mMaxAnrLength; 125 return capacity; 126 } 127 128 public static final Parcelable.Creator<AdnCapacity> CREATOR 129 = new Parcelable.Creator<AdnCapacity>() { 130 @Override 131 public AdnCapacity createFromParcel(Parcel source) { 132 final int maxAdnCount = source.readInt(); 133 final int usedAdnCount = source.readInt(); 134 final int maxEmailCount = source.readInt(); 135 final int usedEmailCount = source.readInt(); 136 final int maxAnrCount = source.readInt(); 137 final int usedAnrCount = source.readInt(); 138 final int maxNameLength = source.readInt(); 139 final int maxNumberLength = source.readInt(); 140 final int maxEmailLength = source.readInt(); 141 final int maxAnrLength = source.readInt(); 142 return new AdnCapacity(maxAdnCount, usedAdnCount, maxEmailCount, 143 usedEmailCount, maxAnrCount, usedAnrCount, maxNameLength, 144 maxNumberLength, maxEmailLength, maxAnrLength); 145 } 146 147 @Override 148 public AdnCapacity[] newArray(int size) { 149 return new AdnCapacity[size]; 150 } 151 }; 152 153 @Override describeContents()154 public int describeContents() { 155 return 0; 156 } 157 158 @Override writeToParcel(Parcel dest, int flags)159 public void writeToParcel(Parcel dest, int flags) { 160 dest.writeInt(mMaxAdnCount); 161 dest.writeInt(mUsedAdnCount); 162 dest.writeInt(mMaxEmailCount); 163 dest.writeInt(mUsedEmailCount); 164 dest.writeInt(mMaxAnrCount); 165 dest.writeInt(mUsedAnrCount); 166 dest.writeInt(mMaxNameLength); 167 dest.writeInt(mMaxNumberLength); 168 dest.writeInt(mMaxEmailLength); 169 dest.writeInt(mMaxAnrLength); 170 } 171 172 @Override equals(Object obj)173 public boolean equals(Object obj) { 174 if (obj instanceof AdnCapacity) { 175 AdnCapacity capacity = (AdnCapacity)obj; 176 return capacity.getMaxAdnCount() == mMaxAdnCount 177 && capacity.getUsedAdnCount() == mUsedAdnCount 178 && capacity.getMaxEmailCount() == mMaxEmailCount 179 && capacity.getUsedEmailCount() == mUsedEmailCount 180 && capacity.getMaxAnrCount() == mMaxAnrCount 181 && capacity.getUsedAnrCount() == mUsedAnrCount 182 && capacity.getMaxNameLength() == mMaxNameLength 183 && capacity.getMaxNumberLength() == mMaxNumberLength 184 && capacity.getMaxEmailLength() == mMaxEmailLength 185 && capacity.getMaxAnrLength() == mMaxAnrLength; 186 } else { 187 return false; 188 } 189 } 190 191 @Override hashCode()192 public int hashCode() { 193 if (mHashCode == 0) { 194 mHashCode = mMaxAdnCount; 195 mHashCode = 31 * mHashCode + mUsedAdnCount; 196 mHashCode = 31 * mHashCode + mMaxEmailCount; 197 mHashCode = 31 * mHashCode + mUsedEmailCount; 198 mHashCode = 31 * mHashCode + mMaxAnrCount; 199 mHashCode = 31 * mHashCode + mUsedAnrCount; 200 mHashCode = 31 * mHashCode + mMaxNameLength; 201 mHashCode = 31 * mHashCode + mMaxNumberLength; 202 mHashCode = 31 * mHashCode + mMaxEmailLength; 203 mHashCode = 31 * mHashCode + mMaxAnrLength; 204 } 205 return mHashCode; 206 } 207 } 208