do not use call integration on devices w/o telephony support
This commit is contained in:
parent
20e1f54277
commit
71763902f8
|
@ -1,6 +1,7 @@
|
||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.ToneGenerator;
|
import android.media.ToneGenerator;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
@ -50,7 +51,12 @@ public class CallIntegration extends Connection {
|
||||||
public CallIntegration(final Context context) {
|
public CallIntegration(final Context context) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
if (selfManaged()) {
|
if (selfManaged()) {
|
||||||
setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
|
||||||
|
} else {
|
||||||
|
throw new AssertionError(
|
||||||
|
"Trying to set connection properties on unsupported version");
|
||||||
|
}
|
||||||
this.appRTCAudioManager = null;
|
this.appRTCAudioManager = null;
|
||||||
} else {
|
} else {
|
||||||
this.appRTCAudioManager = new AppRTCAudioManager(context);
|
this.appRTCAudioManager = new AppRTCAudioManager(context);
|
||||||
|
@ -151,7 +157,11 @@ public class CallIntegration extends Connection {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||||
setAudioDeviceUpsideDownCake(audioDevice);
|
setAudioDeviceUpsideDownCake(audioDevice);
|
||||||
} else if (selfManaged()) {
|
} else if (selfManaged()) {
|
||||||
setAudioDeviceOreo(audioDevice);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
setAudioDeviceOreo(audioDevice);
|
||||||
|
} else {
|
||||||
|
throw new AssertionError("Trying to set audio devices on unsupported version");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setAudioDeviceFallback(audioDevice);
|
setAudioDeviceFallback(audioDevice);
|
||||||
}
|
}
|
||||||
|
@ -309,7 +319,7 @@ public class CallIntegration extends Connection {
|
||||||
@Override
|
@Override
|
||||||
public void onStateChanged(final int state) {
|
public void onStateChanged(final int state) {
|
||||||
Log.d(Config.LOGTAG, "onStateChanged(" + state + ")");
|
Log.d(Config.LOGTAG, "onStateChanged(" + state + ")");
|
||||||
if (notSelfManaged()) {
|
if (notSelfManaged(context)) {
|
||||||
if (state == STATE_DIALING) {
|
if (state == STATE_DIALING) {
|
||||||
requireAppRtcAudioManager().startRingBack();
|
requireAppRtcAudioManager().startRingBack();
|
||||||
} else {
|
} else {
|
||||||
|
@ -432,18 +442,24 @@ public class CallIntegration extends Connection {
|
||||||
callback.onAudioDeviceChanged(selectedAudioDevice, availableAudioDevices);
|
callback.onAudioDeviceChanged(selectedAudioDevice, availableAudioDevices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean selfManaged() {
|
private boolean selfManaged() {
|
||||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
|
return selfManaged(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean notSelfManaged() {
|
public static boolean selfManaged(final Context context) {
|
||||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.O;
|
final var packageManager = context.getPackageManager();
|
||||||
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||||
|
&& packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean notSelfManaged(final Context context) {
|
||||||
|
return !selfManaged(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInitialAudioDevice(final AudioDevice audioDevice) {
|
public void setInitialAudioDevice(final AudioDevice audioDevice) {
|
||||||
Log.d(Config.LOGTAG, "setInitialAudioDevice(" + audioDevice + ")");
|
Log.d(Config.LOGTAG, "setInitialAudioDevice(" + audioDevice + ")");
|
||||||
this.initialAudioDevice = audioDevice;
|
this.initialAudioDevice = audioDevice;
|
||||||
if (CallIntegration.selfManaged()) {
|
if (selfManaged()) {
|
||||||
// once the 'CallIntegration' gets added to the system we receive calls to update audio
|
// once the 'CallIntegration' gets added to the system we receive calls to update audio
|
||||||
// state
|
// state
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -314,7 +314,7 @@ public class CallIntegrationConnectionService extends ConnectionService {
|
||||||
final Account account,
|
final Account account,
|
||||||
final Jid with,
|
final Jid with,
|
||||||
final Set<Media> media) {
|
final Set<Media> media) {
|
||||||
if (CallIntegration.selfManaged()) {
|
if (CallIntegration.selfManaged(service)) {
|
||||||
final var extras = new Bundle();
|
final var extras = new Bundle();
|
||||||
extras.putParcelable(
|
extras.putParcelable(
|
||||||
TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, getHandle(service, account));
|
TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, getHandle(service, account));
|
||||||
|
@ -349,7 +349,7 @@ public class CallIntegrationConnectionService extends ConnectionService {
|
||||||
|
|
||||||
public static void addNewIncomingCall(
|
public static void addNewIncomingCall(
|
||||||
final Context context, final AbstractJingleConnection.Id id) {
|
final Context context, final AbstractJingleConnection.Id id) {
|
||||||
if (CallIntegration.notSelfManaged()) {
|
if (CallIntegration.notSelfManaged(context)) {
|
||||||
Log.d(
|
Log.d(
|
||||||
Config.LOGTAG,
|
Config.LOGTAG,
|
||||||
"not adding incoming call to TelecomManager on Android "
|
"not adding incoming call to TelecomManager on Android "
|
||||||
|
|
|
@ -1692,7 +1692,7 @@ public class JingleRtpConnection extends AbstractJingleConnection
|
||||||
ringingTimeoutFuture =
|
ringingTimeoutFuture =
|
||||||
jingleConnectionManager.schedule(
|
jingleConnectionManager.schedule(
|
||||||
this::ringingTimeout, BUSY_TIME_OUT, TimeUnit.SECONDS);
|
this::ringingTimeout, BUSY_TIME_OUT, TimeUnit.SECONDS);
|
||||||
if (CallIntegration.selfManaged()) {
|
if (CallIntegration.selfManaged(xmppConnectionService)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xmppConnectionService.getNotificationService().startRinging(id, getMedia());
|
xmppConnectionService.getNotificationService().startRinging(id, getMedia());
|
||||||
|
|
Loading…
Reference in a new issue