From bbc14193c535160cdb2c35b17fb16c81f4197062 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 2 May 2018 20:13:55 +0200 Subject: [PATCH 1/3] Update target sdk to 26 to test further --- OsmAnd/AndroidManifest.xml | 2 +- OsmAnd/build.gradle | 2 +- OsmAnd/src/net/osmand/plus/AppInitializer.java | 12 ++++++------ OsmAnd/src/net/osmand/plus/api/SQLiteAPIImpl.java | 6 +++++- OsmAnd/src/net/osmand/plus/api/SettingsAPIImpl.java | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index b7237fd462..6eaa64d670 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -40,7 +40,7 @@ - 0) { if (size != file.length() && !firstTime) { if (writeFileSize) { - activity.getPreferences(Context.MODE_WORLD_WRITEABLE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit(); + activity.getPreferences(Context.MODE_PRIVATE).edit().putLong(EXCEPTION_FILE_SIZE, file.length()).commit(); } return true; } } else { if (size > 0) { - activity.getPreferences(Context.MODE_WORLD_WRITEABLE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit(); + activity.getPreferences(Context.MODE_PRIVATE).edit().putLong(EXCEPTION_FILE_SIZE, 0).commit(); } } return false; @@ -262,7 +262,7 @@ public class AppInitializer implements IProgress { public void checkVectorIndexesDownloaded(final Activity ctx) { OsmandApplication app = (OsmandApplication)ctx.getApplication(); MapRenderRepositories maps = app.getResourceManager().getRenderer(); - SharedPreferences pref = ctx.getPreferences(Context.MODE_WORLD_WRITEABLE); + SharedPreferences pref = ctx.getPreferences(Context.MODE_PRIVATE); boolean check = pref.getBoolean(VECTOR_INDEXES_CHECK, true); // do not show each time if (check && new Random().nextInt() % 5 == 1) { @@ -285,7 +285,7 @@ public class AppInitializer implements IProgress { builder.setNeutralButton(R.string.shared_string_no_thanks, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - ctx.getPreferences(Context.MODE_WORLD_WRITEABLE).edit().putBoolean(VECTOR_INDEXES_CHECK, false).commit(); + ctx.getPreferences(Context.MODE_PRIVATE).edit().putBoolean(VECTOR_INDEXES_CHECK, false).commit(); } }); builder.setNegativeButton(R.string.first_time_continue, null); diff --git a/OsmAnd/src/net/osmand/plus/api/SQLiteAPIImpl.java b/OsmAnd/src/net/osmand/plus/api/SQLiteAPIImpl.java index a1f368d89a..e30033785e 100644 --- a/OsmAnd/src/net/osmand/plus/api/SQLiteAPIImpl.java +++ b/OsmAnd/src/net/osmand/plus/api/SQLiteAPIImpl.java @@ -1,6 +1,8 @@ package net.osmand.plus.api; import net.osmand.plus.OsmandApplication; +import android.annotation.SuppressLint; +import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; @@ -12,10 +14,12 @@ public class SQLiteAPIImpl implements SQLiteAPI { this.app = app; } + @SuppressLint("InlinedApi") @Override public SQLiteConnection getOrCreateDatabase(String name, boolean readOnly) { android.database.sqlite.SQLiteDatabase db = app.openOrCreateDatabase(name, - readOnly ? SQLiteDatabase.OPEN_READONLY : (SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING), null); + Context.MODE_PRIVATE | + (readOnly ? 0 : Context.MODE_ENABLE_WRITE_AHEAD_LOGGING), null); if(db == null) { return null; } diff --git a/OsmAnd/src/net/osmand/plus/api/SettingsAPIImpl.java b/OsmAnd/src/net/osmand/plus/api/SettingsAPIImpl.java index b1801f4b33..456d2ba3d4 100644 --- a/OsmAnd/src/net/osmand/plus/api/SettingsAPIImpl.java +++ b/OsmAnd/src/net/osmand/plus/api/SettingsAPIImpl.java @@ -15,7 +15,7 @@ public class SettingsAPIImpl implements SettingsAPI { @Override public Object getPreferenceObject(String key) { - return app.getSharedPreferences(key, Context.MODE_WORLD_READABLE); + return app.getSharedPreferences(key, Context.MODE_PRIVATE); } @Override From 46a5cedf8d681098373f049b59487c164d93e46e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 2 May 2018 20:56:43 +0200 Subject: [PATCH 2/3] Update notification channel id --- .../src/net/osmand/plus/download/DownloadIndexesThread.java | 4 ++-- .../osmand/plus/notifications/NavigationNotification.java | 3 ++- .../net/osmand/plus/notifications/OsmandNotification.java | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index aa0eadd273..ebee76ad00 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -3,6 +3,7 @@ package net.osmand.plus.download; import android.annotation.SuppressLint; import android.app.Activity; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.ActivityNotFoundException; @@ -19,7 +20,6 @@ import android.support.v4.app.NotificationCompat.Builder; import android.support.v7.app.AlertDialog; import android.view.View; import android.widget.Toast; - import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.map.WorldRegion; @@ -113,7 +113,7 @@ public class DownloadIndexesThread { Intent contentIntent = new Intent(app, DownloadActivity.class); PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); - Builder bld = new NotificationCompat.Builder(app); + Builder bld = new NotificationCompat.Builder(app, NotificationChannel.DEFAULT_CHANNEL_ID); String msg = Version.getAppName(app); if(!isFinished) { msg = task.getDescription(); diff --git a/OsmAnd/src/net/osmand/plus/notifications/NavigationNotification.java b/OsmAnd/src/net/osmand/plus/notifications/NavigationNotification.java index 4e981d5822..ffdd0cad52 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/NavigationNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/NavigationNotification.java @@ -10,10 +10,11 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; + import android.os.Build; import android.support.v4.app.NotificationCompat; -import android.support.v4.app.NotificationCompat.BigTextStyle; import android.support.v4.app.NotificationCompat.Builder; +import android.support.v4.app.NotificationCompat.BigTextStyle; import android.view.View; import net.osmand.plus.NavigationService; diff --git a/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java b/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java index db43e602ce..3bdfa6295c 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java @@ -1,13 +1,14 @@ package net.osmand.plus.notifications; +import android.annotation.SuppressLint; import android.app.Notification; +import android.app.NotificationChannel; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.NotificationCompat; - import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; @@ -57,12 +58,13 @@ public abstract class OsmandNotification { this.top = top; } + @SuppressLint("InlinedApi") protected Builder createBuilder(boolean wearable) { Intent contentIntent = new Intent(app, MapActivity.class); PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); - Builder builder = new Builder(app) + Builder builder = new Builder(app, NotificationChannel.DEFAULT_CHANNEL_ID) .setVisibility(android.support.v4.app.NotificationCompat.VISIBILITY_PUBLIC) .setPriority(top ? NotificationCompat.PRIORITY_HIGH : getPriority()) .setOngoing(ongoing && !wearable) From 33202914268e5fd62e723ae6dcd5a56b5aa5e5e0 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 2 May 2018 21:13:59 +0200 Subject: [PATCH 3/3] Update default notification --- .../net/osmand/plus/NotificationHelper.java | 29 +++++++++++++++---- .../plus/download/DownloadIndexesThread.java | 6 +++- .../notifications/OsmandNotification.java | 10 +++++-- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/NotificationHelper.java b/OsmAnd/src/net/osmand/plus/NotificationHelper.java index 9451710b39..8e5e46317b 100644 --- a/OsmAnd/src/net/osmand/plus/NotificationHelper.java +++ b/OsmAnd/src/net/osmand/plus/NotificationHelper.java @@ -1,19 +1,23 @@ package net.osmand.plus; -import android.app.Notification; -import android.support.v4.app.NotificationCompat.Builder; -import android.support.v4.app.NotificationManagerCompat; +import java.util.ArrayList; +import java.util.List; 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; +import android.annotation.TargetApi; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.support.v4.app.NotificationCompat.Builder; +import android.support.v4.app.NotificationManagerCompat; public class NotificationHelper { + public static final String NOTIFICATION_CHANEL_ID = "osmand_background_service"; private OsmandApplication app; private NavigationNotification navigationNotification; @@ -128,4 +132,17 @@ public class NotificationHelper { notification.removeNotification(); } } + + @TargetApi(26) + public void createNotificationChannel() { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANEL_ID, + app.getString(R.string.osmand_service), NotificationManager.IMPORTANCE_LOW); + channel.enableVibration(false); + channel.setDescription(app.getString(R.string.osmand_service_descr)); + NotificationManager mNotificationManager = (NotificationManager) app + .getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.createNotificationChannel(channel); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index ebee76ad00..2d2b63ad11 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -24,6 +24,7 @@ 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; @@ -113,7 +114,10 @@ public class DownloadIndexesThread { Intent contentIntent = new Intent(app, DownloadActivity.class); PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); - Builder bld = new NotificationCompat.Builder(app, NotificationChannel.DEFAULT_CHANNEL_ID); + 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(); diff --git a/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java b/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java index 3bdfa6295c..99df78bb80 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/OsmandNotification.java @@ -3,13 +3,16 @@ package net.osmand.plus.notifications; import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationChannel; +import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationManagerCompat; import android.support.v4.app.NotificationCompat; +import net.osmand.plus.NotificationHelper; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; public abstract class OsmandNotification { @@ -20,6 +23,7 @@ public abstract class OsmandNotification { public final static int WEAR_NAVIGATION_NOTIFICATION_SERVICE_ID = 1005; public final static int WEAR_GPX_NOTIFICATION_SERVICE_ID = 1006; + protected OsmandApplication app; protected boolean ongoing = true; @@ -63,8 +67,10 @@ public abstract class OsmandNotification { Intent contentIntent = new Intent(app, MapActivity.class); PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); - - Builder builder = new Builder(app, NotificationChannel.DEFAULT_CHANNEL_ID) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { + app.getNotificationHelper().createNotificationChannel(); + } + Builder builder = new Builder(app, NotificationHelper.NOTIFICATION_CHANEL_ID) .setVisibility(android.support.v4.app.NotificationCompat.VISIBILITY_PUBLIC) .setPriority(top ? NotificationCompat.PRIORITY_HIGH : getPriority()) .setOngoing(ongoing && !wearable)