From 00818c6feb62c10769453dc8d4c2f98b0b88f57e Mon Sep 17 00:00:00 2001 From: KennyHuRadar <139801512+KennyHuRadar@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:32:27 -0400 Subject: [PATCH] Remove location permissions for now (#382) * bump version * remove location permissions stuff for now --- .../java/io/radar/example/MainActivity.kt | 14 -- .../java/io/radar/example/MyRadarReceiver.kt | 11 -- sdk/build.gradle | 2 +- sdk/src/main/java/io/radar/sdk/Radar.kt | 59 ------- .../sdk/RadarLocationPermissionManager.kt | 116 ------------- .../main/java/io/radar/sdk/RadarReceiver.kt | 8 - .../model/RadarLocationPermissionStatus.kt | 164 ------------------ 7 files changed, 1 insertion(+), 373 deletions(-) delete mode 100644 sdk/src/main/java/io/radar/sdk/RadarLocationPermissionManager.kt delete mode 100644 sdk/src/main/java/io/radar/sdk/model/RadarLocationPermissionStatus.kt diff --git a/example/src/main/java/io/radar/example/MainActivity.kt b/example/src/main/java/io/radar/example/MainActivity.kt index 4083d237..df01b6c2 100644 --- a/example/src/main/java/io/radar/example/MainActivity.kt +++ b/example/src/main/java/io/radar/example/MainActivity.kt @@ -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 @@ -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() { @@ -60,13 +53,6 @@ class MainActivity : AppCompatActivity() { } fun createButtons() { - createButton("requestForegorundPermission") { - Radar.requestForegroundLocationPermission() - } - - createButton("requestBackgroundPermission") { - Radar.requestBackgroundLocationPermission() - } createButton("getLocation") { Radar.getLocation { status, location, stopped -> diff --git a/example/src/main/java/io/radar/example/MyRadarReceiver.kt b/example/src/main/java/io/radar/example/MyRadarReceiver.kt index 6d7aeffb..01a6e870 100644 --- a/example/src/main/java/io/radar/example/MyRadarReceiver.kt +++ b/example/src/main/java/io/radar/example/MyRadarReceiver.kt @@ -11,8 +11,6 @@ import io.radar.sdk.Radar import io.radar.sdk.RadarReceiver import io.radar.sdk.model.RadarEvent import io.radar.sdk.model.RadarUser -import io.radar.sdk.model.RadarLocationPermissionStatus -import kotlin.random.Random class MyRadarReceiver : RadarReceiver() { @@ -70,13 +68,4 @@ class MyRadarReceiver : RadarReceiver() { 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) - } - } diff --git a/sdk/build.gradle b/sdk/build.gradle index 57097dc1..faa9bb9c 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -10,7 +10,7 @@ apply plugin: "org.jetbrains.dokka" apply plugin: 'io.radar.mvnpublish' ext { - radarVersion = '3.14.0' + radarVersion = '3.15.0' } String buildNumber = ".${System.currentTimeMillis()}" diff --git a/sdk/src/main/java/io/radar/sdk/Radar.kt b/sdk/src/main/java/io/radar/sdk/Radar.kt index a858f445..209e888b 100644 --- a/sdk/src/main/java/io/radar/sdk/Radar.kt +++ b/sdk/src/main/java/io/radar/sdk/Radar.kt @@ -437,22 +437,6 @@ object Radar { 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. - */ - @JvmStatic - fun onActivityCreate(activity: Activity, context: Context?) { - this.context = context ?: activity; - this.activity = activity; - - val application = this.context as? Application - if (!this::locationPermissionManager.isInitialized) { - this.locationPermissionManager = RadarLocationPermissionManager(this.context, this.activity) - application?.registerActivityLifecycleCallbacks(locationPermissionManager) - } - } /** * Initializes the Radar SDK. Call this method from the main thread in `Application.onCreate()` before calling any other Radar methods. @@ -550,11 +534,6 @@ object Radar { } 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() @@ -3123,39 +3102,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. @@ -3496,11 +3442,6 @@ 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) - - logger.i("📍️ Radar location permission updated | status = $status") - } internal fun setLogPersistenceFeatureFlag(enabled: Boolean) { this.logBuffer.setPersistentLogFeatureFlag(enabled) diff --git a/sdk/src/main/java/io/radar/sdk/RadarLocationPermissionManager.kt b/sdk/src/main/java/io/radar/sdk/RadarLocationPermissionManager.kt deleted file mode 100644 index f3112036..00000000 --- a/sdk/src/main/java/io/radar/sdk/RadarLocationPermissionManager.kt +++ /dev/null @@ -1,116 +0,0 @@ -package io.radar.sdk - -import android.Manifest -import android.app.Activity -import android.app.Application -import android.content.Context -import android.content.Intent -import android.net.Uri -import android.os.Build -import android.os.Bundle -import android.provider.Settings -import androidx.activity.ComponentActivity -import androidx.activity.result.ActivityResultLauncher -import androidx.activity.result.contract.ActivityResultContracts -import androidx.annotation.RequiresApi -import io.radar.sdk.model.RadarLocationPermissionStatus - -class RadarLocationPermissionManager(private val context: Context, private val activity: Activity?): Application.ActivityLifecycleCallbacks { - - private var danglingBackgroundPermissionRequest = false - - private lateinit var requestForegroundLocationPermissionLauncher: ActivityResultLauncher - - private lateinit var requestBackgroundLocationPermissionLauncher: ActivityResultLauncher - - init { - if (activity is ComponentActivity) { - requestForegroundLocationPermissionLauncher = activity.registerForActivityResult( - ActivityResultContracts.RequestPermission() - ) { isGranted: Boolean -> - if (!isGranted) { - RadarLocationPermissionStatus.savePreviouslyDeniedForeground(context,true) - } - Radar.sendLocationPermissionStatus(RadarLocationPermissionStatus.initWithStatus(context, activity)) - // TODO: sync the user's permissions status here - } - - requestBackgroundLocationPermissionLauncher = activity.registerForActivityResult( - ActivityResultContracts.RequestPermission() - ) { isGranted: Boolean -> - if (!isGranted) { - RadarLocationPermissionStatus.savePreviouslyDeniedBackground(context, true) - } - Radar.sendLocationPermissionStatus(RadarLocationPermissionStatus.initWithStatus(context, activity)) - // TODO: sync the user's permissions status here - } - } - } - - @RequiresApi(Build.VERSION_CODES.Q) - fun requestBackgroundLocationPermission() { - if (activity is ComponentActivity) { - requestBackgroundLocationPermissionLauncher.launch(Manifest.permission.ACCESS_BACKGROUND_LOCATION) - // TODO: sync the user's location permissions action with the their permissions status here - } - } - - fun requestForegroundLocationPermission() { - if (activity is ComponentActivity) { - Radar.sendLocationPermissionStatus(RadarLocationPermissionStatus.initWithStatus(context,activity,true)) - requestForegroundLocationPermissionLauncher.launch(Manifest.permission.ACCESS_FINE_LOCATION) - // TODO: sync the user's location permissions action with the their permissions status here - } - } - - fun openAppSettings() { - danglingBackgroundPermissionRequest = true - val intent = Intent().apply { - action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS - val uri = Uri.fromParts("package", context.packageName, null) - data = uri - flags = Intent.FLAG_ACTIVITY_NEW_TASK - } - context.startActivity(intent) - } - - fun getLocationPermissionStatus(): RadarLocationPermissionStatus { - if (activity is ComponentActivity) { - return RadarLocationPermissionStatus.initWithStatus(context, activity) - } - return RadarLocationPermissionStatus() - } - - override fun onActivityPaused(activity: Activity) { - // do nothing - } - - override fun onActivityStopped(p0: Activity) { - // do nothing - } - - override fun onActivitySaveInstanceState(p0: Activity, p1: Bundle) { - // do nothing - } - - override fun onActivityDestroyed(p0: Activity) { - // do nothing - } - - override fun onActivityCreated(p0: Activity, p1: Bundle?) { - // do nothing - } - - override fun onActivityStarted(p0: Activity) { - // do nothing - } - - override fun onActivityResumed(activity: Activity) { - if (danglingBackgroundPermissionRequest) { - Radar.sendLocationPermissionStatus(RadarLocationPermissionStatus.initWithStatus(context,activity)) - // TODO: sync the user's location permissions action with the their permissions status here - } - danglingBackgroundPermissionRequest = false - } - -} \ No newline at end of file diff --git a/sdk/src/main/java/io/radar/sdk/RadarReceiver.kt b/sdk/src/main/java/io/radar/sdk/RadarReceiver.kt index 55bd3fb2..de26232c 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarReceiver.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarReceiver.kt @@ -4,7 +4,6 @@ import android.content.Context import android.location.Location import io.radar.sdk.Radar.RadarStatus import io.radar.sdk.model.RadarEvent -import io.radar.sdk.model.RadarLocationPermissionStatus import io.radar.sdk.model.RadarUser /** @@ -57,12 +56,5 @@ abstract class RadarReceiver { */ abstract fun onLog(context: Context, message: String) - /** - * Tells the reciever that the location permissions status was updated. - * - * @param[context] The context. - * @param[status] The location permissions status. - */ - abstract fun onLocationPermissionStatusUpdated(context: Context, status: RadarLocationPermissionStatus) } \ No newline at end of file diff --git a/sdk/src/main/java/io/radar/sdk/model/RadarLocationPermissionStatus.kt b/sdk/src/main/java/io/radar/sdk/model/RadarLocationPermissionStatus.kt deleted file mode 100644 index 627eae22..00000000 --- a/sdk/src/main/java/io/radar/sdk/model/RadarLocationPermissionStatus.kt +++ /dev/null @@ -1,164 +0,0 @@ -package io.radar.sdk.model - -import android.Manifest -import android.app.Activity -import android.content.Context -import android.content.SharedPreferences -import android.content.pm.PackageManager -import android.os.Build -import androidx.core.app.ActivityCompat -import org.json.JSONObject - -class RadarLocationPermissionStatus { - - companion object { - private const val PREFS_NAME = "RadarLocationPermissionStatus" - - internal const val KEY_STATUS = "status" - internal const val KEY_FOREGROUND_PERMISSION_RESULT = "foregroundPermissionResult" - internal const val KEY_BACKGROUND_PERMISSION_RESULT = "backgroundPermissionResult" - internal const val KEY_SHOULD_SHOW_REQUEST_PERMISSION_RATIONALE_FG = "shouldShowRequestPermissionRationale" - internal const val KEY_PREVIOUSLY_DENIED_FOREGROUND = "previouslyDeniedForeground" - internal const val KEY_PREVIOUSLY_DENIED_BACKGROUND = "previouslyDeniedBackground" - internal const val KEY_APPROXIMATE_PERMISSION_REQUEST = "approximatePermissionRequest" - internal const val KEY_SHOULD_SHOW_REQUEST_PERMISSION_RATIONALE_BG = "backgroundPermissionAvailable" - internal const val KEY_IN_LOCATION_POPUP = "inLocationPopup" - - fun initWithStatus(context: Context, activity: Activity, inLocationPopup: Boolean = false): RadarLocationPermissionStatus { - - val newStatus = RadarLocationPermissionStatus() - newStatus.foregroundPermissionResult = ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED - newStatus.approximatePermissionResult = ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - newStatus.backgroundPermissionResult = ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED - } else { - newStatus.backgroundPermissionResult = false - } - newStatus.shouldShowRequestPermissionRationaleFG = ActivityCompat.shouldShowRequestPermissionRationale( - activity, Manifest.permission.ACCESS_FINE_LOCATION) - - newStatus.shouldShowRequestPermissionRationaleBG= if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - ActivityCompat.shouldShowRequestPermissionRationale( - activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) - } else { - false - } - - val prefs: SharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) - if (newStatus.foregroundPermissionResult){ - savePreviouslyDeniedForeground(context,false) - } - newStatus.previouslyDeniedForeground = prefs.getBoolean(KEY_FOREGROUND_PERMISSION_RESULT, false) - if (newStatus.backgroundPermissionResult) { - savePreviouslyDeniedBackground(context,false) - } - newStatus.previouslyDeniedBackground = prefs.getBoolean(KEY_PREVIOUSLY_DENIED_BACKGROUND, false) - - newStatus.inLocationPopup = inLocationPopup - newStatus.status = locationPermissionStateForLocationManagerStatus(newStatus) - - return newStatus - } - - fun savePreviouslyDeniedForeground(context: Context, previouslyDeniedForeground: Boolean) { - val prefs: SharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) - val editor: SharedPreferences.Editor = prefs.edit() - editor.putBoolean(KEY_FOREGROUND_PERMISSION_RESULT, previouslyDeniedForeground) - editor.apply() - } - - fun savePreviouslyDeniedBackground(context: Context, previouslyDeniedBackground: Boolean) { - val prefs: SharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) - val editor: SharedPreferences.Editor = prefs.edit() - editor.putBoolean(KEY_PREVIOUSLY_DENIED_BACKGROUND, previouslyDeniedBackground) - editor.apply() - } - - private fun locationPermissionStateForLocationManagerStatus(status: RadarLocationPermissionStatus): LocationPermissionState { - - if (status.backgroundPermissionResult) { - return LocationPermissionState.BACKGROUND_PERMISSION_GRANTED - } - - if (status.previouslyDeniedBackground && status.foregroundPermissionResult) { - return if (status.shouldShowRequestPermissionRationaleBG) { - LocationPermissionState.BACKGROUND_PERMISSION_REJECTED_ONCE - } else { - LocationPermissionState.BACKGROUND_PERMISSION_REJECTED - } - } - - if (status.foregroundPermissionResult) { - return LocationPermissionState.FOREGROUND_PERMISSION_GRANTED - } else { - if (status.inLocationPopup) { - return LocationPermissionState.FOREGROUND_PERMISSION_PENDING - } - if (status.approximatePermissionResult){ - return LocationPermissionState.APPROXIMATE_PERMISSION_GRANTED - } - return if (status.shouldShowRequestPermissionRationaleFG) { - LocationPermissionState.FOREGROUND_PERMISSION_REJECTED_ONCE - } else { - if (status.previouslyDeniedForeground) { - LocationPermissionState.FOREGROUND_PERMISSION_REJECTED - } else { - LocationPermissionState.NO_PERMISSION_GRANTED - } - } - } - } - - fun stringForLocationPermissionState(state: LocationPermissionState): String { - return when (state) { - LocationPermissionState.NO_PERMISSION_GRANTED -> "NO_PERMISSION_GRANTED" - LocationPermissionState.FOREGROUND_PERMISSION_GRANTED -> "FOREGROUND_PERMISSION_GRANTED" - LocationPermissionState.APPROXIMATE_PERMISSION_GRANTED -> "APPROXIMATE_PERMISSION_GRANTED" - LocationPermissionState.FOREGROUND_PERMISSION_REJECTED_ONCE -> "FOREGROUND_PERMISSION_REJECTED_ONCE" - LocationPermissionState.FOREGROUND_PERMISSION_REJECTED -> "FOREGROUND_PERMISSION_REJECTED" - LocationPermissionState.FOREGROUND_PERMISSION_PENDING -> "FOREGROUND_PERMISSION_PENDING" - LocationPermissionState.BACKGROUND_PERMISSION_GRANTED -> "BACKGROUND_PERMISSION_GRANTED" - LocationPermissionState.BACKGROUND_PERMISSION_REJECTED -> "BACKGROUND_PERMISSION_REJECTED" - LocationPermissionState.BACKGROUND_PERMISSION_REJECTED_ONCE -> "BACKGROUND_PERMISSION_REJECTED_ONCE" - LocationPermissionState.UNKNOWN -> "UNKNOWN" - } - } - } - - fun toJson(): JSONObject { - val jsonObject = JSONObject() - jsonObject.put(KEY_STATUS, status.name) - jsonObject.put(KEY_FOREGROUND_PERMISSION_RESULT, foregroundPermissionResult) - jsonObject.put(KEY_BACKGROUND_PERMISSION_RESULT, backgroundPermissionResult) - jsonObject.put(KEY_SHOULD_SHOW_REQUEST_PERMISSION_RATIONALE_FG, shouldShowRequestPermissionRationaleFG) - jsonObject.put(KEY_PREVIOUSLY_DENIED_FOREGROUND,previouslyDeniedForeground) - jsonObject.put(KEY_APPROXIMATE_PERMISSION_REQUEST,approximatePermissionResult) - jsonObject.put(KEY_SHOULD_SHOW_REQUEST_PERMISSION_RATIONALE_BG,shouldShowRequestPermissionRationaleBG) - jsonObject.put(KEY_PREVIOUSLY_DENIED_BACKGROUND,previouslyDeniedBackground) - jsonObject.put(KEY_IN_LOCATION_POPUP,inLocationPopup) - return jsonObject - } - - enum class LocationPermissionState { - NO_PERMISSION_GRANTED, - FOREGROUND_PERMISSION_GRANTED, - APPROXIMATE_PERMISSION_GRANTED, - FOREGROUND_PERMISSION_REJECTED_ONCE, - FOREGROUND_PERMISSION_REJECTED, - FOREGROUND_PERMISSION_PENDING, - BACKGROUND_PERMISSION_GRANTED, - BACKGROUND_PERMISSION_REJECTED, - BACKGROUND_PERMISSION_REJECTED_ONCE, - UNKNOWN - } - - var status: LocationPermissionState = LocationPermissionState.UNKNOWN - var foregroundPermissionResult: Boolean = false - var backgroundPermissionResult: Boolean = false - var shouldShowRequestPermissionRationaleFG: Boolean = false - var shouldShowRequestPermissionRationaleBG: Boolean = false - var previouslyDeniedForeground: Boolean = false - var inLocationPopup: Boolean = false - var approximatePermissionResult: Boolean = false - var previouslyDeniedBackground: Boolean = false -} \ No newline at end of file