@@ -94,7 +94,6 @@ public class ModLedControl {
94
94
private static Sensor mProxSensor ;
95
95
private static QuietHours mQuietHours ;
96
96
private static Map <String , Long > mNotifTimestamps = new HashMap <String , Long >();
97
- private static boolean mUserPresent ;
98
97
private static Object mNotifManagerService ;
99
98
private static boolean mProximityWakeUpEnabled ;
100
99
private static boolean mScreenOnDueToActiveScreen ;
@@ -170,10 +169,8 @@ public void onReceive(Context context, Intent intent) {
170
169
mQuietHours = new QuietHours (intent .getExtras ());
171
170
} else if (action .equals (Intent .ACTION_USER_PRESENT )) {
172
171
if (DEBUG ) log ("User present" );
173
- mUserPresent = true ;
174
172
mScreenOnDueToActiveScreen = false ;
175
173
} else if (action .equals (Intent .ACTION_SCREEN_OFF )) {
176
- mUserPresent = false ;
177
174
mScreenOnDueToActiveScreen = false ;
178
175
} else if (action .equals (ACTION_CLEAR_NOTIFICATIONS )) {
179
176
clearNotifications ();
@@ -416,13 +413,14 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
416
413
ls .getHeadsUpTimeout ());
417
414
}
418
415
// active screen mode
419
- if (ls .getActiveScreenMode () != ActiveScreenMode .DISABLED &&
416
+ if (mUncActiveScreenEnabled &&
417
+ ls .getActiveScreenMode () != ActiveScreenMode .DISABLED &&
420
418
!(ls .getActiveScreenIgnoreUpdate () && oldN != null ) &&
421
419
getNotificationImportance (param .thisObject ) > NotificationManager .IMPORTANCE_MIN &&
422
420
ls .getVisibilityLs () != VisibilityLs .CLEARABLE &&
423
421
ls .getVisibilityLs () != VisibilityLs .ALL &&
424
422
!qhActiveIncludingActiveScreen && !isOngoing &&
425
- mPm != null && mKm . isKeyguardLocked () ) {
423
+ ! userPresent ) {
426
424
n .extras .putBoolean (NOTIF_EXTRA_ACTIVE_SCREEN , true );
427
425
n .extras .putString (NOTIF_EXTRA_ACTIVE_SCREEN_MODE ,
428
426
ls .getActiveScreenMode ().toString ());
@@ -444,18 +442,40 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
444
442
}
445
443
};
446
444
445
+ private static PowerManager getPowerManager () {
446
+ if (mPm == null ) {
447
+ mPm = (PowerManager ) mContext .getSystemService (Context .POWER_SERVICE );
448
+ }
449
+ return mPm ;
450
+ }
451
+
452
+ private static KeyguardManager getKeyguardManager () {
453
+ if (mKm == null ) {
454
+ mKm = (KeyguardManager ) mContext .getSystemService (Context .KEYGUARD_SERVICE );
455
+ }
456
+ return mKm ;
457
+ }
458
+
459
+ private static TelephonyManager getTelephonyManager () {
460
+ if (mTelephonyManager == null ) {
461
+ mTelephonyManager = (TelephonyManager )
462
+ mContext .getSystemService (Context .TELEPHONY_SERVICE );
463
+ }
464
+ return mTelephonyManager ;
465
+ }
466
+
447
467
private static boolean isUserPresent () {
448
468
try {
449
- if ( mTelephonyManager == null ) {
450
- mTelephonyManager = ( TelephonyManager )
451
- mContext . getSystemService ( Context . TELEPHONY_SERVICE );
452
- }
453
- final int callState = mTelephonyManager . getCallState ();
454
- if ( DEBUG ) log ( "isUserPresent: call state: " + callState );
455
- return (mUserPresent || callState == TelephonyManager .CALL_STATE_OFFHOOK );
469
+ final boolean interactive =
470
+ getPowerManager (). isInteractive () &&
471
+ ! getKeyguardManager (). isKeyguardLocked ( );
472
+ final int callState = getTelephonyManager (). getCallState ();
473
+ if ( DEBUG ) log ( "isUserPresent: interactive=" + interactive +
474
+ "; call state= " + callState );
475
+ return (interactive || callState == TelephonyManager .CALL_STATE_OFFHOOK );
456
476
} catch (Throwable t ) {
457
477
GravityBox .log (TAG , t );
458
- return mUserPresent ;
478
+ return false ;
459
479
}
460
480
}
461
481
@@ -574,14 +594,14 @@ private static boolean shouldIgnoreUpdatedNotificationLight(Object record, boole
574
594
}
575
595
576
596
private static XC_MethodHook applyZenModeHook = new XC_MethodHook () {
577
- @ SuppressWarnings ("deprecation" )
578
597
@ Override
579
598
protected void afterHookedMethod (final MethodHookParam param ) throws Throwable {
580
599
try {
581
600
Notification n = (Notification ) XposedHelpers .callMethod (param .args [0 ], "getNotification" );
582
- if (!n .extras .containsKey (NOTIF_EXTRA_ACTIVE_SCREEN ) ||
601
+ if (!mUncActiveScreenEnabled ||
602
+ !n .extras .containsKey (NOTIF_EXTRA_ACTIVE_SCREEN ) ||
583
603
!n .extras .containsKey (NOTIF_EXTRA_ACTIVE_SCREEN_MODE ) ||
584
- !( mPm != null && ! mPm . isScreenOn () && mKm . isKeyguardLocked () )) {
604
+ isUserPresent ( )) {
585
605
n .extras .remove (NOTIF_EXTRA_ACTIVE_SCREEN );
586
606
return ;
587
607
}
@@ -689,15 +709,11 @@ private static void updateActiveScreenFeature() {
689
709
try {
690
710
final boolean enable = !mUncLocked && mUncActiveScreenEnabled ;
691
711
if (enable && mSm == null ) {
692
- mPm = (PowerManager ) mContext .getSystemService (Context .POWER_SERVICE );
693
- mKm = (KeyguardManager ) mContext .getSystemService (Context .KEYGUARD_SERVICE );
694
712
mSm = (SensorManager ) mContext .getSystemService (Context .SENSOR_SERVICE );
695
713
mProxSensor = mSm .getDefaultSensor (Sensor .TYPE_PROXIMITY );
696
714
} else if (!enable ) {
697
715
mProxSensor = null ;
698
716
mSm = null ;
699
- mPm = null ;
700
- mKm = null ;
701
717
}
702
718
if (DEBUG ) log ("Active screen feature: " + enable );
703
719
} catch (Throwable t ) {
@@ -711,7 +727,7 @@ private static void performActiveScreen() {
711
727
public void run () {
712
728
long ident = Binder .clearCallingIdentity ();
713
729
try {
714
- XposedHelpers .callMethod (mPm , "wakeUp" , SystemClock .uptimeMillis ());
730
+ XposedHelpers .callMethod (getPowerManager () , "wakeUp" , SystemClock .uptimeMillis ());
715
731
mScreenOnDueToActiveScreen = true ;
716
732
} finally {
717
733
Binder .restoreCallingIdentity (ident );
0 commit comments