Single thread for UI, iterate & callbacks

This commit is contained in:
Sylvain Berfini 2014-11-20 12:14:25 +01:00
parent 365d02f226
commit 3b4cc020e9
5 changed files with 63 additions and 7 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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*/

View file

@ -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)) {

View file

@ -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);
}
}