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.ims.feature; 18 19 import android.annotation.SystemApi; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.telephony.ims.stub.ImsRegistrationImplBase; 23 import android.util.ArraySet; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 import java.util.Set; 28 29 /** 30 * Request to send to IMS provider, which will try to enable/disable capabilities that are added to 31 * the request. 32 * {@hide} 33 */ 34 @SystemApi 35 public final class CapabilityChangeRequest implements Parcelable { 36 37 /** 38 * Contains a feature capability, defined as 39 * {@link MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_VOICE}, 40 * {@link MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_VIDEO}, 41 * {@link MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_UT}, or 42 * {@link MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_SMS}, 43 * along with an associated technology, defined as 44 * {@link ImsRegistrationImplBase#REGISTRATION_TECH_LTE} or 45 * {@link ImsRegistrationImplBase#REGISTRATION_TECH_IWLAN} 46 */ 47 public static class CapabilityPair { 48 private final int mCapability; 49 private final int radioTech; 50 CapabilityPair(@mTelFeature.MmTelCapabilities.MmTelCapability int capability, @ImsRegistrationImplBase.ImsRegistrationTech int radioTech)51 public CapabilityPair(@MmTelFeature.MmTelCapabilities.MmTelCapability int capability, 52 @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) { 53 this.mCapability = capability; 54 this.radioTech = radioTech; 55 } 56 57 /** 58 * @hide 59 */ 60 @Override equals(Object o)61 public boolean equals(Object o) { 62 if (this == o) return true; 63 if (!(o instanceof CapabilityPair)) return false; 64 65 CapabilityPair that = (CapabilityPair) o; 66 67 if (getCapability() != that.getCapability()) return false; 68 return getRadioTech() == that.getRadioTech(); 69 } 70 71 /** 72 * @hide 73 */ 74 @Override hashCode()75 public int hashCode() { 76 int result = getCapability(); 77 result = 31 * result + getRadioTech(); 78 return result; 79 } 80 81 /** 82 * @return The stored capability, defined as 83 * {@link MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_VOICE}, 84 * {@link MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_VIDEO}, 85 * {@link MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_UT}, or 86 * {@link MmTelFeature.MmTelCapabilities#CAPABILITY_TYPE_SMS} 87 */ getCapability()88 public @MmTelFeature.MmTelCapabilities.MmTelCapability int getCapability() { 89 return mCapability; 90 } 91 92 /** 93 * @return the stored radio technology, defined as 94 * {@link ImsRegistrationImplBase#REGISTRATION_TECH_LTE} or 95 * {@link ImsRegistrationImplBase#REGISTRATION_TECH_IWLAN} 96 */ getRadioTech()97 public @ImsRegistrationImplBase.ImsRegistrationTech int getRadioTech() { 98 return radioTech; 99 } 100 101 @Override toString()102 public String toString() { 103 return "CapabilityPair{" 104 + "mCapability=" + mCapability 105 + ", radioTech=" + radioTech + '}'; 106 } 107 } 108 109 // Pair contains <radio tech, mCapability> 110 private final Set<CapabilityPair> mCapabilitiesToEnable; 111 // Pair contains <radio tech, mCapability> 112 private final Set<CapabilityPair> mCapabilitiesToDisable; 113 114 /** @hide */ CapabilityChangeRequest()115 public CapabilityChangeRequest() { 116 mCapabilitiesToEnable = new ArraySet<>(); 117 mCapabilitiesToDisable = new ArraySet<>(); 118 } 119 120 /** 121 * Add one or many capabilities to the request to be enabled. 122 * 123 * @param capabilities A bitfield of capabilities to enable, valid values are defined in 124 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. 125 * @param radioTech the radio tech that these capabilities should be enabled for, valid 126 * values are in {@link ImsRegistrationImplBase.ImsRegistrationTech}. 127 */ addCapabilitiesToEnableForTech( @mTelFeature.MmTelCapabilities.MmTelCapability int capabilities, @ImsRegistrationImplBase.ImsRegistrationTech int radioTech)128 public void addCapabilitiesToEnableForTech( 129 @MmTelFeature.MmTelCapabilities.MmTelCapability int capabilities, 130 @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) { 131 addAllCapabilities(mCapabilitiesToEnable, capabilities, radioTech); 132 } 133 134 /** 135 * Add one or many capabilities to the request to be disabled. 136 * @param capabilities A bitfield of capabilities to diable, valid values are defined in 137 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. 138 * @param radioTech the radio tech that these capabilities should be disabled for, valid 139 * values are in {@link ImsRegistrationImplBase.ImsRegistrationTech}. 140 */ addCapabilitiesToDisableForTech( @mTelFeature.MmTelCapabilities.MmTelCapability int capabilities, @ImsRegistrationImplBase.ImsRegistrationTech int radioTech)141 public void addCapabilitiesToDisableForTech( 142 @MmTelFeature.MmTelCapabilities.MmTelCapability int capabilities, 143 @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) { 144 addAllCapabilities(mCapabilitiesToDisable, capabilities, radioTech); 145 } 146 147 /** 148 * @return a {@link List} of {@link CapabilityPair}s that are requesting to be enabled. 149 */ getCapabilitiesToEnable()150 public List<CapabilityPair> getCapabilitiesToEnable() { 151 return new ArrayList<>(mCapabilitiesToEnable); 152 } 153 154 /** 155 * @return a {@link List} of {@link CapabilityPair}s that are requesting to be disabled. 156 */ getCapabilitiesToDisable()157 public List<CapabilityPair> getCapabilitiesToDisable() { 158 return new ArrayList<>(mCapabilitiesToDisable); 159 } 160 161 // Iterate through capabilities bitfield and add each one as a pair associated with the radio 162 // technology addAllCapabilities(Set<CapabilityPair> set, int capabilities, int tech)163 private void addAllCapabilities(Set<CapabilityPair> set, int capabilities, int tech) { 164 long highestCapability = Long.highestOneBit(capabilities); 165 for (int i = 1; i <= highestCapability; i *= 2) { 166 if ((i & capabilities) > 0) { 167 set.add(new CapabilityPair(/*capability*/ i, /*radioTech*/ tech)); 168 } 169 } 170 } 171 172 /** 173 * @hide 174 */ CapabilityChangeRequest(Parcel in)175 protected CapabilityChangeRequest(Parcel in) { 176 int enableSize = in.readInt(); 177 mCapabilitiesToEnable = new ArraySet<>(enableSize); 178 for (int i = 0; i < enableSize; i++) { 179 mCapabilitiesToEnable.add(new CapabilityPair(/*capability*/ in.readInt(), 180 /*radioTech*/ in.readInt())); 181 } 182 int disableSize = in.readInt(); 183 mCapabilitiesToDisable = new ArraySet<>(disableSize); 184 for (int i = 0; i < disableSize; i++) { 185 mCapabilitiesToDisable.add(new CapabilityPair(/*capability*/ in.readInt(), 186 /*radioTech*/ in.readInt())); 187 } 188 } 189 190 public static final @android.annotation.NonNull Creator<CapabilityChangeRequest> CREATOR = 191 new Creator<CapabilityChangeRequest>() { 192 @Override 193 public CapabilityChangeRequest createFromParcel(Parcel in) { 194 return new CapabilityChangeRequest(in); 195 } 196 197 @Override 198 public CapabilityChangeRequest[] newArray(int size) { 199 return new CapabilityChangeRequest[size]; 200 } 201 }; 202 203 @Override describeContents()204 public int describeContents() { 205 return 0; 206 } 207 208 @Override writeToParcel(Parcel dest, int flags)209 public void writeToParcel(Parcel dest, int flags) { 210 dest.writeInt(mCapabilitiesToEnable.size()); 211 for (CapabilityPair pair : mCapabilitiesToEnable) { 212 dest.writeInt(pair.getCapability()); 213 dest.writeInt(pair.getRadioTech()); 214 } 215 dest.writeInt(mCapabilitiesToDisable.size()); 216 for (CapabilityPair pair : mCapabilitiesToDisable) { 217 dest.writeInt(pair.getCapability()); 218 dest.writeInt(pair.getRadioTech()); 219 } 220 } 221 222 @Override toString()223 public String toString() { 224 return "CapabilityChangeRequest{" 225 + "mCapabilitiesToEnable=" + mCapabilitiesToEnable 226 + ", mCapabilitiesToDisable=" + mCapabilitiesToDisable + '}'; 227 } 228 229 /** 230 * @hide 231 */ 232 @Override equals(Object o)233 public boolean equals(Object o) { 234 if (this == o) return true; 235 if (!(o instanceof CapabilityChangeRequest)) return false; 236 237 CapabilityChangeRequest 238 that = (CapabilityChangeRequest) o; 239 240 if (!mCapabilitiesToEnable.equals(that.mCapabilitiesToEnable)) return false; 241 return mCapabilitiesToDisable.equals(that.mCapabilitiesToDisable); 242 } 243 244 /** 245 * @hide 246 */ 247 @Override hashCode()248 public int hashCode() { 249 int result = mCapabilitiesToEnable.hashCode(); 250 result = 31 * result + mCapabilitiesToDisable.hashCode(); 251 return result; 252 } 253 } 254