diff --git a/app/src/main/java/com/jens/automation2/AutomationService.java b/app/src/main/java/com/jens/automation2/AutomationService.java index 81222d38..c40bae19 100644 --- a/app/src/main/java/com/jens/automation2/AutomationService.java +++ b/app/src/main/java/com/jens/automation2/AutomationService.java @@ -37,9 +37,10 @@ public class AutomationService extends Service implements OnInitListener protected TextToSpeech ttsEngine = null; protected final static int notificationId = 1000; protected final static int notificationIdRestrictions = 1005; + protected final static int notificationIdLocationRestriction = 1006; final static String NOTIFICATION_CHANNEL_ID = "com.jens.automation2"; - final static String channelName = "Automation notifications"; + final static String channelName = "Service notification"; protected static Notification myNotification; protected static NotificationCompat.Builder notificationBuilder = null; @@ -365,7 +366,10 @@ public class AutomationService extends Service implements OnInitListener Intent intent = new Intent(AutomationService.this, ActivityPermissions.class); PendingIntent pi = PendingIntent.getActivity(AutomationService.this, 0, intent, 0); - Miscellaneous.createDismissableNotification(getResources().getString(R.string.appRunningInLimitedMode), ActivityPermissions.notificationIdPermissions, pi); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) + Miscellaneous.createDismissableNotificationWithDelay(1010, getResources().getString(R.string.appRunningInLimitedMode), ActivityPermissions.notificationIdPermissions, pi); + else + Miscellaneous.createDismissableNotification(getResources().getString(R.string.appRunningInLimitedMode), ActivityPermissions.notificationIdPermissions, pi); } // else // Toast.makeText(Miscellaneous.getAnyContext(), "Have all required permissions.", Toast.LENGTH_LONG).show(); @@ -385,15 +389,18 @@ public class AutomationService extends Service implements OnInitListener Intent intent = new Intent(AutomationService.this, ActivityMainTabLayout.class); PendingIntent pi = PendingIntent.getActivity(AutomationService.this, 0, intent, 0); // Miscellaneous.createDismissableNotification(getResources().getString(R.string.settingsReferringToRestrictedFeatures), ActivityPermissions.notificationIdPermissions, pi); - Miscellaneous.createDismissableNotification(getResources().getString(R.string.settingsReferringToRestrictedFeatures), notificationIdRestrictions, pi); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) + Miscellaneous.createDismissableNotificationWithDelay(3300, getResources().getString(R.string.settingsReferringToRestrictedFeatures), notificationIdRestrictions, pi); + else + Miscellaneous.createDismissableNotification(getResources().getString(R.string.settingsReferringToRestrictedFeatures), notificationIdRestrictions, pi); } } } protected void checkForMissingBackgroundLocationPermission() { -// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) -// { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) + { if (BuildConfig.FLAVOR.equalsIgnoreCase("googlePlayFlavor")) { if (Rule.isAnyRuleUsing(Trigger_Enum.pointOfInterest)) @@ -401,10 +408,13 @@ public class AutomationService extends Service implements OnInitListener Intent intent = new Intent(AutomationService.this, ActivityDisplayLongMessage.class); intent.putExtra("longMessage", getResources().getString(R.string.locationEngineDisabledLong)); PendingIntent pi = PendingIntent.getActivity(AutomationService.this, 0, intent, 0); - Miscellaneous.createDismissableNotification(getResources().getString(R.string.locationEngineDisabledShort), notificationIdRestrictions, pi); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) + Miscellaneous.createDismissableNotificationWithDelay(2200, getResources().getString(R.string.locationEngineDisabledShort), notificationIdLocationRestriction, pi); + else + Miscellaneous.createDismissableNotification(getResources().getString(R.string.locationEngineDisabledShort), notificationIdLocationRestriction, pi); } } -// } + } } public static void startAutomationService(Context context, boolean startAtBoot) diff --git a/app/src/main/java/com/jens/automation2/Miscellaneous.java b/app/src/main/java/com/jens/automation2/Miscellaneous.java index 07079e27..5f392d48 100644 --- a/app/src/main/java/com/jens/automation2/Miscellaneous.java +++ b/app/src/main/java/com/jens/automation2/Miscellaneous.java @@ -14,6 +14,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; +import android.os.AsyncTask; import android.os.Build; import android.os.Environment; import android.os.IBinder; @@ -766,10 +767,63 @@ public class Miscellaneous extends Service return allHostsValid; } + @SuppressLint("NewApi") + @SuppressWarnings("deprecation") + public static void createDismissableNotificationWithDelay(long delay, String textToDisplay, int notificationId, PendingIntent pendingIntent) + { + /* + Now what's this about? + From SDK 27 onwards you can only fire 1 notification per second: + https://developer.android.com/about/versions/oreo/android-8.1?hl=bn#notify + + There are some situations where the service is just being started - resulting in a notification. But we have + additional need to inform the user about something and want to create another notification. That's why we have + to delay it for a moment, but don't want to hold off the main threat. + */ + + class AsyncTaskCreateNotification extends AsyncTask + { + @Override + protected Void doInBackground(Void... voids) + { + setDefaultBehaviour(this); + + try + { + Thread.sleep(delay); + } + catch(Exception e) + {} + + createDismissableNotification(textToDisplay, notificationId, pendingIntent); + + return null; + } + } + + AsyncTaskCreateNotification astCn = new AsyncTaskCreateNotification(); + astCn.execute(null, null); + } + + private static void setDefaultBehaviour(AsyncTask asyncTask) + { + // without this line debugger will - for some reason - skip all breakpoints in this class + if(android.os.Debug.isDebuggerConnected()) + android.os.Debug.waitForDebugger(); + +// Thread.setDefaultUncaughtExceptionHandler(Miscellaneous.getUncaughtExceptionHandler(activityMainRef, true)); + } + @SuppressLint("NewApi") @SuppressWarnings("deprecation") public static void createDismissableNotification(String textToDisplay, int notificationId, PendingIntent pendingIntent) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + { + createDismissableNotificationSdk26(textToDisplay, notificationId, pendingIntent); + return; + } + NotificationManager mNotificationManager = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder dismissableNotificationBuilder = createDismissableNotificationBuilder(pendingIntent); @@ -781,50 +835,78 @@ public class Miscellaneous extends Service mNotificationManager.notify(notificationId, dismissableNotification); - /*NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) - .setSmallIcon(R.drawable.ic_launcher) // notification icon - .setContentTitle("Notification!") // title for notification - .setContentText("Hello word") // message for notification - .setAutoCancel(true); // clear notification after click - Intent intent = new Intent(this, MainActivity.class); - PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK); - mBuilder.setContentIntent(pi); - NotificationManager mNotificationManager = - (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - mNotificationManager.notify(0, dismissableNotification);*/ + /*NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) + .setSmallIcon(R.drawable.ic_launcher) // notification icon + .setContentTitle("Notification!") // title for notification + .setContentText("Hello word") // message for notification + .setAutoCancel(true); // clear notification after click + Intent intent = new Intent(this, MainActivity.class); + PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK); + mBuilder.setContentIntent(pi); + NotificationManager mNotificationManager = + (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.notify(0, dismissableNotification);*/ } - /*protected static Notification.Builder createDismissableNotificationBuilder() + public static void createDismissableNotificationSdk26(String textToDisplay, int notificationId, PendingIntent pendingIntent) { - Notification.Builder builder = new Notification.Builder(AutomationService.getInstance()); - builder.setContentTitle("Automation"); - builder.setSmallIcon(R.drawable.ic_launcher); - builder.setCategory(Notification.CATEGORY_EVENT); + NotificationManager mNotificationManager = (NotificationManager) AutomationService.getInstance().getSystemService(Context.NOTIFICATION_SERVICE); + + NotificationCompat.Builder builder; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + { + NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Functionality warnings", NotificationManager.IMPORTANCE_DEFAULT); +// chan.setLightColor(Color.BLUE); + chan.enableVibration(false); + chan.setSound(null, null); + chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE); + mNotificationManager.createNotificationChannel(chan); + + builder = new NotificationCompat.Builder(AutomationService.getInstance(), NOTIFICATION_CHANNEL_ID); + } + else + builder = new NotificationCompat.Builder(AutomationService.getInstance()); + +// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) +// builder.setCategory(Notification.CATEGORY_SERVICE); + builder.setWhen(System.currentTimeMillis()); + builder.setContentIntent(pendingIntent); - //static PendingIntent myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, 0); + builder.setContentTitle(AutomationService.getInstance().getResources().getString(R.string.app_name)); + builder.setOnlyAlertOnce(true); - //builder.setContentIntent(myPendingIntent); + if(Settings.showIconWhenServiceIsRunning) + builder.setSmallIcon(R.drawable.ic_launcher); -// Notification defaultNotification = new Notification(); -*//* Notification defaultNotification = builder.build(); + builder.setContentText(textToDisplay); + builder.setStyle(new NotificationCompat.BigTextStyle().bigText(textToDisplay)); - defaultNotification.icon = R.drawable.ic_launcher; - defaultNotification.when = System.currentTimeMillis(); + NotificationManager notificationManager = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE); + notificationManager.notify(1, builder.build()); -// defaultNotification.defaults |= Notification.DEFAULT_VIBRATE; -// defaultNotification.defaults |= Notification.DEFAULT_LIGHTS; - defaultNotification.flags |= Notification.FLAG_AUTO_CANCEL; -// defaultNotification.flags |= Notification.FLAG_SHOW_LIGHTS; - defaultNotification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; - -// defaultNotification.ledARGB = Color.YELLOW; -// defaultNotification.ledOnMS = 1500; -// defaultNotification.ledOffMS = 1500; -*//* - return builder; - }*/ +// Intent notifyIntent = new Intent(context, notification.class); +// notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); +// +// pendingIntent.getIntentSender().g +// +// PendingIntent pendingIntent = PendingIntent.getActivities(context, 0, +// new Intent[]{notifyIntent}, PendingIntent.FLAG_UPDATE_CURRENT); +// +// Notification notification = new Notification.Builder(Miscellaneous.getAnyContext()) +// .setSmallIcon(android.R.drawable.ic_dialog_info) +// .setContentTitle("Automation") +// .setContentText(textToDisplay) +// .setAutoCancel(true) +// .setContentIntent(pendingIntent) +// .build(); +// notification.defaults |= Notification.DEFAULT_SOUND; +// NotificationManager notificationManager = +// (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE); +// notificationManager.notify(1, notification); + } protected static NotificationCompat.Builder createDismissableNotificationBuilder(PendingIntent myPendingIntent) { diff --git a/app/src/main/java/com/jens/automation2/location/CellLocationChangedReceiver.java b/app/src/main/java/com/jens/automation2/location/CellLocationChangedReceiver.java index bdd85e97..9ac60fd5 100644 --- a/app/src/main/java/com/jens/automation2/location/CellLocationChangedReceiver.java +++ b/app/src/main/java/com/jens/automation2/location/CellLocationChangedReceiver.java @@ -114,7 +114,14 @@ public class CellLocationChangedReceiver extends PhoneStateListener myLocationManager = (LocationManager) AutomationService.getInstance().getSystemService(Context.LOCATION_SERVICE); currentLocation = getLocation("coarse"); - AutomationService.getInstance().getLocationProvider().setCurrentLocation(currentLocation, false); + try + { + AutomationService.getInstance().getLocationProvider().setCurrentLocation(currentLocation, false); + } + catch(NullPointerException e) + { + Miscellaneous.logEvent("e", "LocationProvider", "Location provider is null: " + Log.getStackTraceString(e), 1); + } } else { @@ -123,7 +130,6 @@ public class CellLocationChangedReceiver extends PhoneStateListener } } - public Location getLocation(String accuracy) { Criteria crit = new Criteria(); diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 2f38be06..656dd5d7 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -596,5 +596,5 @@ veröffentlicht am Automation benutzt jetzt ein anderes Verzeichnis, um Ihre Daten zu speichern. Alle Ihre Automation-Dateien wurden hierhin verschoben: \"%s\". Die Berechtigung für den externen Speicher wird nun nicht mehr benötigt; Sie können Sie entfernen. In einer künftigen Version wird sie entfernt werden. Die Position kann nicht mehr bestimmt werden. - Beginnend mit Android 10 wurde eine neue Berechtigung eingeführt, die benötigt wird, um als App die Position auch im Hintergrund bestimmen zu können, was, für eine App wie diese, natürlich notwendig ist.
Während ich das grundsätzlich für eine gute Idee halte, gilt das nicht für die Schikane, die damit verbunden ist.
Wenn man eine App entwickelt, kann man versuchen sich für diese Berechtigung zu qualifizieren, indem man einen Katalog von Bedingungen erfüllt. Leider wurden neue Versionen meiner Anwendung über einen Zeitraum von drei Monaten immer wieder abgelehnt.
Das lief auf die immer gleiche Art ab:
Ich habe eine neue Version eingereicht, die all diese Anforderungen erfüllt hat.
Googles miserabler Entwickler-Support behauptete ich würde sie nicht einhalten.
Ich habe Beweise geliefert, daß ich alles einhalte.
Ich bekam eine Antwort wie "Ich kann Ihnen nicht weiterhelfen.

Irgendwann habe ich aufgegeben.

Die Folge davon ist nun, daß die Google Play Version keine Positionsbestimmung mehr im Hintergrund durchführen kann. Die Alternative wäre es gewesen, daß die ganze Anwendung aus dem Store fliegt.

Das tut mir sehr leid, aber ich habe mein Bestes gegeben mit einem Kunden\"dienst\" zu diskutieren, der mehrfach beim Turing-Test durchgefallen ist.
Die gute Nachricht - die Anwendung kann es immer noch!
Automation ist nun Open Source Software und kann ab sofort bei F-Droid heruntergeladen werden. F-Droid ist ein freier Appstore, der Ihre Privatsphäre respektiert - statt nur so zu tun wie Google das macht.
Deinstallieren Sie dazu diese Anwendung und installieren Sie sich bei F-Droid neu. Klicken Sie hier, um mehr herauszufinden.]]>
+ Leider kann die Position nicht mehr bestimmt werden. Großer Dank dafür geht an Google für seine unendliche Weisheit und Großzügigkeit.
Beginnend mit Android 10 wurde eine neue Berechtigung eingeführt, die benötigt wird, um als App die Position auch im Hintergrund bestimmen zu können, was, für eine App wie diese, natürlich notwendig ist.
Während ich das grundsätzlich für eine gute Idee halte, gilt das nicht für die Schikane, die damit verbunden ist.
Wenn man eine App entwickelt, kann man versuchen sich für diese Berechtigung zu qualifizieren, indem man einen Katalog von Bedingungen erfüllt. Leider wurden neue Versionen meiner Anwendung über einen Zeitraum von drei Monaten immer wieder abgelehnt.
Das lief auf die immer gleiche Art ab:
Ich habe eine neue Version eingereicht, die all diese Anforderungen erfüllt hat.
Googles miserabler Entwickler-Support behauptete ich würde sie nicht einhalten.
Ich habe Beweise geliefert, daß ich alles einhalte.
Ich bekam eine Antwort wie "Ich kann Ihnen nicht weiterhelfen.

Irgendwann habe ich aufgegeben.

Die Folge davon ist nun, daß die Google Play Version keine Positionsbestimmung mehr im Hintergrund durchführen kann. Die Alternative wäre es gewesen, daß die ganze Anwendung aus dem Store fliegt.

Das tut mir sehr leid, aber ich habe mein Bestes gegeben mit einem Kunden\"dienst\" zu diskutieren, der mehrfach beim Turing-Test durchgefallen ist.
Die gute Nachricht - die Anwendung kann es immer noch!
Automation ist nun Open Source Software und kann ab sofort bei F-Droid heruntergeladen werden. F-Droid ist ein freier Appstore, der Ihre Privatsphäre respektiert - statt nur so zu tun wie Google das macht.
Deinstallieren Sie dazu diese Anwendung und installieren Sie sich bei F-Droid neu. Klicken Sie hier, um mehr herauszufinden: https://f-droid.org/en/packages/com.jens.automation2/
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d2635a51..01ba3d29 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -608,5 +608,5 @@ Automation now uses another path to store your files. All your Automation-files have been moved here: \"%s\". The external storage permission is not required anymore; you can revoke it. It will be removed in a future version. Would you like to receive (only important) news about this app on the main screen? Those are downloaded from the developer\'s website. There will be no intrusive notification, just a text on the main screen when you open the app. Location cannot be determined anymore. - Let me explain this further. Starting with Android 10 a new permission was introduced that is needed to determine your location in the background (which of course is required for an app like this). Whilst I consider that a good idea the chicanery it involves are not.
When developing an app you can try to qualify for this permission by abiding to a catalog of requirements. Unfortunately new versions of my app have been rejected over a period three months. I fulfilled all these requirements, Google\'s shitty development support claimed I would not. After giving them proof that I did after all - I got a response like \"I cannot help you anymore\". Eventually I gave up.
As a consequence the Google Play version can NOT use your location as a trigger anymore. The alternative would have been to have this application removed from the store entirely.
I\'m very sorry about that, but I've tried my best arguing with a \"support\" that repeatedly failed to pass the Turing test.
The good news - You can still have it all:
Automation is now open source and can be found in F-Droid. That is an app store that really cares about your privacy - rather than just acting like that. Simply uninstall this app and install it again from F-Droid. Click here to find out more.]]>
+ Unfortunately your location cannot be determined anymore. A debt of gratitude is owed to Google for its infinite wisdom and amiableness.
Let me explain this further. Starting with Android 10 a new permission was introduced that is needed to determine your location in the background (which of course is required for an app like this). Whilst I consider that a good idea the chicanery it involves are not.
When developing an app you can try to qualify for this permission by abiding to a catalog of requirements. Unfortunately new versions of my app have been rejected over a period three months. I fulfilled all these requirements, Google\'s shitty development support claimed I would not. After giving them proof that I did after all - I got a response like \"I cannot help you anymore\". Eventually I gave up.
As a consequence the Google Play version can NOT use your location as a trigger anymore. The alternative would have been to have this application removed from the store entirely.
I\'m very sorry about that, but I\'ve tried my best arguing with a \"support\" that repeatedly failed to pass the Turing test.
The good news - You can still have it all:
Automation is now open source and can be found in F-Droid. That is an app store that really cares about your privacy - rather than just acting like that. Simply uninstall this app and install it again from F-Droid. Click here to find out more: https://f-droid.org/en/packages/com.jens.automation2/
\ No newline at end of file