diff --git a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleServiceBinder.kt b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleServiceBinder.kt
index e2246c78aae..97a7d6b73ae 100644
--- a/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleServiceBinder.kt
+++ b/firebase-sessions/src/main/kotlin/com/google/firebase/sessions/SessionLifecycleServiceBinder.kt
@@ -36,12 +36,13 @@ internal class SessionLifecycleServiceBinderImpl(private val firebaseApp: Fireba
SessionLifecycleServiceBinder {
override fun bindToService(callback: Messenger, serviceConnection: ServiceConnection) {
- val appContext = firebaseApp.applicationContext.applicationContext
+ val appContext: Context = firebaseApp.applicationContext.applicationContext
Intent(appContext, SessionLifecycleService::class.java).also { intent ->
Log.d(TAG, "Binding service to application.")
// This is necessary for the onBind() to be called by each process
intent.action = android.os.Process.myPid().toString()
intent.putExtra(SessionLifecycleService.CLIENT_CALLBACK_MESSENGER, callback)
+ intent.setPackage(appContext.packageName)
val isServiceBound =
try {
diff --git a/firebase-sessions/test-app/src/main/AndroidManifest.xml b/firebase-sessions/test-app/src/main/AndroidManifest.xml
index 11c21bdf24d..3e1f4840cb3 100644
--- a/firebase-sessions/test-app/src/main/AndroidManifest.xml
+++ b/firebase-sessions/test-app/src/main/AndroidManifest.xml
@@ -24,13 +24,6 @@
android:supportsRtl="true"
android:theme="@style/Theme.Widget_test_app"
tools:targetApi="31">
-
-
-
-
+
+
+
+
+
diff --git a/firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/ForegroundService.kt b/firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/ForegroundService.kt
index 697dfb5e566..f616a0a54a4 100644
--- a/firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/ForegroundService.kt
+++ b/firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/ForegroundService.kt
@@ -22,6 +22,7 @@ import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
+import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import android.util.Log
@@ -42,7 +43,7 @@ class ForegroundService : Service() {
this,
0,
Intent(this, MainActivity::class.java),
- PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
+ PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
val crashIntent = Intent(CrashBroadcastReceiver.CRASH_ACTION)
@@ -57,7 +58,7 @@ class ForegroundService : Service() {
this,
0,
Intent(this, SecondActivity::class.java).setAction("MESSAGE"),
- PendingIntent.FLAG_IMMUTABLE
+ PendingIntent.FLAG_IMMUTABLE,
)
val notification =
@@ -72,7 +73,11 @@ class ForegroundService : Service() {
.addAction(R.drawable.ic_launcher_foreground, "Send Message", pendingMsg)
.build()
- startForeground(1, notification)
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
+ startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE)
+ } else {
+ startForeground(1, notification)
+ }
return START_STICKY
}
@@ -91,7 +96,7 @@ class ForegroundService : Service() {
NotificationChannel(
CHANNEL_ID,
"Foreground Service Channel",
- NotificationManager.IMPORTANCE_DEFAULT
+ NotificationManager.IMPORTANCE_DEFAULT,
)
val manager = getSystemService(NotificationManager::class.java)
manager!!.createNotificationChannel(serviceChannel)
@@ -105,7 +110,7 @@ class ForegroundService : Service() {
Log.i(TAG, "Starting foreground serice")
ContextCompat.startForegroundService(
context,
- Intent(context, ForegroundService::class.java).putExtra("inputExtra", message)
+ Intent(context, ForegroundService::class.java).putExtra("inputExtra", message),
)
}
diff --git a/firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/TestApplication.kt b/firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/TestApplication.kt
index 6d528f50e5c..10a95261fa8 100644
--- a/firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/TestApplication.kt
+++ b/firebase-sessions/test-app/src/main/kotlin/com/google/firebase/testing/sessions/TestApplication.kt
@@ -18,6 +18,7 @@ package com.google.firebase.testing.sessions
import android.annotation.SuppressLint
import android.content.IntentFilter
+import android.os.Build
import android.os.Handler
import android.os.Looper
import android.widget.TextView
@@ -30,8 +31,21 @@ class TestApplication : MultiDexApplication() {
override fun onCreate() {
super.onCreate()
- registerReceiver(broadcastReceiver, IntentFilter(CrashBroadcastReceiver.CRASH_ACTION))
- registerReceiver(broadcastReceiver, IntentFilter(CrashBroadcastReceiver.TOAST_ACTION))
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ registerReceiver(
+ broadcastReceiver,
+ IntentFilter(CrashBroadcastReceiver.CRASH_ACTION),
+ RECEIVER_NOT_EXPORTED,
+ )
+ registerReceiver(
+ broadcastReceiver,
+ IntentFilter(CrashBroadcastReceiver.TOAST_ACTION),
+ RECEIVER_NOT_EXPORTED,
+ )
+ } else {
+ registerReceiver(broadcastReceiver, IntentFilter(CrashBroadcastReceiver.CRASH_ACTION))
+ registerReceiver(broadcastReceiver, IntentFilter(CrashBroadcastReceiver.TOAST_ACTION))
+ }
}
class FakeSessionSubscriber : SessionSubscriber {