kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
warn repeatedly about missing permissions
rodzic
0c7dac8cb2
commit
b14061e6cc
|
@ -1,22 +1,6 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<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" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="PROTO">
|
||||
|
|
|
@ -291,8 +291,10 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
|
||||
/**
|
||||
* 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
|
||||
val ignoredPermissions = setOf(
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION,
|
||||
|
@ -304,10 +306,12 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
!ignoredPermissions.contains(name)
|
||||
}
|
||||
|
||||
if (deniedPermissions.isNotEmpty()) {
|
||||
return if (deniedPermissions.isNotEmpty()) {
|
||||
errormsg("Denied permissions: ${deniedPermissions.joinToString(",")}")
|
||||
showToast(R.string.permission_missing)
|
||||
}
|
||||
true
|
||||
} else
|
||||
false
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
|
@ -1133,7 +1137,8 @@ class MainActivity : AppCompatActivity(), Logging,
|
|||
val styles = arrayOf(
|
||||
getString(R.string.theme_light),
|
||||
getString(R.string.theme_dark),
|
||||
getString(R.string.theme_system))
|
||||
getString(R.string.theme_system)
|
||||
)
|
||||
|
||||
/// Load preferences and its value
|
||||
val prefs = UIViewModel.getPreferences(this)
|
||||
|
|
|
@ -889,8 +889,22 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
val locationSettingsResponse = LocationServices.getSettingsClient(requireActivity())
|
||||
.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 {
|
||||
debug("We have location access")
|
||||
if(!it.locationSettingsStates.isBleUsable || !it.locationSettingsStates.isLocationUsable)
|
||||
weNeedAccess()
|
||||
else
|
||||
debug("We have location access")
|
||||
}
|
||||
|
||||
locationSettingsResponse.addOnFailureListener { _ ->
|
||||
|
@ -910,13 +924,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
// 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
|
||||
context?.let { c ->
|
||||
Toast.makeText(
|
||||
c,
|
||||
getString(R.string.location_disabled_warning),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
weNeedAccess()
|
||||
|
||||
//} else
|
||||
// Exceptions.report(exception)
|
||||
|
@ -945,20 +953,25 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
|||
if (!hasCompanionDeviceApi)
|
||||
scanModel.startScan()
|
||||
|
||||
requireActivity().registerReceiver(updateProgressReceiver, updateProgressFilter)
|
||||
val activity = requireActivity() as MainActivity
|
||||
|
||||
activity.registerReceiver(updateProgressReceiver, updateProgressFilter)
|
||||
|
||||
// Keep reminding user BLE is still off
|
||||
val hasUSB = activity?.let { SerialInterface.findDrivers(it).isNotEmpty() } ?: true
|
||||
if (!hasUSB) {
|
||||
// Warn user if BLE is disabled
|
||||
if (scanModel.bluetoothAdapter?.isEnabled != true) {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
R.string.error_bluetooth,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
checkLocationEnabled()
|
||||
// First warn about permissions, and then if needed warn abotu settings
|
||||
if(!activity.warnMissingPermissions()) {
|
||||
// Warn user if BLE is disabled
|
||||
if (scanModel.bluetoothAdapter?.isEnabled != true) {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
R.string.error_bluetooth,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
} else {
|
||||
checkLocationEnabled()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 0c080d8f65d69986559f187e667d98a28329ce7f
|
||||
Subproject commit 16385ae6b102be20103fc310fd5e5ad5b178ea7a
|
Ładowanie…
Reference in New Issue