Add the timer for waiting sim ready

When the sim onboarding setup the primary sim,
the psim is not ready.

Bug: 346623465
Test: verified this case.
Change-Id: Ide5a5de4f19deb7de6dd093df4dd267329b82046
This commit is contained in:
songferngwang
2024-06-14 05:19:19 +00:00
committed by SongFerng Wang
parent b3aae5aaf1
commit d73f0e3c77
2 changed files with 43 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ package com.android.settings.network
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.telephony.SubscriptionManager
import android.util.Log
import androidx.compose.foundation.layout.Column
@@ -41,7 +42,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
@@ -54,7 +54,9 @@ import androidx.lifecycle.LifecycleRegistry
import com.android.settings.R
import com.android.settings.SidecarFragment
import com.android.settings.network.telephony.SubscriptionActionDialogActivity
import com.android.settings.network.telephony.SubscriptionRepository
import com.android.settings.network.telephony.ToggleSubscriptionDialogActivity
import com.android.settings.network.telephony.requireSubscriptionManager
import com.android.settings.spa.SpaActivity.Companion.startSpaActivity
import com.android.settings.spa.network.SimOnboardingPageProvider.getRoute
import com.android.settings.wifi.WifiPickerTrackerHelper
@@ -67,13 +69,17 @@ import com.android.settingslib.spa.widget.dialog.getDialogWidth
import com.android.settingslib.spa.widget.dialog.rememberAlertDialogPresenter
import com.android.settingslib.spa.widget.ui.SettingsTitle
import com.android.settingslib.spaprivileged.framework.common.userManager
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class SimOnboardingActivity : SpaBaseDialogActivity() {
lateinit var scope: CoroutineScope
@@ -441,7 +447,9 @@ class SimOnboardingActivity : SpaBaseDialogActivity() {
SidecarFragment.State.SUCCESS -> {
Log.i(TAG, "Successfully enable the eSIM profile.")
switchToEuiccSubscriptionSidecar!!.reset()
callbackListener(CallbackType.CALLBACK_SETUP_NAME)
scope.launch {
checkSimIsReadyAndGoNext()
}
}
SidecarFragment.State.ERROR -> {
@@ -459,7 +467,9 @@ class SimOnboardingActivity : SpaBaseDialogActivity() {
Log.i(TAG, "Successfully switched to removable slot.")
switchToRemovableSlotSidecar!!.reset()
onboardingService.handleTogglePsimAction()
callbackListener(CallbackType.CALLBACK_SETUP_NAME)
scope.launch {
checkSimIsReadyAndGoNext()
}
}
SidecarFragment.State.ERROR -> {
@@ -491,6 +501,35 @@ class SimOnboardingActivity : SpaBaseDialogActivity() {
}
}
suspend fun checkSimIsReadyAndGoNext() {
withContext(Dispatchers.Default) {
val isEnabled = context.requireSubscriptionManager()
.isSubscriptionEnabled(onboardingService.targetSubId)
if (!isEnabled) {
val latch = CountDownLatch(1)
val receiver = CarrierConfigChangedReceiver(latch)
try {
val waitingTimeMillis =
Settings.Global.getLong(
context.contentResolver,
Settings.Global.EUICC_SWITCH_SLOT_TIMEOUT_MILLIS,
UiccSlotUtil.DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS
)
receiver.registerOn(context)
Log.d(TAG, "Start waiting, waitingTime is $waitingTimeMillis")
latch.await(waitingTimeMillis, TimeUnit.MILLISECONDS)
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
Log.e(TAG, "Failed switching to physical slot.", e)
} finally {
context.unregisterReceiver(receiver)
}
}
Log.d(TAG, "Sim is ready then go to next")
callbackListener(CallbackType.CALLBACK_SETUP_NAME)
}
}
@Composable
fun StartingDialogImpl(
nextAction: () -> Unit,

View File

@@ -51,7 +51,7 @@ public class UiccSlotUtil {
private static final String TAG = "UiccSlotUtil";
private static final long DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS = 25 * 1000L;
static final long DEFAULT_WAIT_AFTER_SWITCH_TIMEOUT_MILLIS = 25 * 1000L;
public static final int INVALID_LOGICAL_SLOT_ID = -1;
public static final int INVALID_PHYSICAL_SLOT_ID = -1;