Refine code style

This commit is contained in:
Mygod
2021-08-22 20:19:49 -04:00
parent abf6913de4
commit e9081e67d7

View File

@@ -65,32 +65,31 @@ class LocalOnlyHotspotService : IpNeighbourMonitoringService(), CoroutineScope {
try { try {
Services.wifi.startLocalOnlyHotspot(object : WifiManager.LocalOnlyHotspotCallback() { Services.wifi.startLocalOnlyHotspot(object : WifiManager.LocalOnlyHotspotCallback() {
override fun onStarted(reservation: WifiManager.LocalOnlyHotspotReservation?) { override fun onStarted(reservation: WifiManager.LocalOnlyHotspotReservation?) {
if (reservation == null) onFailed(-2) else { if (reservation == null) return onFailed(-2)
this@LocalOnlyHotspotService.reservation = reservation this@LocalOnlyHotspotService.reservation = reservation
val configuration = binder.configuration!! val configuration = binder.configuration!!
if (Build.VERSION.SDK_INT < 30 && configuration.isAutoShutdownEnabled) { if (Build.VERSION.SDK_INT < 30 && configuration.isAutoShutdownEnabled) {
timeoutMonitor = TetherTimeoutMonitor(configuration.shutdownTimeoutMillis, timeoutMonitor = TetherTimeoutMonitor(configuration.shutdownTimeoutMillis, coroutineContext) {
coroutineContext) { reservation.close() } reservation.close()
} }
// based on: https://android.googlesource.com/platform/packages/services/Car/+/df5cd06/service/src/com/android/car/CarProjectionService.java#160 }
val sticky = registerReceiver(null, IntentFilter(WifiApManager.WIFI_AP_STATE_CHANGED_ACTION))!! // based on: https://android.googlesource.com/platform/packages/services/Car/+/df5cd06/service/src/com/android/car/CarProjectionService.java#160
val apState = sticky.wifiApState val sticky = registerReceiver(null, IntentFilter(WifiApManager.WIFI_AP_STATE_CHANGED_ACTION))!!
val iface = sticky.getStringExtra(WifiApManager.EXTRA_WIFI_AP_INTERFACE_NAME) val apState = sticky.wifiApState
if (apState != WifiApManager.WIFI_AP_STATE_ENABLED || iface.isNullOrEmpty()) { val iface = sticky.getStringExtra(WifiApManager.EXTRA_WIFI_AP_INTERFACE_NAME)
if (apState == WifiApManager.WIFI_AP_STATE_FAILED) { if (apState != WifiApManager.WIFI_AP_STATE_ENABLED || iface.isNullOrEmpty()) {
SmartSnackbar.make(getString(R.string.tethering_temp_hotspot_failure, if (apState == WifiApManager.WIFI_AP_STATE_FAILED) {
WifiApManager.failureReasonLookup(sticky.getIntExtra( SmartSnackbar.make(getString(R.string.tethering_temp_hotspot_failure,
WifiApManager.EXTRA_WIFI_AP_FAILURE_REASON, 0)))).show() WifiApManager.failureReasonLookup(sticky.getIntExtra(
} WifiApManager.EXTRA_WIFI_AP_FAILURE_REASON, 0)))).show()
return stopService()
}
binder.iface = iface
launch {
check(routingManager == null)
routingManager = RoutingManager.LocalOnly(
this@LocalOnlyHotspotService, iface).apply { start() }
IpNeighbourMonitor.registerCallback(this@LocalOnlyHotspotService)
} }
return stopService()
}
binder.iface = iface
launch {
check(routingManager == null)
routingManager = RoutingManager.LocalOnly(this@LocalOnlyHotspotService, iface).apply { start() }
IpNeighbourMonitor.registerCallback(this@LocalOnlyHotspotService)
} }
} }