Fixed crashes reported on play store

This commit is contained in:
Sylvain Berfini 2020-02-28 14:43:59 +01:00
parent 4ba26a6775
commit a42d7a47ae
5 changed files with 52 additions and 23 deletions

View file

@ -90,6 +90,9 @@ public class LinphoneContext {
} }
public static LinphoneContext instance() { public static LinphoneContext instance() {
if (sInstance == null) {
throw new RuntimeException("[Context] Linphone Context not available!");
}
return sInstance; return sInstance;
} }

View file

@ -23,6 +23,7 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.R; import org.linphone.R;
import org.linphone.assistant.MenuAssistantActivity; import org.linphone.assistant.MenuAssistantActivity;
@ -57,9 +58,14 @@ public class LinphoneLauncherActivity extends Activity implements ServiceWaitThr
if (LinphoneService.isReady()) { if (LinphoneService.isReady()) {
onServiceReady(); onServiceReady();
} else { } else {
startService( try {
new Intent().setClass(LinphoneLauncherActivity.this, LinphoneService.class)); startService(
new ServiceWaitThread(this).start(); new Intent()
.setClass(LinphoneLauncherActivity.this, LinphoneService.class));
new ServiceWaitThread(this).start();
} catch (IllegalStateException ise) {
Log.e("Linphone", "Exception raised while starting service: " + ise);
}
} }
} }

View file

@ -49,6 +49,7 @@ import androidx.core.content.ContextCompat;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import org.linphone.LinphoneContext;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.R; import org.linphone.R;
import org.linphone.activities.LinphoneGenericActivity; import org.linphone.activities.LinphoneGenericActivity;
@ -94,6 +95,8 @@ public class CallActivity extends LinphoneGenericActivity
@Override @Override
public void run() { public void run() {
// Make sure that at the time this is executed this is still required // Make sure that at the time this is executed this is still required
if (!LinphoneContext.isReady()) return;
Call call = LinphoneManager.getCore().getCurrentCall(); Call call = LinphoneManager.getCore().getCurrentCall();
if (call != null && call.getCurrentParams().videoEnabled()) { if (call != null && call.getCurrentParams().videoEnabled()) {
CallActivity activity = mWeakCallActivity.get(); CallActivity activity = mWeakCallActivity.get();

View file

@ -36,6 +36,7 @@ import org.linphone.core.Core;
import org.linphone.core.CoreListenerStub; import org.linphone.core.CoreListenerStub;
import org.linphone.core.EcCalibratorStatus; import org.linphone.core.EcCalibratorStatus;
import org.linphone.core.PayloadType; import org.linphone.core.PayloadType;
import org.linphone.core.tools.Log;
import org.linphone.settings.widget.BasicSetting; import org.linphone.settings.widget.BasicSetting;
import org.linphone.settings.widget.ListSetting; import org.linphone.settings.widget.ListSetting;
import org.linphone.settings.widget.SettingListenerBase; import org.linphone.settings.widget.SettingListenerBase;
@ -113,7 +114,11 @@ public class AudioSettingsFragment extends SettingsFragment {
new SettingListenerBase() { new SettingListenerBase() {
@Override @Override
public void onTextValueChanged(String newValue) { public void onTextValueChanged(String newValue) {
mPrefs.setMicGainDb(Float.valueOf(newValue)); try {
mPrefs.setMicGainDb(Float.valueOf(newValue));
} catch (NumberFormatException nfe) {
Log.e("Can't set mic gain, number format exception: " + nfe);
}
} }
}); });
@ -121,7 +126,11 @@ public class AudioSettingsFragment extends SettingsFragment {
new SettingListenerBase() { new SettingListenerBase() {
@Override @Override
public void onTextValueChanged(String newValue) { public void onTextValueChanged(String newValue) {
mPrefs.setPlaybackGainDb(Float.valueOf(newValue)); try {
mPrefs.setPlaybackGainDb(Float.valueOf(newValue));
} catch (NumberFormatException nfe) {
Log.e("Can't set speaker gain, number format exception: " + nfe);
}
} }
}); });
@ -129,14 +138,18 @@ public class AudioSettingsFragment extends SettingsFragment {
new SettingListenerBase() { new SettingListenerBase() {
@Override @Override
public void onListValueChanged(int position, String newLabel, String newValue) { public void onListValueChanged(int position, String newLabel, String newValue) {
int bitrate = Integer.valueOf(newValue); try {
mPrefs.setCodecBitrateLimit(bitrate); int bitrate = Integer.valueOf(newValue);
mPrefs.setCodecBitrateLimit(bitrate);
Core core = LinphoneManager.getCore(); Core core = LinphoneManager.getCore();
for (final PayloadType pt : core.getAudioPayloadTypes()) { for (final PayloadType pt : core.getAudioPayloadTypes()) {
if (pt.isVbr()) { if (pt.isVbr()) {
pt.setNormalBitrate(bitrate); pt.setNormalBitrate(bitrate);
}
} }
} catch (NumberFormatException nfe) {
Log.e("Can't set codec bitrate limit, number format exception: " + nfe);
} }
} }
}); });

View file

@ -245,20 +245,24 @@ public final class LinphoneUtils {
} }
if (username.contains("@")) { if (username.contains("@")) {
String domain = username.split("@")[1]; String[] split = username.split("@");
ProxyConfig lpc = core.getDefaultProxyConfig(); if (split.length > 1) {
if (lpc != null) { String domain = split[1];
if (domain.equals(lpc.getDomain())) { ProxyConfig lpc = core.getDefaultProxyConfig();
return username.split("@")[0]; if (lpc != null) {
} if (domain.equals(lpc.getDomain())) {
} else { return split[0];
if (domain.equals( }
LinphoneContext.instance() } else {
.getApplicationContext() if (domain.equals(
.getString(R.string.default_domain))) { LinphoneContext.instance()
return username.split("@")[0]; .getApplicationContext()
.getString(R.string.default_domain))) {
return split[0];
}
} }
} }
return split[0];
} }
return username; return username;
} }