Skip to content

Commit

Permalink
PhoneLocationManager will now broadcast location changes
Browse files Browse the repository at this point in the history
  • Loading branch information
this-Aditya committed Aug 25, 2023
1 parent b13601b commit 003eca3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/radar-android-phone/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ description = 'Basic phone sensor plugin for RADAR passive remote monitoring app

dependencies {
api project(':radar-commons-android')
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
}

apply from: "$rootDir/gradle/publishing.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.location.LocationListener
import android.location.LocationManager
import android.os.Bundle
import android.os.Process
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import org.radarbase.android.data.DataCache
import org.radarbase.android.source.AbstractSourceManager
import org.radarbase.android.source.BaseSourceState
Expand All @@ -32,6 +33,7 @@ import org.radarbase.android.util.BatteryStageReceiver
import org.radarbase.android.util.ChangeRunner
import org.radarbase.android.util.SafeHandler
import org.radarbase.android.util.StageLevels
import org.radarbase.android.util.send
import org.radarbase.passive.phone.PhoneLocationService.Companion.LOCATION_GPS_INTERVAL_DEFAULT
import org.radarbase.passive.phone.PhoneLocationService.Companion.LOCATION_GPS_INTERVAL_REDUCED_DEFAULT
import org.radarbase.passive.phone.PhoneLocationService.Companion.LOCATION_NETWORK_INTERVAL_DEFAULT
Expand All @@ -55,6 +57,7 @@ class PhoneLocationManager(context: PhoneLocationService) : AbstractSourceManage
private val intervals = ChangeRunner(LocationPollingIntervals())
private var isStarted: Boolean = false
private var referenceId: Int = 0
private lateinit var broadcaster: LocalBroadcastManager
@Volatile
var isAbsoluteLocation: Boolean = false

Expand Down Expand Up @@ -101,6 +104,7 @@ class PhoneLocationManager(context: PhoneLocationService) : AbstractSourceManage
handler.start()

status = SourceStatusListener.Status.READY
broadcaster = LocalBroadcastManager.getInstance(this)

handler.execute {
isStarted = true
Expand Down Expand Up @@ -136,6 +140,7 @@ class PhoneLocationManager(context: PhoneLocationService) : AbstractSourceManage
altitude?.normalize(), accuracy?.normalize(), speed?.normalize(), bearing?.normalize())
send(locationTopic, value)

broadcaster.send(DEVICE_LOCATION_CHANGED)
logger.info("Location: {} {} {} {} {} {} {} {} {}", provider, eventTimestamp, latitude,
longitude, accuracy, altitude, speed, bearing, timestamp)
}
Expand Down

0 comments on commit 003eca3

Please sign in to comment.