Fix crash when don't keep activity flag enabled
This commit is contained in:
parent
6ea2f360ce
commit
4672742b49
2 changed files with 30 additions and 2 deletions
|
@ -46,12 +46,22 @@ import android.widget.Toast;
|
|||
*/
|
||||
public class IncomingCallActivity extends Activity implements LinphoneOnCallStateChangedListener, LinphoneSliderTriggered {
|
||||
|
||||
private static IncomingCallActivity instance;
|
||||
|
||||
private TextView mNameView;
|
||||
private TextView mNumberView;
|
||||
private AvatarWithShadow mPictureView;
|
||||
private LinphoneCall mCall;
|
||||
private LinphoneSliders mIncomingCallWidget;
|
||||
|
||||
public static IncomingCallActivity instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static boolean isInstanciated() {
|
||||
return instance != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
@ -70,11 +80,13 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
|
|||
mIncomingCallWidget.setOnTriggerListener(this);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
instance = this;
|
||||
LinphoneManager.addListener(this);
|
||||
// Only one call ringing at a time is allowed
|
||||
List<LinphoneCall> calls = LinphoneUtils.getLinphoneCalls(LinphoneManager.getLc());
|
||||
|
@ -109,6 +121,12 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
|
|||
LinphoneManager.removeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
instance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (LinphoneManager.isInstanciated() && (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_HOME)) {
|
||||
|
|
|
@ -1030,6 +1030,16 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
|||
mThis.preventSIPCalls();
|
||||
}
|
||||
}
|
||||
|
||||
public Context getActivity() {
|
||||
if (LinphoneActivity.isInstanciated())
|
||||
return LinphoneActivity.instance();
|
||||
else if (InCallActivity.isInstanciated())
|
||||
return InCallActivity.instance();
|
||||
else if (IncomingCallActivity.isInstanciated())
|
||||
return IncomingCallActivity.instance();
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressLint("Wakelock")
|
||||
public void callState(final LinphoneCore lc,final LinphoneCall call, final State state, final String message) {
|
||||
|
@ -1055,7 +1065,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
|||
}
|
||||
|
||||
if (state == CallEnd || state == Error) {
|
||||
TelephonyManager tm = (TelephonyManager) LinphoneActivity.instance().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
|
||||
mAudioManager.setMode(MODE_NORMAL);
|
||||
}
|
||||
|
@ -1432,7 +1442,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
|||
boolean sendCamera = mLc.getConferenceSize() == 0;
|
||||
enableCamera(call, sendCamera);
|
||||
}
|
||||
TelephonyManager tm = (TelephonyManager) LinphoneActivity.instance().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (state == State.CallEnd && mLc.getCallsNb() == 0 && tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
|
||||
routeAudioToReceiver();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue