1 /** 2 * Copyright (C) 2024 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.imsmedia; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 import androidx.annotation.NonNull; 23 import androidx.annotation.Nullable; 24 25 import java.util.Objects; 26 27 /** 28 * The class represents ANBR (Access Network Bitrate Recommendation) parameters. 29 * 30 * @hide 31 */ 32 public final class AnbrMode implements Parcelable { 33 34 private int mAnbrUplinkMode; 35 private int mAnbrDownlinkMode; 36 37 /** @hide **/ AnbrMode(Parcel in)38 public AnbrMode(Parcel in) { 39 mAnbrUplinkMode = in.readInt(); 40 mAnbrDownlinkMode = in.readInt(); 41 } 42 43 /** @hide */ AnbrMode(Builder builder)44 AnbrMode(Builder builder) { 45 this.mAnbrUplinkMode = builder.mAnbrUplinkMode; 46 this.mAnbrDownlinkMode = builder.mAnbrDownlinkMode; 47 } 48 49 /** @hide **/ getAnbrUplinkCodecMode()50 public int getAnbrUplinkCodecMode() { 51 return mAnbrUplinkMode; 52 } 53 54 /** @hide **/ setAnbrUplinkCodecMode(final int anbrUplinkMode)55 public void setAnbrUplinkCodecMode(final int anbrUplinkMode) { 56 this.mAnbrUplinkMode = anbrUplinkMode; 57 } 58 59 /** @hide **/ getAnbrDownlinkCodecMode()60 public int getAnbrDownlinkCodecMode() { 61 return mAnbrDownlinkMode; 62 } 63 64 /** @hide **/ setAnbrDownlinkCodecMode(final int anbrDownlinkMode)65 public void setAnbrDownlinkCodecMode(final int anbrDownlinkMode) { 66 this.mAnbrDownlinkMode = anbrDownlinkMode; 67 } 68 69 @NonNull 70 @Override toString()71 public String toString() { 72 return "AnbrMode: {mAnbrUplinkMode =" + mAnbrUplinkMode 73 + ", mAnbrDownlinkMode =" + mAnbrDownlinkMode 74 + " }"; 75 } 76 77 @Override hashCode()78 public int hashCode() { 79 return Objects.hash(mAnbrUplinkMode, mAnbrDownlinkMode); 80 } 81 82 @Override equals(@ullable Object o)83 public boolean equals(@Nullable Object o) { 84 if (o == null || !(o instanceof AnbrMode) || hashCode() != o.hashCode()) { 85 return false; 86 } 87 88 if (this == o) { 89 return true; 90 } 91 92 AnbrMode s = (AnbrMode) o; 93 94 return ((mAnbrUplinkMode == s.mAnbrUplinkMode) 95 && (mAnbrDownlinkMode == s.mAnbrDownlinkMode)); 96 } 97 98 /** 99 * {@link Parcelable#describeContents} 100 */ describeContents()101 public int describeContents() { 102 return 0; 103 } 104 105 /** 106 * {@link Parcelable#writeToParcel} 107 */ writeToParcel(Parcel dest, int flags)108 public void writeToParcel(Parcel dest, int flags) { 109 dest.writeInt(mAnbrUplinkMode); 110 dest.writeInt(mAnbrDownlinkMode); 111 } 112 113 public static final @NonNull Parcelable.Creator<AnbrMode> 114 CREATOR = new Parcelable.Creator() { 115 public AnbrMode createFromParcel(Parcel in) { 116 // TODO use builder class so it will validate 117 return new AnbrMode(in); 118 } 119 120 public AnbrMode[] newArray(int size) { 121 return new AnbrMode[size]; 122 } 123 }; 124 125 /** 126 * Provides a convenient way to set the fields of the {@link AmrParams} 127 * when creating a new instance. 128 */ 129 public static final class Builder { 130 private int mAnbrUplinkMode; 131 private int mAnbrDownlinkMode; 132 133 /** 134 * Default constructor for Builder. 135 */ Builder()136 public Builder() { 137 } 138 139 /** 140 * Set the AMR codec mode to represent the bit rate 141 * 142 * @param anbrUplinkMode AMR codec mode 143 * @return The same instance of the builder. 144 */ setAnbrUplinkCodecMode(final int anbrUplinkMode)145 public @NonNull Builder setAnbrUplinkCodecMode(final int anbrUplinkMode) { 146 this.mAnbrUplinkMode = anbrUplinkMode; 147 return this; 148 } 149 150 /** 151 * Set the AMR codec mode to represent the bit rate 152 * 153 * @param anbrDownlinkMode AMR codec mode 154 * @return The same instance of the builder. 155 */ setAnbrDownlinkCodecMode(final int anbrDownlinkMode)156 public @NonNull Builder setAnbrDownlinkCodecMode(final int anbrDownlinkMode) { 157 this.mAnbrDownlinkMode = anbrDownlinkMode; 158 return this; 159 } 160 161 /** 162 * Build the AnbrMode. 163 * 164 * @return the AnbrMode object. 165 */ build()166 public @NonNull AnbrMode build() { 167 // TODO validation 168 return new AnbrMode(this); 169 } 170 } 171 } 172