Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f015127 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Fix CellInfoUtilTest

Fix: 337417936
Fix: 337417222
Test: unit test
Change-Id: I47dfa05fd4839885ad7f2115a279a7b4675e85fc
parent 82f3ecab
Loading
Loading
Loading
Loading
+0 −33
Original line number Diff line number Diff line
@@ -17,12 +17,9 @@
package com.android.settings.network.telephony

import android.telephony.CellIdentity
import android.telephony.CellIdentityGsm
import android.telephony.CellInfo
import android.telephony.CellInfoGsm
import android.text.BidiFormatter
import android.text.TextDirectionHeuristics
import com.android.internal.telephony.OperatorInfo

/**
 * Add static Utility functions to get information from the CellInfo object.
@@ -47,36 +44,6 @@ object CellInfoUtil {
        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.
     */
+1 −17
Original line number Diff line number Diff line
@@ -21,11 +21,9 @@ import android.telephony.CellIdentityGsm
import android.telephony.CellInfoCdma
import android.telephony.CellInfoGsm
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.getOperatorNumeric
import com.google.common.truth.Truth.assertThat
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

@@ -97,20 +95,6 @@ class CellInfoUtilTest {
    }

    @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() {
        val cellInfoList =
            listOf(
@@ -127,7 +111,7 @@ class CellInfoUtilTest {

        assertThat(string).isEqualTo(
            "{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, " +
                "mcc = 123, mnc = 01, alphaL = Long, alphaS = Short}"
        )