Clean acceptCall code and add recordFile in params before accepting a call

This commit is contained in:
Mickaël Turnel 2018-11-20 16:57:55 +01:00
parent eb1a3f0e98
commit 90774931d7
3 changed files with 40 additions and 47 deletions

View file

@ -795,7 +795,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
public void setHandsetMode(Boolean on) { public void setHandsetMode(Boolean on) {
if (mLc.isIncomingInvitePending() && on) { if (mLc.isIncomingInvitePending() && on) {
handsetON = true; handsetON = true;
mLc.acceptCall(mLc.getCurrentCall()); acceptCall(mLc.getCurrentCall());
LinphoneActivity.instance().startIncallActivity(); LinphoneActivity.instance().startIncallActivity();
} else if (on && CallActivity.isInstanciated()) { } else if (on && CallActivity.isInstanciated()) {
handsetON = true; handsetON = true;
@ -1173,7 +1173,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
public void run() { public void run() {
if (mLc != null) { if (mLc != null) {
if (mLc.getCallsNb() > 0) { if (mLc.getCallsNb() > 0) {
mLc.acceptCall(call); acceptCall(call);
if (LinphoneManager.getInstance() != null) { if (LinphoneManager.getInstance() != null) {
LinphoneManager.getInstance().routeAudioToReceiver(); LinphoneManager.getInstance().routeAudioToReceiver();
if (LinphoneActivity.instance() != null) if (LinphoneActivity.instance() != null)
@ -1465,12 +1465,22 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
return reinviteWithVideo(); return reinviteWithVideo();
} }
public boolean acceptCallIfIncomingPending() throws CoreException { public boolean acceptCall(Call call) {
if (mLc.isIncomingInvitePending()) { if (call == null) return false;
mLc.acceptCall(mLc.getCurrentCall());
return true; CallParams params = LinphoneManager.getLc().createCallParams(call);
boolean isLowBandwidthConnection = !LinphoneUtils.isHighBandwidthConnection(LinphoneService.instance().getApplicationContext());
if (params != null) {
params.enableLowBandwidth(isLowBandwidthConnection);
params.setRecordFile(LinphoneUtils.getCallRecordingFilename(getContext(), call.getRemoteAddress()));
} else {
Log.e("Could not create call params for call");
return false;
} }
return false;
return acceptCallWithParams(call, params);
} }
public boolean acceptCallWithParams(Call call, CallParams params) { public boolean acceptCallWithParams(Call call, CallParams params) {

View file

@ -246,17 +246,7 @@ public class CallIncomingActivity extends LinphoneGenericActivity {
} }
alreadyAcceptedOrDeniedCall = true; alreadyAcceptedOrDeniedCall = true;
CallParams params = LinphoneManager.getLc().createCallParams(mCall); if (!LinphoneManager.getInstance().acceptCall(mCall)) {
boolean isLowBandwidthConnection = !LinphoneUtils.isHighBandwidthConnection(LinphoneService.instance().getApplicationContext());
if (params != null) {
params.enableLowBandwidth(isLowBandwidthConnection);
} else {
Log.e("Could not create call params for call");
}
if (params == null || !LinphoneManager.getInstance().acceptCallWithParams(mCall, params)) {
// the above method takes care of Samsung Galaxy S // the above method takes care of Samsung Galaxy S
Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG).show();
} else { } else {

View file

@ -58,38 +58,31 @@ public class CallButton extends ImageView implements OnClickListener, AddressAwa
} }
public void onClick(View v) { public void onClick(View v) {
try { if (mAddress.getText().length() > 0) {
if (!LinphoneManager.getInstance().acceptCallIfIncomingPending()) { LinphoneManager.getInstance().newOutgoingCall(mAddress);
if (mAddress.getText().length() > 0) { } else {
LinphoneManager.getInstance().newOutgoingCall(mAddress); if (LinphonePreferences.instance().isBisFeatureEnabled()) {
} else { CallLog[] logs = LinphoneManager.getLc().getCallLogs();
if (LinphonePreferences.instance().isBisFeatureEnabled()) { CallLog log = null;
CallLog[] logs = LinphoneManager.getLc().getCallLogs(); for (CallLog l : logs) {
CallLog log = null; if (l.getDir() == Call.Dir.Outgoing) {
for (CallLog l : logs) { log = l;
if (l.getDir() == Call.Dir.Outgoing) { break;
log = l;
break;
}
}
if (log == null) {
return;
}
ProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
if (lpc != null && log.getToAddress().getDomain().equals(lpc.getDomain())) {
mAddress.setText(log.getToAddress().getUsername());
} else {
mAddress.setText(log.getToAddress().asStringUriOnly());
}
mAddress.setSelection(mAddress.getText().toString().length());
mAddress.setDisplayedName(log.getToAddress().getDisplayName());
} }
} }
if (log == null) {
return;
}
ProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
if (lpc != null && log.getToAddress().getDomain().equals(lpc.getDomain())) {
mAddress.setText(log.getToAddress().getUsername());
} else {
mAddress.setText(log.getToAddress().asStringUriOnly());
}
mAddress.setSelection(mAddress.getText().toString().length());
mAddress.setDisplayedName(log.getToAddress().getDisplayName());
} }
} catch (CoreException e) {
LinphoneManager.getInstance().terminateCall();
onWrongDestinationAddress();
} }
} }