am af6e657a: Merge "Update KeyguardManager.isDeviceLocked API" into lmp-mr1-dev
* commit 'af6e657ab873623ed0e94bc8bcf8ed03f6bbe167': Update KeyguardManager.isDeviceLocked API
This commit is contained in:
@@ -4414,7 +4414,7 @@ package android.app {
|
|||||||
method public android.content.Intent createConfirmDeviceCredentialIntent(java.lang.CharSequence, java.lang.CharSequence);
|
method public android.content.Intent createConfirmDeviceCredentialIntent(java.lang.CharSequence, java.lang.CharSequence);
|
||||||
method public deprecated void exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult);
|
method public deprecated void exitKeyguardSecurely(android.app.KeyguardManager.OnKeyguardExitResult);
|
||||||
method public boolean inKeyguardRestrictedInputMode();
|
method public boolean inKeyguardRestrictedInputMode();
|
||||||
method public boolean isKeyguardInTrustedState();
|
method public boolean isDeviceLocked();
|
||||||
method public boolean isKeyguardLocked();
|
method public boolean isKeyguardLocked();
|
||||||
method public boolean isKeyguardSecure();
|
method public boolean isKeyguardSecure();
|
||||||
method public deprecated android.app.KeyguardManager.KeyguardLock newKeyguardLock(java.lang.String);
|
method public deprecated android.app.KeyguardManager.KeyguardLock newKeyguardLock(java.lang.String);
|
||||||
|
|||||||
@@ -225,28 +225,28 @@ public class KeyguardManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether unlocking the device is currently not requiring a password
|
* Returns whether the device is currently locked and requires a PIN, pattern or
|
||||||
* because of a trust agent.
|
* password to unlock.
|
||||||
*
|
*
|
||||||
* @return true if the keyguard can currently be unlocked without entering credentials
|
* @return true if unlocking the device currently requires a PIN, pattern or
|
||||||
* because the device is in a trusted environment.
|
* password.
|
||||||
*/
|
*/
|
||||||
public boolean isKeyguardInTrustedState() {
|
public boolean isDeviceLocked() {
|
||||||
return isKeyguardInTrustedState(UserHandle.getCallingUserId());
|
return isDeviceLocked(UserHandle.getCallingUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether unlocking the device is currently not requiring a password
|
* Returns whether the device is currently locked and requires a PIN, pattern or
|
||||||
* because of a trust agent.
|
* password to unlock.
|
||||||
*
|
*
|
||||||
* @param userId the user for which the trusted state should be reported.
|
* @param userId the user for which the locked state should be reported.
|
||||||
* @return true if the keyguard can currently be unlocked without entering credentials
|
* @return true if unlocking the device currently requires a PIN, pattern or
|
||||||
* because the device is in a trusted environment.
|
* password.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean isKeyguardInTrustedState(int userId) {
|
public boolean isDeviceLocked(int userId) {
|
||||||
try {
|
try {
|
||||||
return mTrustManager.isTrusted(userId);
|
return mTrustManager.isDeviceLocked(userId);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,5 +29,5 @@ interface ITrustManager {
|
|||||||
void reportRequireCredentialEntry(int userId);
|
void reportRequireCredentialEntry(int userId);
|
||||||
void registerTrustListener(in ITrustListener trustListener);
|
void registerTrustListener(in ITrustListener trustListener);
|
||||||
void unregisterTrustListener(in ITrustListener trustListener);
|
void unregisterTrustListener(in ITrustListener trustListener);
|
||||||
boolean isTrusted(int userId);
|
boolean isDeviceLocked(int userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -384,8 +384,16 @@ public class LockPatternUtils {
|
|||||||
* @return Whether a saved pattern exists.
|
* @return Whether a saved pattern exists.
|
||||||
*/
|
*/
|
||||||
public boolean savedPatternExists() {
|
public boolean savedPatternExists() {
|
||||||
|
return savedPatternExists(getCurrentOrCallingUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if the user has stored a lock pattern.
|
||||||
|
* @return Whether a saved pattern exists.
|
||||||
|
*/
|
||||||
|
public boolean savedPatternExists(int userId) {
|
||||||
try {
|
try {
|
||||||
return getLockSettings().havePattern(getCurrentOrCallingUserId());
|
return getLockSettings().havePattern(userId);
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -396,8 +404,16 @@ public class LockPatternUtils {
|
|||||||
* @return Whether a saved pattern exists.
|
* @return Whether a saved pattern exists.
|
||||||
*/
|
*/
|
||||||
public boolean savedPasswordExists() {
|
public boolean savedPasswordExists() {
|
||||||
|
return savedPasswordExists(getCurrentOrCallingUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if the user has stored a lock pattern.
|
||||||
|
* @return Whether a saved pattern exists.
|
||||||
|
*/
|
||||||
|
public boolean savedPasswordExists(int userId) {
|
||||||
try {
|
try {
|
||||||
return getLockSettings().havePassword(getCurrentOrCallingUserId());
|
return getLockSettings().havePassword(userId);
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -955,8 +971,15 @@ public class LockPatternUtils {
|
|||||||
* @return true if the lockscreen method is set to biometric weak
|
* @return true if the lockscreen method is set to biometric weak
|
||||||
*/
|
*/
|
||||||
public boolean usingBiometricWeak() {
|
public boolean usingBiometricWeak() {
|
||||||
int quality =
|
return usingBiometricWeak(getCurrentOrCallingUserId());
|
||||||
(int) getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the lockscreen method is set to biometric weak
|
||||||
|
*/
|
||||||
|
public boolean usingBiometricWeak(int userId) {
|
||||||
|
int quality = (int) getLong(
|
||||||
|
PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userId);
|
||||||
return quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
|
return quality == DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1096,15 +1119,22 @@ public class LockPatternUtils {
|
|||||||
* @return Whether the lock pattern is enabled, or if it is set as a backup for biometric weak
|
* @return Whether the lock pattern is enabled, or if it is set as a backup for biometric weak
|
||||||
*/
|
*/
|
||||||
public boolean isLockPatternEnabled() {
|
public boolean isLockPatternEnabled() {
|
||||||
|
return isLockPatternEnabled(getCurrentOrCallingUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Whether the lock pattern is enabled, or if it is set as a backup for biometric weak
|
||||||
|
*/
|
||||||
|
public boolean isLockPatternEnabled(int userId) {
|
||||||
final boolean backupEnabled =
|
final boolean backupEnabled =
|
||||||
getLong(PASSWORD_TYPE_ALTERNATE_KEY,
|
getLong(PASSWORD_TYPE_ALTERNATE_KEY,
|
||||||
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED)
|
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userId)
|
||||||
== DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
|
== DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
|
||||||
|
|
||||||
return getBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, false)
|
return getBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, false, userId)
|
||||||
&& (getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED)
|
&& (getLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
|
||||||
== DevicePolicyManager.PASSWORD_QUALITY_SOMETHING ||
|
userId) == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING
|
||||||
(usingBiometricWeak() && backupEnabled));
|
|| (usingBiometricWeak(userId) && backupEnabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1485,15 +1515,20 @@ public class LockPatternUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSecure() {
|
public boolean isSecure() {
|
||||||
long mode = getKeyguardStoredPasswordQuality();
|
return isSecure(getCurrentOrCallingUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSecure(int userId) {
|
||||||
|
long mode = getKeyguardStoredPasswordQuality(userId);
|
||||||
final boolean isPattern = mode == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
|
final boolean isPattern = mode == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
|
||||||
final boolean isPassword = mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
|
final boolean isPassword = mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC
|
||||||
|| mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX
|
|| mode == DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX
|
||||||
|| mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
|
|| mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC
|
||||||
|| mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
|
|| mode == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC
|
||||||
|| mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
|
|| mode == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX;
|
||||||
final boolean secure = isPattern && isLockPatternEnabled() && savedPatternExists()
|
final boolean secure =
|
||||||
|| isPassword && savedPasswordExists();
|
isPattern && isLockPatternEnabled(userId) && savedPatternExists(userId)
|
||||||
|
|| isPassword && savedPasswordExists(userId);
|
||||||
return secure;
|
return secure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,11 +48,11 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
<Button android:id="@+id/check_trusted"
|
<Button android:id="@+id/check_device_locked"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Keyguard in trusted state?" />
|
android:text="Device locked?" />
|
||||||
<TextView android:id="@+id/check_trusted_result"
|
<TextView android:id="@+id/check_device_locked_result"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi
|
|||||||
|
|
||||||
private CheckBox mReportUnlockAttempts;
|
private CheckBox mReportUnlockAttempts;
|
||||||
private CheckBox mManagingTrust;
|
private CheckBox mManagingTrust;
|
||||||
private TextView mCheckTrustedStateResult;
|
private TextView mCheckDeviceLockedResult;
|
||||||
|
|
||||||
private KeyguardManager mKeyguardManager;
|
private KeyguardManager mKeyguardManager;
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi
|
|||||||
findViewById(R.id.enable_trust).setOnClickListener(this);
|
findViewById(R.id.enable_trust).setOnClickListener(this);
|
||||||
findViewById(R.id.revoke_trust).setOnClickListener(this);
|
findViewById(R.id.revoke_trust).setOnClickListener(this);
|
||||||
findViewById(R.id.crash).setOnClickListener(this);
|
findViewById(R.id.crash).setOnClickListener(this);
|
||||||
findViewById(R.id.check_trusted).setOnClickListener(this);
|
findViewById(R.id.check_device_locked).setOnClickListener(this);
|
||||||
|
|
||||||
mReportUnlockAttempts = (CheckBox) findViewById(R.id.report_unlock_attempts);
|
mReportUnlockAttempts = (CheckBox) findViewById(R.id.report_unlock_attempts);
|
||||||
mReportUnlockAttempts.setOnCheckedChangeListener(this);
|
mReportUnlockAttempts.setOnCheckedChangeListener(this);
|
||||||
@@ -56,7 +56,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi
|
|||||||
mManagingTrust = (CheckBox) findViewById(R.id.managing_trust);
|
mManagingTrust = (CheckBox) findViewById(R.id.managing_trust);
|
||||||
mManagingTrust.setOnCheckedChangeListener(this);
|
mManagingTrust.setOnCheckedChangeListener(this);
|
||||||
|
|
||||||
mCheckTrustedStateResult = (TextView) findViewById(R.id.check_trusted_result);
|
mCheckDeviceLockedResult = (TextView) findViewById(R.id.check_device_locked_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,7 +77,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi
|
|||||||
SampleTrustAgent.sendRevokeTrust(this);
|
SampleTrustAgent.sendRevokeTrust(this);
|
||||||
} else if (id == R.id.crash) {
|
} else if (id == R.id.crash) {
|
||||||
throw new RuntimeException("crash");
|
throw new RuntimeException("crash");
|
||||||
} else if (id == R.id.check_trusted) {
|
} else if (id == R.id.check_device_locked) {
|
||||||
updateTrustedState();
|
updateTrustedState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ public class SampleTrustAgentSettings extends Activity implements View.OnClickLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateTrustedState() {
|
private void updateTrustedState() {
|
||||||
mCheckTrustedStateResult.setText(Boolean.toString(
|
mCheckDeviceLockedResult.setText(Boolean.toString(
|
||||||
mKeyguardManager.isKeyguardInTrustedState()));
|
mKeyguardManager.isDeviceLocked()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ import android.util.Log;
|
|||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.util.SparseBooleanArray;
|
import android.util.SparseBooleanArray;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
import android.view.WindowManagerGlobal;
|
||||||
|
import android.view.WindowManagerInternal;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -590,13 +592,26 @@ public class TrustManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTrusted(int userId) throws RemoteException {
|
public boolean isDeviceLocked(int userId) throws RemoteException {
|
||||||
userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId,
|
userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId,
|
||||||
false /* allowAll */, true /* requireFull */, "isTrusted", null);
|
false /* allowAll */, true /* requireFull */, "isDeviceLocked", null);
|
||||||
userId = resolveProfileParent(userId);
|
userId = resolveProfileParent(userId);
|
||||||
|
|
||||||
|
boolean isSecure = mLockPatternUtils.isSecure(userId);
|
||||||
|
|
||||||
|
boolean isTrusted;
|
||||||
synchronized (mUserIsTrusted) {
|
synchronized (mUserIsTrusted) {
|
||||||
return mUserIsTrusted.get(userId);
|
isTrusted = mUserIsTrusted.get(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isLocked;
|
||||||
|
if (ActivityManager.getCurrentUser() != userId) {
|
||||||
|
isLocked = true;
|
||||||
|
} else {
|
||||||
|
isLocked = WindowManagerGlobal.getWindowManagerService().isKeyguardLocked();
|
||||||
|
}
|
||||||
|
|
||||||
|
return isSecure && isLocked && !isTrusted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enforceReportPermission() {
|
private void enforceReportPermission() {
|
||||||
|
|||||||
Reference in New Issue
Block a user