From d87983274e161916123d81a12e03bd82a73dc938 Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 10 Jun 2021 22:50:26 -0400 Subject: [PATCH] Fix permission request --- .../java/be/mygod/vpnhotspot/manage/RepeaterManager.kt | 7 +------ .../java/be/mygod/vpnhotspot/manage/TetheringFragment.kt | 6 +++++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt index 137fd2b1..796c8282 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterManager.kt @@ -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 -> { } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt index 25be6bb0..ba2e52af 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt @@ -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()) {