From 48143cdcfc77880f50b3544ddbf4f5948ab4c1b4 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 30 Jan 2014 16:57:59 +0100 Subject: [PATCH] Fix presence crash --- src/org/linphone/InCallActivity.java | 4 ++++ src/org/linphone/LinphoneManager.java | 26 ++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/org/linphone/InCallActivity.java b/src/org/linphone/InCallActivity.java index 67a3b1dc2..551676ca2 100644 --- a/src/org/linphone/InCallActivity.java +++ b/src/org/linphone/InCallActivity.java @@ -262,6 +262,8 @@ public class InCallActivity extends FragmentActivity implements speaker.setVisibility(View.VISIBLE); } catch (NullPointerException npe) { Log.e("Bluetooth: Audio routes menu disabled on tablets for now (3)"); } } + + LinphoneManager.getInstance().changeStatusToOnThePhone(); } private void refreshInCallActions() { @@ -1172,6 +1174,8 @@ public class InCallActivity extends FragmentActivity implements @Override protected void onDestroy() { + LinphoneManager.getInstance().changeStatusToOnline(); + if (mControlsHandler != null && mControls != null) { mControlsHandler.removeCallbacks(mControls); } diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index f47bfc307..690eefe78 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -352,25 +352,35 @@ public class LinphoneManager implements LinphoneCoreListener { return instance; } + + private boolean isPresenceModelActivitySet() { + return isInstanciated() && getLc().getPresenceModel() != null || getLc().getPresenceModel().getActivity() != null; + } public void changeStatusToOnline() { - if (LinphoneManager.isInstanciated()) { + if (isInstanciated() && isPresenceModelActivitySet() && getLc().getPresenceModel().getActivity().getType() != PresenceActivityType.Online) { + getLc().getPresenceModel().getActivity().setType(PresenceActivityType.Online); + } else if (isInstanciated() && !isPresenceModelActivitySet()) { PresenceModel model = LinphoneCoreFactoryImpl.instance().createPresenceModel(PresenceActivityType.Online, null); - LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceModel(model); + getLc().setPresenceModel(model); } } - public void changeStatusToAway() { - if (LinphoneManager.isInstanciated()) { - PresenceModel model = LinphoneCoreFactoryImpl.instance().createPresenceModel(PresenceActivityType.Away, null); - LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceModel(model); + public void changeStatusToOnThePhone() { + if (isInstanciated() && isPresenceModelActivitySet() && getLc().getPresenceModel().getActivity().getType() != PresenceActivityType.OnThePhone) { + getLc().getPresenceModel().getActivity().setType(PresenceActivityType.OnThePhone); + } else if (isInstanciated() && !isPresenceModelActivitySet()) { + PresenceModel model = LinphoneCoreFactoryImpl.instance().createPresenceModel(PresenceActivityType.OnThePhone, null); + getLc().setPresenceModel(model); } } public void changeStatusToOffline() { - if (LinphoneManager.isInstanciated()) { + if (isInstanciated() && isPresenceModelActivitySet() && getLc().getPresenceModel().getActivity().getType() != PresenceActivityType.Offline) { + getLc().getPresenceModel().getActivity().setType(PresenceActivityType.Offline); + } else if (isInstanciated() && !isPresenceModelActivitySet()) { PresenceModel model = LinphoneCoreFactoryImpl.instance().createPresenceModel(PresenceActivityType.Offline, null); - LinphoneManager.getLcIfManagerNotDestroyedOrNull().setPresenceModel(model); + getLc().setPresenceModel(model); } }