diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternalTest.kt index 60ddfc72..19429c48 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternalTest.kt @@ -8,6 +8,7 @@ import android.content.pm.PackageManager import android.location.Location import android.location.LocationManager import android.os.Build +import androidx.test.filters.SdkSuppress import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation import com.emarsys.core.api.MissingPermissionException import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory @@ -263,15 +264,36 @@ class DefaultGeofenceInternalTest : AnnotationSpec() { } @Test - fun testEnable_registersGeofenceBroadcastReceiver() { - geofenceInternalWithMockContext.enable(null) - geofenceInternalWithMockContext.enable(null) + @SdkSuppress(minSdkVersion = Build.VERSION_CODES.TIRAMISU) + fun testEnable_registersGeofenceBroadcastReceiverAboveTiramisu() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + geofenceInternalWithMockContext.enable(null) + geofenceInternalWithMockContext.enable(null) - verify( - mockContext, - timeout(100).times(1) - ).registerReceiver(any(), any()) + verify( + mockContext, + timeout(100).times(1) + ).registerReceiver( + any(), + any(), + eq(Context.RECEIVER_EXPORTED) + ) + + } + } + @Test + @SdkSuppress(maxSdkVersion = 32) + fun testEnable_registersGeofenceBroadcastReceiverBelowTiramisu() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + geofenceInternalWithMockContext.enable(null) + geofenceInternalWithMockContext.enable(null) + + verify( + mockContext, + timeout(100).times(1) + ).registerReceiver(any(), any()) + } } @Test @@ -309,15 +331,35 @@ class DefaultGeofenceInternalTest : AnnotationSpec() { } @Test - fun testDisable() { - geofenceInternalWithMockContext.enable(null) - geofenceInternalWithMockContext.disable() - geofenceInternalWithMockContext.enable(null) + @SdkSuppress(minSdkVersion = Build.VERSION_CODES.TIRAMISU) + fun testDisableAboveTiramisu() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + geofenceInternalWithMockContext.enable(null) + geofenceInternalWithMockContext.disable() + geofenceInternalWithMockContext.enable(null) - verify( - mockContext, timeout(100).times(2) - ).registerReceiver(any(), any()) + verify( + mockContext, timeout(100).times(2) + ).registerReceiver( + any(), + any(), + eq(Context.RECEIVER_EXPORTED) + ) + } + } + @Test + @SdkSuppress(maxSdkVersion = Build.VERSION_CODES.S_V2) + fun testDisableBelowTiramisu() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + geofenceInternalWithMockContext.enable(null) + geofenceInternalWithMockContext.disable() + geofenceInternalWithMockContext.enable(null) + + verify( + mockContext, timeout(100).times(2) + ).registerReceiver(any(), any()) + } } @Test diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/FetchGeofencesActionTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/FetchGeofencesActionTest.kt index b0da646c..790b6ced 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/FetchGeofencesActionTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/geofence/FetchGeofencesActionTest.kt @@ -8,8 +8,8 @@ import com.emarsys.mobileengage.util.waitForTask import com.emarsys.testUtil.AnnotationSpec -import org.mockito.kotlin.mock -import org.mockito.kotlin.verify +import io.mockk.mockk +import io.mockk.verify class FetchGeofencesActionTest : AnnotationSpec() { @@ -20,8 +20,8 @@ class FetchGeofencesActionTest : AnnotationSpec() { @Before fun setUp() { - mockGeofenceInternal = mock() - mockActivity = mock() + mockGeofenceInternal = mockk(relaxed = true) + mockActivity = mockk(relaxed = true) setupMobileEngageComponent(FakeMobileEngageDependencyContainer()) @@ -39,7 +39,7 @@ class FetchGeofencesActionTest : AnnotationSpec() { fetchGeofencesAction.execute(mockActivity) waitForTask() - verify(mockGeofenceInternal).fetchGeofences(null) + verify { mockGeofenceInternal.fetchGeofences(null) } } diff --git a/mobile-engage/src/main/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternal.kt b/mobile-engage/src/main/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternal.kt index c00bfee9..c826c99c 100644 --- a/mobile-engage/src/main/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternal.kt +++ b/mobile-engage/src/main/java/com/emarsys/mobileengage/geofence/DefaultGeofenceInternal.kt @@ -149,10 +149,18 @@ class DefaultGeofenceInternal( private fun registerBroadcastReceiver() { if (!receiverRegistered) { concurrentHandlerHolder.postOnMain { - context.registerReceiver( - geofenceBroadcastReceiver, - IntentFilter("com.emarsys.sdk.GEOFENCE_ACTION") - ) + if (AndroidVersionUtils.isTiramisuOrAbove) { + context.registerReceiver( + geofenceBroadcastReceiver, + IntentFilter("com.emarsys.sdk.GEOFENCE_ACTION"), + Context.RECEIVER_EXPORTED + ) + } else { + context.registerReceiver( + geofenceBroadcastReceiver, + IntentFilter("com.emarsys.sdk.GEOFENCE_ACTION"), + ) + } } receiverRegistered = true } diff --git a/mobile-engage/src/main/java/com/emarsys/mobileengage/geofence/GeofencePendingIntentProvider.kt b/mobile-engage/src/main/java/com/emarsys/mobileengage/geofence/GeofencePendingIntentProvider.kt index dc70d19b..b0fa1405 100644 --- a/mobile-engage/src/main/java/com/emarsys/mobileengage/geofence/GeofencePendingIntentProvider.kt +++ b/mobile-engage/src/main/java/com/emarsys/mobileengage/geofence/GeofencePendingIntentProvider.kt @@ -10,19 +10,20 @@ import com.emarsys.core.util.AndroidVersionUtils class GeofencePendingIntentProvider(private val context: Context) { fun providePendingIntent(): PendingIntent { val intent = Intent("com.emarsys.sdk.GEOFENCE_ACTION") - if (AndroidVersionUtils.isBelowS) { + intent.setPackage(context.packageName) + if (AndroidVersionUtils.isUOrAbove) { return PendingIntent.getBroadcast( context, 0, intent, - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT ) } else { return PendingIntent.getBroadcast( context, 0, intent, - PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE + PendingIntent.FLAG_UPDATE_CURRENT ) } }