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