Fix CarrierConfigRule#setHoldCarrierPrivilege race
CarrierConfigRule#setHoldCarrierPrivilege will try to acquire/drop the carrier privilege, but does not wait for the result of the operation. If a test immediately calls an API that requires carrier privilege before the operation completes, then it will fail. Fix this by waiting for the operation to succeed before returning. Bug: 295979433 Test: presubmit Change-Id: Ic7cc9e1dbc206fbc0c3b79058b5782d93e89f1d7
This commit is contained in:
parent
451f2dd39d
commit
d3058d5ffe
1 changed files with 5 additions and 0 deletions
|
|
@ -40,6 +40,7 @@ import com.android.modules.utils.build.SdkLevel
|
|||
import com.android.testutils.runAsShell
|
||||
import com.android.testutils.tryTest
|
||||
import java.security.MessageDigest
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.test.assertTrue
|
||||
import org.junit.rules.TestRule
|
||||
|
|
@ -204,6 +205,7 @@ class CarrierConfigRule : TestRule {
|
|||
}
|
||||
return@tryTest
|
||||
}
|
||||
cv.close()
|
||||
if (hold) {
|
||||
addConfigOverrides(subId, PersistableBundle().also {
|
||||
it.putStringArray(CarrierConfigManager.KEY_CARRIER_CERTIFICATE_STRING_ARRAY,
|
||||
|
|
@ -212,6 +214,9 @@ class CarrierConfigRule : TestRule {
|
|||
} else {
|
||||
cleanUpNow()
|
||||
}
|
||||
assertTrue(cv.block(CARRIER_CONFIG_CHANGE_TIMEOUT_MS),
|
||||
"Timed out waiting for CarrierPrivilegesCallback")
|
||||
assertEquals(cpb.hasPrivilege, hold, "Couldn't set carrier privilege")
|
||||
} cleanup @JvmSerializableLambda {
|
||||
runAsShell(READ_PRIVILEGED_PHONE_STATE) @JvmSerializableLambda {
|
||||
tm.unregisterCarrierPrivilegesCallback(cpb)
|
||||
|
|
|
|||
Loading…
Reference in a new issue