From 3b4cc020e9c0992cb53afbdbf39af46cfcaa7398 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 20 Nov 2014 12:14:25 +0100 Subject: [PATCH] Single thread for UI, iterate & callbacks --- .../AcceptCallUpdateDialogFragment.java | 18 +++++++++++ src/org/linphone/InCallActivity.java | 4 --- src/org/linphone/LinphoneManager.java | 9 +++++- src/org/linphone/LinphoneService.java | 9 ++++-- src/org/linphone/UIThreadDispatcher.java | 30 +++++++++++++++++++ 5 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 src/org/linphone/UIThreadDispatcher.java diff --git a/src/org/linphone/AcceptCallUpdateDialogFragment.java b/src/org/linphone/AcceptCallUpdateDialogFragment.java index 27b228f54..52d2d1e5c 100644 --- a/src/org/linphone/AcceptCallUpdateDialogFragment.java +++ b/src/org/linphone/AcceptCallUpdateDialogFragment.java @@ -1,3 +1,21 @@ +/* +AcceptCallUpdateDialogFragment.java +Copyright (C) 2014 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ package org.linphone; import org.linphone.mediastream.Log; diff --git a/src/org/linphone/InCallActivity.java b/src/org/linphone/InCallActivity.java index 0bee9d86a..3798ce7bf 100644 --- a/src/org/linphone/InCallActivity.java +++ b/src/org/linphone/InCallActivity.java @@ -35,9 +35,7 @@ import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration; import org.linphone.ui.AvatarWithShadow; import org.linphone.ui.Numpad; -import android.annotation.SuppressLint; import android.app.Activity; -import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; @@ -46,7 +44,6 @@ import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; import android.os.SystemClock; -import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; @@ -62,7 +59,6 @@ import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnimationUtils; import android.widget.AdapterView; -import android.widget.Button; import android.widget.Chronometer; import android.widget.ImageView; import android.widget.LinearLayout; diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index 8c2dd9ae7..85bac69d8 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -480,7 +480,14 @@ public class LinphoneManager implements LinphoneCoreListener { TimerTask lTask = new TimerTask() { @Override public void run() { - mLc.iterate(); + UIThreadDispatcher.Dispatch(new Runnable() { + @Override + public void run() { + if (mLc != null) { + mLc.iterate(); + } + } + }); } }; /*use schedule instead of scheduleAtFixedRate to avoid iterate from being call in burst after cpu wake up*/ diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java index 19f74ea5b..87347186b 100644 --- a/src/org/linphone/LinphoneService.java +++ b/src/org/linphone/LinphoneService.java @@ -153,14 +153,19 @@ public final class LinphoneService extends Service implements LinphoneServiceLis } mNotif = Compatibility.createNotification(this, mNotificationTitle, "", R.drawable.status_level, IC_LEVEL_OFFLINE, bm, mNotifContentIntent, true); - LinphoneManager.createAndStart(this, this); + UIThreadDispatcher.Dispatch(new Runnable() { + @Override + public void run() { + LinphoneManager.createAndStart(LinphoneService.this, LinphoneService.this); + } + }); + mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (Version.sdkAboveOrEqual(Version.API12_HONEYCOMB_MR1_31X)) { startWifiLock(); } instance = this; // instance is ready once linphone manager has been created - // Retrieve methods to publish notification and keep Android // from killing us and keep the audio quality high. if (Version.sdkStrictlyBelow(Version.API05_ECLAIR_20)) { diff --git a/src/org/linphone/UIThreadDispatcher.java b/src/org/linphone/UIThreadDispatcher.java new file mode 100644 index 000000000..c0295c6ef --- /dev/null +++ b/src/org/linphone/UIThreadDispatcher.java @@ -0,0 +1,30 @@ +/* +UIThreadDispatcher.java +Copyright (C) 2014 Belledonne Communications, Grenoble, France + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +package org.linphone; + +import android.os.Handler; +import android.os.Looper; + +public class UIThreadDispatcher { + private static Handler mHandler = new Handler(Looper.getMainLooper()); + + public static void Dispatch(Runnable r) { + mHandler.post(r); + } +}