Add KeyguardManager.isDeviceSecure
Bug: 19823211
Change-Id: I92a1d2542274bf1dc2d5757511ce495264f90733
diff --git a/api/current.txt b/api/current.txt
index 6de9a03..31a9b91 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -4596,6 +4596,7 @@
method public deprecated void exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult);
method public boolean inKeyguardRestrictedInputMode();
method public boolean isDeviceLocked();
+ method public boolean isDeviceSecure();
method public boolean isKeyguardLocked();
method public boolean isKeyguardSecure();
method public deprecated android.app.KeyguardManager.KeyguardLock newKeyguardLock(java.lang.String);
diff --git a/api/system-current.txt b/api/system-current.txt
index 708394c..c7d85b3 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -4687,6 +4687,7 @@
method public deprecated void exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult);
method public boolean inKeyguardRestrictedInputMode();
method public boolean isDeviceLocked();
+ method public boolean isDeviceSecure();
method public boolean isKeyguardLocked();
method public boolean isKeyguardSecure();
method public deprecated android.app.KeyguardManager.KeyguardLock newKeyguardLock(java.lang.String);
diff --git a/core/java/android/app/KeyguardManager.java b/core/java/android/app/KeyguardManager.java
index ddd21e6..56cd53e 100644
--- a/core/java/android/app/KeyguardManager.java
+++ b/core/java/android/app/KeyguardManager.java
@@ -253,6 +253,32 @@
}
/**
+ * Returns whether the device is secured with a PIN, pattern or
+ * password.
+ *
+ * @return true if a PIN, pattern or password was set.
+ */
+ public boolean isDeviceSecure() {
+ return isDeviceSecure(UserHandle.getCallingUserId());
+ }
+
+ /**
+ * Returns whether the device is secured with a PIN, pattern or
+ * password.
+ *
+ * @param userId the user for which the secure state should be reported.
+ * @return true if a PIN, pattern or password was set.
+ * @hide
+ */
+ public boolean isDeviceSecure(int userId) {
+ try {
+ return mTrustManager.isDeviceSecure(userId);
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
+
+ /**
* @deprecated Use {@link android.view.WindowManager.LayoutParams#FLAG_DISMISS_KEYGUARD}
* and/or {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED}
* instead; this allows you to seamlessly hide the keyguard as your application
diff --git a/core/java/android/app/trust/ITrustManager.aidl b/core/java/android/app/trust/ITrustManager.aidl
index 68ea0aa..17cff5c 100644
--- a/core/java/android/app/trust/ITrustManager.aidl
+++ b/core/java/android/app/trust/ITrustManager.aidl
@@ -31,4 +31,5 @@
void unregisterTrustListener(in ITrustListener trustListener);
void reportKeyguardShowingChanged();
boolean isDeviceLocked(int userId);
+ boolean isDeviceSecure(int userId);
}
diff --git a/services/core/java/com/android/server/trust/TrustManagerService.java b/services/core/java/com/android/server/trust/TrustManagerService.java
index cd1c9a5..b38d33d 100644
--- a/services/core/java/com/android/server/trust/TrustManagerService.java
+++ b/services/core/java/com/android/server/trust/TrustManagerService.java
@@ -691,6 +691,20 @@
return isDeviceLockedInner(userId);
}
+ @Override
+ public boolean isDeviceSecure(int userId) throws RemoteException {
+ userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId,
+ false /* allowAll */, true /* requireFull */, "isDeviceSecure", null);
+ userId = resolveProfileParent(userId);
+
+ long token = Binder.clearCallingIdentity();
+ try {
+ return new LockPatternUtils(mContext).isSecure(userId);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
private void enforceReportPermission() {
mContext.enforceCallingOrSelfPermission(
Manifest.permission.ACCESS_KEYGUARD_SECURE_STORAGE, "reporting trust events");