Merge "Fix CellInfoUtilTest" into main

This commit is contained in:
Chaohui Wang
2024-05-17 07:06:03 +00:00
committed by Android (Google) Code Review
2 changed files with 1 additions and 50 deletions

View File

@@ -17,12 +17,9 @@
package com.android.settings.network.telephony package com.android.settings.network.telephony
import android.telephony.CellIdentity import android.telephony.CellIdentity
import android.telephony.CellIdentityGsm
import android.telephony.CellInfo import android.telephony.CellInfo
import android.telephony.CellInfoGsm
import android.text.BidiFormatter import android.text.BidiFormatter
import android.text.TextDirectionHeuristics import android.text.TextDirectionHeuristics
import com.android.internal.telephony.OperatorInfo
/** /**
* Add static Utility functions to get information from the CellInfo object. * Add static Utility functions to get information from the CellInfo object.
@@ -47,36 +44,6 @@ object CellInfoUtil {
return bidiFormatter.unicodeWrap(operatorNumeric, TextDirectionHeuristics.LTR) return bidiFormatter.unicodeWrap(operatorNumeric, TextDirectionHeuristics.LTR)
} }
/**
* Creates a CellInfo object from OperatorInfo. GsmCellInfo is used here only because
* operatorInfo does not contain technology type while CellInfo is an abstract object that
* requires to specify technology type. It doesn't matter which CellInfo type to use here, since
* we only want to wrap the operator info and PLMN to a CellInfo object.
*/
@JvmStatic
fun convertOperatorInfoToCellInfo(operatorInfo: OperatorInfo): CellInfo {
val operatorNumeric = operatorInfo.operatorNumeric
var mcc: String? = null
var mnc: String? = null
if (operatorNumeric?.matches("^[0-9]{5,6}$".toRegex()) == true) {
mcc = operatorNumeric.substring(0, 3)
mnc = operatorNumeric.substring(3)
}
return CellInfoGsm().apply {
cellIdentity = CellIdentityGsm(
/* lac = */ Int.MAX_VALUE,
/* cid = */ Int.MAX_VALUE,
/* arfcn = */ Int.MAX_VALUE,
/* bsic = */ Int.MAX_VALUE,
/* mccStr = */ mcc,
/* mncStr = */ mnc,
/* alphal = */ operatorInfo.operatorAlphaLong,
/* alphas = */ operatorInfo.operatorAlphaShort,
/* additionalPlmns = */ emptyList(),
)
}
}
/** /**
* Convert a list of cellInfos to readable string without sensitive info. * Convert a list of cellInfos to readable string without sensitive info.
*/ */

View File

@@ -21,11 +21,9 @@ import android.telephony.CellIdentityGsm
import android.telephony.CellInfoCdma import android.telephony.CellInfoCdma
import android.telephony.CellInfoGsm import android.telephony.CellInfoGsm
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.internal.telephony.OperatorInfo
import com.android.settings.network.telephony.CellInfoUtil.getNetworkTitle import com.android.settings.network.telephony.CellInfoUtil.getNetworkTitle
import com.android.settings.network.telephony.CellInfoUtil.getOperatorNumeric import com.android.settings.network.telephony.CellInfoUtil.getOperatorNumeric
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@@ -97,20 +95,6 @@ class CellInfoUtilTest {
} }
@Test @Test
@Ignore("b/337417936")
fun convertOperatorInfoToCellInfo() {
val operatorInfo = OperatorInfo(LONG, SHORT, "12301")
val cellInfo = CellInfoUtil.convertOperatorInfoToCellInfo(operatorInfo)
assertThat(cellInfo.cellIdentity.mccString).isEqualTo("123")
assertThat(cellInfo.cellIdentity.mncString).isEqualTo("01")
assertThat(cellInfo.cellIdentity.operatorAlphaLong).isEqualTo(LONG)
assertThat(cellInfo.cellIdentity.operatorAlphaShort).isEqualTo(SHORT)
}
@Test
@Ignore("b/337417222")
fun cellInfoListToString() { fun cellInfoListToString() {
val cellInfoList = val cellInfoList =
listOf( listOf(
@@ -127,7 +111,7 @@ class CellInfoUtilTest {
assertThat(string).isEqualTo( assertThat(string).isEqualTo(
"{CellType = CellInfoCdma, isRegistered = false, " + "{CellType = CellInfoCdma, isRegistered = false, " +
"mcc = null, mnc = null, alphaL = Long, alphaS = Short}, " + "mcc = null, mnc = null, alphaL = Long, alphaS = Short}${System.lineSeparator()}" +
"{CellType = CellInfoGsm, isRegistered = true, " + "{CellType = CellInfoGsm, isRegistered = true, " +
"mcc = 123, mnc = 01, alphaL = Long, alphaS = Short}" "mcc = 123, mnc = 01, alphaL = Long, alphaS = Short}"
) )