Restart service if foreground service setting is on when app is updated

This commit is contained in:
Sylvain Berfini 2019-10-28 09:30:40 +01:00
parent 426262c3d7
commit 26d61fef4e
4 changed files with 25 additions and 8 deletions

View file

@ -22,6 +22,7 @@ Group changes to describe their impact on the project, as follows:
- Using new AAudio & Camera2 frameworks for better performances (if available) - Using new AAudio & Camera2 frameworks for better performances (if available)
- Android 10 compatibility - Android 10 compatibility
- New plugin loader to be compatible with app bundle distribution mode - New plugin loader to be compatible with app bundle distribution mode
- Restart service if foreground service setting is on when app is updated
## Changed ## Changed
- Improved performances to reduce startup time - Improved performances to reduce startup time

View file

@ -252,9 +252,8 @@
<receiver android:name=".receivers.BootReceiver"> <receiver android:name=".receivers.BootReceiver">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" /> <action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter> </intent-filter>
</receiver> </receiver>

View file

@ -36,17 +36,34 @@ public class BootReceiver extends BroadcastReceiver {
"[Boot Receiver] Device is shutting down, destroying Core to unregister"); "[Boot Receiver] Device is shutting down, destroying Core to unregister");
context.stopService( context.stopService(
new Intent(Intent.ACTION_MAIN).setClass(context, LinphoneService.class)); new Intent(Intent.ACTION_MAIN).setClass(context, LinphoneService.class));
} else { } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
LinphonePreferences.instance().setContext(context); LinphonePreferences.instance().setContext(context);
boolean autostart = LinphonePreferences.instance().isAutoStartEnabled(); boolean autostart = LinphonePreferences.instance().isAutoStartEnabled();
android.util.Log.i( android.util.Log.i(
"Linphone", "[Boot Receiver] Device is starting, auto_start is " + autostart); "Linphone", "[Boot Receiver] Device is starting, auto_start is " + autostart);
if (autostart && !LinphoneService.isReady()) { if (autostart && !LinphoneService.isReady()) {
Intent serviceIntent = new Intent(Intent.ACTION_MAIN); startService(context);
serviceIntent.setClass(context, LinphoneService.class); }
serviceIntent.putExtra("ForceStartForeground", true); } else if (intent.getAction().equalsIgnoreCase(Intent.ACTION_MY_PACKAGE_REPLACED)) {
Compatibility.startService(context, serviceIntent); LinphonePreferences.instance().setContext(context);
boolean foregroundService =
LinphonePreferences.instance().getServiceNotificationVisibility();
android.util.Log.i(
"Linphone",
"[Boot Receiver] App has been updated, foreground service is "
+ foregroundService);
if (foregroundService && !LinphoneService.isReady()) {
startService(context);
} }
} }
} }
private void startService(Context context) {
Intent serviceIntent = new Intent(Intent.ACTION_MAIN);
serviceIntent.setClass(context, LinphoneService.class);
serviceIntent.putExtra("ForceStartForeground", true);
Compatibility.startService(context, serviceIntent);
}
} }