am 520d20c1: am 702d9e31: Merge "Fix DPM.resetPassword("")" into lmp-mr1-dev

* commit '520d20c1a8c2fbd0d6b7fdc19415167a6f45c866':
  Fix DPM.resetPassword("")
This commit is contained in:
Adrian Roos
2014-11-25 15:09:24 +00:00
committed by Android Git Automerger
3 changed files with 65 additions and 36 deletions

View File

@@ -1381,13 +1381,16 @@ public class DevicePolicyManager {
* characters when the requested quality is only numeric), in which case * characters when the requested quality is only numeric), in which case
* the currently active quality will be increased to match. * the currently active quality will be increased to match.
* *
* <p>Calling with a null or empty password will clear any existing PIN,
* pattern or password if the current password constraints allow it.
*
* <p>The calling device admin must have requested * <p>The calling device admin must have requested
* {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call * {@link DeviceAdminInfo#USES_POLICY_RESET_PASSWORD} to be able to call
* this method; if it has not, a security exception will be thrown. * this method; if it has not, a security exception will be thrown.
* *
* <p>Calling this from a managed profile will throw a security exception. * <p>Calling this from a managed profile will throw a security exception.
* *
* @param password The new password for the user. * @param password The new password for the user. Null or empty clears the password.
* @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}. * @param flags May be 0 or {@link #RESET_PASSWORD_REQUIRE_ENTRY}.
* @return Returns true if the password was applied, or false if it is * @return Returns true if the password was applied, or false if it is
* not acceptable for the current constraints. * not acceptable for the current constraints.

View File

@@ -191,9 +191,6 @@ public class LockPatternUtils {
return trust; return trust;
} }
/**
* @param contentResolver Used to look up and save settings.
*/
public LockPatternUtils(Context context) { public LockPatternUtils(Context context) {
mContext = context; mContext = context;
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
@@ -490,17 +487,23 @@ public class LockPatternUtils {
return activePasswordQuality; return activePasswordQuality;
} }
public void clearLock(boolean isFallback) {
clearLock(isFallback, getCurrentOrCallingUserId());
}
/** /**
* Clear any lock pattern or password. * Clear any lock pattern or password.
*/ */
public void clearLock(boolean isFallback) { public void clearLock(boolean isFallback, int userHandle) {
if(!isFallback) deleteGallery(); if(!isFallback) deleteGallery(userHandle);
saveLockPassword(null, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); saveLockPassword(null, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, isFallback,
setLockPatternEnabled(false); userHandle);
saveLockPattern(null); setLockPatternEnabled(false, userHandle);
setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); saveLockPattern(null, isFallback, userHandle);
setLong(PASSWORD_TYPE_ALTERNATE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userHandle);
onAfterChangingPassword(); setLong(PASSWORD_TYPE_ALTERNATE_KEY, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED,
userHandle);
onAfterChangingPassword(userHandle);
} }
/** /**
@@ -547,11 +550,11 @@ public class LockPatternUtils {
/** /**
* Calls back SetupFaceLock to delete the gallery file when the lock type is changed * Calls back SetupFaceLock to delete the gallery file when the lock type is changed
*/ */
void deleteGallery() { void deleteGallery(int userId) {
if(usingBiometricWeak()) { if(usingBiometricWeak(userId)) {
Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY"); Intent intent = new Intent().setAction("com.android.facelock.DELETE_GALLERY");
intent.putExtra("deleteGallery", true); intent.putExtra("deleteGallery", true);
mContext.sendBroadcast(intent); mContext.sendBroadcastAsUser(intent, new UserHandle(userId));
} }
} }
@@ -566,11 +569,20 @@ public class LockPatternUtils {
/** /**
* Save a lock pattern. * Save a lock pattern.
* @param pattern The new pattern to save. * @param pattern The new pattern to save.
* @param isFallback Specifies if this is a fallback to biometric weak
*/ */
public void saveLockPattern(List<LockPatternView.Cell> pattern, boolean isFallback) { public void saveLockPattern(List<LockPatternView.Cell> pattern, boolean isFallback) {
this.saveLockPattern(pattern, isFallback, getCurrentOrCallingUserId());
}
/**
* Save a lock pattern.
* @param pattern The new pattern to save.
* @param isFallback Specifies if this is a fallback to biometric weak
* @param userId the user whose pattern is to be saved.
*/
public void saveLockPattern(List<LockPatternView.Cell> pattern, boolean isFallback,
int userId) {
try { try {
int userId = getCurrentOrCallingUserId();
getLockSettings().setLockPattern(patternToString(pattern), userId); getLockSettings().setLockPattern(patternToString(pattern), userId);
DevicePolicyManager dpm = getDevicePolicyManager(); DevicePolicyManager dpm = getDevicePolicyManager();
if (pattern != null) { if (pattern != null) {
@@ -586,17 +598,17 @@ public class LockPatternUtils {
} }
} }
setBoolean(PATTERN_EVER_CHOSEN_KEY, true); setBoolean(PATTERN_EVER_CHOSEN_KEY, true, userId);
if (!isFallback) { if (!isFallback) {
deleteGallery(); deleteGallery(userId);
setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
pattern.size(), 0, 0, 0, 0, 0, 0, userId); pattern.size(), 0, 0, 0, 0, 0, 0, userId);
} else { } else {
setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK); setLong(PASSWORD_TYPE_KEY, DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK, userId);
setLong(PASSWORD_TYPE_ALTERNATE_KEY, setLong(PASSWORD_TYPE_ALTERNATE_KEY,
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING); DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, userId);
finishBiometricWeak(); finishBiometricWeak(userId);
dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK, dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
0, 0, 0, 0, 0, 0, 0, userId); 0, 0, 0, 0, 0, 0, 0, userId);
} }
@@ -604,7 +616,7 @@ public class LockPatternUtils {
dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0,
0, 0, 0, 0, 0, userId); 0, 0, 0, 0, 0, userId);
} }
onAfterChangingPassword(); onAfterChangingPassword(userId);
} catch (RemoteException re) { } catch (RemoteException re) {
Log.e(TAG, "Couldn't save lock pattern " + re); Log.e(TAG, "Couldn't save lock pattern " + re);
} }
@@ -822,7 +834,7 @@ public class LockPatternUtils {
} }
if (!isFallback) { if (!isFallback) {
deleteGallery(); deleteGallery(userHandle);
setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality), userHandle); setLong(PASSWORD_TYPE_KEY, Math.max(quality, computedQuality), userHandle);
if (computedQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { if (computedQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
int letters = 0; int letters = 0;
@@ -862,7 +874,7 @@ public class LockPatternUtils {
userHandle); userHandle);
setLong(PASSWORD_TYPE_ALTERNATE_KEY, Math.max(quality, computedQuality), setLong(PASSWORD_TYPE_ALTERNATE_KEY, Math.max(quality, computedQuality),
userHandle); userHandle);
finishBiometricWeak(); finishBiometricWeak(userHandle);
dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK, dpm.setActivePasswordState(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK,
0, 0, 0, 0, 0, 0, 0, userHandle); 0, 0, 0, 0, 0, 0, 0, userHandle);
} }
@@ -870,7 +882,7 @@ public class LockPatternUtils {
// password hashes have the same length for simplicity of implementation. // password hashes have the same length for simplicity of implementation.
String passwordHistory = getString(PASSWORD_HISTORY_KEY, userHandle); String passwordHistory = getString(PASSWORD_HISTORY_KEY, userHandle);
if (passwordHistory == null) { if (passwordHistory == null) {
passwordHistory = new String(); passwordHistory = "";
} }
int passwordHistoryLength = getRequestedPasswordHistoryLength(); int passwordHistoryLength = getRequestedPasswordHistoryLength();
if (passwordHistoryLength == 0) { if (passwordHistoryLength == 0) {
@@ -897,7 +909,7 @@ public class LockPatternUtils {
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, 0, 0, 0, 0, 0, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, 0, 0, 0, 0, 0, 0, 0,
userHandle); userHandle);
} }
onAfterChangingPassword(); onAfterChangingPassword(userHandle);
} catch (RemoteException re) { } catch (RemoteException re) {
// Cant do much // Cant do much
Log.e(TAG, "Unable to save lock password " + re); Log.e(TAG, "Unable to save lock password " + re);
@@ -1190,7 +1202,14 @@ public class LockPatternUtils {
* Set whether the lock pattern is enabled. * Set whether the lock pattern is enabled.
*/ */
public void setLockPatternEnabled(boolean enabled) { public void setLockPatternEnabled(boolean enabled) {
setBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, enabled); setLockPatternEnabled(enabled, getCurrentOrCallingUserId());
}
/**
* Set whether the lock pattern is enabled.
*/
public void setLockPatternEnabled(boolean enabled, int userHandle) {
setBoolean(Settings.Secure.LOCK_PATTERN_ENABLED, enabled, userHandle);
} }
/** /**
@@ -1584,15 +1603,15 @@ public class LockPatternUtils {
return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
} }
private void finishBiometricWeak() { private void finishBiometricWeak(int userId) {
setBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, true); setBoolean(BIOMETRIC_WEAK_EVER_CHOSEN_KEY, true, userId);
// Launch intent to show final screen, this also // Launch intent to show final screen, this also
// moves the temporary gallery to the actual gallery // moves the temporary gallery to the actual gallery
Intent intent = new Intent(); Intent intent = new Intent();
intent.setClassName("com.android.facelock", intent.setClassName("com.android.facelock",
"com.android.facelock.SetupEndScreen"); "com.android.facelock.SetupEndScreen");
mContext.startActivity(intent); mContext.startActivityAsUser(intent, new UserHandle(userId));
} }
public void setPowerButtonInstantlyLocks(boolean enabled) { public void setPowerButtonInstantlyLocks(boolean enabled) {
@@ -1686,8 +1705,8 @@ public class LockPatternUtils {
getTrustManager().reportRequireCredentialEntry(userId); getTrustManager().reportRequireCredentialEntry(userId);
} }
private void onAfterChangingPassword() { private void onAfterChangingPassword(int userHandle) {
getTrustManager().reportEnabledTrustAgentsChanged(getCurrentOrCallingUserId()); getTrustManager().reportEnabledTrustAgentsChanged(userHandle);
} }
public boolean isCredentialRequiredToDecrypt(boolean defaultValue) { public boolean isCredentialRequiredToDecrypt(boolean defaultValue) {

View File

@@ -77,6 +77,7 @@ import android.security.Credentials;
import android.security.IKeyChainService; import android.security.IKeyChainService;
import android.security.KeyChain; import android.security.KeyChain;
import android.security.KeyChain.KeyChainConnection; import android.security.KeyChain.KeyChainConnection;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.PrintWriterPrinter; import android.util.PrintWriterPrinter;
import android.util.Printer; import android.util.Printer;
@@ -2575,13 +2576,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
return strictestAdmin; return strictestAdmin;
} }
public boolean resetPassword(String password, int flags, int userHandle) { public boolean resetPassword(String passwordOrNull, int flags, int userHandle) {
if (!mHasFeature) { if (!mHasFeature) {
return false; return false;
} }
enforceCrossUserPermission(userHandle); enforceCrossUserPermission(userHandle);
enforceNotManagedProfile(userHandle, "reset the password"); enforceNotManagedProfile(userHandle, "reset the password");
String password = passwordOrNull != null ? passwordOrNull : "";
int quality; int quality;
synchronized (this) { synchronized (this) {
// This api can only be called by an active device admin, // This api can only be called by an active device admin,
@@ -2685,7 +2688,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
long ident = Binder.clearCallingIdentity(); long ident = Binder.clearCallingIdentity();
try { try {
LockPatternUtils utils = new LockPatternUtils(mContext); LockPatternUtils utils = new LockPatternUtils(mContext);
if (!TextUtils.isEmpty(password)) {
utils.saveLockPassword(password, quality, false, userHandle); utils.saveLockPassword(password, quality, false, userHandle);
} else {
utils.clearLock(false, userHandle);
}
boolean requireEntry = (flags & DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY) != 0; boolean requireEntry = (flags & DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY) != 0;
if (requireEntry) { if (requireEntry) {
utils.requireCredentialEntry(UserHandle.USER_ALL); utils.requireCredentialEntry(UserHandle.USER_ALL);