From 1d07da14b38554fc4d5478639b4460c272bb8a8e Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 18 Jun 2019 18:38:01 +0300 Subject: [PATCH 1/5] Foreground service for downloading maps initial commit --- OsmAnd/AndroidManifest.xml | 5 + OsmAnd/res/values/strings.xml | 1 + .../net/osmand/plus/NotificationHelper.java | 29 +++-- .../net/osmand/plus/OsmandApplication.java | 19 ++++ .../plus/download/DownloadIndexesThread.java | 69 +++-------- .../osmand/plus/download/DownloadService.java | 61 ++++++++++ .../notifications/DownloadNotification.java | 107 ++++++++++++++++++ .../plus/notifications/ErrorNotification.java | 7 ++ .../plus/notifications/GpxNotification.java | 6 + .../notifications/NavigationNotification.java | 6 + .../notifications/OsmandNotification.java | 7 +- 11 files changed, 252 insertions(+), 65 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/download/DownloadService.java create mode 100644 OsmAnd/src/net/osmand/plus/notifications/DownloadNotification.java diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 0ff1017482..1810b1fbe4 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -866,6 +866,11 @@ + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 05d10677eb..23ca4bdf25 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + OsmAnd downloading service Please give us 30 seconds, share feedback and rate our work on Google Play. Rate diff --git a/OsmAnd/src/net/osmand/plus/NotificationHelper.java b/OsmAnd/src/net/osmand/plus/NotificationHelper.java index 1fbcbd83b4..01b18a8e77 100644 --- a/OsmAnd/src/net/osmand/plus/NotificationHelper.java +++ b/OsmAnd/src/net/osmand/plus/NotificationHelper.java @@ -1,14 +1,5 @@ package net.osmand.plus; -import java.util.ArrayList; -import java.util.List; - -import net.osmand.plus.notifications.ErrorNotification; -import net.osmand.plus.notifications.GpxNotification; -import net.osmand.plus.notifications.NavigationNotification; -import net.osmand.plus.notifications.OsmandNotification; -import net.osmand.plus.notifications.OsmandNotification.NotificationType; - import android.annotation.TargetApi; import android.app.Notification; import android.app.NotificationChannel; @@ -19,6 +10,16 @@ import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationManagerCompat; +import net.osmand.plus.notifications.DownloadNotification; +import net.osmand.plus.notifications.ErrorNotification; +import net.osmand.plus.notifications.GpxNotification; +import net.osmand.plus.notifications.NavigationNotification; +import net.osmand.plus.notifications.OsmandNotification; +import net.osmand.plus.notifications.OsmandNotification.NotificationType; + +import java.util.ArrayList; +import java.util.List; + public class NotificationHelper { public static final String NOTIFICATION_CHANEL_ID = "osmand_background_service"; @@ -26,6 +27,7 @@ public class NotificationHelper { private NavigationNotification navigationNotification; private GpxNotification gpxNotification; + private DownloadNotification downloadNotification; private ErrorNotification errorNotification; private List all = new ArrayList<>(); @@ -37,9 +39,11 @@ public class NotificationHelper { private void init() { navigationNotification = new NavigationNotification(app); gpxNotification = new GpxNotification(app); + downloadNotification = new DownloadNotification(app); errorNotification = new ErrorNotification(app); all.add(navigationNotification); all.add(gpxNotification); + all.add(downloadNotification); } @NonNull @@ -59,6 +63,13 @@ public class NotificationHelper { } } + @Nullable + public Notification buildDownloadNotification() { + Builder notificationBuilder = downloadNotification.buildNotification(false); + + return notificationBuilder != null ? notificationBuilder.build() : null; + } + private Notification buildErrorNotification() { removeNotification(errorNotification.getType()); setTopNotification(errorNotification); diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 6edecd3a5b..df3fb10251 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -50,6 +50,7 @@ import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.dialogs.CrashBottomSheetDialogFragment; import net.osmand.plus.dialogs.RateUsBottomSheetDialog; import net.osmand.plus.download.DownloadIndexesThread; +import net.osmand.plus.download.DownloadService; import net.osmand.plus.download.IndexItem; import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.helpers.WaypointHelper; @@ -98,6 +99,7 @@ public class OsmandApplication extends MultiDexApplication { Handler uiHandler; NavigationService navigationService; + DownloadService downloadService; OsmandAidlApi aidlApi; @@ -506,6 +508,14 @@ public class OsmandApplication extends MultiDexApplication { this.navigationService = navigationService; } + public DownloadService getDownloadService() { + return downloadService; + } + + public void setDownloadService(DownloadService downloadService) { + this.downloadService = downloadService; + } + public OsmandAidlApi getAidlApi() { return aidlApi; } @@ -889,6 +899,15 @@ public class OsmandApplication extends MultiDexApplication { //getNotificationHelper().showNotifications(); } + public void startDownloadService() { + final Intent serviceIntent = new Intent(this, DownloadService.class); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(serviceIntent); + } else { + startService(serviceIntent); + } + } public String getLangTranslation(String l) { try { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 015031c9b8..dfcd313edc 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -2,11 +2,7 @@ package net.osmand.plus.download; import android.annotation.SuppressLint; import android.app.Activity; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; import android.content.ActivityNotFoundException; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; @@ -14,8 +10,6 @@ import android.os.AsyncTask; import android.os.AsyncTask.Status; import android.os.StatFs; import android.support.annotation.UiThread; -import android.support.v4.app.NotificationCompat; -import android.support.v4.app.NotificationCompat.Builder; import android.support.v7.app.AlertDialog; import android.view.View; import android.widget.Toast; @@ -25,7 +19,6 @@ import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion.RegionParams; -import net.osmand.plus.NotificationHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.OsmandPreference; @@ -34,6 +27,7 @@ import net.osmand.plus.Version; import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning; import net.osmand.plus.helpers.DatabaseHelper; +import net.osmand.plus.notifications.OsmandNotification; import net.osmand.plus.resources.ResourceManager; import net.osmand.util.Algorithms; @@ -53,7 +47,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; @SuppressLint({ "NewApi", "DefaultLocale" }) public class DownloadIndexesThread { private final static Log LOG = PlatformUtil.getLog(DownloadIndexesThread.class); - private static final int NOTIFICATION_ID = 45; + private OsmandApplication app; private DownloadEvents uiActivity = null; @@ -65,8 +59,7 @@ public class DownloadIndexesThread { private int currentDownloadingItemProgress = 0; private DownloadResources indexes; - private Notification notification; - + public interface DownloadEvents { void newDownloadIndexes(); @@ -109,52 +102,8 @@ public class DownloadIndexesThread { } private void updateNotification() { - if(getCurrentDownloadingItem() != null) { - BasicProgressAsyncTask task = getCurrentRunningTask(); - final boolean isFinished = task == null - || task.getStatus() == AsyncTask.Status.FINISHED; - Intent contentIntent = new Intent(app, DownloadActivity.class); - PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent, - PendingIntent.FLAG_UPDATE_CURRENT); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { - app.getNotificationHelper().createNotificationChannel(); - } - Builder bld = new NotificationCompat.Builder(app, NotificationHelper.NOTIFICATION_CHANEL_ID); - String msg = Version.getAppName(app); - if(!isFinished) { - msg = task.getDescription(); - } - StringBuilder contentText = new StringBuilder(); - List ii = getCurrentDownloadingItems(); - for (IndexItem i : ii) { - if (!isFinished && task.getTag() == i) { - continue; - } - if (contentText.length() > 0) { - contentText.append(", "); - } - contentText.append(i.getVisibleName(app, app.getRegions())); - contentText.append(" ").append(i.getType().getString(app)); - } - bld.setContentTitle(msg).setSmallIcon(android.R.drawable.stat_sys_download) - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setContentText(contentText.toString()) - .setContentIntent(contentPendingIntent).setOngoing(true); - int progress = getCurrentDownloadingItemProgress(); - bld.setProgress(100, Math.max(progress, 0), progress < 0); - notification = bld.build(); - NotificationManager mNotificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE); - mNotificationManager.notify(NOTIFICATION_ID, notification); - } else { - if(notification != null) { - NotificationManager mNotificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE); - mNotificationManager.cancel(NOTIFICATION_ID); - notification = null; - } - } - + app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD); } - @UiThread protected void downloadHasFinished() { @@ -162,6 +111,9 @@ public class DownloadIndexesThread { uiActivity.downloadHasFinished(); } updateNotification(); + if (app.getDownloadService() != null) { + app.getDownloadService().stopService(app); + } } public void initSettingsFirstMap(WorldRegion reg) { @@ -216,6 +168,10 @@ public class DownloadIndexesThread { return res; } + public boolean isDownloading() { + return !getCurrentDownloadingItems().isEmpty() || getCurrentDownloadingItem() != null; + } + public boolean isDownloading(IndexItem item) { if(item == currentDownloadingItem) { return true; @@ -269,6 +225,9 @@ public class DownloadIndexesThread { indexItemDownloading.add(item); } } + if (app.getDownloadService() == null) { + app.startDownloadService(); + } if (currentDownloadingItem == null) { execute(new DownloadIndexesAsyncTask()); } else { diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadService.java b/OsmAnd/src/net/osmand/plus/download/DownloadService.java new file mode 100644 index 0000000000..d0b4a9f4e3 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/download/DownloadService.java @@ -0,0 +1,61 @@ +package net.osmand.plus.download; + +import android.app.Notification; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.Binder; +import android.os.IBinder; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.notifications.OsmandNotification; + + +public class DownloadService extends Service { + + public static class DownloadServiceBinder extends Binder { + + } + + private DownloadServiceBinder binder = new DownloadServiceBinder(); + + @Override + public IBinder onBind(Intent intent) { + return binder; + } + + public void stopService(Context ctx) { + final Intent serviceIntent = new Intent(ctx, DownloadService.class); + ctx.stopService(serviceIntent); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + final OsmandApplication app = (OsmandApplication) getApplication(); + app.setDownloadService(this); + + Notification notification = app.getNotificationHelper().buildDownloadNotification(); + if (notification != null) { + startForeground(OsmandNotification.TOP_NOTIFICATION_SERVICE_ID, notification); + app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD); + } + return START_REDELIVER_INTENT; + } + + @Override + public void onDestroy() { + super.onDestroy(); + final OsmandApplication app = (OsmandApplication) getApplication(); + app.setDownloadService(null); + + // remove notification + stopForeground(Boolean.TRUE); + app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD); + app.runInUIThread(new Runnable() { + @Override + public void run() { + app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD); + } + }, 500); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/notifications/DownloadNotification.java b/OsmAnd/src/net/osmand/plus/notifications/DownloadNotification.java new file mode 100644 index 0000000000..139940e3cf --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/notifications/DownloadNotification.java @@ -0,0 +1,107 @@ +package net.osmand.plus.notifications; + +import android.content.Intent; +import android.os.AsyncTask; +import android.support.v4.app.NotificationCompat; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.Version; +import net.osmand.plus.base.BasicProgressAsyncTask; +import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.download.DownloadIndexesThread; +import net.osmand.plus.download.DownloadService; +import net.osmand.plus.download.IndexItem; + +import java.util.List; + +public class DownloadNotification extends OsmandNotification { + + public final static String GROUP_NAME = "DOWNLOAD"; + + public DownloadNotification(OsmandApplication app) { + super(app, GROUP_NAME); + } + + @Override + public void init() { + } + + @Override + public NotificationType getType() { + return NotificationType.DOWNLOAD; + } + + @Override + public int getPriority() { + return NotificationCompat.PRIORITY_DEFAULT; + } + + @Override + public boolean isActive() { + DownloadService service = app.getDownloadService(); + return isEnabled() && service != null; + } + + @Override + public boolean isEnabled() { + DownloadIndexesThread downloadThread = app.getDownloadThread(); + return downloadThread.isDownloading(); + } + + @Override + public Intent getContentIntent() { + return new Intent(app, DownloadActivity.class); + } + + @Override + public NotificationCompat.Builder buildNotification(boolean wearable) { + if (!isEnabled()) { + return null; + } + icon = android.R.drawable.stat_sys_download; + ongoing = true; + DownloadIndexesThread downloadThread = app.getDownloadThread(); + + if (downloadThread.getCurrentDownloadingItem() == null) { + return null; + } + + BasicProgressAsyncTask task = downloadThread.getCurrentRunningTask(); + final boolean isFinished = task == null || task.getStatus() == AsyncTask.Status.FINISHED; + + NotificationCompat.Builder notificationBuilder = createBuilder(wearable); + String msg = Version.getAppName(app); + if (!isFinished) { + msg = task.getDescription(); + } + StringBuilder contentText = new StringBuilder(); + contentText.append("S "); + List ii = downloadThread.getCurrentDownloadingItems(); + for (IndexItem i : ii) { + if (!isFinished && task.getTag() == i) { + continue; + } + if (contentText.length() > 0) { + contentText.append(", "); + } + contentText.append(i.getVisibleName(app, app.getRegions())); + contentText.append(" ").append(i.getType().getString(app)); + } + notificationBuilder.setContentTitle(msg) + .setContentText(contentText.toString()) + .setOngoing(true); + int progress = downloadThread.getCurrentDownloadingItemProgress(); + notificationBuilder.setProgress(100, Math.max(progress, 0), progress < 0); + return notificationBuilder; + } + + @Override + public int getOsmandNotificationId() { + return DOWNLOAD_NOTIFICATION_SERVICE_ID; + } + + @Override + public int getOsmandWearableNotificationId() { + return WEAR_DOWNLOAD_NOTIFICATION_SERVICE_ID; + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/notifications/ErrorNotification.java b/OsmAnd/src/net/osmand/plus/notifications/ErrorNotification.java index b9c5a794e4..af9a3841c9 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/ErrorNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/ErrorNotification.java @@ -1,11 +1,13 @@ package net.osmand.plus.notifications; +import android.content.Intent; import android.support.v4.app.NotificationCompat; import net.osmand.plus.NavigationService; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.routing.RoutingHelper; @@ -41,6 +43,11 @@ public class ErrorNotification extends OsmandNotification { return true; } + @Override + public Intent getContentIntent() { + return new Intent(app, MapActivity.class); + } + @Override public NotificationCompat.Builder buildNotification(boolean wearable) { String notificationTitle; diff --git a/OsmAnd/src/net/osmand/plus/notifications/GpxNotification.java b/OsmAnd/src/net/osmand/plus/notifications/GpxNotification.java index bd4c5087dc..c56b92027b 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/GpxNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/GpxNotification.java @@ -14,6 +14,7 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.util.Algorithms; @@ -97,6 +98,11 @@ public class GpxNotification extends OsmandNotification { return OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null; } + @Override + public Intent getContentIntent() { + return new Intent(app, MapActivity.class); + } + @Override public void onNotificationDismissed() { if (!wasNoDataDismissed) { diff --git a/OsmAnd/src/net/osmand/plus/notifications/NavigationNotification.java b/OsmAnd/src/net/osmand/plus/notifications/NavigationNotification.java index 4e981d5822..9ad611000d 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/NavigationNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/NavigationNotification.java @@ -21,6 +21,7 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RouteDirectionInfo; @@ -112,6 +113,11 @@ public class NavigationNotification extends OsmandNotification { || (routingHelper.isRoutePlanningMode() && routingHelper.isPauseNavigation()); } + @Override + public Intent getContentIntent() { + return new Intent(app, MapActivity.class); + } + @Override public Builder buildNotification(boolean wearable) { if (!isEnabled()) { diff --git a/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java b/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java index e7ef254fde..96b9b398a4 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java @@ -18,11 +18,13 @@ public abstract class OsmandNotification { public final static int NAVIGATION_NOTIFICATION_SERVICE_ID = 5; public final static int GPX_NOTIFICATION_SERVICE_ID = 6; public final static int ERROR_NOTIFICATION_SERVICE_ID = 7; + public final static int DOWNLOAD_NOTIFICATION_SERVICE_ID = 8; public final static int TOP_NOTIFICATION_SERVICE_ID = 100; public final static int WEAR_NAVIGATION_NOTIFICATION_SERVICE_ID = 1005; public final static int WEAR_GPX_NOTIFICATION_SERVICE_ID = 1006; public final static int WEAR_ERROR_NOTIFICATION_SERVICE_ID = 1007; + public final static int WEAR_DOWNLOAD_NOTIFICATION_SERVICE_ID = 1008; protected OsmandApplication app; @@ -38,6 +40,7 @@ public abstract class OsmandNotification { GPX, GPS, ERROR, + DOWNLOAD, } public OsmandNotification(OsmandApplication app, String groupName) { @@ -65,7 +68,7 @@ public abstract class OsmandNotification { @SuppressLint("InlinedApi") protected Builder createBuilder(boolean wearable) { - Intent contentIntent = new Intent(app, MapActivity.class); + Intent contentIntent = getContentIntent(); PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { @@ -101,6 +104,8 @@ public abstract class OsmandNotification { public abstract boolean isEnabled(); + public abstract Intent getContentIntent(); + public void setupNotification(Notification notification) { } From 0c3621d57aab6fb9fe53223453fc153415e17cc2 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 18 Jun 2019 18:40:23 +0300 Subject: [PATCH 2/5] remove unnecessary changes --- .../src/net/osmand/plus/notifications/DownloadNotification.java | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/notifications/DownloadNotification.java b/OsmAnd/src/net/osmand/plus/notifications/DownloadNotification.java index 139940e3cf..ca4b0a1850 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/DownloadNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/DownloadNotification.java @@ -75,7 +75,6 @@ public class DownloadNotification extends OsmandNotification { msg = task.getDescription(); } StringBuilder contentText = new StringBuilder(); - contentText.append("S "); List ii = downloadThread.getCurrentDownloadingItems(); for (IndexItem i : ii) { if (!isFinished && task.getTag() == i) { From 1ffefa85053451fda39df1899da27e6f9d7b82a9 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 18 Jun 2019 18:45:20 +0300 Subject: [PATCH 3/5] remove unnecessary method calls --- OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index dfcd313edc..e0d470db27 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -169,7 +169,7 @@ public class DownloadIndexesThread { } public boolean isDownloading() { - return !getCurrentDownloadingItems().isEmpty() || getCurrentDownloadingItem() != null; + return !indexItemDownloading.isEmpty() || currentDownloadingItem != null; } public boolean isDownloading(IndexItem item) { From 693aa17ce267fb9b8f4d59b54ddf080a1dd1fbb6 Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 19 Jun 2019 10:20:43 +0300 Subject: [PATCH 4/5] update notification id --- OsmAnd/src/net/osmand/plus/download/DownloadService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadService.java b/OsmAnd/src/net/osmand/plus/download/DownloadService.java index d0b4a9f4e3..206d2e12cc 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadService.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadService.java @@ -36,7 +36,7 @@ public class DownloadService extends Service { Notification notification = app.getNotificationHelper().buildDownloadNotification(); if (notification != null) { - startForeground(OsmandNotification.TOP_NOTIFICATION_SERVICE_ID, notification); + startForeground(OsmandNotification.DOWNLOAD_NOTIFICATION_SERVICE_ID, notification); app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD); } return START_REDELIVER_INTENT; From a31369a55a9cbd5566166970fb47c0c4784d815f Mon Sep 17 00:00:00 2001 From: Chumva Date: Wed, 19 Jun 2019 11:07:14 +0300 Subject: [PATCH 5/5] fix download service recreation --- OsmAnd/src/net/osmand/plus/download/DownloadService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadService.java b/OsmAnd/src/net/osmand/plus/download/DownloadService.java index 206d2e12cc..32b94ae2bb 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadService.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadService.java @@ -39,7 +39,7 @@ public class DownloadService extends Service { startForeground(OsmandNotification.DOWNLOAD_NOTIFICATION_SERVICE_ID, notification); app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD); } - return START_REDELIVER_INTENT; + return START_NOT_STICKY; } @Override