diff --git a/src/com/ceco/oreo/gravitybox/ModLedControl.java b/src/com/ceco/oreo/gravitybox/ModLedControl.java index 35a482769b..27212d73a9 100644 --- a/src/com/ceco/oreo/gravitybox/ModLedControl.java +++ b/src/com/ceco/oreo/gravitybox/ModLedControl.java @@ -94,7 +94,6 @@ public class ModLedControl { private static Sensor mProxSensor; private static QuietHours mQuietHours; private static Map mNotifTimestamps = new HashMap(); - private static boolean mUserPresent; private static Object mNotifManagerService; private static boolean mProximityWakeUpEnabled; private static boolean mScreenOnDueToActiveScreen; @@ -170,10 +169,8 @@ public void onReceive(Context context, Intent intent) { mQuietHours = new QuietHours(intent.getExtras()); } else if (action.equals(Intent.ACTION_USER_PRESENT)) { if (DEBUG) log("User present"); - mUserPresent = true; mScreenOnDueToActiveScreen = false; } else if (action.equals(Intent.ACTION_SCREEN_OFF)) { - mUserPresent = false; mScreenOnDueToActiveScreen = false; } else if (action.equals(ACTION_CLEAR_NOTIFICATIONS)) { clearNotifications(); @@ -416,13 +413,14 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable { ls.getHeadsUpTimeout()); } // active screen mode - if (ls.getActiveScreenMode() != ActiveScreenMode.DISABLED && + if (mUncActiveScreenEnabled && + ls.getActiveScreenMode() != ActiveScreenMode.DISABLED && !(ls.getActiveScreenIgnoreUpdate() && oldN != null) && getNotificationImportance(param.thisObject) > NotificationManager.IMPORTANCE_MIN && ls.getVisibilityLs() != VisibilityLs.CLEARABLE && ls.getVisibilityLs() != VisibilityLs.ALL && !qhActiveIncludingActiveScreen && !isOngoing && - mPm != null && mKm.isKeyguardLocked()) { + !userPresent) { n.extras.putBoolean(NOTIF_EXTRA_ACTIVE_SCREEN, true); n.extras.putString(NOTIF_EXTRA_ACTIVE_SCREEN_MODE, ls.getActiveScreenMode().toString()); @@ -444,18 +442,40 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable { } }; + private static PowerManager getPowerManager() { + if (mPm == null) { + mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); + } + return mPm; + } + + private static KeyguardManager getKeyguardManager() { + if (mKm == null) { + mKm = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); + } + return mKm; + } + + private static TelephonyManager getTelephonyManager() { + if (mTelephonyManager == null) { + mTelephonyManager = (TelephonyManager) + mContext.getSystemService(Context.TELEPHONY_SERVICE); + } + return mTelephonyManager; + } + private static boolean isUserPresent() { try { - if (mTelephonyManager == null) { - mTelephonyManager = (TelephonyManager) - mContext.getSystemService(Context.TELEPHONY_SERVICE); - } - final int callState = mTelephonyManager.getCallState(); - if (DEBUG) log("isUserPresent: call state: " + callState); - return (mUserPresent || callState == TelephonyManager.CALL_STATE_OFFHOOK); + final boolean interactive = + getPowerManager().isInteractive() && + !getKeyguardManager().isKeyguardLocked(); + final int callState = getTelephonyManager().getCallState(); + if (DEBUG) log("isUserPresent: interactive=" + interactive + + "; call state=" + callState); + return (interactive || callState == TelephonyManager.CALL_STATE_OFFHOOK); } catch (Throwable t) { GravityBox.log(TAG, t); - return mUserPresent; + return false; } } @@ -574,14 +594,14 @@ private static boolean shouldIgnoreUpdatedNotificationLight(Object record, boole } private static XC_MethodHook applyZenModeHook = new XC_MethodHook() { - @SuppressWarnings("deprecation") @Override protected void afterHookedMethod(final MethodHookParam param) throws Throwable { try { Notification n = (Notification) XposedHelpers.callMethod(param.args[0], "getNotification"); - if (!n.extras.containsKey(NOTIF_EXTRA_ACTIVE_SCREEN) || + if (!mUncActiveScreenEnabled || + !n.extras.containsKey(NOTIF_EXTRA_ACTIVE_SCREEN) || !n.extras.containsKey(NOTIF_EXTRA_ACTIVE_SCREEN_MODE) || - !(mPm != null && !mPm.isScreenOn() && mKm.isKeyguardLocked())) { + isUserPresent()) { n.extras.remove(NOTIF_EXTRA_ACTIVE_SCREEN); return; } @@ -689,15 +709,11 @@ private static void updateActiveScreenFeature() { try { final boolean enable = !mUncLocked && mUncActiveScreenEnabled; if (enable && mSm == null) { - mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); - mKm = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); mSm = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); mProxSensor = mSm.getDefaultSensor(Sensor.TYPE_PROXIMITY); } else if (!enable) { mProxSensor = null; mSm = null; - mPm = null; - mKm = null; } if (DEBUG) log("Active screen feature: " + enable); } catch (Throwable t) { @@ -711,7 +727,7 @@ private static void performActiveScreen() { public void run() { long ident = Binder.clearCallingIdentity(); try { - XposedHelpers.callMethod(mPm, "wakeUp", SystemClock.uptimeMillis()); + XposedHelpers.callMethod(getPowerManager(), "wakeUp", SystemClock.uptimeMillis()); mScreenOnDueToActiveScreen = true; } finally { Binder.restoreCallingIdentity(ident);