do not use Dialer UI for incoming calls if audio permission is not granted

We cannot always request new permissions when Dialer UI is shown. For
example, Dialer UI can be shown over keyguard, which doesn't allow other
dialogs (like the permission request dialog) to be displayed. However it
doesn't return the failed response either, making ConnectionService kind
of stuck.

If we just do not use the Dialer UI when the permission is not granted,
it is at most a minor annoyance for the first time. After the user has
accepted an incoming call even just once, the permission will be
granted, and the Dialer integration will start to work just fine.
This commit is contained in:
Peter Cai 2022-03-11 17:43:41 -05:00
parent 9cb59cc735
commit 0f581f889a
2 changed files with 9 additions and 18 deletions

View file

@ -268,24 +268,7 @@ public class ConnectionService extends android.telecom.ConnectionService {
xmppConnectionService.getJingleConnectionManager()
.findJingleRtpConnection(account, with, sessionId);
// Request recording permission only when answering
Set<String> permissions = new HashSet<>();
permissions.add(Manifest.permission.RECORD_AUDIO);
mPermissionManager.checkPermissions(permissions, new PermissionManager.PermissionRequestListener() {
@Override
public void onPermissionGranted() {
if (rtpConnection == null || rtpConnection.get() == null) {
setDisconnected(new DisconnectCause(DisconnectCause.ERROR));
} else {
rtpConnection.get().acceptCall();
}
}
@Override
public void onPermissionDenied(DeniedPermissions deniedPermissions) {
setDisconnected(new DisconnectCause(DisconnectCause.ERROR));
}
});
rtpConnection.get().acceptCall();
}
@Override

View file

@ -1,5 +1,6 @@
package eu.siacs.conversations.services;
import android.Manifest;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
@ -8,6 +9,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Typeface;
@ -427,6 +429,12 @@ public class NotificationService {
}
private synchronized boolean tryRingingWithDialerUI(final AbstractJingleConnection.Id id, final Set<Media> media) {
if (mXmppConnectionService.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
// We cannot always request audio permission in Dialer UI
// e.g. when Dialer is shown over keyguard
return false;
}
if (media.size() != 1 || !media.contains(Media.AUDIO)) {
// Currently our ConnectionService only handles single audio calls
Log.w(Config.LOGTAG, "only audio calls can be handled by cheogram connection service");