Fix in-call notification icon flicker when screen goes on/off

We currently suppress the "in-call" status bar notification if the
InCallScreen is the foreground activity.  This helps reduce clutter in the
status bar, since it's already obvious that you're on a call.

Unfortunately, when the screen is off (like when the prox sensor is
active), the InCallScreen is technically not the foreground activity, so
we *were* enabling the status bar icon in that state.  This was causing a
brief flicker of the status bar icon any time the screen turned on during
a call (like when pulling the phone away from your face.)

The fix is simple: just suppress the notification when the screen is off.
This way the transition from "screen off" to "InCallScreen in foreground"
doesn't cause the notification to change state.

TESTED:

  - While on a call, with in-call UI visible, trigger prox sensor several
    times
    ==> no glitches; icon is never visible.

  - While on a call, bail out to Home screen, then, trigger prox sensor
    several times
    ==> no glitches; icon is steadily visible whenever the screen is on.
        (Specifically, this test shows that this CL has no effect if some
        other app is active.  That's because once you bail out of the
        in-call UI, the updateInCallNotification() method doesn't even get
        called when the screen goes on and off; it's only called for phone
        state transitions, or when the InCallScreen gets paused or
        resumed.  So the notification remains enabled the whole time.)

  - Launched an outgoing call
    ==> no glitches; icon doesn't appear at all (even as a brief flicker)
        during the transition from the dialer to the InCallScreen.

  - Incoming call
    ==> no glitches; icon is visible while ringing (which is WAI),
        disappears cleanly when you answer the call.

Bug: 6021909
Change-Id: I43625f4f69ce75c662c211dadc7292fb14641073
diff --git a/src/com/android/phone/NotificationMgr.java b/src/com/android/phone/NotificationMgr.java
index fc7cc87..613f9b2 100644
--- a/src/com/android/phone/NotificationMgr.java
+++ b/src/com/android/phone/NotificationMgr.java
@@ -29,6 +29,7 @@
 import android.database.Cursor;
 import android.media.AudioManager;
 import android.net.Uri;
+import android.os.PowerManager;
 import android.os.SystemClock;
 import android.os.SystemProperties;
 import android.preference.PreferenceManager;
@@ -91,6 +92,7 @@
     private Context mContext;
     private NotificationManager mNotificationManager;
     private StatusBarManager mStatusBarManager;
+    private PowerManager mPowerManager;
     private Toast mToast;
     private boolean mShowingSpeakerphoneIcon;
     private boolean mShowingMuteIcon;
@@ -128,6 +130,8 @@
                 (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
         mStatusBarManager =
                 (StatusBarManager) app.getSystemService(Context.STATUS_BAR_SERVICE);
+        mPowerManager =
+                (PowerManager) app.getSystemService(Context.POWER_SERVICE);
         mPhone = app.phone;  // TODO: better style to use mCM.getDefaultPhone() everywhere instead
         mCM = app.mCM;
         statusBarHelper = new StatusBarHelper();
@@ -706,6 +710,16 @@
         // call.  (The status bar icon is needed only if you navigate *away*
         // from the in-call UI.)
         boolean suppressNotification = mApp.isShowingCallScreen();
+        // if (DBG) log("- suppressNotification: initial value: " + suppressNotification);
+
+        // Additionally, suppress the notification if the screen is off.
+        // (Of course no UI is visible at this point(!) -- we're doing
+        // this purely to avoid a brief flicker of the icon in the status
+        // bar when the screen turns back on (due to the prox sensor, for
+        // example) while still on the InCallScreen.)
+        boolean isScreenOn = mPowerManager.isScreenOn();
+        // if (DBG) log("  - suppressNotification: isScreenOn = " + isScreenOn);
+        if (!isScreenOn) suppressNotification = true;
 
         // ...except for a couple of cases where we *never* suppress the
         // notification:
@@ -721,10 +735,11 @@
         //   - If "voice privacy" mode is active: always show the notification,
         //     since that's the only "voice privacy" indication we have.
         boolean enhancedVoicePrivacy = mApp.notifier.getVoicePrivacyState();
-        if (DBG) log("updateInCallNotification: enhancedVoicePrivacy = " + enhancedVoicePrivacy);
+        // if (DBG) log("updateInCallNotification: enhancedVoicePrivacy = " + enhancedVoicePrivacy);
         if (enhancedVoicePrivacy) suppressNotification = false;
 
         if (suppressNotification) {
+            if (DBG) log("- suppressNotification = true; reducing clutter in status bar...");
             cancelInCall();
             // Suppress the mute and speaker status bar icons too
             // (also to reduce clutter in the status bar.)
@@ -736,7 +751,6 @@
         // Display the appropriate icon in the status bar,
         // based on the current phone and/or bluetooth state.
 
-
         if (hasRingingCall) {
             // There's an incoming ringing call.
             resId = R.drawable.stat_sys_phone_call_ringing;