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; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 import android.annotation.IntDef; 22 import java.lang.annotation.Retention; 23 import java.lang.annotation.RetentionPolicy; 24 25 /** 26 * @hide 27 */ 28 public final class PhysicalChannelConfig implements Parcelable { 29 30 // TODO(b/72993578) consolidate these enums in a central location. 31 @Retention(RetentionPolicy.SOURCE) 32 @IntDef({CONNECTION_PRIMARY_SERVING, CONNECTION_SECONDARY_SERVING, CONNECTION_UNKNOWN}) 33 public @interface ConnectionStatus {} 34 35 /** 36 * UE has connection to cell for signalling and possibly data (3GPP 36.331, 25.331). 37 */ 38 public static final int CONNECTION_PRIMARY_SERVING = 1; 39 40 /** 41 * UE has connection to cell for data (3GPP 36.331, 25.331). 42 */ 43 public static final int CONNECTION_SECONDARY_SERVING = 2; 44 45 /** Connection status is unknown. */ 46 public static final int CONNECTION_UNKNOWN = Integer.MAX_VALUE; 47 48 /** 49 * Connection status of the cell. 50 * 51 * <p>One of {@link #CONNECTION_PRIMARY_SERVING}, {@link #CONNECTION_SECONDARY_SERVING}. 52 */ 53 private int mCellConnectionStatus; 54 55 /** 56 * Cell bandwidth, in kHz. 57 */ 58 private int mCellBandwidthDownlinkKhz; 59 PhysicalChannelConfig(int status, int bandwidth)60 public PhysicalChannelConfig(int status, int bandwidth) { 61 mCellConnectionStatus = status; 62 mCellBandwidthDownlinkKhz = bandwidth; 63 } 64 PhysicalChannelConfig(Parcel in)65 public PhysicalChannelConfig(Parcel in) { 66 mCellConnectionStatus = in.readInt(); 67 mCellBandwidthDownlinkKhz = in.readInt(); 68 } 69 70 @Override describeContents()71 public int describeContents() { 72 return 0; 73 } 74 75 @Override writeToParcel(Parcel dest, int flags)76 public void writeToParcel(Parcel dest, int flags) { 77 dest.writeInt(mCellConnectionStatus); 78 dest.writeInt(mCellBandwidthDownlinkKhz); 79 } 80 81 /** 82 * @return Cell bandwidth, in kHz 83 */ getCellBandwidthDownlink()84 public int getCellBandwidthDownlink() { 85 return mCellBandwidthDownlinkKhz; 86 } 87 88 /** 89 * Gets the connection status of the cell. 90 * 91 * @see #CONNECTION_PRIMARY_SERVING 92 * @see #CONNECTION_SECONDARY_SERVING 93 * @see #CONNECTION_UNKNOWN 94 * 95 * @return Connection status of the cell 96 */ 97 @ConnectionStatus getConnectionStatus()98 public int getConnectionStatus() { 99 return mCellConnectionStatus; 100 } 101 102 /** @return String representation of the connection status */ getConnectionStatusString()103 private String getConnectionStatusString() { 104 switch(mCellConnectionStatus) { 105 case CONNECTION_PRIMARY_SERVING: 106 return "PrimaryServing"; 107 case CONNECTION_SECONDARY_SERVING: 108 return "SecondaryServing"; 109 case CONNECTION_UNKNOWN: 110 return "Unknown"; 111 default: 112 return "Invalid(" + mCellConnectionStatus + ")"; 113 } 114 } 115 116 @Override equals(Object o)117 public boolean equals(Object o) { 118 if (this == o) { 119 return true; 120 } 121 122 if (!(o instanceof PhysicalChannelConfig)) { 123 return false; 124 } 125 126 PhysicalChannelConfig config = (PhysicalChannelConfig) o; 127 return mCellConnectionStatus == config.mCellConnectionStatus 128 && mCellBandwidthDownlinkKhz == config.mCellBandwidthDownlinkKhz; 129 } 130 131 @Override hashCode()132 public int hashCode() { 133 return (mCellBandwidthDownlinkKhz * 29) + (mCellConnectionStatus * 31); 134 } 135 136 public static final Parcelable.Creator<PhysicalChannelConfig> CREATOR = 137 new Parcelable.Creator<PhysicalChannelConfig>() { 138 public PhysicalChannelConfig createFromParcel(Parcel in) { 139 return new PhysicalChannelConfig(in); 140 } 141 142 public PhysicalChannelConfig[] newArray(int size) { 143 return new PhysicalChannelConfig[size]; 144 } 145 }; 146 147 @Override toString()148 public String toString() { 149 return new StringBuilder() 150 .append("{mConnectionStatus=") 151 .append(getConnectionStatusString()) 152 .append(",mCellBandwidthDownlinkKhz=") 153 .append(mCellBandwidthDownlinkKhz) 154 .append("}") 155 .toString(); 156 } 157 } 158