Fix bugs
This commit is contained in:
@@ -59,7 +59,6 @@ class MainActivity : FlutterFragmentActivity(), ServiceConnection.Callback {
|
||||
|
||||
fun startService() {
|
||||
if (!ServiceNotification.checkPermission()) {
|
||||
// Log.d(TAG, "missing notification permission")
|
||||
grantNotificationPermission()
|
||||
return
|
||||
}
|
||||
@@ -81,15 +80,26 @@ class MainActivity : FlutterFragmentActivity(), ServiceConnection.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun prepare() = withContext(Dispatchers.Main) {
|
||||
try {
|
||||
val intent = VpnService.prepare(this@MainActivity)
|
||||
if (intent != null) {
|
||||
startActivityForResult(intent, VPN_PERMISSION_REQUEST_CODE)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
onServiceAlert(Alert.RequestVPNPermission, e.message)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceStatusChanged(status: Status) {
|
||||
Log.d(TAG, "service status changed: $status")
|
||||
serviceStatus.postValue(status)
|
||||
}
|
||||
|
||||
|
||||
override fun onServiceAlert(type: Alert, message: String?) {
|
||||
Log.d(TAG, "service alert: $type")
|
||||
serviceAlerts.postValue(ServiceEvent(Status.Stopped, type, message))
|
||||
}
|
||||
|
||||
@@ -154,22 +164,6 @@ class MainActivity : FlutterFragmentActivity(), ServiceConnection.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun prepare() = withContext(Dispatchers.Main) {
|
||||
try {
|
||||
val intent = VpnService.prepare(this@MainActivity)
|
||||
if (intent != null) {
|
||||
// prepareLauncher.launch(intent)
|
||||
startActivityForResult(intent, VPN_PERMISSION_REQUEST_CODE)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
onServiceAlert(Alert.RequestVPNPermission, e.message)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == VPN_PERMISSION_REQUEST_CODE) {
|
||||
|
||||
@@ -172,5 +172,9 @@ object DefaultNetworkListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun unregister() = Application.connectivity.unregisterNetworkCallback(Callback)
|
||||
private fun unregister() {
|
||||
runCatching {
|
||||
Application.connectivity.unregisterNetworkCallback(Callback)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ class ProxyService : Service(), PlatformInterfaceWrapper {
|
||||
|
||||
private val service = BoxService(this, this)
|
||||
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int) =
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int) =
|
||||
service.onStartCommand(intent, flags, startId)
|
||||
|
||||
override fun onBind(intent: Intent) = service.onBind(intent)
|
||||
|
||||
Reference in New Issue
Block a user