30
30
import de .Maxr1998 .xposed .maxlock .Common ;
31
31
import de .Maxr1998 .xposed .maxlock .util .AppLockHelpers ;
32
32
import de .robv .android .xposed .XC_MethodHook ;
33
- import de .robv .android .xposed .callbacks .XC_LoadPackage ;
34
33
34
+ import static android .os .Build .VERSION .SDK_INT ;
35
35
import static de .Maxr1998 .xposed .maxlock .Common .MAXLOCK_PACKAGE_NAME ;
36
36
import static de .Maxr1998 .xposed .maxlock .hooks .Main .logD ;
37
37
import static de .Maxr1998 .xposed .maxlock .util .AppLockHelpers .IMOD_RESET_ON_HOMESCREEN ;
40
40
import static de .Maxr1998 .xposed .maxlock .util .AppLockHelpers .wasAppClosed ;
41
41
import static de .robv .android .xposed .XposedBridge .log ;
42
42
import static de .robv .android .xposed .XposedHelpers .findAndHookMethod ;
43
- import static de .robv .android .xposed .XposedHelpers .getObjectField ;
44
43
45
44
@ SuppressWarnings ("RedundantThrows" )
46
45
class Apps {
47
46
48
47
private static String launcherPackage ;
49
48
50
- static void init (final XC_LoadPackage . LoadPackageParam lPParam , final SharedPreferences prefsApps , final SharedPreferences prefsHistory ) {
51
- if (!prefsApps .getBoolean (lPParam . packageName , false )) {
52
- initLogging (lPParam , prefsApps , prefsHistory );
49
+ static void init (final String packageName , final Context appContext , final SharedPreferences prefsApps , final SharedPreferences prefsHistory ) {
50
+ if (!prefsApps .getBoolean (packageName , false )) {
51
+ initLogging (packageName , prefsApps , prefsHistory );
53
52
return ;
54
53
}
55
54
try {
@@ -59,21 +58,21 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
59
58
final Activity activity = (Activity ) param .thisObject ;
60
59
String activityName = activity .getClass ().getName ();
61
60
logD ("Started " + activityName + " at " + System .currentTimeMillis ());
62
- if (wasAppClosed (lPParam . packageName , prefsHistory )) {
61
+ if (wasAppClosed (packageName , prefsHistory )) {
63
62
activity .finish ();
64
63
logD ("Finished " + activityName );
65
64
return ;
66
65
}
67
66
if (activityName .equals ("android.app.Activity" ) ||
68
- pass (activity .getTaskId (), lPParam . packageName , activityName , prefsApps , prefsHistory )) {
67
+ pass (activity .getTaskId (), packageName , activityName , prefsApps , prefsHistory )) {
69
68
return ;
70
69
}
71
70
logD ("Show lockscreen for " + activityName );
72
71
Intent i = new Intent ()
73
72
.setComponent (new ComponentName (MAXLOCK_PACKAGE_NAME , MAXLOCK_PACKAGE_NAME + ".ui.LockActivity" ))
74
73
.setFlags (Intent .FLAG_ACTIVITY_NO_ANIMATION | Intent .FLAG_ACTIVITY_REORDER_TO_FRONT )
75
- .putExtra (Common .INTENT_EXTRAS_NAMES , new String []{lPParam . packageName , activityName });
76
- if (prefsApps .getBoolean (lPParam . packageName + Common .APP_FAKE_CRASH_PREFERENCE , false )) {
74
+ .putExtra (Common .INTENT_EXTRAS_NAMES , new String []{packageName , activityName });
75
+ if (prefsApps .getBoolean (packageName + Common .APP_FAKE_CRASH_PREFERENCE , false )) {
77
76
i .putExtra (Common .LOCK_ACTIVITY_MODE , Common .MODE_FAKE_CRASH );
78
77
}
79
78
activity .startActivity (i );
@@ -83,7 +82,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
83
82
@ Override
84
83
protected void beforeHookedMethod (MethodHookParam param ) throws Throwable {
85
84
if ((boolean ) param .args [0 ]) {
86
- if (wasAppClosed (lPParam . packageName , prefsHistory )) {
85
+ if (wasAppClosed (packageName , prefsHistory )) {
87
86
final Activity activity = (Activity ) param .thisObject ;
88
87
activity .finish ();
89
88
logD ("Closed " + activity .getClass ().getName ());
@@ -92,36 +91,42 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
92
91
}
93
92
});
94
93
95
- // Notification content hiding
94
+ final Resources modRes = appContext .getPackageManager ().getResourcesForApplication (MAXLOCK_PACKAGE_NAME );
95
+ final String replacementText = modRes .getString (modRes .getIdentifier ("notification_hidden_by_maxlock" , "string" , MAXLOCK_PACKAGE_NAME ));
96
+ final int mlColor = modRes .getColor (modRes .getIdentifier ("primary_red" , "color" , MAXLOCK_PACKAGE_NAME ));
97
+
98
+ // Notification (content) hiding
96
99
findAndHookMethod (NotificationManager .class , "notify" , String .class , int .class , Notification .class , new XC_MethodHook () {
97
100
@ Override
98
101
protected void beforeHookedMethod (MethodHookParam param ) throws Throwable {
99
- Notification notification = (Notification ) param .args [2 ];
100
102
if (prefsApps .getBoolean (Common .MASTER_SWITCH_ON , true )) {
101
- if (prefsApps .getBoolean (lPParam . packageName + Common .APP_HIDE_NOTIFICATIONS_PREFERENCE , false )) {
102
- logD ("Blocked notification " + param . args [ 1 ] + " from " + lPParam . packageName );
103
+ if (prefsApps .getBoolean (packageName + Common .APP_HIDE_NOTIFICATIONS_PREFERENCE , false )) {
104
+ logD ("Blocked notification from " + packageName );
103
105
param .setResult (null );
104
- } else if (prefsApps .getBoolean (lPParam .packageName + Common .APP_HIDE_NOTIFICATION_CONTENT_PREFERENCE , false )) {
105
- logD ("Hiding content for notification " + param .args [1 ] + " from " + lPParam .packageName );
106
- Context context = (Context ) getObjectField (param .thisObject , "mContext" );
107
- String appName = context .getPackageManager ().getApplicationInfo (lPParam .packageName , 0 ).loadLabel (context .getPackageManager ()).toString ();
108
- Resources modRes = context .getPackageManager ().getResourcesForApplication (MAXLOCK_PACKAGE_NAME );
109
- String replacementText = modRes .getString (modRes .getIdentifier ("notification_hidden_by_maxlock" , "string" , MAXLOCK_PACKAGE_NAME ));
110
- Notification .Builder replacementBuilder = new Notification .Builder (context )
106
+ } else if (prefsApps .getBoolean (packageName + Common .APP_HIDE_NOTIFICATION_CONTENT_PREFERENCE , false )) {
107
+ logD ("Hiding notification content for " + packageName );
108
+ Notification notification = (Notification ) param .args [2 ];
109
+ String appName = appContext .getPackageManager ().getApplicationInfo (packageName , 0 ).loadLabel (appContext .getPackageManager ()).toString ();
110
+ Notification .Builder replacementBuilder = (SDK_INT > Build .VERSION_CODES .O ?
111
+ new Notification .Builder (appContext , notification .getChannelId ()) : new Notification .Builder (appContext ))
111
112
.setContentTitle (appName )
112
113
.setContentText (replacementText )
113
114
.setLights (notification .ledARGB , notification .ledOnMS , notification .ledOffMS )
114
115
.setSound (notification .sound )
115
116
.setContentIntent (notification .contentIntent )
116
117
.setDeleteIntent (notification .deleteIntent )
117
118
.setWhen (notification .when );
118
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
119
- replacementBuilder .setColor (modRes .getColor (modRes .getIdentifier ("primary_red" , "color" , MAXLOCK_PACKAGE_NAME )))
119
+ if (SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
120
+ replacementBuilder .setColor (mlColor )
121
+ .setGroup (notification .getGroup ())
122
+ .setSortKey (notification .getSortKey ())
120
123
.setSound (notification .sound , notification .audioAttributes )
121
124
.setVisibility (Notification .VISIBILITY_SECRET );
122
125
}
123
- if (Build . VERSION . SDK_INT >= Build .VERSION_CODES .M )
126
+ if (SDK_INT >= Build .VERSION_CODES .M )
124
127
replacementBuilder .setSmallIcon (notification .getSmallIcon ());
128
+ if (SDK_INT >= Build .VERSION_CODES .O )
129
+ replacementBuilder .setGroupAlertBehavior (notification .getGroupAlertBehavior ());
125
130
Notification replacement = replacementBuilder .build ();
126
131
replacement .flags = notification .flags ;
127
132
// Replace notification
@@ -135,16 +140,16 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
135
140
}
136
141
}
137
142
138
- private static void initLogging (final XC_LoadPackage . LoadPackageParam lPParam , final SharedPreferences prefsApps , final SharedPreferences prefsHistory ) {
143
+ private static void initLogging (final String packageName , final SharedPreferences prefsApps , final SharedPreferences prefsHistory ) {
139
144
try {
140
- findAndHookMethod ("android.app. Activity" , lPParam . classLoader , "onStart" , new XC_MethodHook () {
145
+ findAndHookMethod (Activity . class , "onStart" , new XC_MethodHook () {
141
146
@ Override
142
147
protected void beforeHookedMethod (MethodHookParam param ) throws Throwable {
143
- addToHistory (((Activity ) param .thisObject ).getTaskId (), lPParam . packageName , prefsHistory );
148
+ addToHistory (((Activity ) param .thisObject ).getTaskId (), packageName , prefsHistory );
144
149
if (launcherPackage == null ) {
145
150
launcherPackage = AppLockHelpers .getLauncherPackage (((Activity ) param .thisObject ).getPackageManager ());
146
151
}
147
- if (lPParam . packageName .equals (launcherPackage ) && prefsApps .getBoolean (IMOD_RESET_ON_HOMESCREEN , false )) {
152
+ if (packageName .equals (launcherPackage ) && prefsApps .getBoolean (IMOD_RESET_ON_HOMESCREEN , false )) {
148
153
prefsHistory .edit ().clear ().apply ();
149
154
logD ("Returned to homescreen, locked apps" );
150
155
}
0 commit comments