Merge "Disable trust button when no screenlock is set" into nyc-dev

This commit is contained in:
Victor Chang
2016-04-22 11:02:41 +00:00
committed by Android (Google) Code Review

View File

@@ -20,6 +20,7 @@ import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.admin.DevicePolicyManager; import android.app.admin.DevicePolicyManager;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.UserInfo;
import android.net.http.SslCertificate; import android.net.http.SslCertificate;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
@@ -31,6 +32,7 @@ import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Spinner; import android.widget.Spinner;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.TrustedCredentialsSettings.CertHolder; import com.android.settings.TrustedCredentialsSettings.CertHolder;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
@@ -184,10 +186,26 @@ class TrustedCredentialsDialogBuilder extends AlertDialog.Builder {
updateNegativeButton(); updateNegativeButton();
} }
/**
* @return true if current user or parent user is guarded by screenlock
*/
private boolean isUserSecure(int userId) {
final LockPatternUtils lockPatternUtils = new LockPatternUtils(mActivity);
if (lockPatternUtils.isSecure(userId)) {
return true;
}
UserInfo parentUser = mUserManager.getProfileParent(userId);
if (parentUser == null) {
return false;
}
return lockPatternUtils.isSecure(parentUser.id);
}
private void updatePositiveButton() { private void updatePositiveButton() {
final CertHolder certHolder = getCurrentCertInfo(); final CertHolder certHolder = getCurrentCertInfo();
mNeedsApproval = !certHolder.isSystemCert() && mNeedsApproval = !certHolder.isSystemCert()
!mDpm.isCaCertApproved(certHolder.getAlias(), certHolder.getUserId()); && isUserSecure(certHolder.getUserId())
&& !mDpm.isCaCertApproved(certHolder.getAlias(), certHolder.getUserId());
// The ok button is optional. User can still dismiss the dialog by other means. // The ok button is optional. User can still dismiss the dialog by other means.
// Display it only when trust button is not displayed, because we want users to // Display it only when trust button is not displayed, because we want users to