Merge "Add a warning dialog to notify user that call may end by operation." into main

This commit is contained in:
Tom Hsu
2024-08-12 02:42:59 +00:00
committed by Android (Google) Code Review

View File

@@ -18,6 +18,7 @@ package com.android.settings.system.reset
import android.app.ProgressDialog import android.app.ProgressDialog
import android.app.settings.SettingsEnums import android.app.settings.SettingsEnums
import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.os.Looper import android.os.Looper
import android.telephony.SubscriptionManager import android.telephony.SubscriptionManager
@@ -56,7 +57,8 @@ import kotlinx.coroutines.withContext
* This is the confirmation screen. * This is the confirmation screen.
*/ */
class ResetNetworkConfirm : InstrumentedFragment() { class ResetNetworkConfirm : InstrumentedFragment() {
@VisibleForTesting lateinit var resetNetworkRequest: ResetNetworkRequest @VisibleForTesting
lateinit var resetNetworkRequest: ResetNetworkRequest
private var progressDialog: ProgressDialog? = null private var progressDialog: ProgressDialog? = null
private var alertDialog: AlertDialog? = null private var alertDialog: AlertDialog? = null
private var resetStarted = false private var resetStarted = false
@@ -87,10 +89,7 @@ class ResetNetworkConfirm : InstrumentedFragment() {
/** Configure the UI for the final confirmation interaction */ /** Configure the UI for the final confirmation interaction */
private fun View.establishFinalConfirmationState() { private fun View.establishFinalConfirmationState() {
requireViewById<View>(R.id.execute_reset_network).setOnClickListener { requireViewById<View>(R.id.execute_reset_network).setOnClickListener {
if (!Utils.isMonkeyRunning() && !resetStarted) { showResetInternetDialog();
resetStarted = true
viewLifecycleOwner.lifecycleScope.launch { onResetClicked() }
}
} }
} }
@@ -118,10 +117,10 @@ class ResetNetworkConfirm : InstrumentedFragment() {
private fun invalidSubIdFlow(): Flow<Int> { private fun invalidSubIdFlow(): Flow<Int> {
val subIdsInRequest = val subIdsInRequest =
listOf( listOf(
resetNetworkRequest.resetTelephonyAndNetworkPolicyManager, resetNetworkRequest.resetTelephonyAndNetworkPolicyManager,
resetNetworkRequest.resetApnSubId, resetNetworkRequest.resetApnSubId,
resetNetworkRequest.resetImsSubId, resetNetworkRequest.resetImsSubId,
) )
.distinct() .distinct()
.filter(SubscriptionManager::isUsableSubscriptionId) .filter(SubscriptionManager::isUsableSubscriptionId)
@@ -162,6 +161,24 @@ class ResetNetworkConfirm : InstrumentedFragment() {
} }
} }
private fun showResetInternetDialog() {
val builder = AlertDialog.Builder(requireContext())
val resetInternetClickListener =
DialogInterface.OnClickListener { dialog, which ->
if (!Utils.isMonkeyRunning() && !resetStarted) {
resetStarted = true
viewLifecycleOwner.lifecycleScope.launch { onResetClicked() }
}
}
builder.setTitle(R.string.reset_your_internet_title)
.setMessage(R.string.reset_internet_text)
.setPositiveButton(R.string.tts_reset, resetInternetClickListener)
.setNegativeButton(android.R.string.cancel, null)
.create()
.show()
}
/** /**
* Do all reset task. * Do all reset task.
* *
@@ -173,7 +190,8 @@ class ResetNetworkConfirm : InstrumentedFragment() {
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
val builder = val builder =
resetNetworkRequest.toResetNetworkOperationBuilder( resetNetworkRequest.toResetNetworkOperationBuilder(
requireContext(), Looper.getMainLooper()) requireContext(), Looper.getMainLooper()
)
resetNetworkRequest.resetEsimPackageName?.let { resetEsimPackageName -> resetNetworkRequest.resetEsimPackageName?.let { resetEsimPackageName ->
builder.resetEsim(resetEsimPackageName) builder.resetEsim(resetEsimPackageName)
builder.resetEsimResultCallback { resetEsimSuccess = it } builder.resetEsimResultCallback { resetEsimSuccess = it }
@@ -199,8 +217,8 @@ class ResetNetworkConfirm : InstrumentedFragment() {
} else { } else {
Toast.makeText(activity, R.string.reset_network_complete_toast, Toast.LENGTH_SHORT) Toast.makeText(activity, R.string.reset_network_complete_toast, Toast.LENGTH_SHORT)
.show() .show()
activity.finish()
} }
activity.finish()
} }
override fun onDestroy() { override fun onDestroy() {