Merge "Add display of password expiration status"
This commit is contained in:
@@ -158,6 +158,20 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout android:orientation="horizontal" android:gravity="center"
|
||||||
|
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView android:id="@+id/password_expiration_status"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<Button android:id="@+id/update_expiration_status_button"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android_layout_gravity="east|center_vertical"
|
||||||
|
android:text="@string/update_expiration_status_label" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout android:orientation="horizontal" android:gravity="center"
|
<LinearLayout android:orientation="horizontal" android:gravity="center"
|
||||||
android:layout_width="match_parent" android:layout_height="wrap_content">
|
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
|||||||
@@ -551,6 +551,7 @@
|
|||||||
<string name="password_history_length_hint">Password History Length</string>
|
<string name="password_history_length_hint">Password History Length</string>
|
||||||
<string name="password_expiration_hint">Password Expiration Timeout (minutes) </string>
|
<string name="password_expiration_hint">Password Expiration Timeout (minutes) </string>
|
||||||
<string name="update_expiration_label">Update</string>
|
<string name="update_expiration_label">Update</string>
|
||||||
|
<string name="update_expiration_status_label">Update Status</string>
|
||||||
<string name="set_password">Set Password</string>
|
<string name="set_password">Set Password</string>
|
||||||
<string name="password_hint">Password</string>
|
<string name="password_hint">Password</string>
|
||||||
<string name="reset_password">Reset Password</string>
|
<string name="reset_password">Reset Password</string>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import android.widget.ArrayAdapter;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@@ -170,7 +171,6 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
EditText mPasswordMinimumSymbols;
|
EditText mPasswordMinimumSymbols;
|
||||||
EditText mPasswordMinimumNonLetter;
|
EditText mPasswordMinimumNonLetter;
|
||||||
EditText mPasswordHistoryLength;
|
EditText mPasswordHistoryLength;
|
||||||
EditText mPasswordExpirationTimeout;
|
|
||||||
Button mSetPasswordButton;
|
Button mSetPasswordButton;
|
||||||
|
|
||||||
EditText mPassword;
|
EditText mPassword;
|
||||||
@@ -190,7 +190,10 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
EditText mProxyList;
|
EditText mProxyList;
|
||||||
Button mProxyButton;
|
Button mProxyButton;
|
||||||
|
|
||||||
|
private EditText mPasswordExpirationTimeout;
|
||||||
private Button mPasswordExpirationButton;
|
private Button mPasswordExpirationButton;
|
||||||
|
private TextView mPasswordExpirationStatus;
|
||||||
|
private Button mPasswordExpirationStatusButton;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -333,12 +336,21 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
mPasswordExpirationButton = (Button) findViewById(R.id.update_expiration_button);
|
mPasswordExpirationButton = (Button) findViewById(R.id.update_expiration_button);
|
||||||
mPasswordExpirationButton.setOnClickListener(new OnClickListener() {
|
mPasswordExpirationButton.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
long expiration;
|
|
||||||
try {
|
try {
|
||||||
setPasswordExpiration(
|
setPasswordExpiration(
|
||||||
Long.parseLong(mPasswordExpirationTimeout.getText().toString()));
|
Long.parseLong(mPasswordExpirationTimeout.getText().toString()));
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
}
|
}
|
||||||
|
updatePasswordExpirationStatus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mPasswordExpirationStatus = (TextView) findViewById(R.id.password_expiration_status);
|
||||||
|
mPasswordExpirationStatusButton =
|
||||||
|
(Button) findViewById(R.id.update_expiration_status_button);
|
||||||
|
mPasswordExpirationStatusButton.setOnClickListener(new OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
updatePasswordExpirationStatus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -458,6 +470,41 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
mMaxFailedPw.setText(Integer.toString(maxFailedPw));
|
mMaxFailedPw.setText(Integer.toString(maxFailedPw));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updatePasswordExpirationStatus() {
|
||||||
|
boolean active = mDPM.isAdminActive(mDeviceAdminSample);
|
||||||
|
String statusText;
|
||||||
|
if (active) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
// We'll query the DevicePolicyManager twice - first for the expiration values
|
||||||
|
// set by the sample app, and later, for the system values (which may be different
|
||||||
|
// if there is another administrator active.)
|
||||||
|
long expirationDate = mDPM.getPasswordExpiration(mDeviceAdminSample);
|
||||||
|
long mSecUntilExpiration = expirationDate - now;
|
||||||
|
if (mSecUntilExpiration >= 0) {
|
||||||
|
statusText = "Expiration in " + countdownString(mSecUntilExpiration);
|
||||||
|
} else {
|
||||||
|
statusText = "Expired " + countdownString(-mSecUntilExpiration) + " ago";
|
||||||
|
}
|
||||||
|
|
||||||
|
// expirationTimeout is the cycle time between required password refresh
|
||||||
|
long expirationTimeout = mDPM.getPasswordExpirationTimeout(mDeviceAdminSample);
|
||||||
|
statusText += " / timeout period " + countdownString(expirationTimeout);
|
||||||
|
|
||||||
|
// Now report the aggregate (global) expiration time
|
||||||
|
statusText += " / Aggregate ";
|
||||||
|
expirationDate = mDPM.getPasswordExpiration(null);
|
||||||
|
mSecUntilExpiration = expirationDate - now;
|
||||||
|
if (mSecUntilExpiration >= 0) {
|
||||||
|
statusText += "expiration in " + countdownString(mSecUntilExpiration);
|
||||||
|
} else {
|
||||||
|
statusText += "expired " + countdownString(-mSecUntilExpiration) + " ago";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
statusText = "<inactive>";
|
||||||
|
}
|
||||||
|
mPasswordExpirationStatus.setText(statusText);
|
||||||
|
}
|
||||||
|
|
||||||
void updatePolicies() {
|
void updatePolicies() {
|
||||||
SharedPreferences prefs = getSamplePreferences(this);
|
SharedPreferences prefs = getSamplePreferences(this);
|
||||||
final int pwQuality = prefs.getInt(PREF_PASSWORD_QUALITY,
|
final int pwQuality = prefs.getInt(PREF_PASSWORD_QUALITY,
|
||||||
@@ -569,6 +616,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
updateButtonStates();
|
updateButtonStates();
|
||||||
|
updatePasswordExpirationStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -615,7 +663,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
|
|
||||||
private OnClickListener mResetPasswordListener = new OnClickListener() {
|
private OnClickListener mResetPasswordListener = new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mAM.isUserAMonkey()) {
|
if (ActivityManager.isUserAMonkey()) {
|
||||||
// Don't trust monkeys to do the right thing!
|
// Don't trust monkeys to do the right thing!
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
|
||||||
builder.setMessage("You can't reset my password because you are a monkey!");
|
builder.setMessage("You can't reset my password because you are a monkey!");
|
||||||
@@ -633,7 +681,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
|
|
||||||
private OnClickListener mForceLockListener = new OnClickListener() {
|
private OnClickListener mForceLockListener = new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mAM.isUserAMonkey()) {
|
if (ActivityManager.isUserAMonkey()) {
|
||||||
// Don't trust monkeys to do the right thing!
|
// Don't trust monkeys to do the right thing!
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
|
||||||
builder.setMessage("You can't lock my screen because you are a monkey!");
|
builder.setMessage("You can't lock my screen because you are a monkey!");
|
||||||
@@ -650,7 +698,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
|
|
||||||
private OnClickListener mWipeDataListener = new OnClickListener() {
|
private OnClickListener mWipeDataListener = new OnClickListener() {
|
||||||
public void onClick(final View v) {
|
public void onClick(final View v) {
|
||||||
if (mAM.isUserAMonkey()) {
|
if (ActivityManager.isUserAMonkey()) {
|
||||||
// Don't trust monkeys to do the right thing!
|
// Don't trust monkeys to do the right thing!
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
|
||||||
builder.setMessage("You can't wipe my data because you are a monkey!");
|
builder.setMessage("You can't wipe my data because you are a monkey!");
|
||||||
@@ -694,7 +742,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
private OnClickListener mSetTimeoutListener = new OnClickListener() {
|
private OnClickListener mSetTimeoutListener = new OnClickListener() {
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mAM.isUserAMonkey()) {
|
if (ActivityManager.isUserAMonkey()) {
|
||||||
// Don't trust monkeys to do the right thing!
|
// Don't trust monkeys to do the right thing!
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
|
||||||
builder.setMessage("You can't lock my screen because you are a monkey!");
|
builder.setMessage("You can't lock my screen because you are a monkey!");
|
||||||
|
|||||||
Reference in New Issue
Block a user