1
1
package net .kzxiv .notify .client ;
2
2
3
- import android .app .*;
4
- import android .content .*;
5
- import android .content .pm .*;
6
- import android .content .res .*;
7
- import android .graphics .*;
8
- import android .graphics .drawable .*;
9
- import android .net .*;
10
- import android .preference .*;
11
- import android .service .notification .*;
12
- import android .util .*;
13
- import org .json .*;
14
- import java .io .*;
15
- import java .nio .charset .*;
16
- import java .util .Arrays ;
3
+ import android .app .Notification ;
4
+ import android .content .Context ;
5
+ import android .content .Intent ;
6
+ import android .content .SharedPreferences ;
7
+ import android .content .pm .ApplicationInfo ;
8
+ import android .content .pm .PackageManager ;
9
+ import android .content .res .Resources ;
10
+ import android .graphics .Bitmap ;
11
+ import android .graphics .drawable .BitmapDrawable ;
12
+ import android .net .ConnectivityManager ;
13
+ import android .net .NetworkInfo ;
14
+ import android .preference .PreferenceManager ;
15
+ import android .service .notification .NotificationListenerService ;
16
+ import android .service .notification .StatusBarNotification ;
17
+ import android .util .Log ;
18
+
19
+ import org .json .JSONException ;
20
+ import org .json .JSONObject ;
21
+
22
+ import java .io .IOException ;
23
+ import java .nio .charset .Charset ;
17
24
import java .util .HashSet ;
18
25
import java .util .Set ;
19
26
20
27
public class NotificationService extends NotificationListenerService
21
28
{
29
+ private static final String TAG = AppConstants .TAG ;
30
+
22
31
public void onCreate ()
23
32
{
24
33
super .onCreate ();
25
34
PreferenceManager .setDefaultValues (this , R .xml .preferences , false );
26
- Log .d ("Notifikator" , "Notification service created." );
35
+ Log .d (TAG , "Notification service created." );
27
36
}
28
37
29
38
public void onDestroy ()
30
39
{
31
- Log .d ("Notifikator" , "Notification service destroyed." );
40
+ Log .d (TAG , "Notification service destroyed." );
32
41
super .onDestroy ();
33
42
}
34
43
35
44
public void onNotificationPosted (StatusBarNotification sbn )
36
45
{
37
46
// Skip notifications from denied packages
38
- // TODO make user-configurable
39
- final Set <String > packageDenylist = new HashSet <String >(
40
- Arrays . asList ( "org.fdroid.fdroid" , "com.topjohnwu.magisk" , "com.aurora.store" , "com.android.messaging" , "dev.ukanth.ufirewall" , "com.android.packageinstaller" ));
47
+ SharedPreferences sharedPreferences = PreferenceManager . getDefaultSharedPreferences ( getApplicationContext ());
48
+ final Set <String > packageDenylist = sharedPreferences . getStringSet ( AppConstants . PACKAGE_DENY_LIST_PREF_KEY , new HashSet <>());
49
+
41
50
String packageName = sbn .getPackageName ();
42
51
if (packageDenylist .contains (packageName )){
52
+ Log .d (TAG , String .format ("blocked notification for package \" %s\" " , packageName ));
43
53
return ;
44
54
}
45
55
@@ -50,7 +60,7 @@ public void onNotificationPosted(StatusBarNotification sbn)
50
60
51
61
if (!enabled )
52
62
{
53
- Log .i ("Notifikator" , "Skipping notification because not enabled." );
63
+ Log .i (TAG , "Skipping notification because not enabled." );
54
64
return ;
55
65
}
56
66
@@ -63,7 +73,7 @@ public void onNotificationPosted(StatusBarNotification sbn)
63
73
64
74
if (ni == null || ni .getType () != ConnectivityManager .TYPE_WIFI )
65
75
{
66
- Log .i ("Notifikator" , "Skipping notification because not connected to wifi." );
76
+ Log .i (TAG , "Skipping notification because not connected to wifi." );
67
77
return ;
68
78
}
69
79
}
@@ -73,7 +83,7 @@ public void onNotificationPosted(StatusBarNotification sbn)
73
83
74
84
if (endpointUrl == null || "" .equals (endpointUrl ))
75
85
{
76
- Log .e ("Notifikator" , "No endpoint specified." );
86
+ Log .e (TAG , "No endpoint specified." );
77
87
return ;
78
88
}
79
89
@@ -99,7 +109,7 @@ else if (res.getString(R.string.protocol_gotify).equals(protocol))
99
109
100
110
if (payload == null )
101
111
{
102
- Log .e ("Notifikator" , String .format ("No payload or unknown protocol \" %s\" ." , protocol ));
112
+ Log .e (TAG , String .format ("No payload or unknown protocol \" %s\" ." , protocol ));
103
113
return ;
104
114
}
105
115
0 commit comments