Home | History | Annotate | Download | only in feature
      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 
     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
     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
     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          */
     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          */
     97         public @ImsRegistrationImplBase.ImsRegistrationTech int getRadioTech() {
     98             return radioTech;
     99         }
    100     }
    101 
    102     // Pair contains <radio tech, mCapability>
    103     private final Set<CapabilityPair> mCapabilitiesToEnable;
    104     // Pair contains <radio tech, mCapability>
    105     private final Set<CapabilityPair> mCapabilitiesToDisable;
    106 
    107     /** @hide */
    108     public CapabilityChangeRequest() {
    109         mCapabilitiesToEnable = new ArraySet<>();
    110         mCapabilitiesToDisable = new ArraySet<>();
    111     }
    112 
    113     /**
    114      * Add one or many capabilities to the request to be enabled.
    115      *
    116      * @param capabilities A bitfield of capabilities to enable, valid values are defined in
    117      *   {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
    118      * @param radioTech  the radio tech that these capabilities should be enabled for, valid
    119      *   values are in {@link ImsRegistrationImplBase.ImsRegistrationTech}.
    120      */
    121     public void addCapabilitiesToEnableForTech(
    122             @MmTelFeature.MmTelCapabilities.MmTelCapability int capabilities,
    123             @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) {
    124         addAllCapabilities(mCapabilitiesToEnable, capabilities, radioTech);
    125     }
    126 
    127     /**
    128      * Add one or many capabilities to the request to be disabled.
    129      * @param capabilities A bitfield of capabilities to diable, valid values are defined in
    130      *   {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
    131      * @param radioTech the radio tech that these capabilities should be disabled for, valid
    132      *   values are in {@link ImsRegistrationImplBase.ImsRegistrationTech}.
    133      */
    134     public void addCapabilitiesToDisableForTech(
    135             @MmTelFeature.MmTelCapabilities.MmTelCapability int capabilities,
    136             @ImsRegistrationImplBase.ImsRegistrationTech int radioTech) {
    137         addAllCapabilities(mCapabilitiesToDisable, capabilities, radioTech);
    138     }
    139 
    140     /**
    141      * @return a {@link List} of {@link CapabilityPair}s that are requesting to be enabled.
    142      */
    143     public List<CapabilityPair> getCapabilitiesToEnable() {
    144         return new ArrayList<>(mCapabilitiesToEnable);
    145     }
    146 
    147     /**
    148      * @return a {@link List} of {@link CapabilityPair}s that are requesting to be disabled.
    149      */
    150     public List<CapabilityPair> getCapabilitiesToDisable() {
    151         return new ArrayList<>(mCapabilitiesToDisable);
    152     }
    153 
    154     // Iterate through capabilities bitfield and add each one as a pair associated with the radio
    155     // technology
    156     private void addAllCapabilities(Set<CapabilityPair> set, int capabilities, int tech) {
    157         long highestCapability = Long.highestOneBit(capabilities);
    158         for (int i = 1; i <= highestCapability; i *= 2) {
    159             if ((i & capabilities) > 0) {
    160                 set.add(new CapabilityPair(/*capability*/ i, /*radioTech*/ tech));
    161             }
    162         }
    163     }
    164 
    165     /**
    166      * @hide
    167      */
    168     protected CapabilityChangeRequest(Parcel in) {
    169         int enableSize = in.readInt();
    170         mCapabilitiesToEnable = new ArraySet<>(enableSize);
    171         for (int i = 0; i < enableSize; i++) {
    172             mCapabilitiesToEnable.add(new CapabilityPair(/*capability*/ in.readInt(),
    173                     /*radioTech*/ in.readInt()));
    174         }
    175         int disableSize = in.readInt();
    176         mCapabilitiesToDisable = new ArraySet<>(disableSize);
    177         for (int i = 0; i < disableSize; i++) {
    178             mCapabilitiesToDisable.add(new CapabilityPair(/*capability*/ in.readInt(),
    179                     /*radioTech*/ in.readInt()));
    180         }
    181     }
    182 
    183     public static final Creator<CapabilityChangeRequest> CREATOR =
    184             new Creator<CapabilityChangeRequest>() {
    185                 @Override
    186                 public CapabilityChangeRequest createFromParcel(Parcel in) {
    187                     return new CapabilityChangeRequest(in);
    188                 }
    189 
    190                 @Override
    191                 public CapabilityChangeRequest[] newArray(int size) {
    192                     return new CapabilityChangeRequest[size];
    193                 }
    194             };
    195 
    196     @Override
    197     public int describeContents() {
    198         return 0;
    199     }
    200 
    201     @Override
    202     public void writeToParcel(Parcel dest, int flags) {
    203         dest.writeInt(mCapabilitiesToEnable.size());
    204         for (CapabilityPair pair : mCapabilitiesToEnable) {
    205             dest.writeInt(pair.getCapability());
    206             dest.writeInt(pair.getRadioTech());
    207         }
    208         dest.writeInt(mCapabilitiesToDisable.size());
    209         for (CapabilityPair pair : mCapabilitiesToDisable) {
    210             dest.writeInt(pair.getCapability());
    211             dest.writeInt(pair.getRadioTech());
    212         }
    213     }
    214 
    215     /**
    216      * @hide
    217      */
    218     @Override
    219     public boolean equals(Object o) {
    220         if (this == o) return true;
    221         if (!(o instanceof CapabilityChangeRequest)) return false;
    222 
    223         CapabilityChangeRequest
    224                 that = (CapabilityChangeRequest) o;
    225 
    226         if (!mCapabilitiesToEnable.equals(that.mCapabilitiesToEnable)) return false;
    227         return mCapabilitiesToDisable.equals(that.mCapabilitiesToDisable);
    228     }
    229 
    230     /**
    231      * @hide
    232      */
    233     @Override
    234     public int hashCode() {
    235         int result = mCapabilitiesToEnable.hashCode();
    236         result = 31 * result + mCapabilitiesToDisable.hashCode();
    237         return result;
    238     }
    239 }
    240