From 7098d1de327109e9f0d339ccc6c4fb96ef0d66b6 Mon Sep 17 00:00:00 2001 From: plusCubed Date: Sat, 20 Apr 2019 01:26:01 -0700 Subject: [PATCH] Allow "only gmap navigation" without accessibility service --- .../GmapsNavNotificationListener.java | 58 ------------------- .../detection/GmapsNavNotificationListener.kt | 56 ++++++++++++++++++ 2 files changed, 56 insertions(+), 58 deletions(-) delete mode 100644 app/src/main/java/com/pluscubed/velociraptor/detection/GmapsNavNotificationListener.java create mode 100644 app/src/main/java/com/pluscubed/velociraptor/detection/GmapsNavNotificationListener.kt diff --git a/app/src/main/java/com/pluscubed/velociraptor/detection/GmapsNavNotificationListener.java b/app/src/main/java/com/pluscubed/velociraptor/detection/GmapsNavNotificationListener.java deleted file mode 100644 index 8cf0a6c..0000000 --- a/app/src/main/java/com/pluscubed/velociraptor/detection/GmapsNavNotificationListener.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.pluscubed.velociraptor.detection; - -import android.app.Notification; -import android.content.Intent; -import android.service.notification.NotificationListenerService; -import android.service.notification.StatusBarNotification; -import android.text.TextUtils; - -import com.pluscubed.velociraptor.limit.LimitService; -import com.pluscubed.velociraptor.utils.PrefUtils; - -public class GmapsNavNotificationListener extends NotificationListenerService { - - @Override - public void onNotificationPosted(StatusBarNotification sbn) { - if (sbn == null) { - return; - } - - final String packageName = sbn.getPackageName(); - if (TextUtils.isEmpty(packageName) - || !packageName.equals(AppDetectionService.GOOGLE_MAPS_PACKAGE) - || sbn.getNotification().priority != Notification.PRIORITY_MAX - || AppDetectionService.get() == null - || !PrefUtils.isGmapsOnlyInNavigation(this)) { - return; - } - - AppDetectionService.get().setGmapsNavigating(true); - - Intent intent = new Intent(this, LimitService.class); - intent.putExtra(LimitService.EXTRA_NOTIF_START, true); - startService(intent); - } - - @Override - public void onNotificationRemoved(StatusBarNotification sbn) { - if (sbn == null) { - return; - } - - final String packageName = sbn.getPackageName(); - if (TextUtils.isEmpty(packageName) - || !packageName.equals(AppDetectionService.GOOGLE_MAPS_PACKAGE) - || sbn.getNotification().priority != Notification.PRIORITY_MAX - || AppDetectionService.get() == null - || !PrefUtils.isGmapsOnlyInNavigation(this)) { - return; - } - - AppDetectionService.get().setGmapsNavigating(false); - - Intent intent = new Intent(this, LimitService.class); - intent.putExtra(LimitService.EXTRA_NOTIF_CLOSE, true); - startService(intent); - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/pluscubed/velociraptor/detection/GmapsNavNotificationListener.kt b/app/src/main/java/com/pluscubed/velociraptor/detection/GmapsNavNotificationListener.kt new file mode 100644 index 0000000..7a7fb43 --- /dev/null +++ b/app/src/main/java/com/pluscubed/velociraptor/detection/GmapsNavNotificationListener.kt @@ -0,0 +1,56 @@ +package com.pluscubed.velociraptor.detection + +import android.app.Notification +import android.content.Intent +import android.service.notification.NotificationListenerService +import android.service.notification.StatusBarNotification +import android.text.TextUtils + +import com.pluscubed.velociraptor.limit.LimitService +import com.pluscubed.velociraptor.utils.PrefUtils + +class GmapsNavNotificationListener : NotificationListenerService() { + + override fun onNotificationPosted(sbn: StatusBarNotification?) { + if (sbn == null) { + return + } + + val packageName = sbn.packageName + if (TextUtils.isEmpty(packageName) + || packageName != AppDetectionService.GOOGLE_MAPS_PACKAGE + || sbn.notification.priority != Notification.PRIORITY_MAX + || !PrefUtils.isGmapsOnlyInNavigation(this) + ) { + return + } + + AppDetectionService.get()?.setGmapsNavigating(true) + + val intent = Intent(this, LimitService::class.java) + intent.putExtra(LimitService.EXTRA_NOTIF_START, true) + startService(intent) + } + + override fun onNotificationRemoved(sbn: StatusBarNotification?) { + if (sbn == null) { + return + } + + val packageName = sbn.packageName + if (TextUtils.isEmpty(packageName) + || packageName != AppDetectionService.GOOGLE_MAPS_PACKAGE + || sbn.notification.priority != Notification.PRIORITY_MAX + || !PrefUtils.isGmapsOnlyInNavigation(this) + ) { + return + } + + AppDetectionService.get()?.setGmapsNavigating(false) + + val intent = Intent(this, LimitService::class.java) + intent.putExtra(LimitService.EXTRA_NOTIF_CLOSE, true) + startService(intent) + } + +} \ No newline at end of file