[Sims Enhancement] update the sim's name after renaming sim

-Remove remember to update the title and summary
-Sim Onboarding primary sim page removes the catogory

Bug: 318310357
Bug: 298898436
Bug: 298891941
Test: Build pass
Change-Id: Ibc0922511cd1b2e65c6af86eab06b6f9d6fce54d
diff --git a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
index b6d83f2..7330366 100644
--- a/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
+++ b/src/com/android/settings/spa/network/NetworkCellularGroupProvider.kt
@@ -219,24 +219,24 @@
             mutableStateOf(false)
         }
         //TODO: Add the Restricted TwoTargetSwitchPreference in SPA
-        TwoTargetSwitchPreference(remember {
-            object : SwitchPreferenceModel {
-                override val title = subInfo.displayName.toString()
-                override val summary = { subInfo.number }
-                override val checked = {
-                    coroutineScope.launch {
-                        withContext(Dispatchers.Default) {
-                            checked.value = subscriptionManager?.isSubscriptionEnabled(
+        TwoTargetSwitchPreference(
+                object : SwitchPreferenceModel {
+                    override val title = subInfo.displayName.toString()
+                    override val summary = { subInfo.number }
+                    override val checked = {
+                        coroutineScope.launch {
+                            withContext(Dispatchers.Default) {
+                                checked.value = subscriptionManager?.isSubscriptionEnabled(
                                     subInfo.subscriptionId)?:false
+                            }
                         }
+                        checked.value
                     }
-                    checked.value
+                    override val onCheckedChange = { newChecked: Boolean ->
+                        startToggleSubscriptionDialog(context, subInfo, newChecked)
+                    }
                 }
-                override val onCheckedChange = { newChecked: Boolean ->
-                    startToggleSubscriptionDialog(context, subInfo, newChecked)
-                }
-            }
-        }) {
+        ) {
             startMobileNetworkSettings(context, subInfo)
         }
     }
@@ -258,7 +258,7 @@
 }
 
 @Composable
-fun PrimarySimSectionImpl(
+fun PrimarySimImpl(
     subscriptionInfoList: List<SubscriptionInfo>,
     callsSelectedId: MutableIntState,
     textsSelectedId: MutableIntState,
@@ -323,10 +323,12 @@
             callsAndSmsList.add(item)
             dataList.add(item)
         }
-        callsAndSmsList.add(ListPreferenceOption(
+        callsAndSmsList.add(
+            ListPreferenceOption(
                 id = SubscriptionManager.INVALID_SUBSCRIPTION_ID,
                 text = stringResource(id = R.string.sim_calls_ask_first_prefs_title)
-        ))
+            )
+        )
     } else {
         // hide the primary sim
         state.value = false
@@ -341,33 +343,31 @@
             mutableStateOf(false)
         }
 
-        Category(title = stringResource(id = R.string.primary_sim_title)) {
-            CreatePrimarySimListPreference(
-                    stringResource(id = R.string.primary_sim_calls_title),
-                    callsAndSmsList,
-                    callsSelectedId,
-                    ImageVector.vectorResource(R.drawable.ic_phone),
-                    actionSetCalls
-            )
-            CreatePrimarySimListPreference(
-                    stringResource(id = R.string.primary_sim_texts_title),
-                    callsAndSmsList,
-                    textsSelectedId,
-                    Icons.AutoMirrored.Outlined.Message,
-                    actionSetTexts
-            )
-            CreatePrimarySimListPreference(
-                    stringResource(id = R.string.mobile_data_settings_title),
-                    dataList,
-                    mobileDataSelectedId,
-                    Icons.Outlined.DataUsage,
-                    actionSetMobileData
-            )
-        }
+        CreatePrimarySimListPreference(
+            stringResource(id = R.string.primary_sim_calls_title),
+            callsAndSmsList,
+            callsSelectedId,
+            ImageVector.vectorResource(R.drawable.ic_phone),
+            actionSetCalls
+        )
+        CreatePrimarySimListPreference(
+            stringResource(id = R.string.primary_sim_texts_title),
+            callsAndSmsList,
+            textsSelectedId,
+            Icons.AutoMirrored.Outlined.Message,
+            actionSetTexts
+        )
+        CreatePrimarySimListPreference(
+            stringResource(id = R.string.mobile_data_settings_title),
+            dataList,
+            mobileDataSelectedId,
+            Icons.Outlined.DataUsage,
+            actionSetMobileData
+        )
 
         val autoDataTitle = stringResource(id = R.string.primary_sim_automatic_data_title)
         val autoDataSummary = stringResource(id = R.string.primary_sim_automatic_data_msg)
-        SwitchPreference(remember {
+        SwitchPreference(
             object : SwitchPreferenceModel {
                 override val title = autoDataTitle
                 override val summary = { autoDataSummary }
@@ -375,6 +375,11 @@
                     if (nonDds.intValue != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
                         coroutineScope.launch {
                             automaticDataChecked.value = getAutomaticData(telephonyManagerForNonDds)
+                            Log.d(
+                                NetworkCellularGroupProvider.name,
+                                "NonDds:${nonDds.intValue}" +
+                                    "getAutomaticData:${automaticDataChecked.value}"
+                            )
                         }
                     }
                     automaticDataChecked.value
@@ -384,7 +389,26 @@
                     actionSetAutoDataSwitch(it)
                 }
             }
-        })
+        )
+    }
+}
+
+@Composable
+fun PrimarySimSectionImpl(
+    subscriptionInfoList: List<SubscriptionInfo>,
+    callsSelectedId: MutableIntState,
+    textsSelectedId: MutableIntState,
+    mobileDataSelectedId: MutableIntState,
+    nonDds: MutableIntState,
+) {
+    Category(title = stringResource(id = R.string.primary_sim_title)) {
+        PrimarySimImpl(
+            subscriptionInfoList,
+            callsSelectedId,
+            textsSelectedId,
+            mobileDataSelectedId,
+            nonDds
+        )
     }
 }
 
@@ -442,32 +466,42 @@
 }
 
 suspend fun setDefaultVoice(
-        subscriptionManager: SubscriptionManager?,
-        subId: Int): Unit = withContext(Dispatchers.Default) {
-    subscriptionManager?.setDefaultVoiceSubscriptionId(subId)
-}
+    subscriptionManager: SubscriptionManager?,
+    subId: Int
+): Unit =
+    withContext(Dispatchers.Default) {
+        subscriptionManager?.setDefaultVoiceSubscriptionId(subId)
+    }
 
 suspend fun setDefaultSms(
-        subscriptionManager: SubscriptionManager?,
-        subId: Int): Unit = withContext(Dispatchers.Default) {
-    subscriptionManager?.setDefaultSmsSubId(subId)
-}
+    subscriptionManager: SubscriptionManager?,
+    subId: Int
+): Unit =
+    withContext(Dispatchers.Default) {
+        subscriptionManager?.setDefaultSmsSubId(subId)
+    }
 
-suspend fun setDefaultData(context: Context,
-                                   subscriptionManager: SubscriptionManager?,
-                                   wifiPickerTrackerHelper: WifiPickerTrackerHelper?,
-                                   subId: Int): Unit = withContext(Dispatchers.Default) {
-    subscriptionManager?.setDefaultDataSubId(subId)
-    MobileNetworkUtils.setMobileDataEnabled(
+suspend fun setDefaultData(
+    context: Context,
+    subscriptionManager: SubscriptionManager?,
+    wifiPickerTrackerHelper: WifiPickerTrackerHelper?,
+    subId: Int
+): Unit =
+    withContext(Dispatchers.Default) {
+        subscriptionManager?.setDefaultDataSubId(subId)
+        MobileNetworkUtils.setMobileDataEnabled(
             context,
             subId,
             true /* enabled */,
-            true /* disableOtherSubscriptions */)
-    if (wifiPickerTrackerHelper != null
-            && !wifiPickerTrackerHelper.isCarrierNetworkProvisionEnabled(subId)) {
-        wifiPickerTrackerHelper.setCarrierNetworkEnabled(true)
+            true /* disableOtherSubscriptions */
+        )
+        if (wifiPickerTrackerHelper != null
+            && !wifiPickerTrackerHelper.isCarrierNetworkProvisionEnabled(subId)
+        ) {
+            wifiPickerTrackerHelper.setCarrierNetworkEnabled(true)
+        }
     }
-}
+
 suspend fun getAutomaticData(telephonyManagerForNonDds: TelephonyManager?): Boolean =
     withContext(Dispatchers.Default) {
         telephonyManagerForNonDds != null
@@ -478,7 +512,7 @@
 suspend fun setAutomaticData(telephonyManager: TelephonyManager?, newState: Boolean): Unit =
     withContext(Dispatchers.Default) {
         Log.d(
-            "NetworkCellularGroupProvider",
+            NetworkCellularGroupProvider.name,
             "setAutomaticData: MOBILE_DATA_POLICY_AUTO_DATA_SWITCH as $newState"
         )
         telephonyManager?.setMobileDataPolicyEnabled(
diff --git a/src/com/android/settings/spa/network/SimOnboardingPrimarySim.kt b/src/com/android/settings/spa/network/SimOnboardingPrimarySim.kt
index 999abb4..a5f55d0 100644
--- a/src/com/android/settings/spa/network/SimOnboardingPrimarySim.kt
+++ b/src/com/android/settings/spa/network/SimOnboardingPrimarySim.kt
@@ -24,7 +24,6 @@
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.MutableIntState
 import androidx.compose.runtime.mutableIntStateOf
-import androidx.compose.runtime.remember
 import androidx.compose.runtime.saveable.rememberSaveable
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.vector.ImageVector
@@ -82,7 +81,7 @@
         callsSelectedId.intValue = onboardingService.targetPrimarySimCalls
         textsSelectedId.intValue = onboardingService.targetPrimarySimTexts
         mobileDataSelectedId.intValue = onboardingService.targetPrimarySimMobileData
-        PrimarySimSectionImpl(
+        PrimarySimImpl(
             subscriptionInfoList = selectedSubscriptionInfoList,
             callsSelectedId = callsSelectedId,
             textsSelectedId = textsSelectedId,
@@ -110,7 +109,7 @@
         selectedId: MutableIntState,
         icon: ImageVector,
         onIdSelected: (id: Int) -> Unit
-) = ListPreference(remember {
+) = ListPreference(
     object : ListPreferenceModel {
         override val title = title
         override val options = list
@@ -119,5 +118,4 @@
         override val icon = @Composable {
             SettingsIcon(icon)
         }
-    }
 })
\ No newline at end of file