kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
warn repeatedly about missing permissions
rodzic
0c7dac8cb2
commit
b14061e6cc
|
@ -1,22 +1,6 @@
|
||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<code_scheme name="Project" version="173">
|
<code_scheme name="Project" version="173">
|
||||||
<JetCodeStyleSettings>
|
<JetCodeStyleSettings>
|
||||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
|
||||||
<value>
|
|
||||||
<package name="java.util" alias="false" withSubpackages="false" />
|
|
||||||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
|
||||||
<package name="io.ktor" alias="false" withSubpackages="true" />
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
|
||||||
<value>
|
|
||||||
<package name="" alias="false" withSubpackages="true" />
|
|
||||||
<package name="java" alias="false" withSubpackages="true" />
|
|
||||||
<package name="javax" alias="false" withSubpackages="true" />
|
|
||||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
|
||||||
<package name="" alias="true" withSubpackages="true" />
|
|
||||||
</value>
|
|
||||||
</option>
|
|
||||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||||
</JetCodeStyleSettings>
|
</JetCodeStyleSettings>
|
||||||
<codeStyleSettings language="PROTO">
|
<codeStyleSettings language="PROTO">
|
||||||
|
|
|
@ -291,8 +291,10 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remind user he's disabled permissions we need
|
* Remind user he's disabled permissions we need
|
||||||
|
*
|
||||||
|
* @return true if we did warn
|
||||||
*/
|
*/
|
||||||
private fun warnMissingPermissions() {
|
fun warnMissingPermissions(): Boolean {
|
||||||
// Older versions of android don't know about these permissions - ignore failure to grant
|
// Older versions of android don't know about these permissions - ignore failure to grant
|
||||||
val ignoredPermissions = setOf(
|
val ignoredPermissions = setOf(
|
||||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||||
|
@ -304,10 +306,12 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
!ignoredPermissions.contains(name)
|
!ignoredPermissions.contains(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deniedPermissions.isNotEmpty()) {
|
return if (deniedPermissions.isNotEmpty()) {
|
||||||
errormsg("Denied permissions: ${deniedPermissions.joinToString(",")}")
|
errormsg("Denied permissions: ${deniedPermissions.joinToString(",")}")
|
||||||
showToast(R.string.permission_missing)
|
showToast(R.string.permission_missing)
|
||||||
}
|
true
|
||||||
|
} else
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRequestPermissionsResult(
|
override fun onRequestPermissionsResult(
|
||||||
|
@ -1133,7 +1137,8 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||||
val styles = arrayOf(
|
val styles = arrayOf(
|
||||||
getString(R.string.theme_light),
|
getString(R.string.theme_light),
|
||||||
getString(R.string.theme_dark),
|
getString(R.string.theme_dark),
|
||||||
getString(R.string.theme_system))
|
getString(R.string.theme_system)
|
||||||
|
)
|
||||||
|
|
||||||
/// Load preferences and its value
|
/// Load preferences and its value
|
||||||
val prefs = UIViewModel.getPreferences(this)
|
val prefs = UIViewModel.getPreferences(this)
|
||||||
|
|
|
@ -889,7 +889,21 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||||
val locationSettingsResponse = LocationServices.getSettingsClient(requireActivity())
|
val locationSettingsResponse = LocationServices.getSettingsClient(requireActivity())
|
||||||
.checkLocationSettings(builder.build())
|
.checkLocationSettings(builder.build())
|
||||||
|
|
||||||
|
fun weNeedAccess() {
|
||||||
|
context?.let { c ->
|
||||||
|
warn("Telling user we need need location accesss")
|
||||||
|
Toast.makeText(
|
||||||
|
c,
|
||||||
|
getString(R.string.location_disabled_warning),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
locationSettingsResponse.addOnSuccessListener {
|
locationSettingsResponse.addOnSuccessListener {
|
||||||
|
if(!it.locationSettingsStates.isBleUsable || !it.locationSettingsStates.isLocationUsable)
|
||||||
|
weNeedAccess()
|
||||||
|
else
|
||||||
debug("We have location access")
|
debug("We have location access")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -910,13 +924,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||||
// For now just punt and show a dialog
|
// For now just punt and show a dialog
|
||||||
|
|
||||||
// The context might be gone (if activity is going away) by the time this handler is called
|
// The context might be gone (if activity is going away) by the time this handler is called
|
||||||
context?.let { c ->
|
weNeedAccess()
|
||||||
Toast.makeText(
|
|
||||||
c,
|
|
||||||
getString(R.string.location_disabled_warning),
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
//} else
|
//} else
|
||||||
// Exceptions.report(exception)
|
// Exceptions.report(exception)
|
||||||
|
@ -945,11 +953,15 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||||
if (!hasCompanionDeviceApi)
|
if (!hasCompanionDeviceApi)
|
||||||
scanModel.startScan()
|
scanModel.startScan()
|
||||||
|
|
||||||
requireActivity().registerReceiver(updateProgressReceiver, updateProgressFilter)
|
val activity = requireActivity() as MainActivity
|
||||||
|
|
||||||
|
activity.registerReceiver(updateProgressReceiver, updateProgressFilter)
|
||||||
|
|
||||||
// Keep reminding user BLE is still off
|
// Keep reminding user BLE is still off
|
||||||
val hasUSB = activity?.let { SerialInterface.findDrivers(it).isNotEmpty() } ?: true
|
val hasUSB = activity?.let { SerialInterface.findDrivers(it).isNotEmpty() } ?: true
|
||||||
if (!hasUSB) {
|
if (!hasUSB) {
|
||||||
|
// First warn about permissions, and then if needed warn abotu settings
|
||||||
|
if(!activity.warnMissingPermissions()) {
|
||||||
// Warn user if BLE is disabled
|
// Warn user if BLE is disabled
|
||||||
if (scanModel.bluetoothAdapter?.isEnabled != true) {
|
if (scanModel.bluetoothAdapter?.isEnabled != true) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
|
@ -963,4 +975,5 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0c080d8f65d69986559f187e667d98a28329ce7f
|
Subproject commit 16385ae6b102be20103fc310fd5e5ad5b178ea7a
|
Ładowanie…
Reference in New Issue