Fix permission request
This commit is contained in:
@@ -5,7 +5,6 @@ import android.content.ComponentName
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.wifi.SoftApConfiguration
|
||||
import android.net.wifi.p2p.WifiP2pGroup
|
||||
import android.os.Build
|
||||
@@ -90,11 +89,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
||||
when (binder?.service?.status) {
|
||||
RepeaterService.Status.IDLE -> if (Build.VERSION.SDK_INT < 29) parent.requireContext().let { context ->
|
||||
ContextCompat.startForegroundService(context, Intent(context, RepeaterService::class.java))
|
||||
} else if (parent.requireContext().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) ==
|
||||
PackageManager.PERMISSION_GRANTED ||
|
||||
parent.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
parent.startRepeater.launch(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
} else SmartSnackbar.make(R.string.repeater_missing_location_permissions).shortToast().show()
|
||||
} else parent.startRepeater.launch(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
RepeaterService.Status.ACTIVE -> binder.shutdown()
|
||||
else -> { }
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import be.mygod.vpnhotspot.root.RootManager
|
||||
import be.mygod.vpnhotspot.root.WifiApCommands
|
||||
import be.mygod.vpnhotspot.util.*
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import timber.log.Timber
|
||||
@@ -130,7 +131,10 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
||||
|
||||
@RequiresApi(29)
|
||||
val startRepeater = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
|
||||
if (granted) requireActivity().startForegroundService(Intent(activity, RepeaterService::class.java))
|
||||
if (granted) requireActivity().startForegroundService(Intent(activity, RepeaterService::class.java)) else {
|
||||
Snackbar.make((activity as MainActivity).binding.fragmentHolder,
|
||||
R.string.repeater_missing_location_permissions, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
@RequiresApi(26)
|
||||
val startLocalOnlyHotspot = registerForActivityResult(ActivityResultContracts.RequestPermission()) {
|
||||
|
||||
Reference in New Issue
Block a user