Enable light status bar when top of wallpaper is light.

(Light status bar = dark icons)

Bug: 29452834
Change-Id: I9f61a05d80158827761c8b62ab40fc50971e27a6
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 2b64d42..d059da2 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -277,9 +277,10 @@
     private LauncherAccessibilityDelegate mAccessibilityDelegate;
     private boolean mIsResumeFromActionScreenOff;
     @Thunk boolean mUserPresent = true;
-    private boolean mVisible = false;
-    private boolean mHasFocus = false;
-    private boolean mAttached = false;
+    private boolean mVisible;
+    private boolean mHasFocus;
+    private boolean mAttached;
+    private boolean mIsLightStatusBar;
 
     /** Maps launcher activity components to their list of shortcut ids. */
     private MultiHashMap<ComponentKey, String> mDeepShortcutMap = new MultiHashMap<>();
@@ -488,9 +489,31 @@
             mExtractedColors.load(this);
             mHotseat.updateColor(mExtractedColors, !mPaused);
             mWorkspace.getPageIndicator().updateColor(mExtractedColors);
+            setLightStatusBar(shouldBeLightStatusBar());
         }
     }
 
+    /** Returns whether a light status bar (dark icons) should be used based on the wallpaper. */
+    public boolean shouldBeLightStatusBar() {
+        return mExtractedColors.getColor(ExtractedColors.STATUS_BAR_INDEX,
+                ExtractedColors.DEFAULT_LIGHT) == ExtractedColors.DEFAULT_LIGHT;
+    }
+
+    public void setLightStatusBar(boolean lightStatusBar) {
+        // Already set correctly
+        if (mIsLightStatusBar == lightStatusBar) {
+            return;
+        }
+        mIsLightStatusBar = lightStatusBar;
+        int systemUiFlags = getWindow().getDecorView().getSystemUiVisibility();
+        if (lightStatusBar) {
+            systemUiFlags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
+        } else {
+            systemUiFlags &= ~(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+        }
+        getWindow().getDecorView().setSystemUiVisibility(systemUiFlags);
+    }
+
     private LauncherCallbacks mLauncherCallbacks;
 
     public void onPostCreate(Bundle savedInstanceState) {