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.stub; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 import android.telephony.ims.feature.ImsFeature; 25 import android.util.ArraySet; 26 27 import java.util.Set; 28 29 /** 30 * Container class for IMS Feature configuration. This class contains the features that the 31 * ImsService supports, which are defined in {@link ImsFeature} as 32 * {@link ImsFeature#FEATURE_EMERGENCY_MMTEL}, {@link ImsFeature#FEATURE_MMTEL}, and 33 * {@link ImsFeature#FEATURE_RCS}. 34 * 35 * @hide 36 */ 37 @SystemApi 38 public final class ImsFeatureConfiguration implements Parcelable { 39 40 public static final class FeatureSlotPair { 41 /** 42 * SIM slot that this feature is associated with. 43 */ 44 public final int slotId; 45 /** 46 * The feature that this slotId supports. Supported values are 47 * {@link ImsFeature#FEATURE_EMERGENCY_MMTEL}, {@link ImsFeature#FEATURE_MMTEL}, and 48 * {@link ImsFeature#FEATURE_RCS}. 49 */ 50 public final @ImsFeature.FeatureType int featureType; 51 52 /** 53 * A mapping from slotId to IMS Feature type. 54 * @param slotId the SIM slot ID associated with this feature. 55 * @param featureType The feature that this slotId supports. Supported values are 56 * {@link ImsFeature#FEATURE_EMERGENCY_MMTEL}, {@link ImsFeature#FEATURE_MMTEL}, and 57 * {@link ImsFeature#FEATURE_RCS}. 58 */ FeatureSlotPair(int slotId, @ImsFeature.FeatureType int featureType)59 public FeatureSlotPair(int slotId, @ImsFeature.FeatureType int featureType) { 60 this.slotId = slotId; 61 this.featureType = featureType; 62 } 63 64 @Override equals(@ullable Object o)65 public boolean equals(@Nullable Object o) { 66 if (this == o) return true; 67 if (o == null || getClass() != o.getClass()) return false; 68 69 FeatureSlotPair that = (FeatureSlotPair) o; 70 71 if (slotId != that.slotId) return false; 72 return featureType == that.featureType; 73 } 74 75 @Override hashCode()76 public int hashCode() { 77 int result = slotId; 78 result = 31 * result + featureType; 79 return result; 80 } 81 82 @NonNull 83 @Override toString()84 public String toString() { 85 return "{s=" + slotId + ", f=" + ImsFeature.FEATURE_LOG_MAP.get(featureType) + "}"; 86 } 87 } 88 89 /** 90 * Features that this ImsService supports. 91 */ 92 private final Set<FeatureSlotPair> mFeatures; 93 94 /** 95 * Builder for {@link ImsFeatureConfiguration}. 96 */ 97 public static class Builder { 98 ImsFeatureConfiguration mConfig; Builder()99 public Builder() { 100 mConfig = new ImsFeatureConfiguration(); 101 } 102 103 /** 104 * Adds an IMS feature associated with a SIM slot ID. 105 * @param slotId The slot ID associated with the IMS feature. 106 * @param featureType The feature that the slot ID supports. Supported values are 107 * {@link ImsFeature#FEATURE_EMERGENCY_MMTEL}, {@link ImsFeature#FEATURE_MMTEL}, and 108 * {@link ImsFeature#FEATURE_RCS}. 109 * @return a {@link Builder} to continue constructing the ImsFeatureConfiguration. 110 */ addFeature(int slotId, @ImsFeature.FeatureType int featureType)111 public Builder addFeature(int slotId, @ImsFeature.FeatureType int featureType) { 112 mConfig.addFeature(slotId, featureType); 113 return this; 114 } 115 build()116 public ImsFeatureConfiguration build() { 117 return mConfig; 118 } 119 } 120 121 /** 122 * Creates with all registration features empty. 123 * @hide 124 */ ImsFeatureConfiguration()125 public ImsFeatureConfiguration() { 126 mFeatures = new ArraySet<>(); 127 } 128 129 /** 130 * Configuration of the ImsService, which describes which features the ImsService supports 131 * (for registration). 132 * @param features a set of {@link FeatureSlotPair}s that describe which features this 133 * ImsService supports. 134 * @hide 135 */ ImsFeatureConfiguration(Set<FeatureSlotPair> features)136 public ImsFeatureConfiguration(Set<FeatureSlotPair> features) { 137 mFeatures = new ArraySet<>(); 138 139 if (features != null) { 140 mFeatures.addAll(features); 141 } 142 } 143 144 /** 145 * @return a set of supported slot ID to feature type pairs contained within a 146 * {@link FeatureSlotPair}. 147 */ getServiceFeatures()148 public Set<FeatureSlotPair> getServiceFeatures() { 149 return new ArraySet<>(mFeatures); 150 } 151 152 /** 153 * @hide 154 */ addFeature(int slotId, int feature)155 void addFeature(int slotId, int feature) { 156 mFeatures.add(new FeatureSlotPair(slotId, feature)); 157 } 158 159 /** @hide */ ImsFeatureConfiguration(Parcel in)160 protected ImsFeatureConfiguration(Parcel in) { 161 int featurePairLength = in.readInt(); 162 // length 163 mFeatures = new ArraySet<>(featurePairLength); 164 for (int i = 0; i < featurePairLength; i++) { 165 // pair of reads for each entry (slotId->featureType) 166 mFeatures.add(new FeatureSlotPair(in.readInt(), in.readInt())); 167 } 168 } 169 170 public static final @android.annotation.NonNull Creator<ImsFeatureConfiguration> CREATOR 171 = new Creator<ImsFeatureConfiguration>() { 172 @Override 173 public ImsFeatureConfiguration createFromParcel(Parcel in) { 174 return new ImsFeatureConfiguration(in); 175 } 176 177 @Override 178 public ImsFeatureConfiguration[] newArray(int size) { 179 return new ImsFeatureConfiguration[size]; 180 } 181 }; 182 183 @Override describeContents()184 public int describeContents() { 185 return 0; 186 } 187 188 @Override writeToParcel(Parcel dest, int flags)189 public void writeToParcel(Parcel dest, int flags) { 190 FeatureSlotPair[] featureSlotPairs = new FeatureSlotPair[mFeatures.size()]; 191 mFeatures.toArray(featureSlotPairs); 192 // length of list 193 dest.writeInt(featureSlotPairs.length); 194 // then pairs of integers for each entry (slotId->featureType). 195 for (FeatureSlotPair featureSlotPair : featureSlotPairs) { 196 dest.writeInt(featureSlotPair.slotId); 197 dest.writeInt(featureSlotPair.featureType); 198 } 199 } 200 201 /** 202 * @hide 203 */ 204 @Override equals(Object o)205 public boolean equals(Object o) { 206 if (this == o) return true; 207 if (!(o instanceof ImsFeatureConfiguration)) return false; 208 209 ImsFeatureConfiguration 210 that = (ImsFeatureConfiguration) o; 211 212 return mFeatures.equals(that.mFeatures); 213 } 214 215 /** 216 * @hide 217 */ 218 @Override hashCode()219 public int hashCode() { 220 return mFeatures.hashCode(); 221 } 222 } 223