Wait for Keyguard to be drawn after boot.

The old logic with waiting for the Keyguard to be drawn assumed that
it is in an own window, and just checked for the visibility. This is
no longer possible as the Keyguard is in the status bar, and the status
bar might have been drawn without the Keyguard. So we have to wait
explicitely until Keyguard told PhoneWindowManager that it has now been
drawn and we can turn on the screen.

In addition, the starting logic of SystemUI is moved into
SystemUIApplication such the we can make sure that the status bar
already exists when the callbacks from PhoneWindowManager reach
KeyguardService. This simplifies the logic a lot.

Bug: 13635952
Change-Id: Ifd6ba795647edcf3501641e39052e4d04bc826fb
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
new file mode 100644
index 0000000..8265c86
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.systemui;
+
+import android.app.Application;
+import android.content.res.Configuration;
+import android.util.Log;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Application class for SystemUI.
+ */
+public class SystemUIApplication extends Application {
+
+    private static final String TAG = "SystemUIService";
+    private static final boolean DEBUG = false;
+
+    /**
+     * The classes of the stuff to start.
+     */
+    private final Class<?>[] SERVICES = new Class[] {
+            com.android.systemui.keyguard.KeyguardViewMediator.class,
+            com.android.systemui.recent.Recents.class,
+            com.android.systemui.statusbar.SystemBars.class,
+            com.android.systemui.usb.StorageNotification.class,
+            com.android.systemui.power.PowerUI.class,
+            com.android.systemui.media.RingtonePlayer.class,
+            com.android.systemui.settings.SettingsUI.class,
+    };
+
+    /**
+     * Hold a reference on the stuff we start.
+     */
+    private final SystemUI[] mServices = new SystemUI[SERVICES.length];
+    private final Map<Class<?>, Object> mComponents = new HashMap<Class<?>, Object>();
+
+    @Override
+    public void onCreate() {
+        final int N = SERVICES.length;
+        for (int i=0; i<N; i++) {
+            Class<?> cl = SERVICES[i];
+            if (DEBUG) Log.d(TAG, "loading: " + cl);
+            try {
+                mServices[i] = (SystemUI)cl.newInstance();
+            } catch (IllegalAccessException ex) {
+                throw new RuntimeException(ex);
+            } catch (InstantiationException ex) {
+                throw new RuntimeException(ex);
+            }
+            mServices[i].mContext = this;
+            mServices[i].mComponents = mComponents;
+            if (DEBUG) Log.d(TAG, "running: " + mServices[i]);
+            mServices[i].start();
+        }
+    }
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        int len = mServices.length;
+        for (int i = 0; i < len; i++) {
+            mServices[i].onConfigurationChanged(newConfig);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public <T> T getComponent(Class<T> interfaceType) {
+        return (T) mComponents.get(interfaceType);
+    }
+
+    public SystemUI[] getServices() {
+        return mServices;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/SystemUIService.java b/packages/SystemUI/src/com/android/systemui/SystemUIService.java
index ca5f7d1..da8654c 100644
--- a/packages/SystemUI/src/com/android/systemui/SystemUIService.java
+++ b/packages/SystemUI/src/com/android/systemui/SystemUIService.java
@@ -18,65 +18,13 @@
 
 import android.app.Service;
 import android.content.Intent;
-import android.content.res.Configuration;
 import android.os.IBinder;
-import android.util.Log;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
-import java.util.HashMap;
 
 public class SystemUIService extends Service {
-    private static final String TAG = "SystemUIService";
 
-    /**
-     * The classes of the stuff to start.
-     */
-    private final Class<?>[] SERVICES = new Class[] {
-            com.android.systemui.recent.Recents.class,
-            com.android.systemui.statusbar.SystemBars.class,
-            com.android.systemui.usb.StorageNotification.class,
-            com.android.systemui.power.PowerUI.class,
-            com.android.systemui.media.RingtonePlayer.class,
-            com.android.systemui.settings.SettingsUI.class,
-        };
-
-    /**
-     * Hold a reference on the stuff we start.
-     */
-    private final SystemUI[] mServices = new SystemUI[SERVICES.length];
-
-    @Override
-    public void onCreate() {
-        HashMap<Class<?>, Object> components = new HashMap<Class<?>, Object>();
-        final int N = SERVICES.length;
-        for (int i=0; i<N; i++) {
-            Class<?> cl = SERVICES[i];
-            Log.d(TAG, "loading: " + cl);
-            try {
-                mServices[i] = (SystemUI)cl.newInstance();
-            } catch (IllegalAccessException ex) {
-                throw new RuntimeException(ex);
-            } catch (InstantiationException ex) {
-                throw new RuntimeException(ex);
-            }
-            mServices[i].mContext = this;
-            mServices[i].mComponents = components;
-            Log.d(TAG, "running: " + mServices[i]);
-            mServices[i].start();
-        }
-    }
-
-    @Override
-    public void onConfigurationChanged(Configuration newConfig) {
-        for (SystemUI ui: mServices) {
-            ui.onConfigurationChanged(newConfig);
-        }
-    }
-
-    /**
-     * Nobody binds to us.
-     */
     @Override
     public IBinder onBind(Intent intent) {
         return null;
@@ -84,14 +32,15 @@
 
     @Override
     protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        SystemUI[] services = ((SystemUIApplication) getApplication()).getServices();
         if (args == null || args.length == 0) {
-            for (SystemUI ui: mServices) {
+            for (SystemUI ui: services) {
                 pw.println("dumping service: " + ui.getClass().getName());
                 ui.dump(fd, pw, args);
             }
         } else {
             String svc = args[0];
-            for (SystemUI ui: mServices) {
+            for (SystemUI ui: services) {
                 String name = ui.getClass().getName();
                 if (name.endsWith(svc)) {
                     ui.dump(fd, pw, args);
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java
index c7d29f0..fdf374f 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardService.java
@@ -16,15 +16,6 @@
 
 package com.android.systemui.keyguard;
 
-import com.android.internal.policy.IKeyguardExitCallback;
-import com.android.internal.policy.IKeyguardService;
-import com.android.internal.policy.IKeyguardServiceConstants;
-import com.android.internal.policy.IKeyguardShowCallback;
-import com.android.internal.widget.LockPatternUtils;
-import com.android.systemui.statusbar.phone.PhoneStatusBar;
-import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
-import com.android.systemui.statusbar.phone.StatusBarWindowManager;
-
 import android.app.Service;
 import android.content.Intent;
 import android.os.Binder;
@@ -33,7 +24,12 @@
 import android.os.IBinder;
 import android.util.Log;
 import android.view.MotionEvent;
-import android.view.ViewGroup;
+
+import com.android.internal.policy.IKeyguardExitCallback;
+import com.android.internal.policy.IKeyguardService;
+import com.android.internal.policy.IKeyguardServiceConstants;
+import com.android.internal.policy.IKeyguardShowCallback;
+import com.android.systemui.SystemUIApplication;
 
 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
 
@@ -41,23 +37,17 @@
     static final String TAG = "KeyguardService";
     static final String PERMISSION = android.Manifest.permission.CONTROL_KEYGUARD;
 
-    public static final String ACTION_STATUS_BAR_BIND = "action.status_bar_bind";
-
     private KeyguardViewMediator mKeyguardViewMediator;
 
     @Override
     public void onCreate() {
-        LockPatternUtils lockPatternUtils = new LockPatternUtils(this);
-        mKeyguardViewMediator = new KeyguardViewMediator(this, lockPatternUtils);
+        mKeyguardViewMediator =
+                ((SystemUIApplication) getApplication()).getComponent(KeyguardViewMediator.class);
     }
 
     @Override
     public IBinder onBind(Intent intent) {
-        if (ACTION_STATUS_BAR_BIND.equals(intent.getAction())) {
-            return mKeyguardStatusBarBinder;
-        } else {
-            return mBinder;
-        }
+        return mBinder;
     }
 
     void checkPermission() {
@@ -68,16 +58,6 @@
         }
     }
 
-    private final KeyguardStatusBarBinder mKeyguardStatusBarBinder = new KeyguardStatusBarBinder() {
-
-        @Override
-        public void registerStatusBar(PhoneStatusBar phoneStatusBar, ViewGroup container,
-                StatusBarWindowManager statusBarWindowManager) {
-            mKeyguardViewMediator.registerStatusBar(phoneStatusBar, container,
-                    statusBarWindowManager);
-        }
-    };
-
     private final IKeyguardService.Stub mBinder = new IKeyguardService.Stub() {
 
         private boolean mIsOccluded;
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardStatusBarBinder.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardStatusBarBinder.java
deleted file mode 100644
index 04b6c29..0000000
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardStatusBarBinder.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.systemui.keyguard;
-
-import com.android.systemui.statusbar.phone.PhoneStatusBar;
-import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
-import com.android.systemui.statusbar.phone.StatusBarWindowManager;
-
-import android.os.Binder;
-import android.view.ViewGroup;
-
-/**
- * Communication interface from status bar to {@link com.android.systemui.keyguard.KeyguardService}.
- */
-public abstract class KeyguardStatusBarBinder extends Binder {
-
-    public abstract void registerStatusBar(PhoneStatusBar phoneStatusBar, ViewGroup container,
-            StatusBarWindowManager statusBarWindowManager);
-}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
index b300bea..1dfea2f 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java
@@ -60,6 +60,7 @@
 import com.android.keyguard.ViewMediatorCallback;
 import com.android.keyguard.analytics.KeyguardAnalytics;
 import com.android.keyguard.analytics.Session;
+import com.android.systemui.SystemUI;
 import com.android.systemui.statusbar.phone.PhoneStatusBar;
 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
 import com.android.systemui.statusbar.phone.StatusBarWindowManager;
@@ -111,7 +112,7 @@
  * directly to the keyguard UI is posted to a {@link android.os.Handler} to ensure it is taken on the UI
  * thread of the keyguard.
  */
-public class KeyguardViewMediator {
+public class KeyguardViewMediator extends SystemUI {
     private static final int KEYGUARD_DISPLAY_TIMEOUT_DELAY_DEFAULT = 30000;
     final static boolean DEBUG = false;
     private static final boolean ENABLE_ANALYTICS = Build.IS_DEBUGGABLE;
@@ -181,7 +182,6 @@
     /** The stream type that the lock sounds are tied to. */
     private int mMasterStreamType;
 
-    private Context mContext;
     private AlarmManager mAlarmManager;
     private AudioManager mAudioManager;
     private StatusBarManager mStatusBarManager;
@@ -211,7 +211,7 @@
 
     private StatusBarKeyguardViewManager mStatusBarKeyguardViewManager;
 
-    private final KeyguardAnalytics mKeyguardAnalytics;
+    private KeyguardAnalytics mKeyguardAnalytics;
 
     // these are protected by synchronized (this)
 
@@ -284,7 +284,7 @@
     /**
      * The volume applied to the lock/unlock sounds.
      */
-    private final float mLockSoundVolume;
+    private float mLockSoundVolume;
 
     /**
      * For managing external displays
@@ -460,42 +460,34 @@
         mPM.userActivity(SystemClock.uptimeMillis(), false);
     }
 
-    /**
-     * Construct a KeyguardViewMediator
-     * @param context
-     * @param lockPatternUtils optional mock interface for LockPatternUtils
-     */
-    public KeyguardViewMediator(Context context, LockPatternUtils lockPatternUtils) {
-        mContext = context;
-        mPM = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+    private void setup() {
+        mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
         mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
         mShowKeyguardWakeLock = mPM.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "show keyguard");
         mShowKeyguardWakeLock.setReferenceCounted(false);
 
         mContext.registerReceiver(mBroadcastReceiver, new IntentFilter(DELAYED_KEYGUARD_ACTION));
 
-        mKeyguardDisplayManager = new KeyguardDisplayManager(context);
+        mKeyguardDisplayManager = new KeyguardDisplayManager(mContext);
 
-        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
 
-        mUpdateMonitor = KeyguardUpdateMonitor.getInstance(context);
+        mUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
 
-        mLockPatternUtils = lockPatternUtils != null
-                ? lockPatternUtils : new LockPatternUtils(mContext);
+        mLockPatternUtils = new LockPatternUtils(mContext);
         mLockPatternUtils.setCurrentUser(UserHandle.USER_OWNER);
 
         // Assume keyguard is showing (unless it's disabled) until we know for sure...
         mShowing = (mUpdateMonitor.isDeviceProvisioned() || mLockPatternUtils.isSecure())
                 && !mLockPatternUtils.isLockScreenDisabled();
 
-        mStatusBarKeyguardViewManager = new StatusBarKeyguardViewManager(mContext, mViewMediatorCallback,
-                lockPatternUtils);
-        WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
+        mStatusBarKeyguardViewManager = new StatusBarKeyguardViewManager(mContext,
+                mViewMediatorCallback, mLockPatternUtils);
         final ContentResolver cr = mContext.getContentResolver();
 
         if (ENABLE_ANALYTICS && !LockPatternUtils.isSafeModeEnabled() &&
                 Settings.Secure.getInt(cr, KEYGUARD_ANALYTICS_SETTING, 0) == 1) {
-            mKeyguardAnalytics = new KeyguardAnalytics(context, new SessionTypeAdapter() {
+            mKeyguardAnalytics = new KeyguardAnalytics(mContext, new SessionTypeAdapter() {
 
                 @Override
                 public int getSessionType() {
@@ -526,11 +518,17 @@
         if (soundPath == null || mUnlockSoundId == 0) {
             Log.w(TAG, "failed to load unlock sound from " + soundPath);
         }
-        int lockSoundDefaultAttenuation = context.getResources().getInteger(
+        int lockSoundDefaultAttenuation = mContext.getResources().getInteger(
                 com.android.internal.R.integer.config_lockSoundVolumeDb);
         mLockSoundVolume = (float)Math.pow(10, (float)lockSoundDefaultAttenuation/20);
     }
 
+    @Override
+    public void start() {
+        setup();
+        putComponent(KeyguardViewMediator.class, this);
+    }
+
     /**
      * Let us know that the system is ready after startup.
      */
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index bdcf83c..ecdca20 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -16,14 +16,15 @@
 
 package com.android.systemui.statusbar.phone;
 
+
 import static android.app.StatusBarManager.NAVIGATION_HINT_BACK_ALT;
 import static android.app.StatusBarManager.WINDOW_STATE_HIDDEN;
 import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
 import static android.app.StatusBarManager.windowStateToString;
+import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT;
 import static com.android.systemui.statusbar.phone.BarTransitions.MODE_OPAQUE;
 import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
 import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSLUCENT;
-import static com.android.systemui.statusbar.phone.BarTransitions.MODE_LIGHTS_OUT;
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
@@ -35,11 +36,9 @@
 import android.app.PendingIntent;
 import android.app.StatusBarManager;
 import android.content.BroadcastReceiver;
-import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.ServiceConnection;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.database.ContentObserver;
@@ -67,7 +66,6 @@
 import android.util.Log;
 import android.view.Display;
 import android.view.Gravity;
-import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.VelocityTracker;
 import android.view.View;
@@ -75,28 +73,23 @@
 import android.view.ViewGroup.LayoutParams;
 import android.view.ViewPropertyAnimator;
 import android.view.ViewStub;
-import android.view.ViewTreeObserver;
 import android.view.WindowManager;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
 import android.view.animation.DecelerateInterpolator;
-import android.widget.Button;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
-import com.android.internal.policy.IKeyguardShowCallback;
 import com.android.internal.statusbar.StatusBarIcon;
-import com.android.keyguard.KeyguardHostView;
-import com.android.keyguard.KeyguardSimpleHostView;
 import com.android.systemui.DemoMode;
 import com.android.systemui.EventLogTags;
 import com.android.systemui.R;
 import com.android.systemui.SwipeHelper;
-import com.android.systemui.keyguard.KeyguardService;
-import com.android.systemui.keyguard.KeyguardStatusBarBinder;
+import com.android.systemui.SystemUIApplication;
+import com.android.systemui.keyguard.KeyguardViewMediator;
 import com.android.systemui.statusbar.BaseStatusBar;
 import com.android.systemui.statusbar.CommandQueue;
 import com.android.systemui.statusbar.GestureRecorder;
@@ -104,7 +97,6 @@
 import com.android.systemui.statusbar.NotificationData.Entry;
 import com.android.systemui.statusbar.SignalClusterView;
 import com.android.systemui.statusbar.StatusBarIconView;
-
 import com.android.systemui.statusbar.policy.BatteryController;
 import com.android.systemui.statusbar.policy.BluetoothController;
 import com.android.systemui.statusbar.policy.DateView;
@@ -114,7 +106,6 @@
 import com.android.systemui.statusbar.policy.NotificationRowLayout;
 import com.android.systemui.statusbar.policy.OnSizeChangedListener;
 import com.android.systemui.statusbar.policy.RotationLockController;
-
 import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
 
 import java.io.FileDescriptor;
@@ -279,7 +270,6 @@
 
     DisplayMetrics mDisplayMetrics = new DisplayMetrics();
 
-    protected KeyguardStatusBarBinder mKeyguardService;
     // XXX: gesture research
     private final GestureRecorder mGestureRec = DEBUG_GESTURES
         ? new GestureRecorder("/sdcard/statusbar_gestures.dat")
@@ -713,26 +703,8 @@
     }
 
     private void startKeyguard() {
-
-        // Create the connection to KeyguardService.
-        Intent intent = new Intent(mContext, KeyguardService.class);
-        intent.setAction(KeyguardService.ACTION_STATUS_BAR_BIND);
-        if (!mContext.bindService(intent, new ServiceConnection() {
-            @Override
-            public void onServiceConnected(ComponentName name, IBinder service) {
-                mKeyguardService = (KeyguardStatusBarBinder) service;
-                mKeyguardService.registerStatusBar(PhoneStatusBar.this, mStatusBarWindow,
-                        mStatusBarWindowManager);
-            }
-
-            @Override
-            public void onServiceDisconnected(ComponentName name) {
-                if (DEBUG) Log.v(TAG, "Keyguard disconnected.");
-                mKeyguardService = null;
-            }
-        }, Context.BIND_AUTO_CREATE)) {
-            throw new RuntimeException("Couldn't bind status bar keyguard.");
-        }
+        getComponent(KeyguardViewMediator.class).registerStatusBar(
+                this, mStatusBarWindow, mStatusBarWindowManager);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
index 722a958..9ccd8e4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
@@ -56,7 +56,6 @@
     private StatusBarWindowManager mStatusBarWindowManager;
 
     private boolean mScreenOn = false;
-    private boolean mShowOnRegister;
 
     public StatusBarKeyguardViewManager(Context context, ViewMediatorCallback callback,
             LockPatternUtils lockPatternUtils) {
@@ -71,13 +70,6 @@
         mPhoneStatusBar = phoneStatusBar;
         mContainer = container;
         mStatusBarWindowManager = statusBarWindowManager;
-        if (mShowOnRegister) {
-            mShowOnRegister = false;
-            show(null);
-            if (mScreenOn) {
-                onScreenTurnedOn(null);
-            }
-        }
     }
 
     /**
@@ -85,13 +77,9 @@
      * lazily.
      */
     public void show(Bundle options) {
-        if (mStatusBarWindowManager != null) {
-            ensureView();
-            mStatusBarWindowManager.setKeyguardShowing(true);
-            mKeyguardView.requestFocus();
-        } else {
-            mShowOnRegister = true;
-        }
+        ensureView();
+        mStatusBarWindowManager.setKeyguardShowing(true);
+        mKeyguardView.requestFocus();
     }
 
     private void ensureView() {
@@ -168,9 +156,7 @@
     }
 
     public void setNeedsInput(boolean needsInput) {
-        if (mStatusBarWindowManager != null) {
-            mStatusBarWindowManager.setKeyguardNeedsInput(needsInput);
-        }
+        mStatusBarWindowManager.setKeyguardNeedsInput(needsInput);
     }
 
     public void updateUserActivityTimeout() {
@@ -190,24 +176,19 @@
     }
 
     public void setOccluded(boolean occluded) {
-        if (mStatusBarWindowManager != null) {
-            mStatusBarWindowManager.setKeyguardOccluded(occluded);
-        }
+        mStatusBarWindowManager.setKeyguardOccluded(occluded);
     }
 
     /**
      * Hides the keyguard view
      */
     public void hide() {
-        if (mPhoneStatusBar != null) {
-            mStatusBarWindowManager.setKeyguardShowing(false);
-            if (mKeyguardView != null) {
-                mKeyguardView.cleanUp();
-                mViewMediatorCallback.keyguardGone();
-            }
-            removeView();
+        mStatusBarWindowManager.setKeyguardShowing(false);
+        if (mKeyguardView != null) {
+            mKeyguardView.cleanUp();
+            mViewMediatorCallback.keyguardGone();
         }
-        mShowOnRegister = false;
+        removeView();
     }
 
     /**