Explicit prompt for location (#1096)

* Add a very explicit warning about location permissions.

* Fix weekly deploy...
This commit is contained in:
Justin Bassett 2020-10-23 16:18:55 -04:00 committed by GitHub
parent 6c2c082e6d
commit 5652c45623
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 15 deletions

View file

@ -55,7 +55,7 @@ jobs:
- name: Check for build need
run: |
commits=$(git log --since="24 hours ago" --oneline | wc -l)
commits=$(git log --since="7 days ago" --oneline | wc -l)
echo "commits=$commits" >> $GITHUB_ENV
- name: Deploy to Playstore Beta

View file

@ -12,6 +12,7 @@ import android.provider.Settings
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatButton
import androidx.fragment.app.Fragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -38,6 +39,8 @@ class MobileAppIntegrationFragment : Fragment(), MobileAppIntegrationView {
private const val LOCATION_REQUEST_CODE = 0
private var dialog: AlertDialog? = null
fun newInstance(): MobileAppIntegrationFragment {
return MobileAppIntegrationFragment()
}
@ -72,19 +75,18 @@ class MobileAppIntegrationFragment : Fragment(), MobileAppIntegrationView {
it.setOnCheckedChangeListener { _, isChecked ->
setLocationTracking(isChecked)
if (isChecked && !LocationSensorManager().checkPermission(requireContext(), sensorId)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
this@MobileAppIntegrationFragment.requestPermissions(
LocationSensorManager().requiredPermissions(sensorId)
.toList().minus(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
.toTypedArray(),
LOCATION_REQUEST_CODE
)
} else {
this@MobileAppIntegrationFragment.requestPermissions(
LocationSensorManager().requiredPermissions(sensorId),
LOCATION_REQUEST_CODE
)
}
dialog = AlertDialog.Builder(requireContext())
.setTitle(R.string.enable_location_tracking)
.setMessage(R.string.enable_location_tracking_prompt)
.setPositiveButton(android.R.string.ok) { _, _ ->
requestPermissions(
sensorId
)
}
.setNegativeButton(android.R.string.cancel) { _, _ -> }
.setOnDismissListener { _ -> it.isChecked = LocationSensorManager().checkPermission(requireContext(), sensorId) }
.create()
dialog?.show()
}
}
}
@ -130,6 +132,22 @@ class MobileAppIntegrationFragment : Fragment(), MobileAppIntegrationView {
super.onDestroy()
}
private fun requestPermissions(sensorId: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
this@MobileAppIntegrationFragment.requestPermissions(
LocationSensorManager().requiredPermissions(sensorId)
.toList().minus(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
.toTypedArray(),
LOCATION_REQUEST_CODE
)
} else {
this@MobileAppIntegrationFragment.requestPermissions(
LocationSensorManager().requiredPermissions(sensorId),
LOCATION_REQUEST_CODE
)
}
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
@ -137,9 +155,11 @@ class MobileAppIntegrationFragment : Fragment(), MobileAppIntegrationView {
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
dialog?.dismiss()
if (permissions.contains(Manifest.permission.ACCESS_FINE_LOCATION) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
requestPermissions(arrayOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION), 0)
requestPermissions(arrayOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION), LOCATION_REQUEST_CODE)
}
if (requestCode == LOCATION_REQUEST_CODE) {

View file

@ -91,6 +91,7 @@ to your home internet.</string>
<string name="enable_all_sensors_summary">All required permissions will be requested upon enabling</string>
<string name="enable_location_tracking">Enable Location Tracking</string>
<string name="enable_location_tracking_description">Enabling this sensor will allow the Home Assistant application to track you location and report it back to your instance of Home Assistant. Ensure that you enable background access to location, otherwise we cannot enable location tracking. Your location data is sent directly to your Home Assistant instance and is never sent to a 3rd party.</string>
<string name="enable_location_tracking_prompt">This app collects location data to enable Location Tracking, Wifi Connection Status, and URL decision making even when the app is closed or not in use.</string>
<string name="enable_remaining_sensors">Enable %1$d Sensors</string>
<string name="enabled_summary">When enabled values will be sent to Home Assistant</string>
<string name="enabled_title">Enabled</string>