Show calling service notification immediately.

This commit is contained in:
Cody Henthorne
2022-05-25 13:37:02 -04:00
committed by Alex Hart
parent 652d0d46ed
commit 26a84c5546
3 changed files with 21 additions and 2 deletions

View File

@@ -116,6 +116,8 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
public void onCreate() {
Log.v(TAG, "onCreate");
super.onCreate();
startForegroundCompat(CallNotificationBuilder.getStartingStoppingNotificationId(), CallNotificationBuilder.getStartingNotification(this));
this.callManager = ApplicationDependencies.getSignalCallManager();
this.hangUpRtcOnDeviceCallAnswered = new HangUpRtcOnPstnCallAnsweredListener();
this.lastNotificationId = INVALID_NOTIFICATION_ID;
@@ -203,7 +205,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
startForegroundCompat(lastNotificationId, lastNotification);
} else {
Log.w(TAG, "Service running without having called start first, show temp notification and terminate service.");
startForegroundCompat(CallNotificationBuilder.getStoppingNotificationId(), CallNotificationBuilder.getStoppingNotification(this));
startForegroundCompat(CallNotificationBuilder.getStartingStoppingNotificationId(), CallNotificationBuilder.getStoppingNotification(this));
stop();
}
}
@@ -280,6 +282,7 @@ public final class WebRtcCallService extends Service implements SignalAudioManag
callManager.onBluetoothPermissionDenied();
}
@SuppressWarnings("deprecation")
private class HangUpRtcOnPstnCallAnsweredListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, @NonNull String phoneNumber) {

View File

@@ -81,6 +81,20 @@ public class CallNotificationBuilder {
}
}
public static @NonNull Notification getStartingNotification(@NonNull Context context) {
Intent contentIntent = new Intent(context, MainActivity.class);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0);
return new NotificationCompat.Builder(context, NotificationChannels.CALL_STATUS).setSmallIcon(R.drawable.ic_call_secure_white_24dp)
.setContentIntent(pendingIntent)
.setOngoing(true)
.setContentTitle(context.getString(R.string.NotificationBarManager__starting_signal_call_service))
.setPriority(NotificationCompat.PRIORITY_MIN)
.build();
}
public static @NonNull Notification getStoppingNotification(@NonNull Context context) {
Intent contentIntent = new Intent(context, MainActivity.class);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
@@ -95,7 +109,7 @@ public class CallNotificationBuilder {
.build();
}
public static int getStoppingNotificationId() {
public static int getStartingStoppingNotificationId() {
return WEBRTC_NOTIFICATION;
}