Fix lateinit property allowedNetworkTypesFlow
Which has not been initialized. Convert it to factory to fix. Fix: 317353030 Test: manual - on Mobile Settings Test: unit test Change-Id: Ie5f22d47cb3f3fe036c706ba77ed3bdaad0b54a2
This commit is contained in:
@@ -21,7 +21,6 @@ import android.content.Intent
|
|||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.telephony.ServiceState
|
import android.telephony.ServiceState
|
||||||
import android.telephony.TelephonyManager
|
import android.telephony.TelephonyManager
|
||||||
import androidx.annotation.VisibleForTesting
|
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
@@ -39,13 +38,16 @@ import kotlinx.coroutines.withContext
|
|||||||
/**
|
/**
|
||||||
* Preference controller for "Open network select"
|
* Preference controller for "Open network select"
|
||||||
*/
|
*/
|
||||||
class OpenNetworkSelectPagePreferenceController(context: Context, key: String) :
|
class OpenNetworkSelectPagePreferenceController @JvmOverloads constructor(
|
||||||
TelephonyBasePreferenceController(context, key),
|
context: Context,
|
||||||
|
key: String,
|
||||||
|
private val allowedNetworkTypesFlowFactory: (subId: Int) -> Flow<Long> =
|
||||||
|
context::allowedNetworkTypesFlow,
|
||||||
|
private val serviceStateFlowFactory: (subId: Int) -> Flow<ServiceState> =
|
||||||
|
context::serviceStateFlow,
|
||||||
|
) : TelephonyBasePreferenceController(context, key),
|
||||||
AutoSelectPreferenceController.OnNetworkSelectModeListener {
|
AutoSelectPreferenceController.OnNetworkSelectModeListener {
|
||||||
|
|
||||||
private lateinit var allowedNetworkTypesFlow: Flow<Long>
|
|
||||||
private lateinit var serviceStateFlow: Flow<ServiceState>
|
|
||||||
|
|
||||||
private var preference: Preference? = null
|
private var preference: Preference? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,22 +55,9 @@ class OpenNetworkSelectPagePreferenceController(context: Context, key: String) :
|
|||||||
*/
|
*/
|
||||||
fun init(subId: Int): OpenNetworkSelectPagePreferenceController {
|
fun init(subId: Int): OpenNetworkSelectPagePreferenceController {
|
||||||
mSubId = subId
|
mSubId = subId
|
||||||
allowedNetworkTypesFlow = mContext.allowedNetworkTypesFlow(subId)
|
|
||||||
serviceStateFlow = mContext.serviceStateFlow(subId)
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
fun init(
|
|
||||||
subId: Int,
|
|
||||||
allowedNetworkTypesFlow: Flow<Long>,
|
|
||||||
serviceStateFlow: Flow<ServiceState>,
|
|
||||||
) {
|
|
||||||
mSubId = subId
|
|
||||||
this.allowedNetworkTypesFlow = allowedNetworkTypesFlow
|
|
||||||
this.serviceStateFlow = serviceStateFlow
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getAvailabilityStatus(subId: Int) =
|
override fun getAvailabilityStatus(subId: Int) =
|
||||||
if (MobileNetworkUtils.shouldDisplayNetworkSelectOptions(mContext, subId)) AVAILABLE
|
if (MobileNetworkUtils.shouldDisplayNetworkSelectOptions(mContext, subId)) AVAILABLE
|
||||||
else CONDITIONALLY_UNAVAILABLE
|
else CONDITIONALLY_UNAVAILABLE
|
||||||
@@ -83,13 +72,13 @@ class OpenNetworkSelectPagePreferenceController(context: Context, key: String) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
|
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
|
||||||
allowedNetworkTypesFlow.collectLatestWithLifecycle(viewLifecycleOwner) {
|
allowedNetworkTypesFlowFactory(mSubId).collectLatestWithLifecycle(viewLifecycleOwner) {
|
||||||
preference?.isVisible = withContext(Dispatchers.Default) {
|
preference?.isVisible = withContext(Dispatchers.Default) {
|
||||||
MobileNetworkUtils.shouldDisplayNetworkSelectOptions(mContext, mSubId)
|
MobileNetworkUtils.shouldDisplayNetworkSelectOptions(mContext, mSubId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceStateFlow
|
serviceStateFlowFactory(mSubId)
|
||||||
.collectLatestWithLifecycle(viewLifecycleOwner) { serviceState ->
|
.collectLatestWithLifecycle(viewLifecycleOwner) { serviceState ->
|
||||||
preference?.summary = if (serviceState.state == ServiceState.STATE_IN_SERVICE) {
|
preference?.summary = if (serviceState.state == ServiceState.STATE_IN_SERVICE) {
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
|
|||||||
@@ -59,21 +59,19 @@ class OpenNetworkSelectPagePreferenceControllerTest {
|
|||||||
private val preference = Preference(context).apply { key = TEST_KEY }
|
private val preference = Preference(context).apply { key = TEST_KEY }
|
||||||
private val preferenceScreen = PreferenceManager(context).createPreferenceScreen(context)
|
private val preferenceScreen = PreferenceManager(context).createPreferenceScreen(context)
|
||||||
|
|
||||||
private val controller = OpenNetworkSelectPagePreferenceController(context, TEST_KEY)
|
|
||||||
|
|
||||||
private val serviceState = ServiceState()
|
private val serviceState = ServiceState()
|
||||||
|
|
||||||
|
private val controller = OpenNetworkSelectPagePreferenceController(
|
||||||
|
context = context,
|
||||||
|
key = TEST_KEY,
|
||||||
|
allowedNetworkTypesFlowFactory = { emptyFlow() },
|
||||||
|
serviceStateFlowFactory = { flowOf(serviceState) },
|
||||||
|
).init(subId = SUB_ID)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
preferenceScreen.addPreference(preference)
|
preferenceScreen.addPreference(preference)
|
||||||
controller.apply {
|
controller.displayPreference(preferenceScreen)
|
||||||
init(
|
|
||||||
subId = SUB_ID,
|
|
||||||
allowedNetworkTypesFlow = emptyFlow(),
|
|
||||||
serviceStateFlow = flowOf(serviceState),
|
|
||||||
)
|
|
||||||
displayPreference(preferenceScreen)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user