Unregister when task is killed and push is disabled and when device shuts down
This commit is contained in:
parent
839353de7a
commit
c58e24aaed
3 changed files with 24 additions and 10 deletions
|
@ -189,6 +189,7 @@
|
||||||
|
|
||||||
<receiver android:name="org.linphone.BootReceiver">
|
<receiver android:name="org.linphone.BootReceiver">
|
||||||
<intent-filter><action android:name="android.intent.action.BOOT_COMPLETED"></action></intent-filter>
|
<intent-filter><action android:name="android.intent.action.BOOT_COMPLETED"></action></intent-filter>
|
||||||
|
<intent-filter><action android:name="android.intent.action.ACTION_SHUTDOWN"></action></intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<receiver android:name="org.linphone.PhoneStateChangedReceiver">
|
<receiver android:name="org.linphone.PhoneStateChangedReceiver">
|
||||||
|
@ -244,8 +245,8 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="org.linphone.tutorials.TutorialCardDavSync"
|
<activity android:name="org.linphone.tutorials.TutorialCardDavSync"
|
||||||
android:theme="@style/NoTitle">
|
android:theme="@style/NoTitle">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
|
@ -18,8 +18,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
package org.linphone;
|
package org.linphone;
|
||||||
|
|
||||||
|
import org.linphone.core.LinphoneCore;
|
||||||
import org.linphone.core.LinphoneCoreFactory;
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
import org.linphone.core.LpConfig;
|
import org.linphone.core.LpConfig;
|
||||||
|
import org.linphone.mediastream.Log;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -29,13 +31,20 @@ public class BootReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_SHUTDOWN)) {
|
||||||
String path = context.getFilesDir().getAbsolutePath() + "/.linphonerc";
|
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
LpConfig lpConfig = LinphoneCoreFactory.instance().createLpConfig(path);
|
if (lc != null) {
|
||||||
if (lpConfig.getBool("app", "auto_start", false)) {
|
Log.w("Device is shutting down, destroying LinphoneCore to unregister");
|
||||||
Intent lLinphoneServiceIntent = new Intent(Intent.ACTION_MAIN);
|
lc.destroy();
|
||||||
lLinphoneServiceIntent.setClass(context, LinphoneService.class);
|
}
|
||||||
context.startService(lLinphoneServiceIntent);
|
} else {
|
||||||
|
String path = context.getFilesDir().getAbsolutePath() + "/.linphonerc";
|
||||||
|
LpConfig lpConfig = LinphoneCoreFactory.instance().createLpConfig(path);
|
||||||
|
if (lpConfig.getBool("app", "auto_start", false)) {
|
||||||
|
Intent lLinphoneServiceIntent = new Intent(Intent.ACTION_MAIN);
|
||||||
|
lLinphoneServiceIntent.setClass(context, LinphoneService.class);
|
||||||
|
context.startService(lLinphoneServiceIntent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -539,7 +539,11 @@ public final class LinphoneService extends Service {
|
||||||
public void onTaskRemoved(Intent rootIntent) {
|
public void onTaskRemoved(Intent rootIntent) {
|
||||||
if (getResources().getBoolean(R.bool.kill_service_with_task_manager)) {
|
if (getResources().getBoolean(R.bool.kill_service_with_task_manager)) {
|
||||||
Log.d("Task removed, stop service");
|
Log.d("Task removed, stop service");
|
||||||
LinphoneManager.getLc().setNetworkReachable(false);
|
|
||||||
|
// If push is enabled, don't unregister account, otherwise do unregister
|
||||||
|
if (LinphonePreferences.instance().isPushNotificationEnabled()) {
|
||||||
|
LinphoneManager.getLc().setNetworkReachable(false);
|
||||||
|
}
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
super.onTaskRemoved(rootIntent);
|
super.onTaskRemoved(rootIntent);
|
||||||
|
|
Loading…
Reference in a new issue