1 /* 2 * Copyright (C) 2018 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 android.telephony; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 import java.util.ArrayList; 24 import java.util.Arrays; 25 import java.util.List; 26 import java.util.Objects; 27 28 /** 29 * Define capability of a modem group. That is, the capabilities 30 * are shared between those modems defined by list of modem IDs. 31 * 32 * @hide 33 */ 34 public final class PhoneCapability implements Parcelable { 35 // Hardcoded default DSDS capability. 36 /** @hide */ 37 public static final PhoneCapability DEFAULT_DSDS_CAPABILITY; 38 // Hardcoded default Single SIM single standby capability. 39 /** @hide */ 40 public static final PhoneCapability DEFAULT_SSSS_CAPABILITY; 41 42 static { 43 ModemInfo modemInfo1 = new ModemInfo(0, 0, true, true); 44 ModemInfo modemInfo2 = new ModemInfo(1, 0, true, true); 45 46 List<ModemInfo> logicalModemList = new ArrayList<>(); 47 logicalModemList.add(modemInfo1); 48 logicalModemList.add(modemInfo2); 49 DEFAULT_DSDS_CAPABILITY = new PhoneCapability(1, 1, 0, logicalModemList, false); 50 51 logicalModemList = new ArrayList<>(); 52 logicalModemList.add(modemInfo1); 53 DEFAULT_SSSS_CAPABILITY = new PhoneCapability(1, 1, 0, logicalModemList, false); 54 } 55 56 /** @hide */ 57 public final int maxActiveVoiceCalls; 58 /** @hide */ 59 public final int maxActiveData; 60 /** @hide */ 61 public final int max5G; 62 /** @hide */ 63 public final boolean validationBeforeSwitchSupported; 64 /** @hide */ 65 public final List<ModemInfo> logicalModemList; 66 67 /** @hide */ PhoneCapability(int maxActiveVoiceCalls, int maxActiveData, int max5G, List<ModemInfo> logicalModemList, boolean validationBeforeSwitchSupported)68 public PhoneCapability(int maxActiveVoiceCalls, int maxActiveData, int max5G, 69 List<ModemInfo> logicalModemList, boolean validationBeforeSwitchSupported) { 70 this.maxActiveVoiceCalls = maxActiveVoiceCalls; 71 this.maxActiveData = maxActiveData; 72 this.max5G = max5G; 73 // Make sure it's not null. 74 this.logicalModemList = logicalModemList == null ? new ArrayList<>() : logicalModemList; 75 this.validationBeforeSwitchSupported = validationBeforeSwitchSupported; 76 } 77 78 @Override toString()79 public String toString() { 80 return "maxActiveVoiceCalls=" + maxActiveVoiceCalls + " maxActiveData=" + maxActiveData 81 + " max5G=" + max5G + "logicalModemList:" 82 + Arrays.toString(logicalModemList.toArray()); 83 } 84 PhoneCapability(Parcel in)85 private PhoneCapability(Parcel in) { 86 maxActiveVoiceCalls = in.readInt(); 87 maxActiveData = in.readInt(); 88 max5G = in.readInt(); 89 validationBeforeSwitchSupported = in.readBoolean(); 90 logicalModemList = new ArrayList<>(); 91 in.readList(logicalModemList, ModemInfo.class.getClassLoader()); 92 } 93 94 @Override hashCode()95 public int hashCode() { 96 return Objects.hash(maxActiveVoiceCalls, maxActiveData, max5G, logicalModemList, 97 validationBeforeSwitchSupported); 98 } 99 100 @Override equals(Object o)101 public boolean equals(Object o) { 102 if (o == null || !(o instanceof PhoneCapability) || hashCode() != o.hashCode()) { 103 return false; 104 } 105 106 if (this == o) { 107 return true; 108 } 109 110 PhoneCapability s = (PhoneCapability) o; 111 112 return (maxActiveVoiceCalls == s.maxActiveVoiceCalls 113 && maxActiveData == s.maxActiveData 114 && max5G == s.max5G 115 && validationBeforeSwitchSupported == s.validationBeforeSwitchSupported 116 && logicalModemList.equals(s.logicalModemList)); 117 } 118 119 /** 120 * {@link Parcelable#describeContents} 121 */ describeContents()122 public int describeContents() { 123 return 0; 124 } 125 126 /** 127 * {@link Parcelable#writeToParcel} 128 */ writeToParcel(@onNull Parcel dest, @Parcelable.WriteFlags int flags)129 public void writeToParcel(@NonNull Parcel dest, @Parcelable.WriteFlags int flags) { 130 dest.writeInt(maxActiveVoiceCalls); 131 dest.writeInt(maxActiveData); 132 dest.writeInt(max5G); 133 dest.writeBoolean(validationBeforeSwitchSupported); 134 dest.writeList(logicalModemList); 135 } 136 137 public static final @android.annotation.NonNull Parcelable.Creator<PhoneCapability> CREATOR = new Parcelable.Creator() { 138 public PhoneCapability createFromParcel(Parcel in) { 139 return new PhoneCapability(in); 140 } 141 142 public PhoneCapability[] newArray(int size) { 143 return new PhoneCapability[size]; 144 } 145 }; 146 } 147