Changes to call Service.startForeground sooner

This commit is contained in:
Sylvain Berfini 2019-05-06 10:18:23 +02:00
parent 630876fa8d
commit 3e95ed8ed4
3 changed files with 15 additions and 11 deletions

View file

@ -192,18 +192,20 @@ public final class LinphoneService extends Service {
return START_STICKY; return START_STICKY;
} }
mNotificationManager = new NotificationsManager(this);
if (Version.sdkAboveOrEqual(Version.API26_O_80)
&& intent != null
&& intent.getBooleanExtra("ForceStartForeground", false)) {
// We need to call this asap
mNotificationManager.startForeground();
}
mLinphoneManager = new LinphoneManager(this); mLinphoneManager = new LinphoneManager(this);
sInstance = this; // sInstance is ready once linphone manager has been created sInstance = this; // sInstance is ready once linphone manager has been created
mLinphoneManager.startLibLinphone(isPush); mLinphoneManager.startLibLinphone(isPush);
LinphoneManager.getCore().addListener(mListener); LinphoneManager.getCore().addListener(mListener);
mNotificationManager = new NotificationsManager(this); mNotificationManager.onCoreReady();
if (Version.sdkAboveOrEqual(Version.API26_O_80)
&& intent != null
&& intent.getBooleanExtra("ForceStartForeground", false)) {
mNotificationManager.startForeground();
}
mContactsManager = new ContactsManager(this, handler); mContactsManager = new ContactsManager(this, handler);
if (!Version.sdkAboveOrEqual(Version.API26_O_80) if (!Version.sdkAboveOrEqual(Version.API26_O_80)

View file

@ -203,7 +203,9 @@ public class NotificationsManager {
} }
} }
}; };
}
public void onCoreReady() {
Core core = LinphoneManager.getCore(); Core core = LinphoneManager.getCore();
if (core != null) { if (core != null) {
core.addListener(mListener); core.addListener(mListener);

View file

@ -41,10 +41,10 @@ public class BootReceiver extends BroadcastReceiver {
android.util.Log.i( android.util.Log.i(
"LinphoneBootReceiver", "Device is starting, auto_start is " + autostart); "LinphoneBootReceiver", "Device is starting, auto_start is " + autostart);
if (autostart && !LinphoneService.isReady()) { if (autostart && !LinphoneService.isReady()) {
Intent linphoneServiceIntent = new Intent(Intent.ACTION_MAIN); Intent serviceIntent = new Intent(Intent.ACTION_MAIN);
linphoneServiceIntent.setClass(context, LinphoneService.class); serviceIntent.setClass(context, LinphoneService.class);
linphoneServiceIntent.putExtra("ForceStartForeground", true); serviceIntent.putExtra("ForceStartForeground", true);
Compatibility.startService(context, linphoneServiceIntent); Compatibility.startService(context, serviceIntent);
} }
} }
} }