Merge "Add Duplex mode to ServiceState."

This commit is contained in:
Eric Schwarzenbach
2018-03-09 21:19:10 +00:00
committed by Gerrit Code Review
6 changed files with 205 additions and 3 deletions

View File

@@ -0,0 +1,167 @@
package android.telephony;
import static android.telephony.ServiceState.DUPLEX_MODE_FDD;
import static android.telephony.ServiceState.DUPLEX_MODE_TDD;
import static android.telephony.ServiceState.DUPLEX_MODE_UNKNOWN;
import android.telephony.AccessNetworkConstants.EutranBand;
import android.telephony.ServiceState.DuplexMode;
/**
* Utilities to map between radio constants.
*
* @hide
*/
public class AccessNetworkUtils {
// do not instantiate
private AccessNetworkUtils() {}
public static final int INVALID_BAND = -1;
/**
* Gets the duplex mode for the given EUTRAN operating band.
*
* <p>See 3GPP 36.101 sec 5.5-1 for calculation
*
* @param band The EUTRAN band number
* @return The duplex mode of the given EUTRAN band
*/
@DuplexMode
public static int getDuplexModeForEutranBand(int band) {
if (band == INVALID_BAND) {
return DUPLEX_MODE_UNKNOWN;
}
if (band >= EutranBand.BAND_68) {
return DUPLEX_MODE_UNKNOWN;
} else if (band >= EutranBand.BAND_65) {
return DUPLEX_MODE_FDD;
} else if (band >= EutranBand.BAND_47) {
return DUPLEX_MODE_UNKNOWN;
} else if (band >= EutranBand.BAND_33) {
return DUPLEX_MODE_TDD;
} else if (band >= EutranBand.BAND_1) {
return DUPLEX_MODE_FDD;
}
return DUPLEX_MODE_UNKNOWN;
}
/**
* Gets the EUTRAN Operating band for a given downlink EARFCN.
*
* <p>See 3GPP 36.101 sec 5.7.3-1 for calculation.
*
* @param earfcn The downlink EARFCN
* @return Operating band number, or {@link #INVALID_BAND} if no corresponding band exists
*/
public static int getOperatingBandForEarfcn(int earfcn) {
if (earfcn > 67535) {
return INVALID_BAND;
} else if (earfcn >= 67366) {
return INVALID_BAND; // band 67 only for CarrierAgg
} else if (earfcn >= 66436) {
return EutranBand.BAND_66;
} else if (earfcn >= 65536) {
return EutranBand.BAND_65;
} else if (earfcn > 54339) {
return INVALID_BAND;
} else if (earfcn >= 46790 /* inferred from the end range of BAND_45 */) {
return EutranBand.BAND_46;
} else if (earfcn >= 46590) {
return EutranBand.BAND_45;
} else if (earfcn >= 45590) {
return EutranBand.BAND_44;
} else if (earfcn >= 43590) {
return EutranBand.BAND_43;
} else if (earfcn >= 41590) {
return EutranBand.BAND_42;
} else if (earfcn >= 39650) {
return EutranBand.BAND_41;
} else if (earfcn >= 38650) {
return EutranBand.BAND_40;
} else if (earfcn >= 38250) {
return EutranBand.BAND_39;
} else if (earfcn >= 37750) {
return EutranBand.BAND_38;
} else if (earfcn >= 37550) {
return EutranBand.BAND_37;
} else if (earfcn >= 36950) {
return EutranBand.BAND_36;
} else if (earfcn >= 36350) {
return EutranBand.BAND_35;
} else if (earfcn >= 36200) {
return EutranBand.BAND_34;
} else if (earfcn >= 36000) {
return EutranBand.BAND_33;
} else if (earfcn > 10359) {
return INVALID_BAND;
} else if (earfcn >= 9920) {
return INVALID_BAND; // band 32 only for CarrierAgg
} else if (earfcn >= 9870) {
return EutranBand.BAND_31;
} else if (earfcn >= 9770) {
return EutranBand.BAND_30;
} else if (earfcn >= 9660) {
return INVALID_BAND; // band 29 only for CarrierAgg
} else if (earfcn >= 9210) {
return EutranBand.BAND_28;
} else if (earfcn >= 9040) {
return EutranBand.BAND_27;
} else if (earfcn >= 8690) {
return EutranBand.BAND_26;
} else if (earfcn >= 8040) {
return EutranBand.BAND_25;
} else if (earfcn >= 7700) {
return EutranBand.BAND_24;
} else if (earfcn >= 7500) {
return EutranBand.BAND_23;
} else if (earfcn >= 6600) {
return EutranBand.BAND_22;
} else if (earfcn >= 6450) {
return EutranBand.BAND_21;
} else if (earfcn >= 6150) {
return EutranBand.BAND_20;
} else if (earfcn >= 6000) {
return EutranBand.BAND_19;
} else if (earfcn >= 5850) {
return EutranBand.BAND_18;
} else if (earfcn >= 5730) {
return EutranBand.BAND_17;
} else if (earfcn > 5379) {
return INVALID_BAND;
} else if (earfcn >= 5280) {
return EutranBand.BAND_14;
} else if (earfcn >= 5180) {
return EutranBand.BAND_13;
} else if (earfcn >= 5010) {
return EutranBand.BAND_12;
} else if (earfcn >= 4750) {
return EutranBand.BAND_11;
} else if (earfcn >= 4150) {
return EutranBand.BAND_10;
} else if (earfcn >= 3800) {
return EutranBand.BAND_9;
} else if (earfcn >= 3450) {
return EutranBand.BAND_8;
} else if (earfcn >= 2750) {
return EutranBand.BAND_7;
} else if (earfcn >= 2650) {
return EutranBand.BAND_6;
} else if (earfcn >= 2400) {
return EutranBand.BAND_5;
} else if (earfcn >= 1950) {
return EutranBand.BAND_4;
} else if (earfcn >= 1200) {
return EutranBand.BAND_3;
} else if (earfcn >= 600) {
return EutranBand.BAND_2;
} else if (earfcn >= 0) {
return EutranBand.BAND_1;
}
return INVALID_BAND;
}
}

View File

@@ -68,6 +68,9 @@ public abstract class CellIdentity implements Parcelable {
*/
public static final int TYPE_TDSCDMA = 5;
/** @hide */
public static final int INVALID_CHANNEL_NUMBER = -1;
// Log tag
/** @hide */
protected final String mTag;
@@ -124,6 +127,16 @@ public abstract class CellIdentity implements Parcelable {
*/
public @Type int getType() { return mType; }
/**
* Returns the channel number of the cell identity.
*
* @hide
* @return The channel number, or {@link #INVALID_CHANNEL_NUMBER} if not implemented
*/
public int getChannelNumber() {
return INVALID_CHANNEL_NUMBER;
}
/**
* Used by child classes for parceling.
*

View File

@@ -203,6 +203,11 @@ public final class CellIdentityGsm extends CellIdentity {
return mAlphaShort;
}
/** @hide */
@Override
public int getChannelNumber() {
return mArfcn;
}
/**
* @deprecated Primary Scrambling Code is not applicable to GSM.

View File

@@ -213,6 +213,12 @@ public final class CellIdentityLte extends CellIdentity {
return mAlphaShort;
}
/** @hide */
@Override
public int getChannelNumber() {
return mEarfcn;
}
@Override
public int hashCode() {
return Objects.hash(mMccStr, mMncStr, mCi, mPci, mTac, mAlphaLong, mAlphaShort);

View File

@@ -206,6 +206,12 @@ public final class CellIdentityWcdma extends CellIdentity {
return mUarfcn;
}
/** @hide */
@Override
public int getChannelNumber() {
return mUarfcn;
}
@Override
public boolean equals(Object other) {
if (this == other) {

View File

@@ -470,9 +470,13 @@ public class ServiceState implements Parcelable {
*/
@DuplexMode
public int getDuplexMode() {
// TODO(b/72117602) determine duplex mode from channel number, using 3GPP 36.101 sections
// 5.7.3-1 and 5.5-1
return DUPLEX_MODE_UNKNOWN;
// only support LTE duplex mode
if (!isLte(mRilDataRadioTechnology)) {
return DUPLEX_MODE_UNKNOWN;
}
int band = AccessNetworkUtils.getOperatingBandForEarfcn(mChannelNumber);
return AccessNetworkUtils.getDuplexModeForEutranBand(band);
}
/**
@@ -890,6 +894,7 @@ public class ServiceState implements Parcelable {
.append(", mDataRegState=").append(mDataRegState)
.append("(" + rilServiceStateToString(mDataRegState) + ")")
.append(", mChannelNumber=").append(mChannelNumber)
.append(", duplexMode()=").append(getDuplexMode())
.append(", mCellBandwidths=").append(Arrays.toString(mCellBandwidths))
.append(", mVoiceRoamingType=").append(getRoamingLogString(mVoiceRoamingType))
.append(", mDataRoamingType=").append(getRoamingLogString(mDataRoamingType))