Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional location setting to combine connected BT devices and e… #2491

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
private const val SETTING_HIGH_ACCURACY_MODE_UPDATE_INTERVAL = "location_ham_update_interval"
private const val SETTING_HIGH_ACCURACY_MODE_BLUETOOTH_DEVICES = "location_ham_only_bt_dev"
private const val SETTING_HIGH_ACCURACY_MODE_ZONE = "location_ham_only_enter_zone"
private const val SETTING_HIGH_ACCURACY_BT_ZONE_COMBINED = "location_ham_zone_bt_combined"
private const val SETTING_HIGH_ACCURACY_MODE_TRIGGER_RANGE_ZONE = "location_ham_trigger_range"

private const val DEFAULT_MINIMUM_ACCURACY = 200
Expand Down Expand Up @@ -269,6 +270,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
enableDisableSetting(latestContext, backgroundLocation, SETTING_HIGH_ACCURACY_MODE_BLUETOOTH_DEVICES, highAccuracyModeSettingEnabled)
enableDisableSetting(latestContext, backgroundLocation, SETTING_HIGH_ACCURACY_MODE_ZONE, highAccuracyModeSettingEnabled && isZoneEnable)
enableDisableSetting(latestContext, backgroundLocation, SETTING_HIGH_ACCURACY_MODE_TRIGGER_RANGE_ZONE, highAccuracyModeSettingEnabled && isZoneEnable)
enableDisableSetting(latestContext, backgroundLocation, SETTING_HIGH_ACCURACY_BT_ZONE_COMBINED, highAccuracyModeSettingEnabled && isZoneEnable)

lastHighAccuracyZones = highAccuracyZones
lastHighAccuracyTriggerRange = highAccuracyTriggerRange
Expand Down Expand Up @@ -354,6 +356,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
"list-bluetooth",
""
)
val highAccuracyBtZoneCombined = getHighAccuracyBTZoneCombinedSetting()

val useTriggerRange = getHighAccuracyModeTriggerRange() > 0
val highAccuracyZones = getHighAccuracyModeZones(false)
Expand Down Expand Up @@ -400,13 +403,15 @@ class LocationSensorManager : LocationSensorManagerBase() {
// true = High accuracy mode enabled
// false = High accuracy mode disabled
//
// if either BT Device is connected or in Zone -> High accuracy mode enabled (true)
// if BT device and zone are combined and BT device is connected AND in zone -> High accuracy mode enabled (true)
// if BT device and zone are NOT combined and either BT Device is connected OR in Zone -> High accuracy mode enabled (true)
// Else (NO BT dev connected and NOT in Zone), if min. one constraint is used -> High accuracy mode disabled (false)
// if no constraint is used -> High accuracy mode enabled (true)
return if (btDevConnected || inZone) {
true
} else {
!constraintsUsed
return when {
highAccuracyBtZoneCombined && btDevConnected && inZone -> true
!highAccuracyBtZoneCombined && (btDevConnected || inZone) -> true
highAccuracyBtZoneCombined && !constraintsUsed -> false
else -> !constraintsUsed
}
}

Expand All @@ -420,6 +425,16 @@ class LocationSensorManager : LocationSensorManagerBase() {
).toBoolean()
}

private fun getHighAccuracyBTZoneCombinedSetting(): Boolean {
return getSetting(
latestContext,
backgroundLocation,
SETTING_HIGH_ACCURACY_BT_ZONE_COMBINED,
"toggle",
"false"
).toBoolean()
}

private fun removeAllLocationUpdateRequests() {
Log.d(TAG, "Removing all location requests.")
removeBackgroundUpdateRequests()
Expand Down
1 change: 1 addition & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@
<string name="sensor_setting_lastupdate_add_new_intent_title">Add New Intent</string>
<string name="sensor_setting_lastupdate_intent_title" translatable="false">Intent %1$1s</string>
<string name="sensor_setting_location_ham_enabled_title">High accuracy mode (May drain battery fast)</string>
<string name="sensor_setting_location_ham_zone_bt_combined_title">High accuracy mode enabled only when in zone and BT device connected</string>
<string name="sensor_setting_location_ham_only_bt_dev_title">High accuracy mode only when connected to BT devices</string>
<string name="sensor_setting_location_ham_only_enter_zone_title">High accuracy mode only when entering zone</string>
<string name="sensor_setting_location_ham_trigger_range_title">High accuracy mode trigger range for zone (meters)</string>
Expand Down