More device admin work:
- Example warning message when disabling. - UI to set maximum failed password attempts.
This commit is contained in:
@@ -87,6 +87,18 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:orientation="horizontal" android:gravity="center"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||
|
||||
<EditText android:id="@+id/max_failed_pw"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/max_failed_pw_hint"
|
||||
android:inputType="number">
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:orientation="horizontal" android:gravity="center"
|
||||
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||
|
||||
|
||||
@@ -453,6 +453,7 @@
|
||||
<string name="set_password">Set Password</string>
|
||||
<string name="password_hint">Password</string>
|
||||
<string name="reset_password">Reset Password</string>
|
||||
<string name="max_failed_pw_hint">Password Attempts Wipe Data</string>
|
||||
<string name="force_lock">Force Lock</string>
|
||||
<string name="wipe_data">Wipe Data</string>
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
||||
|
||||
static String PREF_PASSWORD_MODE = "password_mode";
|
||||
static String PREF_PASSWORD_LENGTH = "password_length";
|
||||
static String PREF_MAX_FAILED_PW = "max_failed_pw";
|
||||
|
||||
void showToast(Context context, CharSequence msg) {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
@@ -63,6 +64,11 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
||||
showToast(context, "Sample Device Admin: enabled");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence onDisableRequested(Context context, Intent intent) {
|
||||
return "This is an optional message to warn the user about disabling.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisabled(Context context, Intent intent) {
|
||||
showToast(context, "Sample Device Admin: disabled");
|
||||
@@ -115,6 +121,8 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
||||
EditText mPassword;
|
||||
Button mResetPasswordButton;
|
||||
|
||||
EditText mMaxFailedPw;
|
||||
|
||||
Button mForceLockButton;
|
||||
Button mWipeDataButton;
|
||||
|
||||
@@ -169,6 +177,20 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
||||
mResetPasswordButton = (Button)findViewById(R.id.reset_password);
|
||||
mResetPasswordButton.setOnClickListener(mResetPasswordListener);
|
||||
|
||||
mMaxFailedPw = (EditText)findViewById(R.id.max_failed_pw);
|
||||
mMaxFailedPw.addTextChangedListener(new TextWatcher() {
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
try {
|
||||
setMaxFailedPw(Integer.parseInt(s.toString()));
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mForceLockButton = (Button)findViewById(R.id.force_lock);
|
||||
mForceLockButton.setOnClickListener(mForceLockListener);
|
||||
mWipeDataButton = (Button)findViewById(R.id.wipe_data);
|
||||
@@ -205,12 +227,15 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
||||
final int pwMode = prefs.getInt(PREF_PASSWORD_MODE,
|
||||
DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED);
|
||||
final int pwLength = prefs.getInt(PREF_PASSWORD_LENGTH, 0);
|
||||
final int maxFailedPw = prefs.getInt(PREF_MAX_FAILED_PW, 0);
|
||||
|
||||
for (int i=0; i<mPasswordModeValues.length; i++) {
|
||||
if (mPasswordModeValues[i] == pwMode) {
|
||||
mPasswordMode.setSelection(i);
|
||||
}
|
||||
}
|
||||
mPasswordLength.setText(Integer.toString(pwLength));
|
||||
mMaxFailedPw.setText(Integer.toString(maxFailedPw));
|
||||
}
|
||||
|
||||
void updatePolicies() {
|
||||
@@ -218,11 +243,13 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
||||
final int pwMode = prefs.getInt(PREF_PASSWORD_MODE,
|
||||
DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED);
|
||||
final int pwLength = prefs.getInt(PREF_PASSWORD_LENGTH, 0);
|
||||
final int maxFailedPw = prefs.getInt(PREF_PASSWORD_LENGTH, 0);
|
||||
|
||||
boolean active = mDPM.isAdminActive(mSampleDeviceAdmin);
|
||||
if (active) {
|
||||
mDPM.setPasswordMode(mSampleDeviceAdmin, pwMode);
|
||||
mDPM.setMinimumPasswordLength(mSampleDeviceAdmin, pwLength);
|
||||
mDPM.setMaximumFailedPasswordsForWipe(mSampleDeviceAdmin, maxFailedPw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,6 +265,12 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
||||
updatePolicies();
|
||||
}
|
||||
|
||||
void setMaxFailedPw(int length) {
|
||||
SharedPreferences prefs = getSamplePreferences(this);
|
||||
prefs.edit().putInt(PREF_MAX_FAILED_PW, length).commit();
|
||||
updatePolicies();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
@@ -265,6 +298,8 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
||||
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
|
||||
mSampleDeviceAdmin);
|
||||
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
|
||||
"Additional text explaining why this needs to be added.");
|
||||
startActivityForResult(intent, RESULT_ENABLE);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user