Fixed infinite loop of LinphoneActivity stop/start when screen is locked and incoming call is hung up by remote

This commit is contained in:
Sylvain Berfini 2019-03-14 12:46:29 +01:00
parent 251212c15d
commit 44259e5c10
9 changed files with 26 additions and 82 deletions

View file

@ -65,7 +65,6 @@ import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.linphone.LinphoneManager.AddressType; import org.linphone.LinphoneManager.AddressType;
@ -279,10 +278,7 @@ public class LinphoneActivity extends LinphoneGenericActivity
public void onCallStateChanged( public void onCallStateChanged(
Core lc, Call call, Call.State state, String message) { Core lc, Call call, Call.State state, String message) {
if (state == State.IncomingReceived) { if (state == State.IncomingReceived) {
startActivity( // This case will be handled by the service listener
new Intent(
LinphoneActivity.instance(),
CallIncomingActivity.class));
} else if (state == State.OutgoingInit || state == State.OutgoingProgress) { } else if (state == State.OutgoingInit || state == State.OutgoingProgress) {
startActivity( startActivity(
new Intent( new Intent(
@ -1472,21 +1468,6 @@ public class LinphoneActivity extends LinphoneGenericActivity
sInstance = null; sInstance = null;
super.onDestroy(); super.onDestroy();
unbindDrawables(findViewById(R.id.topLayout));
System.gc();
}
private void unbindDrawables(View view) {
if (view != null && view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
} }
@Override @Override
@ -1528,12 +1509,8 @@ public class LinphoneActivity extends LinphoneGenericActivity
startIncallActivity(); startIncallActivity();
} }
} else if (extras.getBoolean("StartCall", false)) { } else if (extras.getBoolean("StartCall", false)) {
if (CallActivity.isInstanciated()) {
CallActivity.instance().startIncomingCallActivity();
} else {
addressWaitingToBeCalled = extras.getString("NumberToCall"); addressWaitingToBeCalled = extras.getString("NumberToCall");
goToDialerFragment(); goToDialerFragment();
}
} else if (extras.getBoolean("Transfer", false)) { } else if (extras.getBoolean("Transfer", false)) {
intent.putExtra("DoNotGoToCallActivity", true); intent.putExtra("DoNotGoToCallActivity", true);
} else if (extras.getBoolean("AddCall", false)) { } else if (extras.getBoolean("AddCall", false)) {
@ -1577,19 +1554,6 @@ public class LinphoneActivity extends LinphoneGenericActivity
} }
} }
setIntent(intent); setIntent(intent);
if (LinphoneManager.getLc().getCalls().length > 0) {
// If a call is ringing, start incomingcallactivity
Collection<Call.State> incoming = new ArrayList<>();
incoming.add(Call.State.IncomingReceived);
if (LinphoneUtils.getCallsInState(LinphoneManager.getLc(), incoming).size() > 0) {
if (CallActivity.isInstanciated()) {
CallActivity.instance().startIncomingCallActivity();
} else {
startActivity(new Intent(this, CallIncomingActivity.class));
}
}
}
} }
public boolean isOnBackground() { public boolean isOnBackground() {

View file

@ -1419,16 +1419,6 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
} }
} }
public boolean hasLinphoneAccount() {
for (ProxyConfig proxyConfig : mCore.getProxyConfigList()) {
if (getString(R.string.default_domain)
.equals(proxyConfig.getIdentityAddress().getDomain())) {
return true;
}
}
return false;
}
/** @return false if already in video call. */ /** @return false if already in video call. */
public boolean addVideo() { public boolean addVideo() {
Call call = mCore.getCurrentCall(); Call call = mCore.getCurrentCall();

View file

@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import android.app.Activity; import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.app.Service; import android.app.Service;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
@ -29,9 +30,11 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.PowerManager;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.view.WindowManager; import android.view.WindowManager;
import java.util.ArrayList; import java.util.ArrayList;
import org.linphone.call.CallIncomingActivity;
import org.linphone.contacts.ContactsManager; import org.linphone.contacts.ContactsManager;
import org.linphone.core.Call; import org.linphone.core.Call;
import org.linphone.core.Call.State; import org.linphone.core.Call.State;
@ -82,7 +85,7 @@ public final class LinphoneService extends Service {
private Application.ActivityLifecycleCallbacks mActivityCallbacks; private Application.ActivityLifecycleCallbacks mActivityCallbacks;
private NotificationsManager mNotificationManager; private NotificationsManager mNotificationManager;
private String mIncomingReceivedActivityName; private String mIncomingReceivedActivityName;
private Class<? extends Activity> mIncomingReceivedActivity = LinphoneActivity.class; private Class<? extends Activity> mIncomingReceivedActivity = CallIncomingActivity.class;
private LoggingServiceListener mJavaLoggingService = private LoggingServiceListener mJavaLoggingService =
new LoggingServiceListener() { new LoggingServiceListener() {
@ -429,10 +432,15 @@ public final class LinphoneService extends Service {
private void onIncomingReceived() { private void onIncomingReceived() {
// wakeup linphone // wakeup linphone
startActivity(
new Intent() PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
.setClass(this, mIncomingReceivedActivity) Intent intent = new Intent().setClass(this, mIncomingReceivedActivity);
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); if (!pm.isInteractive()) {
// This is to workaround an infinite loop of pause/start in LinphoneActivity issue
// if incoming call is being stopped by caller while screen if off and locked
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
startActivity(intent);
} }
/*Believe me or not, but knowing the application visibility state on Android is a nightmare. /*Believe me or not, but knowing the application visibility state on Android is a nightmare.

View file

@ -210,7 +210,7 @@ public class CallActivity extends LinphoneGenericActivity
} }
if (state == State.IncomingReceived) { if (state == State.IncomingReceived) {
startIncomingCallActivity(); // This scenario will be handled by the Service listener
return; return;
} else if (state == State.Paused } else if (state == State.Paused
|| state == State.PausedByRemote || state == State.PausedByRemote
@ -1190,10 +1190,6 @@ public class CallActivity extends LinphoneGenericActivity
LinphoneManager.getLc().acceptCallUpdate(call, params); LinphoneManager.getLc().acceptCallUpdate(call, params);
} }
public void startIncomingCallActivity() {
startActivity(new Intent(this, CallIncomingActivity.class));
}
private void hideStatusBar() { private void hideStatusBar() {
if (isTablet()) { if (isTablet()) {
return; return;

View file

@ -80,19 +80,15 @@ public class CallIncomingActivity extends LinphoneGenericActivity {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
} }
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow()
.addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
setContentView(R.layout.call_incoming); setContentView(R.layout.call_incoming);
mName = findViewById(R.id.contact_name); mName = findViewById(R.id.contact_name);
mNumber = findViewById(R.id.contact_number); mNumber = findViewById(R.id.contact_number);
// set this flag so this activity will stay in front of the keyguard
int flags =
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
getWindow().addFlags(flags);
mAccept = findViewById(R.id.answer_button); mAccept = findViewById(R.id.answer_button);
mDecline = findViewById(R.id.decline_button); mDecline = findViewById(R.id.decline_button);
mAcceptIcon = findViewById(R.id.acceptIcon); mAcceptIcon = findViewById(R.id.acceptIcon);

View file

@ -81,13 +81,6 @@ public class CallOutgoingActivity extends LinphoneGenericActivity implements OnC
mSpeaker = findViewById(R.id.speaker); mSpeaker = findViewById(R.id.speaker);
mSpeaker.setOnClickListener(this); mSpeaker.setOnClickListener(this);
// set this flag so this activity will stay in front of the keyguard
int flags =
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
getWindow().addFlags(flags);
mHangUp = findViewById(R.id.outgoing_hang_up); mHangUp = findViewById(R.id.outgoing_hang_up);
mHangUp.setOnClickListener(this); mHangUp.setOnClickListener(this);

View file

@ -322,7 +322,8 @@ public class ChatMessagesAdapter extends SelectableAdapter<ChatMessageViewHolder
} }
} }
} }
if (position >= 0 && position < mHistory.size() - 1 if (position >= 0
&& position < mHistory.size() - 1
&& mContext.getResources() && mContext.getResources()
.getBoolean(R.bool.lower_space_between_chat_bubbles_if_same_person)) { .getBoolean(R.bool.lower_space_between_chat_bubbles_if_same_person)) {
EventLog nextEvent = (EventLog) getItem(position + 1); EventLog nextEvent = (EventLog) getItem(position + 1);

View file

@ -1310,7 +1310,8 @@ public class LinphonePreferences {
public String getActivityToLaunchOnIncomingReceived() { public String getActivityToLaunchOnIncomingReceived() {
return getConfig() return getConfig()
.getString("app", "incoming_call_activity", "org.linphone.LinphoneActivity"); .getString(
"app", "incoming_call_activity", "org.linphone.call.CallIncomingActivity");
} }
public void setActivityToLaunchOnIncomingReceived(String name) { public void setActivityToLaunchOnIncomingReceived(String name) {

View file

@ -25,7 +25,6 @@ import android.net.Uri;
import java.util.ArrayList; import java.util.ArrayList;
import org.linphone.LinphoneActivity; import org.linphone.LinphoneActivity;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.call.CallActivity;
import org.linphone.contacts.ContactsManager; import org.linphone.contacts.ContactsManager;
import org.linphone.core.tools.Log; import org.linphone.core.tools.Log;
@ -71,11 +70,7 @@ public class IntentUtils {
&& (intent.getStringExtra("NumberToCall") != null)) { && (intent.getStringExtra("NumberToCall") != null)) {
String numberToCall = intent.getStringExtra("NumberToCall"); String numberToCall = intent.getStringExtra("NumberToCall");
Log.i("[Intent Utils] ACTION_CALL_LINPHONE with number: " + numberToCall); Log.i("[Intent Utils] ACTION_CALL_LINPHONE with number: " + numberToCall);
if (CallActivity.isInstanciated()) {
CallActivity.instance().startIncomingCallActivity();
} else {
LinphoneManager.getInstance().newOutgoingCall(numberToCall, null); LinphoneManager.getInstance().newOutgoingCall(numberToCall, null);
}
} else if (Intent.ACTION_CALL.equals(action)) { } else if (Intent.ACTION_CALL.equals(action)) {
if (intent.getData() != null) { if (intent.getData() != null) {
addressToCall = intent.getData().toString(); addressToCall = intent.getData().toString();