Merge "DO NOT MERGE Fix mTrustManager NPE" into mnc-dev
diff --git a/core/java/android/app/KeyguardManager.java b/core/java/android/app/KeyguardManager.java
index 2c12317..4bebdfa 100644
--- a/core/java/android/app/KeyguardManager.java
+++ b/core/java/android/app/KeyguardManager.java
@@ -249,7 +249,7 @@
      */
     public boolean isDeviceLocked(int userId) {
         try {
-            return mTrustManager.isDeviceLocked(userId);
+            return getTrustManager().isDeviceLocked(userId);
         } catch (RemoteException e) {
             return false;
         }
@@ -274,12 +274,20 @@
      */
     public boolean isDeviceSecure(int userId) {
         try {
-            return mTrustManager.isDeviceSecure(userId);
+            return getTrustManager().isDeviceSecure(userId);
         } catch (RemoteException e) {
             return false;
         }
     }
 
+    private synchronized ITrustManager getTrustManager() {
+        if (mTrustManager == null) {
+            mTrustManager = ITrustManager.Stub.asInterface(
+                    ServiceManager.getService(Context.TRUST_SERVICE));
+        }
+        return mTrustManager;
+    }
+
     /**
      * @deprecated Use {@link android.view.WindowManager.LayoutParams#FLAG_DISMISS_KEYGUARD}
      * and/or {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED}