Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 10 additions & 8 deletions firebase-sessions/test-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
android:supportsRtl="true"
android:theme="@style/Theme.Widget_test_app"
tools:targetApi="31">
<meta-data
android:name="firebase_performance_logcat_enabled"
android:value="true" />
<!-- Override the background timeout for the test app to be 5s instead of 30m -->
<meta-data
android:name="firebase_sessions_sessions_restart_timeout"
android:value="5" />
<activity
android:exported="true"
android:label="@string/app_name"
Expand All @@ -42,14 +35,22 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- Override the background timeout for the test app to be 5s instead of 30m -->
<activity
android:exported="true"
android:label="@string/app_name"
android:name=".SecondActivity"
android:process=":second"
android:theme="@style/Theme.Widget_test_app.NoActionBar" />

<meta-data
android:name="firebase_performance_logcat_enabled"
android:value="true" />

<meta-data
android:name="firebase_sessions_sessions_restart_timeout"
android:value="5" />

<receiver
android:exported="false"
android:name="CrashWidgetProvider"
Expand All @@ -67,6 +68,7 @@
<service
android:enabled="true"
android:exported="false"
android:foregroundServiceType="shortService"
android:name=".ForegroundService"
android:process=":foregroundServiceProcess" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -57,7 +58,7 @@ class ForegroundService : Service() {
this,
0,
Intent(this, SecondActivity::class.java).setAction("MESSAGE"),
PendingIntent.FLAG_IMMUTABLE
PendingIntent.FLAG_IMMUTABLE,
)

val notification =
Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Loading