Compare commits
4 commits
0f581f889a
...
f092430c84
Author | SHA1 | Date | |
---|---|---|---|
Peter Cai | f092430c84 | ||
Peter Cai | 3ba7f3e207 | ||
Peter Cai | d8d9571476 | ||
Peter Cai | b7b2bb0cdd |
|
@ -5,9 +5,12 @@ import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
import android.os.Build;
|
||||||
import android.telecom.CallAudioState;
|
import android.telecom.CallAudioState;
|
||||||
import android.telecom.Connection;
|
import android.telecom.Connection;
|
||||||
import android.telecom.ConnectionRequest;
|
import android.telecom.ConnectionRequest;
|
||||||
|
@ -65,8 +68,17 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private PermissionManager mPermissionManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
mPermissionManager = PermissionManager.getInstance(this);
|
||||||
|
mPermissionManager.setNotificationSettings(
|
||||||
|
new NotificationSettings.Builder()
|
||||||
|
.withMessage(R.string.microphone_permission_for_call)
|
||||||
|
.withSmallIcon(R.drawable.ic_notification).build()
|
||||||
|
);
|
||||||
|
|
||||||
// From XmppActivity.connectToBackend
|
// From XmppActivity.connectToBackend
|
||||||
Intent intent = new Intent(this, XmppConnectionService.class);
|
Intent intent = new Intent(this, XmppConnectionService.class);
|
||||||
intent.setAction("ui");
|
intent.setAction("ui");
|
||||||
|
@ -112,16 +124,9 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
Jid with = Jid.ofLocalAndDomain(tel, gateway[1]);
|
Jid with = Jid.ofLocalAndDomain(tel, gateway[1]);
|
||||||
CheogramConnection connection = new CheogramConnection(account, with, postDial);
|
CheogramConnection connection = new CheogramConnection(account, with, postDial);
|
||||||
|
|
||||||
PermissionManager permissionManager = PermissionManager.getInstance(this);
|
Set<String> permissions = new HashSet<>();
|
||||||
permissionManager.setNotificationSettings(
|
|
||||||
new NotificationSettings.Builder()
|
|
||||||
.withMessage(R.string.microphone_permission_for_call)
|
|
||||||
.withSmallIcon(R.drawable.ic_notification).build()
|
|
||||||
);
|
|
||||||
|
|
||||||
Set<String> permissions = new HashSet();
|
|
||||||
permissions.add(Manifest.permission.RECORD_AUDIO);
|
permissions.add(Manifest.permission.RECORD_AUDIO);
|
||||||
permissionManager.checkPermissions(permissions, new PermissionManager.PermissionRequestListener() {
|
mPermissionManager.checkPermissions(permissions, new PermissionManager.PermissionRequestListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPermissionGranted() {
|
public void onPermissionGranted() {
|
||||||
connection.setSessionId(xmppConnectionService.getJingleConnectionManager().proposeJingleRtpSession(
|
connection.setSessionId(xmppConnectionService.getJingleConnectionManager().proposeJingleRtpSession(
|
||||||
|
@ -150,11 +155,34 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connection onCreateIncomingConnection(PhoneAccountHandle handle, ConnectionRequest request) {
|
||||||
|
Bundle extras = request.getExtras();
|
||||||
|
String accountJid = extras.getString("account");
|
||||||
|
String withJid = extras.getString("with");
|
||||||
|
String sessionId = extras.getString("sessionId");
|
||||||
|
|
||||||
|
Account account = xmppConnectionService.findAccountByJid(Jid.of(accountJid));
|
||||||
|
Jid with = Jid.of(withJid);
|
||||||
|
|
||||||
|
CheogramConnection connection = new CheogramConnection(account, with, null);
|
||||||
|
connection.setSessionId(sessionId);
|
||||||
|
connection.setAddress(
|
||||||
|
Uri.fromParts("tel", with.getLocal(), null),
|
||||||
|
TelecomManager.PRESENTATION_ALLOWED
|
||||||
|
);
|
||||||
|
connection.setRinging();
|
||||||
|
|
||||||
|
xmppConnectionService.setOnRtpConnectionUpdateListener(connection);
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
public class CheogramConnection extends Connection implements XmppConnectionService.OnJingleRtpConnectionUpdate {
|
public class CheogramConnection extends Connection implements XmppConnectionService.OnJingleRtpConnectionUpdate {
|
||||||
protected Account account;
|
protected Account account;
|
||||||
protected Jid with;
|
protected Jid with;
|
||||||
protected String sessionId = null;
|
protected String sessionId = null;
|
||||||
protected Stack<String> postDial = new Stack();
|
protected Stack<String> postDial = new Stack<>();
|
||||||
protected Icon gatewayIcon;
|
protected Icon gatewayIcon;
|
||||||
protected WeakReference<JingleRtpConnection> rtpConnection = null;
|
protected WeakReference<JingleRtpConnection> rtpConnection = null;
|
||||||
|
|
||||||
|
@ -203,6 +231,8 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
setInitialized();
|
setInitialized();
|
||||||
} else if (state == RtpEndUserState.RINGING) {
|
} else if (state == RtpEndUserState.RINGING) {
|
||||||
setDialing();
|
setDialing();
|
||||||
|
} else if (state == RtpEndUserState.INCOMING_CALL) {
|
||||||
|
setRinging();
|
||||||
} else if (state == RtpEndUserState.CONNECTED) {
|
} else if (state == RtpEndUserState.CONNECTED) {
|
||||||
xmppConnectionService.setDiallerIntegrationActive(true);
|
xmppConnectionService.setDiallerIntegrationActive(true);
|
||||||
setActive();
|
setActive();
|
||||||
|
@ -221,6 +251,8 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
|
public void onAudioDeviceChanged(AppRTCAudioManager.AudioDevice selectedAudioDevice, Set<AppRTCAudioManager.AudioDevice> availableAudioDevices) {
|
||||||
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) return;
|
||||||
|
|
||||||
switch(selectedAudioDevice) {
|
switch(selectedAudioDevice) {
|
||||||
case SPEAKER_PHONE:
|
case SPEAKER_PHONE:
|
||||||
setAudioRoute(CallAudioState.ROUTE_SPEAKER);
|
setAudioRoute(CallAudioState.ROUTE_SPEAKER);
|
||||||
|
@ -235,6 +267,17 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnswer() {
|
||||||
|
// For incoming calls, a connection update may not have been triggered before answering
|
||||||
|
// so we have to acquire the rtp connection object here
|
||||||
|
this.rtpConnection =
|
||||||
|
xmppConnectionService.getJingleConnectionManager()
|
||||||
|
.findJingleRtpConnection(account, with, sessionId);
|
||||||
|
|
||||||
|
rtpConnection.get().acceptCall();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect() {
|
public void onDisconnect() {
|
||||||
if (rtpConnection == null || rtpConnection.get() == null) {
|
if (rtpConnection == null || rtpConnection.get() == null) {
|
||||||
|
@ -276,9 +319,9 @@ public class ConnectionService extends android.telecom.ConnectionService {
|
||||||
while (!postDial.empty()) {
|
while (!postDial.empty()) {
|
||||||
String next = postDial.pop();
|
String next = postDial.pop();
|
||||||
if (next.equals(";")) {
|
if (next.equals(";")) {
|
||||||
Stack v = (Stack) postDial.clone();
|
Vector<String> v = new Vector<>(postDial);
|
||||||
Collections.reverse(v);
|
Collections.reverse(v);
|
||||||
setPostDialWait(String.join("", v));
|
setPostDialWait(Joiner.on("").join(v));
|
||||||
return;
|
return;
|
||||||
} else if (next.equals(",")) {
|
} else if (next.equals(",")) {
|
||||||
sleep(2000);
|
sleep(2000);
|
||||||
|
|
|
@ -599,7 +599,7 @@ public class Contact implements ListItem, Blockable {
|
||||||
"/" + getJid().asBareJid().toString();
|
"/" + getJid().asBareJid().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PhoneAccountHandle phoneAccountHandle() {
|
public PhoneAccountHandle phoneAccountHandle() {
|
||||||
ComponentName componentName = new ComponentName(
|
ComponentName componentName = new ComponentName(
|
||||||
"com.cheogram.android",
|
"com.cheogram.android",
|
||||||
"com.cheogram.android.ConnectionService"
|
"com.cheogram.android.ConnectionService"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationChannelGroup;
|
import android.app.NotificationChannelGroup;
|
||||||
|
@ -8,6 +9,7 @@ import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
@ -16,9 +18,12 @@ import android.media.Ringtone;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.telecom.PhoneAccountHandle;
|
||||||
|
import android.telecom.TelecomManager;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.style.StyleSpan;
|
import android.text.style.StyleSpan;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
@ -423,7 +428,59 @@ public class NotificationService {
|
||||||
notify(DELIVERY_FAILED_NOTIFICATION_ID, summaryNotification);
|
notify(DELIVERY_FAILED_NOTIFICATION_ID, summaryNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized boolean tryRingingWithDialerUI(final AbstractJingleConnection.Id id, final Set<Media> media) {
|
||||||
|
if (mXmppConnectionService.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
// We cannot request audio permission in Dialer UI
|
||||||
|
// when Dialer is shown over keyguard, the user cannot even necessarily
|
||||||
|
// see notifications.
|
||||||
|
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");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhoneAccountHandle handle = null;
|
||||||
|
for (Contact contact : id.account.getRoster().getContacts()) {
|
||||||
|
if (!contact.getJid().getDomain().equals(id.with.getDomain()))
|
||||||
|
continue;
|
||||||
|
if (!contact.getPresences().anyIdentity("gateway", "pstn"))
|
||||||
|
continue;
|
||||||
|
handle = contact.phoneAccountHandle();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handle == null) {
|
||||||
|
Log.w(Config.LOGTAG, "Could not find phone account handle for " + id.account.getJid().toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bundle callInfo = new Bundle();
|
||||||
|
callInfo.putString("account", id.account.getJid().toString());
|
||||||
|
callInfo.putString("with", id.with.toString());
|
||||||
|
callInfo.putString("sessionId", id.sessionId);
|
||||||
|
|
||||||
|
TelecomManager telecomManager = mXmppConnectionService.getSystemService(TelecomManager.class);
|
||||||
|
|
||||||
|
try {
|
||||||
|
telecomManager.addNewIncomingCall(handle, callInfo);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
// There *could* be race conditions where the account is not registered yet
|
||||||
|
// when an incoming call is already received
|
||||||
|
Log.w(Config.LOGTAG, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void startRinging(final AbstractJingleConnection.Id id, final Set<Media> media) {
|
public synchronized void startRinging(final AbstractJingleConnection.Id id, final Set<Media> media) {
|
||||||
|
if (tryRingingWithDialerUI(id, media)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
showIncomingCallNotification(id, media);
|
showIncomingCallNotification(id, media);
|
||||||
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
|
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
final int currentInterruptionFilter;
|
final int currentInterruptionFilter;
|
||||||
|
|
Loading…
Reference in a new issue