Commit e3610272 authored by Ricki Hirner's avatar Ricki Hirner

Restrict sync to WiFi SSIDs: explain why Location permissions are required

parent 5ef9693a
Pipeline #43106093 passed with stages
in 9 minutes and 55 seconds
......@@ -8,6 +8,7 @@
package at.bitfire.davdroid.resource
import android.provider.CalendarContract.Events
import at.bitfire.davdroid.model.SyncState
interface LocalCollection<out T: LocalResource<*>> {
......@@ -24,14 +25,23 @@ interface LocalCollection<out T: LocalResource<*>> {
/**
* Marks all entries which are not dirty with the given flags only.
* @return number of marked entries
**/
* Sets the [LocalEvent.COLUMN_FLAGS] value for entries which are not dirty ([Events.DIRTY] is 0)
* and have an [Events.ORIGINAL_ID] of null.
*
* @param flags value of flags to set (for instance, [LocalResource.FLAG_REMOTELY_PRESENT]])
*
* @return number of marked entries
*/
fun markNotDirty(flags: Int): Int
/**
* Removes all entries with are not dirty and are marked with exactly the given flags.
* @return number of removed entries
* Removes entries which are not dirty ([Events.DIRTY] is 0 and an [Events.ORIGINAL_ID] is null) with
* a given flag combination.
*
* @param flags exact flags value to remove entries with (for instance, if this is [LocalResource.FLAG_REMOTELY_PRESENT]],
* all entries with exactly this flag will be removed)
*
* @return number of removed entries
*/
fun removeNotDirtyMarked(flags: Int): Int
......
......@@ -23,11 +23,11 @@ import android.security.KeyChain
import android.view.MenuItem
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.app.NavUtils
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import androidx.preference.*
import at.bitfire.davdroid.App
import at.bitfire.davdroid.R
import at.bitfire.davdroid.model.Credentials
import at.bitfire.davdroid.resource.LocalCalendar
......@@ -230,7 +230,8 @@ class AccountSettingsActivity: AppCompatActivity() {
val onlySSIDs = accountSettings.getSyncWifiOnlySSIDs()?.joinToString(", ")
prefWifiOnlySSIDs.text = onlySSIDs
if (onlySSIDs != null)
prefWifiOnlySSIDs.summary = getString(R.string.settings_sync_wifi_only_ssids_on, onlySSIDs)
prefWifiOnlySSIDs.summary = getString(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1)
R.string.settings_sync_wifi_only_ssids_on_location_services else R.string.settings_sync_wifi_only_ssids_on, onlySSIDs)
else
prefWifiOnlySSIDs.setSummary(R.string.settings_sync_wifi_only_ssids_off)
prefWifiOnlySSIDs.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
......@@ -244,7 +245,7 @@ class AccountSettingsActivity: AppCompatActivity() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 &&
accountSettings.getSyncWifiOnly() && onlySSIDs != null &&
ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(requireActivity(), arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), 0)
requestPermissions(arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), 0)
// preference group: CardDAV
(findPreference("contact_group_method") as ListPreference).let {
......@@ -365,6 +366,30 @@ class AccountSettingsActivity: AppCompatActivity() {
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (permissions.first() == Manifest.permission.ACCESS_COARSE_LOCATION && grantResults.first() == PackageManager.PERMISSION_DENIED) {
// location permission denied, reset SSID restriction
AccountSettings(requireActivity(), account).setSyncWifiOnlySSIDs(null)
reload()
AlertDialog.Builder(requireActivity())
.setIcon(R.drawable.ic_network_wifi_dark)
.setTitle(R.string.settings_sync_wifi_only_ssids)
.setMessage(R.string.settings_sync_wifi_only_ssids_location_permission)
.setPositiveButton(android.R.string.ok) { _, _ -> }
.setNeutralButton(R.string.settings_more_info_faq) { _, _ ->
val faqUrl = App.homepageUrl(requireActivity()).buildUpon()
.appendEncodedPath("faq/wifi-ssid-restriction-location-permission")
.build()
val intent = Intent(Intent.ACTION_VIEW, faqUrl)
startActivity(Intent.createChooser(intent, null))
}
.show()
}
}
}
}
......@@ -205,8 +205,11 @@
<string name="settings_sync_wifi_only_off">Connection type is not taken into consideration</string>
<string name="settings_sync_wifi_only_ssids">WiFi SSID restriction</string>
<string name="settings_sync_wifi_only_ssids_on">Will only sync over %s</string>
<string name="settings_sync_wifi_only_ssids_on_location_services">Will only sync over %s (requires active location services)</string>
<string name="settings_sync_wifi_only_ssids_off">All WiFi connections will be used</string>
<string name="settings_sync_wifi_only_ssids_message">Comma-separated names (SSIDs) of allowed WiFi networks (leave blank for all)</string>
<string name="settings_sync_wifi_only_ssids_location_permission">To read WiFi names, the Location permission and permanently activated location services are required.</string>
<string name="settings_more_info_faq">More information (FAQ)</string>
<string name="settings_carddav">CardDAV</string>
<string name="settings_contact_group_method">Contact group method</string>
<string-array name="settings_contact_group_method_values" translatable="false">
......
Subproject commit 1f48a6620c806c218eb8cd8c31e0025f44b5a933
Subproject commit 324c4cf62d612c553c6a01744898be3819cdfb2d
Subproject commit 7c49ba213d823fcb3b06c567227d53e723864043
Subproject commit d36b93cc80a93d62c126091aebaad702b049f3d2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment