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