From 59c7a2d313dcd9816ce3d585b5f5b21b9570b57f Mon Sep 17 00:00:00 2001 From: jens Date: Mon, 17 Jan 2022 20:09:46 +0100 Subject: [PATCH] Notification channels --- .../jens/automation2/ActivityMainScreen.java | 5 ---- .../jens/automation2/AutomationService.java | 30 +++++++------------ .../com/jens/automation2/Miscellaneous.java | 9 +++++- .../java/com/jens/automation2/Settings.java | 1 + 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/jens/automation2/ActivityMainScreen.java b/app/src/main/java/com/jens/automation2/ActivityMainScreen.java index 722ac78..b74f6aa 100644 --- a/app/src/main/java/com/jens/automation2/ActivityMainScreen.java +++ b/app/src/main/java/com/jens/automation2/ActivityMainScreen.java @@ -3,7 +3,6 @@ package com.jens.automation2; import android.Manifest; import android.annotation.SuppressLint; import android.app.AlertDialog; -import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -11,7 +10,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.util.Log; -import android.util.Xml; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; @@ -29,11 +27,8 @@ import androidx.core.text.HtmlCompat; import com.jens.automation2.AutomationService.serviceCommands; import com.jens.automation2.Trigger.Trigger_Enum; -import com.jens.automation2.location.CellLocationChangedReceiver; import com.jens.automation2.location.LocationProvider; -import java.io.File; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Calendar; diff --git a/app/src/main/java/com/jens/automation2/AutomationService.java b/app/src/main/java/com/jens/automation2/AutomationService.java index 51d4aac..c1c505f 100644 --- a/app/src/main/java/com/jens/automation2/AutomationService.java +++ b/app/src/main/java/com/jens/automation2/AutomationService.java @@ -41,8 +41,6 @@ public class AutomationService extends Service implements OnInitListener protected final static int notificationIdRestrictions = 1005; protected final static int notificationIdLocationRestriction = 1006; -// final static String NOTIFICATION_CHANNEL_ID = "com.jens.automation2"; - final static String NOTIFICATION_CHANNEL_ID_SERVICE = "com.jens.automation2_service"; final static String NOTIFICATION_CHANNEL_NAME_SERVICE = "Service notification"; @@ -73,7 +71,6 @@ public class AutomationService extends Service implements OnInitListener lockSoundChangesEnd = Calendar.getInstance(); lockSoundChangesEnd.add(Calendar.MINUTE, Settings.lockSoundChangesInterval); -// ActivityMainScreen.getActivityMainScreenInstance().updateMainScreen(); } public void checkLockSoundChangesTimeElapsed() @@ -117,18 +114,6 @@ public class AutomationService extends Service implements OnInitListener public boolean checkStartupRequirements(Context context, boolean startAtBoot) { -// if (!ActivityPermissions.havePermission(ActivityPermissions.writeExternalStoragePermissionName, AutomationService.this)) -// { -// /* -// Don't have permission to access external storage. This is a show stopper as -// the configuration file is stored on external storage. -// */ -// Miscellaneous.logEvent("e", "Permission", "Don't have permission to access external storage. Will request it now.", 4); -//// Toast.makeText(AutomationService.this, getResources().getString(R.string.appRequiresPermissiontoAccessExternalStorage), Toast.LENGTH_LONG).show(); -// ActivityPermissions.requestSpecificPermission(ActivityPermissions.writeExternalStoragePermissionName); -// return false; -// } - if(Build.VERSION.SDK_INT >= 28) { if (!ActivityPermissions.havePermission(Manifest.permission.FOREGROUND_SERVICE, AutomationService.this)) @@ -143,10 +128,15 @@ public class AutomationService extends Service implements OnInitListener } } - if (PointOfInterest.getPointOfInterestCollection() == null | PointOfInterest.getPointOfInterestCollection().size() == 0 - | - Rule.getRuleCollection() == null | Rule.getRuleCollection().size() == 0 - ) + if ( + PointOfInterest.getPointOfInterestCollection() == null + || + PointOfInterest.getPointOfInterestCollection().size() == 0 + || + Rule.getRuleCollection() == null + || + Rule.getRuleCollection().size() == 0 + ) { if (startAtBoot) { @@ -181,7 +171,7 @@ public class AutomationService extends Service implements OnInitListener } //if still no POIs... - if (Rule.getRuleCollection() == null | Rule.getRuleCollection().size() == 0) + if (Rule.getRuleCollection() == null || Rule.getRuleCollection().size() == 0) { Miscellaneous.logEvent("w", "AutomationService", context.getResources().getString(R.string.serviceWontStart), 1); Toast.makeText(context, context.getResources().getString(R.string.serviceWontStart), Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index 4f3335e..27b6230 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -85,6 +85,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Scanner; +import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @@ -984,10 +985,16 @@ public class Miscellaneous extends Service { NotificationManager nm = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE); List channels = nm.getNotificationChannels(); - if(channels.size() > 3) + + if(!Settings.hasBeenDone(Settings.constNotificationChannelCleanupApk118) && BuildConfig.VERSION_CODE < 120) { + // Perform a one-time cleanup of notification channels as they have been redesigned. + for(NotificationChannel c : channels) nm.deleteNotificationChannel(c.getId()); + + Settings.considerDone(Settings.constNotificationChannelCleanupApk118); + Settings.writeSettings(Miscellaneous.getAnyContext()); } NotificationChannel channel = findExistingChannel(channels, channelId); diff --git a/app/src/main/java/com/jens/automation2/Settings.java b/app/src/main/java/com/jens/automation2/Settings.java index d1941d7..691bfa8 100644 --- a/app/src/main/java/com/jens/automation2/Settings.java +++ b/app/src/main/java/com/jens/automation2/Settings.java @@ -20,6 +20,7 @@ public class Settings implements SharedPreferences public static final String zipFileName = "automation.zip"; public static final String constNewsOptInDone ="newsOptInDone"; + public static final String constNotificationChannelCleanupApk118 ="notificationChannelCleanupApk118"; public static long minimumDistanceChangeForGpsUpdate; public static long minimumDistanceChangeForNetworkUpdate;