54
54
import android .os .SystemClock ;
55
55
import android .provider .Settings ;
56
56
import android .service .notification .StatusBarNotification ;
57
+ import android .telephony .TelephonyManager ;
57
58
import de .robv .android .xposed .XC_MethodHook ;
58
59
import de .robv .android .xposed .XSharedPreferences ;
59
60
import de .robv .android .xposed .XposedBridge ;
@@ -99,6 +100,7 @@ public class ModLedControl {
99
100
private static boolean mScreenOnDueToActiveScreen ;
100
101
private static AudioManager mAudioManager ;
101
102
private static Constructor <?> mNotificationLightConstructor ;
103
+ private static TelephonyManager mTelephonyManager ;
102
104
103
105
// UNC settings
104
106
private static boolean mUncLocked ;
@@ -290,6 +292,7 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
290
292
Object oldRecord = getOldNotificationRecord (sbn .getKey ());
291
293
Notification oldN = getNotificationFromRecord (oldRecord );
292
294
final String pkgName = sbn .getPackageName ();
295
+ final boolean userPresent = isUserPresent ();
293
296
294
297
LedSettings ls ;
295
298
if (n .extras .containsKey ("gbUncPreviewNotification" )) {
@@ -301,18 +304,18 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
301
304
if (!ls .getEnabled ()) {
302
305
// use default settings in case they are active
303
306
ls = resolveLedSettings ("default" );
304
- if (!ls .getEnabled () && !mQuietHours .quietHoursActive (ls , n , mUserPresent )) {
307
+ if (!ls .getEnabled () && !mQuietHours .quietHoursActive (ls , n , userPresent )) {
305
308
return ;
306
309
}
307
310
}
308
311
if (DEBUG ) log (pkgName + ": " + ls .toString ());
309
312
}
310
313
311
- final boolean qhActive = mQuietHours .quietHoursActive (ls , n , mUserPresent );
314
+ final boolean qhActive = mQuietHours .quietHoursActive (ls , n , userPresent );
312
315
final boolean qhActiveIncludingLed = qhActive && mQuietHours .muteLED ;
313
316
final boolean qhActiveIncludingVibe = qhActive && (
314
317
(mQuietHours .mode != QuietHours .Mode .WEAR && mQuietHours .muteVibe ) ||
315
- (mQuietHours .mode == QuietHours .Mode .WEAR && mUserPresent ));
318
+ (mQuietHours .mode == QuietHours .Mode .WEAR && userPresent ));
316
319
final boolean qhActiveIncludingActiveScreen = qhActive && !mUncActiveScreenIgnoreQh ;
317
320
if (DEBUG ) log ("qhActive=" + qhActive + "; qhActiveIncludingLed=" + qhActiveIncludingLed +
318
321
"; qhActiveIncludingVibe=" + qhActiveIncludingVibe +
@@ -441,6 +444,21 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
441
444
}
442
445
};
443
446
447
+ private static boolean isUserPresent () {
448
+ 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 );
456
+ } catch (Throwable t ) {
457
+ GravityBox .log (TAG , t );
458
+ return mUserPresent ;
459
+ }
460
+ }
461
+
444
462
private static Object createNotificationLight (int color , int onMs , int offMs ) {
445
463
try {
446
464
if (mNotificationLightConstructor == null ) {
0 commit comments