Skip to content

Commit

Permalink
Merge pull request #424 from radarlabs/start-tracking-verified-accuracy
Browse files Browse the repository at this point in the history
force fresh locations
  • Loading branch information
nickpatrick authored Jan 4, 2025
2 parents 3a55d56 + 80de1d8 commit cff00be
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 24 deletions.
2 changes: 1 addition & 1 deletion example/src/main/java/io/radar/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)

val receiver = MyRadarReceiver()
Radar.initialize(this, "prj_test_pk_000000000000000000000000000000000000", receiver, Radar.RadarLocationServicesProvider.GOOGLE, true)
Radar.initialize(this, "prj_test_pk_0000000000000000000000000000000000000000", receiver, Radar.RadarLocationServicesProvider.GOOGLE, true)
Radar.sdkVersion().let { Log.i("version", it) }

val verifiedReceiver = object : RadarVerifiedReceiver() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: "org.jetbrains.dokka"
apply plugin: 'io.radar.mvnpublish'

ext {
radarVersion = '3.18.10'
radarVersion = '3.18.11'
}

String buildNumber = ".${System.currentTimeMillis()}"
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/io/radar/sdk/Radar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ object Radar {
* Optionally sets the user's expected country and state for jurisdiction checks.
*
* @param[countryCode] The user's expected country code.
* * @param[countryCode] The user's expected country code.
* @param[stateCode] The user's expected state code.
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
@JvmStatic
Expand Down
11 changes: 10 additions & 1 deletion sdk/src/main/java/io/radar/sdk/RadarApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,23 @@ internal class RadarApiClient(
if (verified) {
params.putOpt("integrityToken", integrityToken)
params.putOpt("integrityException", integrityException)
params.putOpt("sharing", RadarUtils.isScreenSharing(context))
params.putOpt("encrypted", encrypted)
if (expectedCountryCode != null) {
params.putOpt("expectedCountryCode", expectedCountryCode)
}
if (expectedStateCode != null) {
params.putOpt("expectedStateCode", expectedStateCode)
}
val fraudFailureReasons = JSONArray()
if (RadarUtils.hasMultipleDisplays(context)) {
fraudFailureReasons.put("fraud_sharing_multiple_displays")
}
if (RadarUtils.hasVirtualInputDevice(context)) {
fraudFailureReasons.put("fraud_sharing_virtual_input_device")
}
if (fraudFailureReasons.length() > 0) {
params.putOpt("fraudFailureReasons", fraudFailureReasons)
}
}
params.putOpt("appId", context.packageName)
if (RadarSettings.getSdkConfiguration(context).useLocationMetadata) {
Expand Down
19 changes: 14 additions & 5 deletions sdk/src/main/java/io/radar/sdk/RadarGoogleLocationClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.Intent
import android.location.Location
import android.os.Build
import com.google.android.gms.location.CurrentLocationRequest
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingClient
Expand All @@ -28,9 +29,16 @@ internal class RadarGoogleLocationClient(
override fun getCurrentLocation(desiredAccuracy: RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy, block: (location: Location?) -> Unit) {
val priority = priorityForDesiredAccuracy(desiredAccuracy)

var currentLocationRequestBuilder = CurrentLocationRequest.Builder()
.setPriority(priority)
if (desiredAccuracy == RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH) {
currentLocationRequestBuilder = currentLocationRequestBuilder.setMaxUpdateAgeMillis(0)
}
val currentLocationRequest = currentLocationRequestBuilder.build()

logger.d("Requesting location")

locationClient.getCurrentLocation(priority, null).addOnSuccessListener { location ->
locationClient.getCurrentLocation(currentLocationRequest, null).addOnSuccessListener { location ->
logger.d("Received current location")

block(location)
Expand All @@ -47,11 +55,12 @@ internal class RadarGoogleLocationClient(
) {
val priority = priorityForDesiredAccuracy(desiredAccuracy)

val locationRequest = LocationRequest().apply {
this.priority = priority
this.interval = interval * 1000L
this.fastestInterval = fastestInterval * 1000L
var locationRequestBuilder = LocationRequest.Builder(priority, interval * 1000L)
.setMinUpdateIntervalMillis(fastestInterval * 1000L)
if (desiredAccuracy == RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH) {
locationRequestBuilder = locationRequestBuilder.setMaxUpdateAgeMillis(0)
}
val locationRequest = locationRequestBuilder.build()

locationClient.requestLocationUpdates(locationRequest, pendingIntent)
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/io/radar/sdk/RadarLocationManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class RadarLocationManager(
private val apiClient: RadarApiClient,
private val logger: RadarLogger,
private val batteryManager: RadarBatteryManager,
private val provider: Radar.RadarLocationServicesProvider,
provider: Radar.RadarLocationServicesProvider,
internal var permissionsHelper: RadarPermissionsHelper = RadarPermissionsHelper(),
) {

Expand Down
19 changes: 19 additions & 0 deletions sdk/src/main/java/io/radar/sdk/RadarLocationReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ class RadarLocationReceiver : BroadcastReceiver() {
internal const val ACTION_SYNCED_GEOFENCES = "io.radar.sdk.LocationReceiver.SYNCED_GEOFENCES"
internal const val ACTION_BEACON = "io.radar.sdk.LocationReceiver.BEACON"
internal const val ACTION_ACTIVITY = "io.radar.sdk.LocationReceiver.ACTIVITY"
internal const val ACTION_VERIFIED_LOCATION = "io.radar.sdk.LocationReceiver.VERIFIED_LOCATION"

private const val REQUEST_CODE_LOCATION = 201605250
private const val REQUEST_CODE_BUBBLE_GEOFENCE = 201605251
private const val REQUEST_CODE_SYNCED_GEOFENCES = 201605252
private const val REQUEST_CODE_BEACON = 201605253
private const val REQUEST_CODE_ACTIVITY = 201605254
private const val REQUEST_CODE_VERIFIED_LOCATION = 201605255

internal fun getLocationPendingIntent(context: Context): PendingIntent {
val intent = baseIntent(context).apply {
Expand All @@ -46,6 +48,23 @@ class RadarLocationReceiver : BroadcastReceiver() {
)
}

internal fun getVerifiedLocationPendingIntent(context: Context): PendingIntent {
val intent = baseIntent(context).apply {
action = ACTION_VERIFIED_LOCATION
}
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
return PendingIntent.getBroadcast(
context,
REQUEST_CODE_VERIFIED_LOCATION,
intent,
flags
)
}

internal fun getBubbleGeofencePendingIntent(context: Context): PendingIntent {
val intent = baseIntent(context).apply {
action = ACTION_BUBBLE_GEOFENCE
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/main/java/io/radar/sdk/RadarNotificationHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class RadarNotificationHelper {

val notificationOptions = RadarSettings.getNotificationOptions(context);

val iconString = notificationOptions?.getEventIcon()?: context.applicationContext.applicationInfo.icon.toString()
val iconString = notificationOptions?.getEventIcon() ?: context.applicationContext.applicationInfo.icon.toString()
val smallIcon = context.applicationContext.resources.getIdentifier(iconString, "drawable", context.applicationContext.packageName)

val builder = NotificationCompat.Builder(context, CHANNEL_NAME)
Expand All @@ -64,7 +64,7 @@ class RadarNotificationHelper {
.setStyle(NotificationCompat.BigTextStyle().bigText(notificationText))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)

val iconColor = notificationOptions?.getEventColor()?: ""
val iconColor = notificationOptions?.getEventColor() ?: ""
if (iconColor.isNotEmpty()) {
builder.setColor(Color.parseColor(iconColor))
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/main/java/io/radar/sdk/RadarSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ internal object RadarSettings {
val notificationOptionsJson = notificationOptions.toJson().toString()
getSharedPreferences(context).edit { putString(KEY_NOTIFICATION_OPTIONS, notificationOptionsJson) }
var previousValue = getForegroundService(context)
setForegroundService(context,RadarTrackingOptions.RadarTrackingOptionsForegroundService(
setForegroundService(context, RadarTrackingOptions.RadarTrackingOptionsForegroundService(
previousValue.text,
previousValue.title,
previousValue.icon,
Expand All @@ -241,8 +241,8 @@ internal object RadarSettings {
previousValue.importance,
previousValue.id,
previousValue.channelName,
notificationOptions.getForegroundServiceIcon()?:previousValue.iconString,
notificationOptions.getForegroundServiceColor()?:previousValue.iconColor
notificationOptions.getForegroundServiceIcon() ?: previousValue.iconString,
notificationOptions.getForegroundServiceColor() ?: previousValue.iconColor
))
}

Expand Down
13 changes: 5 additions & 8 deletions sdk/src/main/java/io/radar/sdk/RadarUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,13 @@ internal object RadarUtils {
|| Build.PRODUCT.contains("simulator");
}

internal fun isScreenSharing(context: Context): Boolean {
if (Build.VERSION.SDK_INT < 17) {
return false
}
internal fun hasMultipleDisplays(context: Context): Boolean {
val displayManager = DisplayManagerCompat.getInstance(context)
val multipleDisplays = displayManager.displays.size > 1

val sharing = RadarSettings.getSharing(context)
return displayManager.displays.size > 1
}

return multipleDisplays || sharing
internal fun hasVirtualInputDevice(context: Context): Boolean {
return RadarSettings.getSharing(context)
}

internal fun isoStringToDate(str: String?): Date? {
Expand Down
10 changes: 9 additions & 1 deletion sdk/src/main/java/io/radar/sdk/RadarVerificationManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,21 @@ internal class RadarVerificationManager(
connectivityManager.registerNetworkCallback(request, it)
}

if (startedInterval < 20) {
Radar.locationManager.locationClient.requestLocationUpdates(RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH, 0, 0, RadarLocationReceiver.getVerifiedLocationPendingIntent(context))
}

callTrackVerified()
}

fun stopTrackingVerified() {
this.started = false

try {
if (startedInterval < 20) {
Radar.locationManager.locationClient.removeLocationUpdates(RadarLocationReceiver.getVerifiedLocationPendingIntent(context))
}

networkCallback?.let {
connectivityManager.unregisterNetworkCallback(it)
}
Expand Down Expand Up @@ -397,7 +405,7 @@ internal class RadarVerificationManager(
stringBuffer.append(location.latitude)
stringBuffer.append(location.longitude)
stringBuffer.append(location.isFromMockProvider)
stringBuffer.append(RadarUtils.isScreenSharing(this.context))
stringBuffer.append(false)
return hashSHA256(stringBuffer.toString())
}

Expand Down

0 comments on commit cff00be

Please # to comment.