Fix 2527411: Extend sample DPM app to test setMaximumTimeToLock()
Change-Id: I1a0ff93a27d7d27b66acbacf953eb0984e85e4cf
This commit is contained in:
@@ -4,9 +4,9 @@
|
|||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@@ -27,47 +27,47 @@
|
|||||||
android:paddingBottom="4dip"
|
android:paddingBottom="4dip"
|
||||||
android:text="@string/sample_device_admin_summary"/>
|
android:text="@string/sample_device_admin_summary"/>
|
||||||
|
|
||||||
<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">
|
||||||
|
|
||||||
|
<Button android:id="@+id/enable"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:text="@string/enable_admin">
|
||||||
|
<requestFocus />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button android:id="@+id/disable"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:text="@string/disable_admin">
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button android:id="@+id/enable"
|
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
|
||||||
android:text="@string/enable_admin">
|
|
||||||
<requestFocus />
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button android:id="@+id/disable"
|
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
|
||||||
android:text="@string/disable_admin">
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</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">
|
||||||
|
|
||||||
<Spinner android:id="@+id/password_quality"
|
<Spinner android:id="@+id/password_quality"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:drawSelectorOnTop="true"
|
android:drawSelectorOnTop="true"
|
||||||
android:prompt="@string/password_quality">
|
android:prompt="@string/password_quality">
|
||||||
</Spinner>
|
</Spinner>
|
||||||
|
|
||||||
<EditText android:id="@+id/password_length"
|
<EditText android:id="@+id/password_length"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="@string/password_length_hint"
|
android:hint="@string/password_length_hint"
|
||||||
android:inputType="number">
|
android:inputType="number">
|
||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<Button android:id="@+id/set_password"
|
<Button android:id="@+id/set_password"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
android_layout_gravity="east|center_vertical"
|
android_layout_gravity="east|center_vertical"
|
||||||
android:text="@string/set_password">
|
android:text="@string/set_password">
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<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">
|
||||||
|
|
||||||
@@ -78,15 +78,15 @@
|
|||||||
android:hint="@string/password_hint"
|
android:hint="@string/password_hint"
|
||||||
android:freezesText="true">
|
android:freezesText="true">
|
||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
<Button android:id="@+id/reset_password"
|
<Button android:id="@+id/reset_password"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
android:layout_weight="0"
|
android:layout_weight="0"
|
||||||
android:text="@string/reset_password">
|
android:text="@string/reset_password">
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
</LinearLayout>
|
</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">
|
||||||
|
|
||||||
@@ -96,25 +96,45 @@
|
|||||||
android:hint="@string/max_failed_pw_hint"
|
android:hint="@string/max_failed_pw_hint"
|
||||||
android:inputType="number">
|
android:inputType="number">
|
||||||
</EditText>
|
</EditText>
|
||||||
|
|
||||||
</LinearLayout>
|
</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">
|
||||||
|
|
||||||
<Button android:id="@+id/force_lock"
|
<Button android:id="@+id/force_lock"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
android:layout_weight="0"
|
android:layout_weight="0"
|
||||||
android:text="@string/force_lock">
|
android:text="@string/force_lock">
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button android:id="@+id/wipe_data"
|
<Button android:id="@+id/wipe_data"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
android:layout_weight="0"
|
android:layout_weight="0"
|
||||||
android:text="@string/wipe_data">
|
android:text="@string/wipe_data">
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout android:orientation="horizontal" android:gravity="center"
|
||||||
|
android:layout_width="match_parent" android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<EditText android:id="@+id/timeout"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:hint="@string/timeout_hint"
|
||||||
|
android:inputType="number"
|
||||||
|
android:freezesText="true">
|
||||||
|
</EditText>
|
||||||
|
|
||||||
|
<Button android:id="@+id/set_timeout"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:text="@string/set_timeout_label">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
<string name="activity_setwallpaper">App/Activity/SetWallpaper</string>
|
<string name="activity_setwallpaper">App/Activity/SetWallpaper</string>
|
||||||
<string name="set_wallpaper">Set Wallpaper</string>
|
<string name="set_wallpaper">Set Wallpaper</string>
|
||||||
<string name="randomize">Randomize</string>
|
<string name="randomize">Randomize</string>
|
||||||
|
|
||||||
<string name="activity_translucent">App/Activity/Translucent</string>
|
<string name="activity_translucent">App/Activity/Translucent</string>
|
||||||
<string name="translucent_background">Example of how you can make an
|
<string name="translucent_background">Example of how you can make an
|
||||||
activity have a translucent background, compositing over
|
activity have a translucent background, compositing over
|
||||||
@@ -146,7 +146,7 @@
|
|||||||
<string name="startfail_service">Start failed delivery</string>
|
<string name="startfail_service">Start failed delivery</string>
|
||||||
<string name="service_created">Service created.</string>
|
<string name="service_created">Service created.</string>
|
||||||
<string name="service_destroyed">Service destroyed.</string>
|
<string name="service_destroyed">Service destroyed.</string>
|
||||||
|
|
||||||
<string name="foreground_service_started">Service is in the foreground</string>
|
<string name="foreground_service_started">Service is in the foreground</string>
|
||||||
<string name="foreground_service_label">Sample Foreground Service</string>
|
<string name="foreground_service_label">Sample Foreground Service</string>
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@
|
|||||||
<string name="activity_external_storage">Content/Storage/External Storage</string>
|
<string name="activity_external_storage">Content/Storage/External Storage</string>
|
||||||
<string name="create">Create</string>
|
<string name="create">Create</string>
|
||||||
<string name="delete">Delete</string>
|
<string name="delete">Delete</string>
|
||||||
|
|
||||||
<string name="activity_styled_text">Content/Resources/<i>Styled</i> <b>Text</b></string>
|
<string name="activity_styled_text">Content/Resources/<i>Styled</i> <b>Text</b></string>
|
||||||
<string name="styled_text_rsrc">Initialized from a resource:</string>
|
<string name="styled_text_rsrc">Initialized from a resource:</string>
|
||||||
<string name="styled_text">Plain, <b>bold</b>, <i>italic</i>, <b><i>bold-italic</i></b></string>
|
<string name="styled_text">Plain, <b>bold</b>, <i>italic</i>, <b><i>bold-italic</i></b></string>
|
||||||
@@ -249,11 +249,11 @@
|
|||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
<!-- app/intents examples strings -->
|
<!-- app/intents examples strings -->
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
|
|
||||||
<string name="activity_intents">App/Intents</string>
|
<string name="activity_intents">App/Intents</string>
|
||||||
<string name="intents">Example of launching various Intents.</string>
|
<string name="intents">Example of launching various Intents.</string>
|
||||||
<string name="get_music">Get Music</string>
|
<string name="get_music">Get Music</string>
|
||||||
|
|
||||||
<!-- =================================== -->
|
<!-- =================================== -->
|
||||||
<!-- app/notification examples strings -->
|
<!-- app/notification examples strings -->
|
||||||
<!-- =================================== -->
|
<!-- =================================== -->
|
||||||
@@ -440,18 +440,18 @@
|
|||||||
|
|
||||||
<string name="msg_launcher_shortcuts">This activity creates shortcuts for the launcher (home screen), and receives intents from those shortcuts. To try it, return to the launcher and long-press to create a shortcut.</string>
|
<string name="msg_launcher_shortcuts">This activity creates shortcuts for the launcher (home screen), and receives intents from those shortcuts. To try it, return to the launcher and long-press to create a shortcut.</string>
|
||||||
<string name="label_intent">Intent:</string>
|
<string name="label_intent">Intent:</string>
|
||||||
|
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
<!-- app/device policies examples strings -->
|
<!-- app/device policies examples strings -->
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
|
|
||||||
<string name="activity_sample_device_admin">App/Device Admin</string>
|
<string name="activity_sample_device_admin">App/Device Admin</string>
|
||||||
<string name="sample_device_admin">Sample Device Admin</string>
|
<string name="sample_device_admin">Sample Device Admin</string>
|
||||||
<string name="sample_device_admin_description">Sample code for writing
|
<string name="sample_device_admin_description">Sample code for writing
|
||||||
a DeviceAdmin class. This implementation provides a UI (in ApiDemos)
|
a DeviceAdmin class. This implementation provides a UI (in ApiDemos)
|
||||||
for you to directly control what the DeviceAdmin does with the
|
for you to directly control what the DeviceAdmin does with the
|
||||||
system.</string>
|
system.</string>
|
||||||
|
|
||||||
<string name="sample_device_admin_summary">Demonstration of a DeviceAdmin
|
<string name="sample_device_admin_summary">Demonstration of a DeviceAdmin
|
||||||
class for administering the user\'s device.</string>
|
class for administering the user\'s device.</string>
|
||||||
<string name="enable_admin">Enable Admin</string>
|
<string name="enable_admin">Enable Admin</string>
|
||||||
@@ -464,7 +464,9 @@
|
|||||||
<string name="max_failed_pw_hint">Password Attempts Wipe Data</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>
|
||||||
|
<string name="timeout_hint">Max screen timeout</string>
|
||||||
|
<string name="set_timeout_label">Set Timeout</string>
|
||||||
|
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
<!-- app/voice recognition examples strings -->
|
<!-- app/voice recognition examples strings -->
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
@@ -472,7 +474,7 @@
|
|||||||
<string name="voice_recognition_prompt">This activity demonstrates the voice recognition APIs.</string>
|
<string name="voice_recognition_prompt">This activity demonstrates the voice recognition APIs.</string>
|
||||||
<string name="speak_button">Speak!</string>
|
<string name="speak_button">Speak!</string>
|
||||||
<string name="voice_recognition_results">Results:</string>
|
<string name="voice_recognition_results">Results:</string>
|
||||||
|
|
||||||
<!-- ============================ -->
|
<!-- ============================ -->
|
||||||
<!-- graphics examples strings -->
|
<!-- graphics examples strings -->
|
||||||
<!-- ============================ -->
|
<!-- ============================ -->
|
||||||
@@ -480,7 +482,7 @@
|
|||||||
<string name="hide_me">Hide Me!</string>
|
<string name="hide_me">Hide Me!</string>
|
||||||
|
|
||||||
<string name="density_title">Density: Unknown Screen</string>
|
<string name="density_title">Density: Unknown Screen</string>
|
||||||
|
|
||||||
<!-- ============================ -->
|
<!-- ============================ -->
|
||||||
<!-- media examples strings -->
|
<!-- media examples strings -->
|
||||||
<!-- ============================ -->
|
<!-- ============================ -->
|
||||||
|
|||||||
@@ -51,15 +51,15 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
static SharedPreferences getSamplePreferences(Context context) {
|
static SharedPreferences getSamplePreferences(Context context) {
|
||||||
return context.getSharedPreferences(DeviceAdminReceiver.class.getName(), 0);
|
return context.getSharedPreferences(DeviceAdminReceiver.class.getName(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String PREF_PASSWORD_QUALITY = "password_quality";
|
static String PREF_PASSWORD_QUALITY = "password_quality";
|
||||||
static String PREF_PASSWORD_LENGTH = "password_length";
|
static String PREF_PASSWORD_LENGTH = "password_length";
|
||||||
static String PREF_MAX_FAILED_PW = "max_failed_pw";
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnabled(Context context, Intent intent) {
|
public void onEnabled(Context context, Intent intent) {
|
||||||
showToast(context, "Sample Device Admin: enabled");
|
showToast(context, "Sample Device Admin: enabled");
|
||||||
@@ -94,20 +94,20 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
* <p>UI control for the sample device admin. This provides an interface
|
* <p>UI control for the sample device admin. This provides an interface
|
||||||
* to enable, disable, and perform other operations with it to see
|
* to enable, disable, and perform other operations with it to see
|
||||||
* their effect.</p>
|
* their effect.</p>
|
||||||
*
|
*
|
||||||
* <p>Note that this is implemented as an inner class only keep the sample
|
* <p>Note that this is implemented as an inner class only keep the sample
|
||||||
* all together; typically this code would appear in some separate class.
|
* all together; typically this code would appear in some separate class.
|
||||||
*/
|
*/
|
||||||
public static class Controller extends Activity {
|
public static class Controller extends Activity {
|
||||||
static final int RESULT_ENABLE = 1;
|
static final int RESULT_ENABLE = 1;
|
||||||
|
|
||||||
DevicePolicyManager mDPM;
|
DevicePolicyManager mDPM;
|
||||||
ActivityManager mAM;
|
ActivityManager mAM;
|
||||||
ComponentName mDeviceAdminSample;
|
ComponentName mDeviceAdminSample;
|
||||||
|
|
||||||
Button mEnableButton;
|
Button mEnableButton;
|
||||||
Button mDisableButton;
|
Button mDisableButton;
|
||||||
|
|
||||||
// Password quality spinner choices
|
// Password quality spinner choices
|
||||||
// This list must match the list found in samples/ApiDemos/res/values/arrays.xml
|
// This list must match the list found in samples/ApiDemos/res/values/arrays.xml
|
||||||
final static int mPasswordQualityValues[] = new int[] {
|
final static int mPasswordQualityValues[] = new int[] {
|
||||||
@@ -120,15 +120,19 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
Spinner mPasswordQuality;
|
Spinner mPasswordQuality;
|
||||||
EditText mPasswordLength;
|
EditText mPasswordLength;
|
||||||
Button mSetPasswordButton;
|
Button mSetPasswordButton;
|
||||||
|
|
||||||
EditText mPassword;
|
EditText mPassword;
|
||||||
Button mResetPasswordButton;
|
Button mResetPasswordButton;
|
||||||
|
|
||||||
EditText mMaxFailedPw;
|
EditText mMaxFailedPw;
|
||||||
|
|
||||||
Button mForceLockButton;
|
Button mForceLockButton;
|
||||||
Button mWipeDataButton;
|
Button mWipeDataButton;
|
||||||
|
|
||||||
|
private Button mTimeoutButton;
|
||||||
|
|
||||||
|
private EditText mTimeout;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -136,7 +140,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
mAM = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
|
mAM = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
mDeviceAdminSample = new ComponentName(Controller.this, DeviceAdminSample.class);
|
mDeviceAdminSample = new ComponentName(Controller.this, DeviceAdminSample.class);
|
||||||
|
|
||||||
setContentView(R.layout.device_admin_sample);
|
setContentView(R.layout.device_admin_sample);
|
||||||
|
|
||||||
// Watch for button clicks.
|
// Watch for button clicks.
|
||||||
@@ -144,7 +148,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
mEnableButton.setOnClickListener(mEnableListener);
|
mEnableButton.setOnClickListener(mEnableListener);
|
||||||
mDisableButton = (Button)findViewById(R.id.disable);
|
mDisableButton = (Button)findViewById(R.id.disable);
|
||||||
mDisableButton.setOnClickListener(mDisableListener);
|
mDisableButton.setOnClickListener(mDisableListener);
|
||||||
|
|
||||||
mPasswordQuality = (Spinner)findViewById(R.id.password_quality);
|
mPasswordQuality = (Spinner)findViewById(R.id.password_quality);
|
||||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
|
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
|
||||||
this, R.array.password_qualities, android.R.layout.simple_spinner_item);
|
this, R.array.password_qualities, android.R.layout.simple_spinner_item);
|
||||||
@@ -176,11 +180,11 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
});
|
});
|
||||||
mSetPasswordButton = (Button)findViewById(R.id.set_password);
|
mSetPasswordButton = (Button)findViewById(R.id.set_password);
|
||||||
mSetPasswordButton.setOnClickListener(mSetPasswordListener);
|
mSetPasswordButton.setOnClickListener(mSetPasswordListener);
|
||||||
|
|
||||||
mPassword = (EditText)findViewById(R.id.password);
|
mPassword = (EditText)findViewById(R.id.password);
|
||||||
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 = (EditText)findViewById(R.id.max_failed_pw);
|
||||||
mMaxFailedPw.addTextChangedListener(new TextWatcher() {
|
mMaxFailedPw.addTextChangedListener(new TextWatcher() {
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
@@ -199,11 +203,15 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
||||||
mWipeDataButton.setOnClickListener(mWipeDataListener);
|
mWipeDataButton.setOnClickListener(mWipeDataListener);
|
||||||
|
|
||||||
|
mTimeout = (EditText) findViewById(R.id.timeout);
|
||||||
|
mTimeoutButton = (Button) findViewById(R.id.set_timeout);
|
||||||
|
mTimeoutButton.setOnClickListener(mSetTimeoutListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateButtonStates() {
|
void updateButtonStates() {
|
||||||
@@ -230,14 +238,14 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
mWipeDataButton.setEnabled(false);
|
mWipeDataButton.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateControls() {
|
void updateControls() {
|
||||||
SharedPreferences prefs = getSamplePreferences(this);
|
SharedPreferences prefs = getSamplePreferences(this);
|
||||||
final int pwQuality = prefs.getInt(PREF_PASSWORD_QUALITY,
|
final int pwQuality = prefs.getInt(PREF_PASSWORD_QUALITY,
|
||||||
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
|
DevicePolicyManager.PASSWORD_QUALITY_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);
|
final int maxFailedPw = prefs.getInt(PREF_MAX_FAILED_PW, 0);
|
||||||
|
|
||||||
for (int i=0; i<mPasswordQualityValues.length; i++) {
|
for (int i=0; i<mPasswordQualityValues.length; i++) {
|
||||||
if (mPasswordQualityValues[i] == pwQuality) {
|
if (mPasswordQualityValues[i] == pwQuality) {
|
||||||
mPasswordQuality.setSelection(i);
|
mPasswordQuality.setSelection(i);
|
||||||
@@ -246,14 +254,14 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
mPasswordLength.setText(Integer.toString(pwLength));
|
mPasswordLength.setText(Integer.toString(pwLength));
|
||||||
mMaxFailedPw.setText(Integer.toString(maxFailedPw));
|
mMaxFailedPw.setText(Integer.toString(maxFailedPw));
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
|
DevicePolicyManager.PASSWORD_QUALITY_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);
|
final int maxFailedPw = prefs.getInt(PREF_MAX_FAILED_PW, 0);
|
||||||
|
|
||||||
boolean active = mDPM.isAdminActive(mDeviceAdminSample);
|
boolean active = mDPM.isAdminActive(mDeviceAdminSample);
|
||||||
if (active) {
|
if (active) {
|
||||||
mDPM.setPasswordQuality(mDeviceAdminSample, pwQuality);
|
mDPM.setPasswordQuality(mDeviceAdminSample, pwQuality);
|
||||||
@@ -261,25 +269,25 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
mDPM.setMaximumFailedPasswordsForWipe(mDeviceAdminSample, maxFailedPw);
|
mDPM.setMaximumFailedPasswordsForWipe(mDeviceAdminSample, maxFailedPw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPasswordQuality(int quality) {
|
void setPasswordQuality(int quality) {
|
||||||
SharedPreferences prefs = getSamplePreferences(this);
|
SharedPreferences prefs = getSamplePreferences(this);
|
||||||
prefs.edit().putInt(PREF_PASSWORD_QUALITY, quality).commit();
|
prefs.edit().putInt(PREF_PASSWORD_QUALITY, quality).commit();
|
||||||
updatePolicies();
|
updatePolicies();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPasswordLength(int length) {
|
void setPasswordLength(int length) {
|
||||||
SharedPreferences prefs = getSamplePreferences(this);
|
SharedPreferences prefs = getSamplePreferences(this);
|
||||||
prefs.edit().putInt(PREF_PASSWORD_LENGTH, length).commit();
|
prefs.edit().putInt(PREF_PASSWORD_LENGTH, length).commit();
|
||||||
updatePolicies();
|
updatePolicies();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMaxFailedPw(int length) {
|
void setMaxFailedPw(int length) {
|
||||||
SharedPreferences prefs = getSamplePreferences(this);
|
SharedPreferences prefs = getSamplePreferences(this);
|
||||||
prefs.edit().putInt(PREF_MAX_FAILED_PW, length).commit();
|
prefs.edit().putInt(PREF_MAX_FAILED_PW, length).commit();
|
||||||
updatePolicies();
|
updatePolicies();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@@ -297,7 +305,7 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -397,5 +405,24 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
|
|||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private OnClickListener mSetTimeoutListener = new OnClickListener() {
|
||||||
|
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (mAM.isUserAMonkey()) {
|
||||||
|
// Don't trust monkeys to do the right thing!
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(Controller.this);
|
||||||
|
builder.setMessage("You can't lock my screen because you are a monkey!");
|
||||||
|
builder.setPositiveButton("I admit defeat", null);
|
||||||
|
builder.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean active = mDPM.isAdminActive(mDeviceAdminSample);
|
||||||
|
if (active) {
|
||||||
|
long timeMs = 1000L*Long.parseLong(mTimeout.getText().toString());
|
||||||
|
mDPM.setMaximumTimeToLock(mDeviceAdminSample, timeMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user