Fix race condition when requestNetworkScan

requestNetworkScan() could call callbacks concurrently, so we use a
single thread to avoid racing conditions.

Fix: 345494692
Flag: EXEMPT bug fix
Test: manual - do network scan
Change-Id: Ibf38442bbd9cfbbd0762b31347645810aca1113b
This commit is contained in:
Chaohui Wang
2024-07-25 10:23:21 +08:00
parent 92e46317d2
commit c181d60bac

View File

@@ -30,8 +30,8 @@ import com.android.settings.R
import com.android.settings.network.telephony.CellInfoUtil.getNetworkTitle import com.android.settings.network.telephony.CellInfoUtil.getNetworkTitle
import com.android.settings.network.telephony.telephonyManager import com.android.settings.network.telephony.telephonyManager
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
import java.util.concurrent.Executors
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.callbackFlow
@@ -96,7 +96,9 @@ class NetworkScanRepository(private val context: Context, subId: Int) {
val networkScan = telephonyManager.requestNetworkScan( val networkScan = telephonyManager.requestNetworkScan(
createNetworkScan(), createNetworkScan(),
Dispatchers.Default.asExecutor(), // requestNetworkScan() could call callbacks concurrently, so we use a single thread
// to avoid racing conditions.
Executors.newSingleThreadExecutor(),
callback, callback,
) )