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