Skip to content

Commit c2f7abe

Browse files
committed
QH: consider session interactive during phone call
More info GravityBox#1667 (comment)
1 parent 69c45f4 commit c2f7abe

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/com/ceco/oreo/gravitybox/ModLedControl.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import android.os.SystemClock;
5555
import android.provider.Settings;
5656
import android.service.notification.StatusBarNotification;
57+
import android.telephony.TelephonyManager;
5758
import de.robv.android.xposed.XC_MethodHook;
5859
import de.robv.android.xposed.XSharedPreferences;
5960
import de.robv.android.xposed.XposedBridge;
@@ -99,6 +100,7 @@ public class ModLedControl {
99100
private static boolean mScreenOnDueToActiveScreen;
100101
private static AudioManager mAudioManager;
101102
private static Constructor<?> mNotificationLightConstructor;
103+
private static TelephonyManager mTelephonyManager;
102104

103105
// UNC settings
104106
private static boolean mUncLocked;
@@ -290,6 +292,7 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
290292
Object oldRecord = getOldNotificationRecord(sbn.getKey());
291293
Notification oldN = getNotificationFromRecord(oldRecord);
292294
final String pkgName = sbn.getPackageName();
295+
final boolean userPresent = isUserPresent();
293296

294297
LedSettings ls;
295298
if (n.extras.containsKey("gbUncPreviewNotification")) {
@@ -301,18 +304,18 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
301304
if (!ls.getEnabled()) {
302305
// use default settings in case they are active
303306
ls = resolveLedSettings("default");
304-
if (!ls.getEnabled() && !mQuietHours.quietHoursActive(ls, n, mUserPresent)) {
307+
if (!ls.getEnabled() && !mQuietHours.quietHoursActive(ls, n, userPresent)) {
305308
return;
306309
}
307310
}
308311
if (DEBUG) log(pkgName + ": " + ls.toString());
309312
}
310313

311-
final boolean qhActive = mQuietHours.quietHoursActive(ls, n, mUserPresent);
314+
final boolean qhActive = mQuietHours.quietHoursActive(ls, n, userPresent);
312315
final boolean qhActiveIncludingLed = qhActive && mQuietHours.muteLED;
313316
final boolean qhActiveIncludingVibe = qhActive && (
314317
(mQuietHours.mode != QuietHours.Mode.WEAR && mQuietHours.muteVibe) ||
315-
(mQuietHours.mode == QuietHours.Mode.WEAR && mUserPresent));
318+
(mQuietHours.mode == QuietHours.Mode.WEAR && userPresent));
316319
final boolean qhActiveIncludingActiveScreen = qhActive && !mUncActiveScreenIgnoreQh;
317320
if (DEBUG) log("qhActive=" + qhActive + "; qhActiveIncludingLed=" + qhActiveIncludingLed +
318321
"; qhActiveIncludingVibe=" + qhActiveIncludingVibe +
@@ -441,6 +444,21 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
441444
}
442445
};
443446

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+
444462
private static Object createNotificationLight(int color, int onMs, int offMs) {
445463
try {
446464
if (mNotificationLightConstructor == null) {

0 commit comments

Comments
 (0)