Start foreground not allowed

This commit is contained in:
M66B 2024-04-16 12:39:35 +02:00
parent 96be6d30a1
commit 27e955a13f
3 changed files with 49 additions and 9 deletions

View File

@ -69,7 +69,14 @@ public class ServiceExternal extends ServiceBase {
public void onCreate() { public void onCreate() {
Log.i("Service external create"); Log.i("Service external create");
super.onCreate(); super.onCreate();
startForeground(NotificationHelper.NOTIFICATION_EXTERNAL, getNotification()); try {
startForeground(NotificationHelper.NOTIFICATION_EXTERNAL, getNotification());
} catch (Throwable ex) {
if (Helper.isPlayStoreInstall())
Log.i(ex);
else
Log.e(ex);
}
} }
@Override @Override
@ -92,7 +99,14 @@ public class ServiceExternal extends ServiceBase {
Log.logExtras(intent); Log.logExtras(intent);
super.onStartCommand(intent, flags, startId); super.onStartCommand(intent, flags, startId);
startForeground(NotificationHelper.NOTIFICATION_EXTERNAL, getNotification()); try {
startForeground(NotificationHelper.NOTIFICATION_EXTERNAL, getNotification());
} catch (Throwable ex) {
if (Helper.isPlayStoreInstall())
Log.i(ex);
else
Log.e(ex);
}
if (intent == null) if (intent == null)
return START_NOT_STICKY; return START_NOT_STICKY;

View File

@ -106,7 +106,14 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
public void onCreate() { public void onCreate() {
EntityLog.log(this, "Service send create"); EntityLog.log(this, "Service send create");
super.onCreate(); super.onCreate();
startForeground(NotificationHelper.NOTIFICATION_SEND, getNotificationService(false)); try {
startForeground(NotificationHelper.NOTIFICATION_SEND, getNotificationService(false));
} catch (Throwable ex) {
if (Helper.isPlayStoreInstall())
Log.i(ex);
else
Log.e(ex);
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
retry_max = prefs.getInt("send_retry_max", RETRY_MAX_DEFAULT); retry_max = prefs.getInt("send_retry_max", RETRY_MAX_DEFAULT);
@ -241,7 +248,14 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId); super.onStartCommand(intent, flags, startId);
startForeground(NotificationHelper.NOTIFICATION_SEND, getNotificationService(false)); try {
startForeground(NotificationHelper.NOTIFICATION_SEND, getNotificationService(false));
} catch (Throwable ex) {
if (Helper.isPlayStoreInstall())
Log.i(ex);
else
Log.e(ex);
}
Log.i("Send intent=" + intent); Log.i("Send intent=" + intent);
Log.logExtras(intent); Log.logExtras(intent);

View File

@ -205,8 +205,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
startForeground(NotificationHelper.NOTIFICATION_SYNCHRONIZE, startForeground(NotificationHelper.NOTIFICATION_SYNCHRONIZE,
getNotificationService(null, null)); getNotificationService(null, null));
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); if (Helper.isPlayStoreInstall())
stopSelf(); Log.i(ex);
else
Log.e(ex);
} }
isOptimizing = Boolean.FALSE.equals(Helper.isIgnoringOptimizations(this)); isOptimizing = Boolean.FALSE.equals(Helper.isIgnoringOptimizations(this));
@ -1114,8 +1116,15 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (isBackgroundService(this)) if (isBackgroundService(this))
stopForeground(true); stopForeground(true);
else else
startForeground(NotificationHelper.NOTIFICATION_SYNCHRONIZE, try {
getNotificationService(null, null)); startForeground(NotificationHelper.NOTIFICATION_SYNCHRONIZE,
getNotificationService(null, null));
} catch (Throwable ex) {
if (Helper.isPlayStoreInstall())
Log.i(ex);
else
Log.e(ex);
}
if (action != null) { if (action != null) {
switch (action.split(":")[0]) { switch (action.split(":")[0]) {
@ -3549,7 +3558,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
else else
ContextCompat.startForegroundService(context, intent); ContextCompat.startForegroundService(context, intent);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); if (Helper.isPlayStoreInstall())
Log.i(ex);
else
Log.e(ex);
} }
} }