@@ -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 ();
@@ -422,7 +419,7 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
422
419
ls .getVisibilityLs () != VisibilityLs .CLEARABLE &&
423
420
ls .getVisibilityLs () != VisibilityLs .ALL &&
424
421
!qhActiveIncludingActiveScreen && !isOngoing &&
425
- mPm != null && mKm . isKeyguardLocked () ) {
422
+ ! userPresent ) {
426
423
n .extras .putBoolean (NOTIF_EXTRA_ACTIVE_SCREEN , true );
427
424
n .extras .putString (NOTIF_EXTRA_ACTIVE_SCREEN_MODE ,
428
425
ls .getActiveScreenMode ().toString ());
@@ -444,18 +441,40 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
444
441
}
445
442
};
446
443
444
+ private static PowerManager getPowerManager () {
445
+ if (mPm == null ) {
446
+ mPm = (PowerManager ) mContext .getSystemService (Context .POWER_SERVICE );
447
+ }
448
+ return mPm ;
449
+ }
450
+
451
+ private static KeyguardManager getKeyguardManager () {
452
+ if (mKm == null ) {
453
+ mKm = (KeyguardManager ) mContext .getSystemService (Context .KEYGUARD_SERVICE );
454
+ }
455
+ return mKm ;
456
+ }
457
+
458
+ private static TelephonyManager getTelephonyManager () {
459
+ if (mTelephonyManager == null ) {
460
+ mTelephonyManager = (TelephonyManager )
461
+ mContext .getSystemService (Context .TELEPHONY_SERVICE );
462
+ }
463
+ return mTelephonyManager ;
464
+ }
465
+
447
466
private static boolean isUserPresent () {
448
467
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 );
468
+ final boolean interactive =
469
+ getPowerManager (). isInteractive () &&
470
+ ! getKeyguardManager (). isKeyguardLocked ( );
471
+ final int callState = getTelephonyManager (). getCallState ();
472
+ if ( DEBUG ) log ( "isUserPresent: interactive=" + interactive +
473
+ "; call state= " + callState );
474
+ return (interactive || callState == TelephonyManager .CALL_STATE_OFFHOOK );
456
475
} catch (Throwable t ) {
457
476
GravityBox .log (TAG , t );
458
- return mUserPresent ;
477
+ return false ;
459
478
}
460
479
}
461
480
@@ -574,14 +593,13 @@ private static boolean shouldIgnoreUpdatedNotificationLight(Object record, boole
574
593
}
575
594
576
595
private static XC_MethodHook applyZenModeHook = new XC_MethodHook () {
577
- @ SuppressWarnings ("deprecation" )
578
596
@ Override
579
597
protected void afterHookedMethod (final MethodHookParam param ) throws Throwable {
580
598
try {
581
599
Notification n = (Notification ) XposedHelpers .callMethod (param .args [0 ], "getNotification" );
582
600
if (!n .extras .containsKey (NOTIF_EXTRA_ACTIVE_SCREEN ) ||
583
601
!n .extras .containsKey (NOTIF_EXTRA_ACTIVE_SCREEN_MODE ) ||
584
- !( mPm != null && ! mPm . isScreenOn () && mKm . isKeyguardLocked () )) {
602
+ isUserPresent ( )) {
585
603
n .extras .remove (NOTIF_EXTRA_ACTIVE_SCREEN );
586
604
return ;
587
605
}
@@ -689,15 +707,11 @@ private static void updateActiveScreenFeature() {
689
707
try {
690
708
final boolean enable = !mUncLocked && mUncActiveScreenEnabled ;
691
709
if (enable && mSm == null ) {
692
- mPm = (PowerManager ) mContext .getSystemService (Context .POWER_SERVICE );
693
- mKm = (KeyguardManager ) mContext .getSystemService (Context .KEYGUARD_SERVICE );
694
710
mSm = (SensorManager ) mContext .getSystemService (Context .SENSOR_SERVICE );
695
711
mProxSensor = mSm .getDefaultSensor (Sensor .TYPE_PROXIMITY );
696
712
} else if (!enable ) {
697
713
mProxSensor = null ;
698
714
mSm = null ;
699
- mPm = null ;
700
- mKm = null ;
701
715
}
702
716
if (DEBUG ) log ("Active screen feature: " + enable );
703
717
} catch (Throwable t ) {
@@ -711,7 +725,7 @@ private static void performActiveScreen() {
711
725
public void run () {
712
726
long ident = Binder .clearCallingIdentity ();
713
727
try {
714
- XposedHelpers .callMethod (mPm , "wakeUp" , SystemClock .uptimeMillis ());
728
+ XposedHelpers .callMethod (getPowerManager () , "wakeUp" , SystemClock .uptimeMillis ());
715
729
mScreenOnDueToActiveScreen = true ;
716
730
} finally {
717
731
Binder .restoreCallingIdentity (ident );
0 commit comments