Refine location permission check for repeater
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.ComponentName
|
|||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.net.wifi.SoftApConfiguration
|
import android.net.wifi.SoftApConfiguration
|
||||||
import android.net.wifi.p2p.WifiP2pGroup
|
import android.net.wifi.p2p.WifiP2pGroup
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@@ -88,7 +89,11 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
when (binder?.service?.status) {
|
when (binder?.service?.status) {
|
||||||
RepeaterService.Status.IDLE -> if (Build.VERSION.SDK_INT < 29) parent.requireContext().let { context ->
|
RepeaterService.Status.IDLE -> if (Build.VERSION.SDK_INT < 29) parent.requireContext().let { context ->
|
||||||
ContextCompat.startForegroundService(context, Intent(context, RepeaterService::class.java))
|
ContextCompat.startForegroundService(context, Intent(context, RepeaterService::class.java))
|
||||||
} else parent.startRepeater.launch(Manifest.permission.ACCESS_FINE_LOCATION)
|
} 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()
|
||||||
RepeaterService.Status.ACTIVE -> binder.shutdown()
|
RepeaterService.Status.ACTIVE -> binder.shutdown()
|
||||||
else -> { }
|
else -> { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
package be.mygod.vpnhotspot.manage
|
package be.mygod.vpnhotspot.manage
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.content.*
|
import android.content.*
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@@ -12,7 +11,6 @@ import android.view.LayoutInflater
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
@@ -126,11 +124,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
|
|||||||
|
|
||||||
@RequiresApi(29)
|
@RequiresApi(29)
|
||||||
val startRepeater = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
|
val startRepeater = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
|
||||||
val activity = requireActivity()
|
if (granted) requireActivity().startForegroundService(Intent(activity, RepeaterService::class.java))
|
||||||
if (granted) activity.startForegroundService(Intent(activity, RepeaterService::class.java))
|
|
||||||
else if (!activity.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
|
||||||
Toast.makeText(activity, "Repeater requires LOCATION permission", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@RequiresApi(26)
|
@RequiresApi(26)
|
||||||
val startLocalOnlyHotspot = registerForActivityResult(ActivityResultContracts.RequestPermission()) {
|
val startLocalOnlyHotspot = registerForActivityResult(ActivityResultContracts.RequestPermission()) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
<string name="repeater_failure_reason_no_service_requests">未添加服务请求</string>
|
<string name="repeater_failure_reason_no_service_requests">未添加服务请求</string>
|
||||||
<string name="repeater_failure_reason_unsupported_operation">不支持此操作</string>
|
<string name="repeater_failure_reason_unsupported_operation">不支持此操作</string>
|
||||||
<string name="repeater_failure_disconnected">服务不可用,请稍后重试</string>
|
<string name="repeater_failure_disconnected">服务不可用,请稍后重试</string>
|
||||||
|
<string name="repeater_missing_location_permissions">无线中继需要精确位置权限</string>
|
||||||
|
|
||||||
<string name="tethering_temp_hotspot">临时 WLAN 热点</string>
|
<string name="tethering_temp_hotspot">临时 WLAN 热点</string>
|
||||||
<string name="tethering_temp_hotspot_location">使用临时热点需要打开位置服务。</string>
|
<string name="tethering_temp_hotspot_location">使用临时热点需要打开位置服务。</string>
|
||||||
|
|||||||
@@ -45,6 +45,8 @@
|
|||||||
<string name="repeater_failure_reason_no_service_requests">no service requests added</string>
|
<string name="repeater_failure_reason_no_service_requests">no service requests added</string>
|
||||||
<string name="repeater_failure_reason_unsupported_operation">unsupported operation</string>
|
<string name="repeater_failure_reason_unsupported_operation">unsupported operation</string>
|
||||||
<string name="repeater_failure_disconnected">Service unavailable. Try again later</string>
|
<string name="repeater_failure_disconnected">Service unavailable. Try again later</string>
|
||||||
|
<string name="repeater_missing_location_permissions">Repeater requires permissions for accessing fine
|
||||||
|
location</string>
|
||||||
|
|
||||||
<string name="tethering_temp_hotspot">Temporary Wi\u2011Fi hotspot</string>
|
<string name="tethering_temp_hotspot">Temporary Wi\u2011Fi hotspot</string>
|
||||||
<string name="tethering_temp_hotspot_location">Temporary hotspot requires location to be turned on.</string>
|
<string name="tethering_temp_hotspot_location">Temporary hotspot requires location to be turned on.</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user