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>
|
||||||
|
|
||||||
|
<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"
|
<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">
|
||||||
|
|
||||||
|
|||||||
@@ -453,6 +453,7 @@
|
|||||||
<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>
|
||||||
|
<string name="max_failed_pw_hint">Password Attempts Wipe Data</string>
|
||||||
<string name="force_lock">Force Lock</string>
|
<string name="force_lock">Force Lock</string>
|
||||||
<string name="wipe_data">Wipe Data</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_MODE = "password_mode";
|
||||||
static String PREF_PASSWORD_LENGTH = "password_length";
|
static String PREF_PASSWORD_LENGTH = "password_length";
|
||||||
|
static String PREF_MAX_FAILED_PW = "max_failed_pw";
|
||||||
|
|
||||||
void showToast(Context context, CharSequence msg) {
|
void showToast(Context context, CharSequence msg) {
|
||||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||||
@@ -63,6 +64,11 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
|||||||
showToast(context, "Sample Device Admin: enabled");
|
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
|
@Override
|
||||||
public void onDisabled(Context context, Intent intent) {
|
public void onDisabled(Context context, Intent intent) {
|
||||||
showToast(context, "Sample Device Admin: disabled");
|
showToast(context, "Sample Device Admin: disabled");
|
||||||
@@ -115,6 +121,8 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
|||||||
EditText mPassword;
|
EditText mPassword;
|
||||||
Button mResetPasswordButton;
|
Button mResetPasswordButton;
|
||||||
|
|
||||||
|
EditText mMaxFailedPw;
|
||||||
|
|
||||||
Button mForceLockButton;
|
Button mForceLockButton;
|
||||||
Button mWipeDataButton;
|
Button mWipeDataButton;
|
||||||
|
|
||||||
@@ -169,6 +177,20 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
|||||||
mResetPasswordButton = (Button)findViewById(R.id.reset_password);
|
mResetPasswordButton = (Button)findViewById(R.id.reset_password);
|
||||||
mResetPasswordButton.setOnClickListener(mResetPasswordListener);
|
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 = (Button)findViewById(R.id.force_lock);
|
||||||
mForceLockButton.setOnClickListener(mForceLockListener);
|
mForceLockButton.setOnClickListener(mForceLockListener);
|
||||||
mWipeDataButton = (Button)findViewById(R.id.wipe_data);
|
mWipeDataButton = (Button)findViewById(R.id.wipe_data);
|
||||||
@@ -205,12 +227,15 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
|||||||
final int pwMode = prefs.getInt(PREF_PASSWORD_MODE,
|
final int pwMode = prefs.getInt(PREF_PASSWORD_MODE,
|
||||||
DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED);
|
DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED);
|
||||||
final int pwLength = prefs.getInt(PREF_PASSWORD_LENGTH, 0);
|
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++) {
|
for (int i=0; i<mPasswordModeValues.length; i++) {
|
||||||
if (mPasswordModeValues[i] == pwMode) {
|
if (mPasswordModeValues[i] == pwMode) {
|
||||||
mPasswordMode.setSelection(i);
|
mPasswordMode.setSelection(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mPasswordLength.setText(Integer.toString(pwLength));
|
mPasswordLength.setText(Integer.toString(pwLength));
|
||||||
|
mMaxFailedPw.setText(Integer.toString(maxFailedPw));
|
||||||
}
|
}
|
||||||
|
|
||||||
void updatePolicies() {
|
void updatePolicies() {
|
||||||
@@ -218,11 +243,13 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
|||||||
final int pwMode = prefs.getInt(PREF_PASSWORD_MODE,
|
final int pwMode = prefs.getInt(PREF_PASSWORD_MODE,
|
||||||
DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED);
|
DevicePolicyManager.PASSWORD_MODE_UNSPECIFIED);
|
||||||
final int pwLength = prefs.getInt(PREF_PASSWORD_LENGTH, 0);
|
final int pwLength = prefs.getInt(PREF_PASSWORD_LENGTH, 0);
|
||||||
|
final int maxFailedPw = prefs.getInt(PREF_PASSWORD_LENGTH, 0);
|
||||||
|
|
||||||
boolean active = mDPM.isAdminActive(mSampleDeviceAdmin);
|
boolean active = mDPM.isAdminActive(mSampleDeviceAdmin);
|
||||||
if (active) {
|
if (active) {
|
||||||
mDPM.setPasswordMode(mSampleDeviceAdmin, pwMode);
|
mDPM.setPasswordMode(mSampleDeviceAdmin, pwMode);
|
||||||
mDPM.setMinimumPasswordLength(mSampleDeviceAdmin, pwLength);
|
mDPM.setMinimumPasswordLength(mSampleDeviceAdmin, pwLength);
|
||||||
|
mDPM.setMaximumFailedPasswordsForWipe(mSampleDeviceAdmin, maxFailedPw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,6 +265,12 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
|||||||
updatePolicies();
|
updatePolicies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setMaxFailedPw(int length) {
|
||||||
|
SharedPreferences prefs = getSamplePreferences(this);
|
||||||
|
prefs.edit().putInt(PREF_MAX_FAILED_PW, length).commit();
|
||||||
|
updatePolicies();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -265,6 +298,8 @@ public class SampleDeviceAdmin extends DeviceAdmin {
|
|||||||
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
|
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
|
||||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
|
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
|
||||||
mSampleDeviceAdmin);
|
mSampleDeviceAdmin);
|
||||||
|
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
|
||||||
|
"Additional text explaining why this needs to be added.");
|
||||||
startActivityForResult(intent, RESULT_ENABLE);
|
startActivityForResult(intent, RESULT_ENABLE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user