1 /* 2 * Copyright (C) 2020 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 com.android.ims; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.IBinder; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 import android.telephony.ims.ImsService; 25 import android.telephony.ims.aidl.IImsConfig; 26 import android.telephony.ims.aidl.IImsRegistration; 27 import android.telephony.ims.aidl.ISipTransport; 28 import android.telephony.ims.feature.ImsFeature; 29 30 import java.util.Objects; 31 32 /** 33 * Contains an IBinder linking to the appropriate ImsFeature as well as the associated 34 * interfaces. 35 * @hide 36 */ 37 public final class ImsFeatureContainer implements Parcelable { 38 /** 39 * ImsFeature that is being tracked. 40 */ 41 public final IBinder imsFeature; 42 43 /** 44 * IImsConfig interface that should be associated with the ImsFeature. 45 */ 46 public final android.telephony.ims.aidl.IImsConfig imsConfig; 47 48 /** 49 * IImsRegistration interface that should be associated with this ImsFeature. 50 */ 51 public final IImsRegistration imsRegistration; 52 53 /** 54 * An optional interface containing the SIP transport implementation from the ImsService. 55 */ 56 public final ISipTransport sipTransport; 57 58 /** 59 * State of the feature that is being tracked. 60 */ 61 private @ImsFeature.ImsState int mState = ImsFeature.STATE_UNAVAILABLE; 62 63 /** 64 * Capabilities of this ImsService. 65 */ 66 private @ImsService.ImsServiceCapability long mCapabilities; 67 /** 68 * Contains the ImsFeature IBinder as well as the ImsService interfaces associated with 69 * that feature. 70 * @param iFace IBinder connection to the ImsFeature. 71 * @param iConfig IImsConfig interface associated with the ImsFeature. 72 * @param iReg IImsRegistration interface associated with the ImsFeature 73 * @param initialCaps The initial capabilities that the ImsService supports. 74 */ ImsFeatureContainer(@onNull IBinder iFace, @NonNull IImsConfig iConfig, @NonNull IImsRegistration iReg, @Nullable ISipTransport transport, long initialCaps)75 public ImsFeatureContainer(@NonNull IBinder iFace, @NonNull IImsConfig iConfig, 76 @NonNull IImsRegistration iReg, @Nullable ISipTransport transport, long initialCaps) { 77 imsFeature = iFace; 78 imsConfig = iConfig; 79 imsRegistration = iReg; 80 sipTransport = transport; 81 mCapabilities = initialCaps; 82 } 83 84 /** 85 * Create an ImsFeatureContainer from a Parcel. 86 */ ImsFeatureContainer(Parcel in)87 private ImsFeatureContainer(Parcel in) { 88 imsFeature = in.readStrongBinder(); 89 imsConfig = IImsConfig.Stub.asInterface(in.readStrongBinder()); 90 imsRegistration = IImsRegistration.Stub.asInterface(in.readStrongBinder()); 91 sipTransport = ISipTransport.Stub.asInterface(in.readStrongBinder()); 92 mState = in.readInt(); 93 mCapabilities = in.readLong(); 94 } 95 96 /** 97 * @return the capabilties that are associated with the ImsService that this ImsFeature 98 * belongs to. 99 */ getCapabilities()100 public @ImsService.ImsServiceCapability long getCapabilities() { 101 return mCapabilities; 102 } 103 104 /** 105 * Update the capabilities that are associated with the ImsService that this ImsFeature 106 * belongs to. 107 */ setCapabilities(@msService.ImsServiceCapability long caps)108 public void setCapabilities(@ImsService.ImsServiceCapability long caps) { 109 mCapabilities = caps; 110 } 111 112 /** 113 * @return The state of the ImsFeature. 114 */ getState()115 public @ImsFeature.ImsState int getState() { 116 return mState; 117 } 118 119 /** 120 * Set the state that is associated with the ImsService that this ImsFeature 121 * belongs to. 122 */ setState(@msFeature.ImsState int state)123 public void setState(@ImsFeature.ImsState int state) { 124 mState = state; 125 } 126 127 @Override equals(Object o)128 public boolean equals(Object o) { 129 if (this == o) return true; 130 if (o == null || getClass() != o.getClass()) return false; 131 ImsFeatureContainer that = (ImsFeatureContainer) o; 132 return imsFeature.equals(that.imsFeature) && 133 imsConfig.equals(that.imsConfig) && 134 imsRegistration.equals(that.imsRegistration) && 135 sipTransport.equals(that.sipTransport) && 136 mState == that.getState() && 137 mCapabilities == that.getCapabilities(); 138 } 139 140 @Override hashCode()141 public int hashCode() { 142 return Objects.hash(imsFeature, imsConfig, imsRegistration, sipTransport, mState, 143 mCapabilities); 144 } 145 146 @Override toString()147 public String toString() { 148 return "FeatureContainer{" + 149 "imsFeature=" + imsFeature + 150 ", imsConfig=" + imsConfig + 151 ", imsRegistration=" + imsRegistration + 152 ", sipTransport=" + sipTransport + 153 ", state=" + ImsFeature.STATE_LOG_MAP.get(mState) + 154 ", capabilities = " + ImsService.getCapabilitiesString(mCapabilities) + 155 '}'; 156 } 157 158 @Override describeContents()159 public int describeContents() { 160 return 0; 161 } 162 163 @Override writeToParcel(Parcel dest, int flags)164 public void writeToParcel(Parcel dest, int flags) { 165 dest.writeStrongBinder(imsFeature); 166 dest.writeStrongInterface(imsConfig); 167 dest.writeStrongInterface(imsRegistration); 168 dest.writeStrongInterface(sipTransport); 169 dest.writeInt(mState); 170 dest.writeLong(mCapabilities); 171 } 172 173 174 public static final Creator<ImsFeatureContainer> CREATOR = new Creator<ImsFeatureContainer>() { 175 @Override 176 public ImsFeatureContainer createFromParcel(Parcel source) { 177 return new ImsFeatureContainer(source); 178 } 179 180 @Override 181 public ImsFeatureContainer[] newArray(int size) { 182 return new ImsFeatureContainer[size]; 183 } 184 }; 185 } 186