Skip to content

Commit

Permalink
Add additional location setting to combine connected BT devices and e…
Browse files Browse the repository at this point in the history
…ntering a zone to enable high accuracy mode (#2491)
  • Loading branch information
ThoSig authored May 29, 2022
1 parent 7b87209 commit 10f2e0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 @@ -281,6 +282,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 @@ -381,6 +383,7 @@ class LocationSensorManager : LocationSensorManagerBase() {
SensorSettingType.LIST_BLUETOOTH,
""
)
val highAccuracyBtZoneCombined = getHighAccuracyBTZoneCombinedSetting()

val useTriggerRange = getHighAccuracyModeTriggerRange() > 0
val highAccuracyZones = getHighAccuracyModeZones(false)
Expand Down Expand Up @@ -427,13 +430,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 @@ -447,6 +452,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 @@ -553,6 +553,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

0 comments on commit 10f2e0f

Please sign in to comment.