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

Shicheng/indoors #388

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 8 additions & 14 deletions example/src/main/java/io/radar/example/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package io.radar.example

import android.Manifest
import android.content.Context
import android.location.Location
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View.OnClickListener
import android.widget.Button
import android.widget.LinearLayout
import android.widget.ScrollView
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import io.radar.sdk.Radar
import io.radar.sdk.RadarTrackingOptions
Expand All @@ -20,7 +14,6 @@ import io.radar.sdk.RadarVerifiedReceiver
import io.radar.sdk.model.RadarVerifiedLocationToken
import org.json.JSONObject
import java.util.EnumSet
import androidx.core.content.edit

class MainActivity : AppCompatActivity() {

Expand All @@ -31,7 +24,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

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

Expand Down Expand Up @@ -60,12 +53,13 @@ class MainActivity : AppCompatActivity() {
}

fun createButtons() {
createButton("requestForegorundPermission") {
Radar.requestForegroundLocationPermission()
}

createButton("requestBackgroundPermission") {
Radar.requestBackgroundLocationPermission()
createButton("doIndoorSurvey") {
Radar.doIndoorSurvey("", 5) { status, payload ->
Log.v(
"example",
"Indoors survey: status = ${status}; payload = $payload"
)
}
}

createButton("getLocation") {
Expand Down
10 changes: 0 additions & 10 deletions example/src/main/java/io/radar/example/MyRadarReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,4 @@ class MyRadarReceiver : RadarReceiver() {
override fun onLog(context: Context, message: String) {
notify(context, message)
}

override fun onLocationPermissionStatusUpdated(
context: Context,
status: RadarLocationPermissionStatus
) {
val statusString = RadarLocationPermissionStatus.stringForLocationPermissionState(status.status)
val body = "Location permission status updated: ${statusString}"
notify(context, body)
}

}
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.14.0'
radarVersion = '3.16.0-beta.1'
}

String buildNumber = ".${System.currentTimeMillis()}"
Expand Down
168 changes: 84 additions & 84 deletions sdk/src/main/java/io/radar/sdk/Radar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ object Radar {
)
}


interface RadarIndoorSurveyCallback {
fun onComplete(status: RadarStatus, payload: String)
}

/**
* Called when a request to log a conversion succeeds, fails, or times out.
*/
Expand All @@ -273,6 +278,13 @@ object Radar {
)
}

// interface RadarIndoorSurveyCallback {
// fun onComplete(
// status: RadarStatus,
// indoorsPayload: String
// )
// }

/**
* The status types for a request. See [](https://radar.com/documentation/sdk/android#foreground-tracking).
*/
Expand Down Expand Up @@ -431,13 +443,13 @@ object Radar {
private var verifiedReceiver: RadarVerifiedReceiver? = null
internal lateinit var logger: RadarLogger
internal lateinit var apiClient: RadarApiClient
internal lateinit var indoorSurveyManager: RadarIndoorSurveyManager
internal lateinit var locationManager: RadarLocationManager
internal lateinit var beaconManager: RadarBeaconManager
private lateinit var logBuffer: RadarLogBuffer
private lateinit var replayBuffer: RadarReplayBuffer
internal lateinit var batteryManager: RadarBatteryManager
private lateinit var verificationManager: RadarVerificationManager
private lateinit var locationPermissionManager: RadarLocationPermissionManager

/**
* Used by React Native module to setup the activity.
Expand All @@ -448,10 +460,6 @@ object Radar {
this.activity = activity;

val application = this.context as? Application
if (!this::locationPermissionManager.isInitialized) {
this.locationPermissionManager = RadarLocationPermissionManager(this.context, this.activity)
application?.registerActivityLifecycleCallbacks(locationPermissionManager)
}
}

/**
Expand Down Expand Up @@ -544,17 +552,16 @@ object Radar {
this.logger.d("Using Huawei location services")
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !this::indoorSurveyManager.isInitialized) {
this.indoorSurveyManager = RadarIndoorSurveyManager(this.context, logger, locationManager, apiClient)
}

val application = this.context as? Application
if (fraud) {
RadarSettings.setSharing(this.context, false)
}
application?.registerActivityLifecycleCallbacks(RadarActivityLifecycleCallbacks(fraud))

if (!this::locationPermissionManager.isInitialized) {
this.locationPermissionManager = RadarLocationPermissionManager(this.context, this.activity)
application?.registerActivityLifecycleCallbacks(locationPermissionManager)
}

val featureSettings = RadarSettings.getFeatureSettings(this.context)
if (featureSettings.usePersistence) {
Radar.loadReplayBufferFromSharedPreferences()
Expand Down Expand Up @@ -825,8 +832,8 @@ object Radar {
return
}

val callTrackApi = { beacons: Array<RadarBeacon>? ->
apiClient.track(location, stopped, true, RadarLocationSource.FOREGROUND_LOCATION, false, beacons, callback = object : RadarApiClient.RadarTrackApiCallback {
val callTrackApi = { beacons: Array<RadarBeacon>?, indoorsPayload: String? ->
apiClient.track(location, stopped, true, RadarLocationSource.FOREGROUND_LOCATION, false, beacons, indoorsPayload, callback = object : RadarApiClient.RadarTrackApiCallback {
override fun onComplete(
status: RadarStatus,
res: JSONObject?,
Expand All @@ -846,45 +853,61 @@ object Radar {
})
}

if (beacons && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
apiClient.searchBeacons(location, 1000, 10, object : RadarApiClient.RadarSearchBeaconsApiCallback {
override fun onComplete(status: RadarStatus, res: JSONObject?, beacons: Array<RadarBeacon>?, uuids: Array<String>?, uids: Array<String>?) {
if (!uuids.isNullOrEmpty() || !uids.isNullOrEmpty()) {
beaconManager.startMonitoringBeaconUUIDs(uuids, uids)

beaconManager.rangeBeaconUUIDs(uuids, uids, false, object : RadarBeaconCallback {
override fun onComplete(status: RadarStatus, beacons: Array<RadarBeacon>?) {
if (status != RadarStatus.SUCCESS || beacons == null) {
callTrackApi(null)

return
}

callTrackApi(beacons)
}
})
} else if (beacons != null) {
beaconManager.startMonitoringBeacons(beacons)

beaconManager.rangeBeacons(beacons, false, object : RadarBeaconCallback {
override fun onComplete(status: RadarStatus, beacons: Array<RadarBeacon>?) {
if (status != RadarStatus.SUCCESS || beacons == null) {
callTrackApi(null)

return
}

callTrackApi(beacons)
}
})
val maybeIndoorSurveyThenCallTrackAPI = { beacons: Array<RadarBeacon>? ->
if (getTrackingOptions().indoors && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
logger.i("calling RadarIndoorsSurvey", RadarLogType.SDK_CALL)
indoorSurveyManager.start("WHEREAMI", 10, location, true) { status, payload ->
if (status != RadarStatus.SUCCESS) {
callTrackApi(beacons, null)
} else {
callTrackApi(arrayOf());
callTrackApi(beacons, payload)
}
}
}, false)
} else {
callTrackApi(null)
} else {
callTrackApi(beacons, null)
}
}


if (beacons && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
apiClient.searchBeacons(location, 1000, 10, false, object : RadarApiClient.RadarSearchBeaconsApiCallback {
override fun onComplete(status: RadarStatus, res: JSONObject?, beacons: Array<RadarBeacon>?, uuids: Array<String>?, uids: Array<String>?) {
if (!uuids.isNullOrEmpty() || !uids.isNullOrEmpty()) {
beaconManager.startMonitoringBeaconUUIDs(uuids, uids)

beaconManager.rangeBeaconUUIDs(uuids, uids, false, object : RadarBeaconCallback {
override fun onComplete(status: RadarStatus, beacons: Array<RadarBeacon>?) {
if (status != RadarStatus.SUCCESS || beacons == null) {
maybeIndoorSurveyThenCallTrackAPI(null)

return
}

maybeIndoorSurveyThenCallTrackAPI(beacons)
}
})
} else if (beacons != null) {
beaconManager.startMonitoringBeacons(beacons)

beaconManager.rangeBeacons(beacons, false, object : RadarBeaconCallback {
override fun onComplete(status: RadarStatus, beacons: Array<RadarBeacon>?) {
if (status != RadarStatus.SUCCESS || beacons == null) {
callTrackApi(null, null)

return
}

maybeIndoorSurveyThenCallTrackAPI(beacons)
}
})
} else {
maybeIndoorSurveyThenCallTrackAPI(arrayOf());
}
}
})
} else {
callTrackApi(null, null)
}
}
})
}
Expand Down Expand Up @@ -2959,6 +2982,16 @@ object Radar {
})
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
@JvmStatic
fun doIndoorSurvey(placeLabel: String, surveyLengthSeconds: Int, callback: (status: RadarStatus, payload: String) -> Unit) {
indoorSurveyManager.start(placeLabel, surveyLengthSeconds, null, false) { status, payload ->
handler.post {
callback(status, payload);
}
}
}

/**
* Logs a conversion.
*
Expand Down Expand Up @@ -3123,39 +3156,6 @@ object Radar {
})
}
}
/**
* Requests foreground location permissions.
*/
@JvmStatic
fun requestForegroundLocationPermission() {
locationPermissionManager.requestForegroundLocationPermission()
}

/**
* Requests background location permissions.
*/
@JvmStatic
fun requestBackgroundLocationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
locationPermissionManager.requestBackgroundLocationPermission()
}
}

/**
* @return A RadarPermissionStatus object with the current location permissions status.
*/
@JvmStatic
fun getLocationPermissionStatus():RadarLocationPermissionStatus {
return locationPermissionManager.getLocationPermissionStatus()
}

/**
* Directs the user to the app settings to enable location permissions.
*/
@JvmStatic
fun openAppSettings() {
locationPermissionManager.openAppSettings()
}

/**
* Sets the log level for debug logs.
Expand Down Expand Up @@ -3496,11 +3496,11 @@ object Radar {
logger.i("📍️ Radar token updated | passed = ${token.passed}; expiresAt = ${token.expiresAt}; expiresIn = ${token.expiresIn}; token = ${token.token}")
}

internal fun sendLocationPermissionStatus(status: RadarLocationPermissionStatus) {
receiver?.onLocationPermissionStatusUpdated(context, status)
// internal fun sendLocationPermissionStatus(status: RadarLocationPermissionStatus) {
// receiver?.onLocationPermissionStatusUpdated(context, status)

logger.i("📍️ Radar location permission updated | status = $status")
}
// logger.i("📍️ Radar location permission updated | status = $status")
// }

internal fun setLogPersistenceFeatureFlag(enabled: Boolean) {
this.logBuffer.setPersistentLogFeatureFlag(enabled)
Expand Down
7 changes: 5 additions & 2 deletions sdk/src/main/java/io/radar/sdk/RadarApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ internal class RadarApiClient(
)
}

internal fun track(location: Location, stopped: Boolean, foreground: Boolean, source: RadarLocationSource, replayed: Boolean, beacons: Array<RadarBeacon>?, verified: Boolean = false, integrityToken: String? = null, integrityException: String? = null, encrypted: Boolean? = false, callback: RadarTrackApiCallback? = null) {
internal fun track(location: Location, stopped: Boolean, foreground: Boolean, source: RadarLocationSource, replayed: Boolean, beacons: Array<RadarBeacon>?, indoorsWhereAmIScan: String? = null, verified: Boolean = false, integrityToken: String? = null, integrityException: String? = null, encrypted: Boolean? = false, callback: RadarTrackApiCallback? = null) {
val publishableKey = RadarSettings.getPublishableKey(context)
if (publishableKey == null) {
callback?.onComplete(RadarStatus.ERROR_PUBLISHABLE_KEY)
Expand Down Expand Up @@ -341,6 +341,9 @@ internal class RadarApiClient(
params.putOpt("sharing", RadarUtils.isScreenSharing(context))
params.putOpt("encrypted", encrypted)
}
if (indoorsWhereAmIScan != null) {
params.putOpt("indoorsWhereAmIScan", indoorsWhereAmIScan)
}
params.putOpt("appId", context.packageName)
} catch (e: JSONException) {
callback?.onComplete(RadarStatus.ERROR_BAD_REQUEST)
Expand Down Expand Up @@ -771,8 +774,8 @@ internal class RadarApiClient(
location: Location,
radius: Int,
limit: Int?,
cache: Boolean,
callback: RadarSearchBeaconsApiCallback,
cache: Boolean
) {
val publishableKey = RadarSettings.getPublishableKey(context)
if (publishableKey == null) {
Expand Down
Loading