Attempt to fix bad notification for call service shutdown.

This commit is contained in:
Cody Henthorne
2024-04-05 14:49:50 -04:00
committed by Greyson Parrelli
parent ba3473c61a
commit 791dc2724f
3 changed files with 31 additions and 2 deletions

View File

@@ -9,8 +9,10 @@ import android.app.Notification
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import androidx.annotation.RequiresApi
import androidx.core.app.ServiceCompat
import org.signal.core.util.logging.Log
import org.thoughtcrime.securesms.jobs.ForegroundServiceUtil
@@ -122,6 +124,10 @@ abstract class SafeForegroundService : Service() {
}
}
fun isStopping(intent: Intent): Boolean {
return intent.action == ACTION_STOP
}
private fun currentState(clazz: Class<out SafeForegroundService>): State {
return states.getOrPut(clazz) { State.STOPPED }
}
@@ -137,7 +143,11 @@ abstract class SafeForegroundService : Service() {
Log.d(tag, "[onStartCommand] action: ${intent.action}")
startForeground(notificationId, getForegroundNotification(intent))
if (Build.VERSION.SDK_INT >= 30 && serviceType != 0) {
startForeground(notificationId, getForegroundNotification(intent), serviceType)
} else {
startForeground(notificationId, getForegroundNotification(intent))
}
when (val action = intent.action) {
ACTION_START -> {
@@ -187,6 +197,10 @@ abstract class SafeForegroundService : Service() {
/** Notification ID to use when posting the foreground notification */
abstract val notificationId: Int
/** Special service type to use when calling start service if needed */
@RequiresApi(30)
open val serviceType: Int = 0
/** Notification to post as our foreground notification. */
abstract fun getForegroundNotification(intent: Intent): Notification

View File

@@ -10,11 +10,13 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.ServiceInfo
import android.net.ConnectivityManager
import android.os.Build
import android.telephony.PhoneStateListener
import android.telephony.TelephonyManager
import androidx.annotation.MainThread
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationManagerCompat
import androidx.core.os.bundleOf
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
@@ -194,6 +196,10 @@ class ActiveCallManager(
override val notificationId: Int
get() = CallNotificationBuilder.WEBRTC_NOTIFICATION
@get:RequiresApi(30)
override val serviceType: Int
get() = ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
private var hangUpRtcOnDeviceCallAnswered: PhoneStateListener? = null
private var notification: Notification? = null
private var notificationDisposable: Disposable = Disposable.disposed()
@@ -222,6 +228,11 @@ class ActiveCallManager(
}
override fun getForegroundNotification(intent: Intent): Notification {
if (SafeForegroundService.isStopping(intent)) {
Log.v(TAG, "Service is stopping, using generic stopping notification")
return CallNotificationBuilder.getStoppingNotification(this)
}
if (notification != null) {
return notification!!
} else if (!intent.hasExtra(EXTRA_RECIPIENT_ID)) {