Fix SecurityExceptions caused by LOH
This commit is contained in:
@@ -2,13 +2,16 @@ package be.mygod.vpnhotspot.manage
|
|||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import android.provider.Settings
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.Toast
|
||||||
import be.mygod.vpnhotspot.LocalOnlyHotspotService
|
import be.mygod.vpnhotspot.LocalOnlyHotspotService
|
||||||
import be.mygod.vpnhotspot.R
|
import be.mygod.vpnhotspot.R
|
||||||
import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
|
import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
|
||||||
@@ -31,13 +34,28 @@ class LocalOnlyHotspotManager(private val parent: TetheringFragment) : Manager()
|
|||||||
val binder = manager.binder
|
val binder = manager.binder
|
||||||
if (binder?.iface != null) binder.stop() else {
|
if (binder?.iface != null) binder.stop() else {
|
||||||
val context = manager.parent.requireContext()
|
val context = manager.parent.requireContext()
|
||||||
if (context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) ==
|
if (context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) !=
|
||||||
PackageManager.PERMISSION_GRANTED) {
|
PackageManager.PERMISSION_GRANTED) {
|
||||||
context.startForegroundService(Intent(context, LocalOnlyHotspotService::class.java))
|
|
||||||
} else {
|
|
||||||
manager.parent.requestPermissions(arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION),
|
manager.parent.requestPermissions(arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION),
|
||||||
TetheringFragment.START_LOCAL_ONLY_HOTSPOT)
|
TetheringFragment.START_LOCAL_ONLY_HOTSPOT)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* LOH also requires location to be turned on. Source:
|
||||||
|
* https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/53e0284/service/java/com/android/server/wifi/WifiServiceImpl.java#1204
|
||||||
|
* https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/53e0284/service/java/com/android/server/wifi/WifiSettingsStore.java#228
|
||||||
|
*/
|
||||||
|
if (Settings.Secure.getInt(view.context.contentResolver, Settings.Secure.LOCATION_MODE,
|
||||||
|
Settings.Secure.LOCATION_MODE_OFF) == Settings.Secure.LOCATION_MODE_OFF) {
|
||||||
|
Toast.makeText(view.context, R.string.tethering_temp_hotspot_location, Toast.LENGTH_LONG).show()
|
||||||
|
try {
|
||||||
|
view.context.startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
|
||||||
|
} catch (exc: ActivityNotFoundException) {
|
||||||
|
exc.printStackTrace()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
context.startForegroundService(Intent(context, LocalOnlyHotspotService::class.java))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
<string name="repeater_failure_reason_no_service_requests">未添加服务请求</string>
|
<string name="repeater_failure_reason_no_service_requests">未添加服务请求</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_failure">打开热点失败 (原因:%s)</string>
|
<string name="tethering_temp_hotspot_failure">打开热点失败 (原因:%s)</string>
|
||||||
<string name="tethering_temp_hotspot_failure_no_channel">无频段</string>
|
<string name="tethering_temp_hotspot_failure_no_channel">无频段</string>
|
||||||
<string name="tethering_temp_hotspot_failure_generic">通用错误</string>
|
<string name="tethering_temp_hotspot_failure_generic">通用错误</string>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
<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="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_failure">Failed to start hotspot (reason: %s)</string>
|
<string name="tethering_temp_hotspot_failure">Failed to start hotspot (reason: %s)</string>
|
||||||
<string name="tethering_temp_hotspot_failure_no_channel">no channel</string>
|
<string name="tethering_temp_hotspot_failure_no_channel">no channel</string>
|
||||||
<string name="tethering_temp_hotspot_failure_generic">generic error</string>
|
<string name="tethering_temp_hotspot_failure_generic">generic error</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user