Some fixes for setting platform ap config

This commit is contained in:
Mygod
2023-05-19 15:51:20 -04:00
parent 395942782b
commit 05753976c7

View File

@@ -238,36 +238,51 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
AlertDialogFragment.setResultListener<WifiApDialogFragment, WifiApDialogFragment.Arg>(this) { which, ret -> AlertDialogFragment.setResultListener<WifiApDialogFragment, WifiApDialogFragment.Arg>(this) { which, ret ->
if (which == DialogInterface.BUTTON_POSITIVE) GlobalScope.launch { if (which == DialogInterface.BUTTON_POSITIVE) GlobalScope.launch {
val configuration = ret!!.configuration val configuration = ret!!.configuration
@Suppress("DEPRECATION") if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") {
if (Build.VERSION.SDK_INT < 30 && if (configuration.isAutoShutdownEnabled != TetherTimeoutMonitor.enabled) try {
configuration.isAutoShutdownEnabled != TetherTimeoutMonitor.enabled) try { TetherTimeoutMonitor.setEnabled(configuration.isAutoShutdownEnabled)
TetherTimeoutMonitor.setEnabled(configuration.isAutoShutdownEnabled) } catch (e: Exception) {
} catch (e: Exception) { Timber.w(e)
Timber.w(e) SmartSnackbar.make(e).show()
SmartSnackbar.make(e).show() }
} val wc = configuration.toWifiConfiguration()
val success = try {
if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") {
WifiApManager.setConfiguration(configuration.toWifiConfiguration())
} else WifiApManager.setConfiguration(configuration.toPlatform())
} catch (e: InvocationTargetException) {
try { try {
if (Build.VERSION.SDK_INT < 30) @Suppress("DEPRECATION") { if (WifiApManager.setConfiguration(wc)) return@launch
val wc = configuration.toWifiConfiguration() } catch (e: InvocationTargetException) {
RootManager.use { it.execute(WifiApCommands.SetConfigurationLegacy(wc)) } try {
} else { if (RootManager.use { it.execute(WifiApCommands.SetConfigurationLegacy(wc)) }
val platform = configuration.toPlatform() .value) return@launch
RootManager.use { it.execute(WifiApCommands.SetConfiguration(platform)) } } catch (e: CancellationException) {
return@launch SmartSnackbar.make(e).show()
} catch (eRoot: Exception) {
eRoot.addSuppressed(e)
Timber.w(eRoot)
return@launch SmartSnackbar.make(eRoot).show()
}
}
} else {
val platform = try {
configuration.toPlatform()
} catch (e: InvocationTargetException) {
Timber.w(e)
return@launch SmartSnackbar.make(e).show()
}
try {
if (WifiApManager.setConfiguration(platform)) return@launch
} catch (e: InvocationTargetException) {
try {
if (RootManager.use { it.execute(WifiApCommands.SetConfiguration(platform)) }
.value) return@launch
} catch (e: CancellationException) {
return@launch SmartSnackbar.make(e).show()
} catch (eRoot: Exception) {
eRoot.addSuppressed(e)
Timber.w(eRoot)
return@launch SmartSnackbar.make(eRoot).show()
} }
} catch (_: CancellationException) {
} catch (eRoot: Exception) {
eRoot.addSuppressed(e)
Timber.w(eRoot)
SmartSnackbar.make(eRoot).show()
null
} }
} }
if (success == false) SmartSnackbar.make(R.string.configuration_rejected).show() SmartSnackbar.make(R.string.configuration_rejected).show()
} }
} }
binding = FragmentTetheringBinding.inflate(inflater, container, false) binding = FragmentTetheringBinding.inflate(inflater, container, false)