implement keep alive handler every 10mn

This commit is contained in:
Jehan Monnier 2013-03-26 15:59:09 +01:00
parent d74ec55c77
commit a01e7d5837
5 changed files with 19 additions and 4 deletions

View file

@ -122,7 +122,8 @@
<receiver android:name="org.linphone.PhoneStateChangedReceiver"> <receiver android:name="org.linphone.PhoneStateChangedReceiver">
<intent-filter><action android:name="android.intent.action.PHONE_STATE" /></intent-filter> <intent-filter><action android:name="android.intent.action.PHONE_STATE" /></intent-filter>
</receiver> </receiver>
<receiver android:name="KeepAliveHandler" >
</receiver>
<!-- Needed for push notification --> <!-- Needed for push notification -->
<receiver android:name="org.linphone.gcm.GCMReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <receiver android:name="org.linphone.gcm.GCMReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter> <intent-filter>

View file

@ -25,7 +25,9 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
/*
* Purpose of this receiver is to disable keep alives when screen is off
* */
public class KeepAliveReceiver extends BroadcastReceiver { public class KeepAliveReceiver extends BroadcastReceiver {
@Override @Override

View file

@ -576,7 +576,8 @@ public final class LinphoneManager implements LinphoneCoreListener {
mLc.iterate(); mLc.iterate();
} }
}; };
mTimer.scheduleAtFixedRate(lTask, 0, 20); /*use schedule instead of scheduleAtFixedRate to avoid iterate from being call in burst after cpu wake up*/
mTimer.schedule(lTask, 0, 20);
IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON); IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
lFilter.addAction(Intent.ACTION_SCREEN_OFF); lFilter.addAction(Intent.ACTION_SCREEN_OFF);

View file

@ -40,6 +40,7 @@ import org.linphone.mediastream.Log;
import org.linphone.mediastream.Version; import org.linphone.mediastream.Version;
import android.app.Activity; import android.app.Activity;
import android.app.AlarmManager;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
@ -58,6 +59,7 @@ import android.net.wifi.WifiManager.WifiLock;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.SystemClock;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.MediaStore; import android.provider.MediaStore;
@ -112,6 +114,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
private Notification mCustomNotif; private Notification mCustomNotif;
private int mMsgNotifCount; private int mMsgNotifCount;
private PendingIntent mNotifContentIntent; private PendingIntent mNotifContentIntent;
private PendingIntent mkeepAlivePendingIntent;
private String mNotificationTitle; private String mNotificationTitle;
@ -198,6 +201,13 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
} }
LinphoneManager.getLc().setPresenceInfo(0, "", OnlineStatus.Online); LinphoneManager.getLc().setPresenceInfo(0, "", OnlineStatus.Online);
//make sure the application will at least wakes up every 10 mn
Intent intent = new Intent(this, KeepAliveHandler.class);
mkeepAlivePendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
((AlarmManager) this.getSystemService(Context.ALARM_SERVICE)).setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP
, SystemClock.elapsedRealtime()+600000
, 600000
, mkeepAlivePendingIntent);
} }
private enum IncallIconState {INCALL, PAUSE, VIDEO, IDLE} private enum IncallIconState {INCALL, PAUSE, VIDEO, IDLE}
@ -474,6 +484,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
mNM.cancel(INCALL_NOTIF_ID); mNM.cancel(INCALL_NOTIF_ID);
mNM.cancel(MESSAGE_NOTIF_ID); mNM.cancel(MESSAGE_NOTIF_ID);
mWifiLock.release(); mWifiLock.release();
((AlarmManager) this.getSystemService(Context.ALARM_SERVICE)).cancel(mkeepAlivePendingIntent);
super.onDestroy(); super.onDestroy();
} }

@ -1 +1 @@
Subproject commit ecfff5f64d95723ed194bae09b96509aeb778159 Subproject commit 43ad4169d316649ed2e31eba1f9b19792d5cc492