+ if (screenState == Display.STATE_UNKNOWN) {
+ // We'll keep it in the existing state
+ return;
+ }
+ boolean messagePending = mHandler.hasCallbacks(mApplyPendingScreenState);
+ if (messagePending || oldState == DozeMachine.State.INITIALIZED) {
+ // During initialization, we hide the navigation bar. That is however only applied after
+ // a traversal; setting the screen state here is immediate however, so it can happen
+ // that the screen turns on again before the navigation bar is hidden. To work around
+ // that, wait for a traversal to happen before applying the initial screen state.
+ mPendingScreenState = screenState;
+ if (!messagePending) {
+ mHandler.post(mApplyPendingScreenState);
+ }
+ return;
+ }
+ applyScreenState(screenState);
+ }
+
+ private void applyPendingScreenState() {
+ applyScreenState(mPendingScreenState);
+ mPendingScreenState = Display.STATE_UNKNOWN;
+ }
+
+ private void applyScreenState(int screenState) {