mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-06-05 21:49:48 +02:00
Allow ignore notifications from work profile
This commit is contained in:
@@ -35,6 +35,8 @@ import android.media.session.MediaSession;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
import android.os.Process;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
|
|
||||||
@@ -280,6 +282,13 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
if (isServiceNotRunningAndShouldIgnoreNotifications()) return;
|
if (isServiceNotRunningAndShouldIgnoreNotifications()) return;
|
||||||
|
|
||||||
final Prefs prefs = GBApplication.getPrefs();
|
final Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
|
final boolean ignoreWorkProfile = prefs.getBoolean("notifications_ignore_work_profile", false);
|
||||||
|
if (ignoreWorkProfile && isWorkProfile(sbn)) {
|
||||||
|
LOG.debug("Ignoring notification from work profile");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final boolean mediaIgnoresAppList = prefs.getBoolean("notification_media_ignores_application_list", false);
|
final boolean mediaIgnoresAppList = prefs.getBoolean("notification_media_ignores_application_list", false);
|
||||||
|
|
||||||
// If media notifications ignore app list, check them before
|
// If media notifications ignore app list, check them before
|
||||||
@@ -717,6 +726,13 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
if (isServiceNotRunningAndShouldIgnoreNotifications()) return;
|
if (isServiceNotRunningAndShouldIgnoreNotifications()) return;
|
||||||
|
|
||||||
final Prefs prefs = GBApplication.getPrefs();
|
final Prefs prefs = GBApplication.getPrefs();
|
||||||
|
|
||||||
|
final boolean ignoreWorkProfile = prefs.getBoolean("notifications_ignore_work_profile", false);
|
||||||
|
if (ignoreWorkProfile && isWorkProfile(sbn)) {
|
||||||
|
LOG.debug("Ignoring notification removal from work profile");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final boolean mediaIgnoresAppList = prefs.getBoolean("notification_media_ignores_application_list", false);
|
final boolean mediaIgnoresAppList = prefs.getBoolean("notification_media_ignores_application_list", false);
|
||||||
|
|
||||||
// If media notifications ignore app list, check them before
|
// If media notifications ignore app list, check them before
|
||||||
@@ -885,6 +901,11 @@ public class NotificationListener extends NotificationListenerService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isWorkProfile(StatusBarNotification sbn) {
|
||||||
|
final UserHandle currentUser = Process.myUserHandle();
|
||||||
|
return !sbn.getUser().equals(currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
private boolean shouldIgnoreNotification(StatusBarNotification sbn, boolean remove) {
|
private boolean shouldIgnoreNotification(StatusBarNotification sbn, boolean remove) {
|
||||||
Notification notification = sbn.getNotification();
|
Notification notification = sbn.getNotification();
|
||||||
String source = sbn.getPackageName();
|
String source = sbn.getPackageName();
|
||||||
|
@@ -253,6 +253,8 @@
|
|||||||
<string name="pref_title_whenscreenon">…also when screen is on</string>
|
<string name="pref_title_whenscreenon">…also when screen is on</string>
|
||||||
<string name="pref_title_notifications_ignore_low_priority">Ignore low priority notifications</string>
|
<string name="pref_title_notifications_ignore_low_priority">Ignore low priority notifications</string>
|
||||||
<string name="pref_summary_notifications_ignore_low_priority">Do not send low and minimum priority notifications to the watch</string>
|
<string name="pref_summary_notifications_ignore_low_priority">Do not send low and minimum priority notifications to the watch</string>
|
||||||
|
<string name="pref_title_notifications_ignore_work_profile">Ignore work profile notifications</string>
|
||||||
|
<string name="pref_summary_notifications_ignore_work_profile">Do not send notifications from apps in the work profile to the watch</string>
|
||||||
<string name="pref_title_notification_prefer_long_text">Prefer long notification text</string>
|
<string name="pref_title_notification_prefer_long_text">Prefer long notification text</string>
|
||||||
<string name="pref_summary_notification_prefer_long_text">If available, send the long notification text to the device</string>
|
<string name="pref_summary_notification_prefer_long_text">If available, send the long notification text to the device</string>
|
||||||
<string name="pref_title_notification_cache_while_disconnected">Cache while out of range</string>
|
<string name="pref_title_notification_cache_while_disconnected">Cache while out of range</string>
|
||||||
|
@@ -30,6 +30,14 @@
|
|||||||
android:title="@string/pref_title_notifications_ignore_low_priority"
|
android:title="@string/pref_title_notifications_ignore_low_priority"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
|
<SwitchPreferenceCompat
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="notifications_ignore_work_profile"
|
||||||
|
android:layout="@layout/preference_checkbox"
|
||||||
|
android:summary="@string/pref_summary_notifications_ignore_work_profile"
|
||||||
|
android:title="@string/pref_title_notifications_ignore_work_profile"
|
||||||
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="notification_prefer_long_text"
|
android:key="notification_prefer_long_text"
|
||||||
|
Reference in New Issue
Block a user