mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Resume call PIP on app foreground.
This commit is contained in:
@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.service.webrtc;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.ResultReceiver;
|
||||
|
||||
@@ -125,14 +126,14 @@ public final class SignalCallManager implements CallManager.Observer, GroupCall.
|
||||
|
||||
@Nullable private final CallManager callManager;
|
||||
|
||||
private final Context context;
|
||||
private final ExecutorService serviceExecutor;
|
||||
private final Executor networkExecutor;
|
||||
private final LockManager lockManager;
|
||||
private final Context context;
|
||||
private final ExecutorService serviceExecutor;
|
||||
private final Executor networkExecutor;
|
||||
private final LockManager lockManager;
|
||||
|
||||
private WebRtcServiceState serviceState;
|
||||
private RxStore<WebRtcEphemeralState> ephemeralStateStore;
|
||||
private boolean needsToSetSelfUuid = true;
|
||||
private boolean needsToSetSelfUuid = true;
|
||||
|
||||
private RxStore<Map<RecipientId, CallLinkPeekInfo>> linkPeekInfoStore;
|
||||
|
||||
@@ -182,8 +183,8 @@ public final class SignalCallManager implements CallManager.Observer, GroupCall.
|
||||
}
|
||||
|
||||
private void process(@NonNull ProcessAction action) {
|
||||
Throwable t = new Throwable();
|
||||
String caller = t.getStackTrace().length > 1 ? t.getStackTrace()[1].getMethodName() : "unknown";
|
||||
Throwable t = new Throwable();
|
||||
String caller = t.getStackTrace().length > 1 ? t.getStackTrace()[1].getMethodName() : "unknown";
|
||||
|
||||
if (callManager == null) {
|
||||
Log.w(TAG, "Unable to process action, call manager is not initialized");
|
||||
@@ -1151,6 +1152,10 @@ public final class SignalCallManager implements CallManager.Observer, GroupCall.
|
||||
return new SignalCallLinkManager(Objects.requireNonNull(callManager));
|
||||
}
|
||||
|
||||
public void relaunchPipOnForeground() {
|
||||
ApplicationDependencies.getAppForegroundObserver().addListener(new RelaunchListener(ApplicationDependencies.getAppForegroundObserver().isForegrounded()));
|
||||
}
|
||||
|
||||
private void processSendMessageFailureWithChangeDetection(@NonNull RemotePeer remotePeer,
|
||||
@NonNull ProcessAction failureProcessAction)
|
||||
{
|
||||
@@ -1169,6 +1174,44 @@ public final class SignalCallManager implements CallManager.Observer, GroupCall.
|
||||
});
|
||||
}
|
||||
|
||||
private class RelaunchListener implements AppForegroundObserver.Listener {
|
||||
private boolean canRelaunch;
|
||||
|
||||
public RelaunchListener(boolean isForegrounded) {
|
||||
canRelaunch = !isForegrounded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onForeground() {
|
||||
if (canRelaunch) {
|
||||
if (isSystemPipEnabledAndAvailable()) {
|
||||
process((s, p) -> {
|
||||
WebRtcViewModel.State callState = s.getCallInfoState().getCallState();
|
||||
|
||||
if (callState.getInOngoingCall()) {
|
||||
Intent intent = new Intent(context, WebRtcCallActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(WebRtcCallActivity.EXTRA_LAUNCH_IN_PIP, true);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
return s;
|
||||
});
|
||||
}
|
||||
ApplicationDependencies.getAppForegroundObserver().removeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackground() {
|
||||
canRelaunch = true;
|
||||
}
|
||||
|
||||
private boolean isSystemPipEnabledAndAvailable() {
|
||||
return Build.VERSION.SDK_INT >= 26 && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE);
|
||||
}
|
||||
}
|
||||
|
||||
interface ProcessAction {
|
||||
@NonNull WebRtcServiceState process(@NonNull WebRtcServiceState currentState, @NonNull WebRtcActionProcessor processor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user