mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-24 03:35:58 +00:00
Fix mic usage for api34 when app is backgrounded.
This commit is contained in:
committed by
mtang-signal
parent
8932eef991
commit
aebaff736c
@@ -22,6 +22,7 @@ import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.os.bundleOf
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
import io.reactivex.rxjava3.core.SingleObserver
|
||||
import io.reactivex.rxjava3.disposables.Disposable
|
||||
import io.reactivex.rxjava3.kotlin.subscribeBy
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||
@@ -179,8 +180,26 @@ class ActiveCallManager(
|
||||
previousNotificationId = notificationId
|
||||
|
||||
if (type != CallNotificationBuilder.TYPE_ESTABLISHED) {
|
||||
val notification = CallNotificationBuilder.getCallInProgressNotification(application, type, Recipient.resolved(recipientId), isVideoCall, false)
|
||||
val requiresAsyncNotificationLoad = Build.VERSION.SDK_INT <= 29
|
||||
|
||||
val notification = CallNotificationBuilder.getCallInProgressNotification(application, type, Recipient.resolved(recipientId), isVideoCall, requiresAsyncNotificationLoad)
|
||||
NotificationManagerCompat.from(application).notify(notificationId, notification)
|
||||
|
||||
if (requiresAsyncNotificationLoad) {
|
||||
Single.fromCallable { CallNotificationBuilder.getCallInProgressNotification(application, type, Recipient.resolved(recipientId), isVideoCall, false) }
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(object : SingleObserver<Notification> {
|
||||
override fun onSuccess(t: Notification) {
|
||||
if (NotificationManagerCompat.from(application).activeNotifications.any { n -> n.id == notificationId }) {
|
||||
NotificationManagerCompat.from(application).notify(notificationId, notification!!)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSubscribe(d: Disposable) = Unit
|
||||
override fun onError(e: Throwable) = Unit
|
||||
})
|
||||
}
|
||||
} else {
|
||||
ActiveCallForegroundService.start(application, recipientId, isVideoCall)
|
||||
}
|
||||
@@ -274,7 +293,7 @@ class ActiveCallManager(
|
||||
|
||||
@get:RequiresApi(30)
|
||||
override val serviceType: Int
|
||||
get() = ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
||||
get() = ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
|
||||
|
||||
private var hangUpRtcOnDeviceCallAnswered: PhoneStateListener? = null
|
||||
private var notification: Notification? = null
|
||||
|
||||
@@ -87,8 +87,12 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
|
||||
private Disposable lastNotificationDisposable = Disposable.disposed();
|
||||
private boolean stopping = false;
|
||||
|
||||
private static boolean useActiveCallManager() {
|
||||
return Build.VERSION.SDK_INT >= 34 || RemoteConfig.useActiveCallManager();
|
||||
}
|
||||
|
||||
public synchronized static void update(@NonNull Context context, int type, @NonNull RecipientId recipientId, boolean isVideoCall) {
|
||||
if (RemoteConfig.useActiveCallManager()) {
|
||||
if (useActiveCallManager()) {
|
||||
ActiveCallManager.update(context, type, recipientId, isVideoCall);
|
||||
|
||||
return;
|
||||
@@ -104,7 +108,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
|
||||
}
|
||||
|
||||
public static void denyCall(@NonNull Context context) {
|
||||
if (RemoteConfig.useActiveCallManager()) {
|
||||
if (useActiveCallManager()) {
|
||||
ActiveCallManager.denyCall();
|
||||
return;
|
||||
}
|
||||
@@ -113,7 +117,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
|
||||
}
|
||||
|
||||
public static void hangup(@NonNull Context context) {
|
||||
if (RemoteConfig.useActiveCallManager()) {
|
||||
if (useActiveCallManager()) {
|
||||
ActiveCallManager.hangup();
|
||||
return;
|
||||
}
|
||||
@@ -122,7 +126,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
|
||||
}
|
||||
|
||||
public synchronized static void stop(@NonNull Context context) {
|
||||
if (RemoteConfig.useActiveCallManager()) {
|
||||
if (useActiveCallManager()) {
|
||||
ActiveCallManager.stop();
|
||||
return;
|
||||
}
|
||||
@@ -134,7 +138,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
|
||||
}
|
||||
|
||||
public synchronized static @NonNull PendingIntent denyCallIntent(@NonNull Context context) {
|
||||
if (RemoteConfig.useActiveCallManager()) {
|
||||
if (useActiveCallManager()) {
|
||||
return ActiveCallManager.denyCallIntent(context);
|
||||
}
|
||||
|
||||
@@ -142,7 +146,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
|
||||
}
|
||||
|
||||
public synchronized static @NonNull PendingIntent hangupIntent(@NonNull Context context) {
|
||||
if (RemoteConfig.useActiveCallManager()) {
|
||||
if (useActiveCallManager()) {
|
||||
return ActiveCallManager.hangupIntent(context);
|
||||
}
|
||||
|
||||
@@ -150,7 +154,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
|
||||
}
|
||||
|
||||
public synchronized static void sendAudioManagerCommand(@NonNull Context context, @NonNull AudioManagerCommand command) {
|
||||
if (RemoteConfig.useActiveCallManager()) {
|
||||
if (useActiveCallManager()) {
|
||||
ActiveCallManager.sendAudioManagerCommand(context, command);
|
||||
return;
|
||||
}
|
||||
@@ -162,7 +166,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
|
||||
}
|
||||
|
||||
public synchronized static void changePowerButtonReceiver(@NonNull Context context, boolean register) {
|
||||
if (RemoteConfig.useActiveCallManager()) {
|
||||
if (useActiveCallManager()) {
|
||||
ActiveCallManager.changePowerButtonReceiver(context, register);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -961,7 +961,7 @@ object RemoteConfig {
|
||||
@JvmStatic
|
||||
@get:JvmName("useActiveCallManager")
|
||||
val useActiveCallManager: Boolean by remoteBoolean(
|
||||
key = "android.calling.useActiveCallManager.5",
|
||||
key = "android.calling.useActiveCallManager.6",
|
||||
defaultValue = false,
|
||||
hotSwappable = false
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user