Add test case for new keyguard widget API
Change-Id: Ibcb19c15964f4ea4bad36ec102e9aed8b4ea9c41
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 04c7dc3..e1e8adb 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -173,7 +173,7 @@
<string name="fragment_stack">App/Fragment/Stack</string>
<string name="new_fragment">Push</string>
<string name="delete_fragment">Pop</string>
-
+
<string name="first">First</string>
<string name="last">Last</string>
@@ -677,6 +677,12 @@
<string name="enable_admin">Enable admin</string>
<string name="device_capabilities_category">Device capabilities</string>
<string name="disable_camera">Disable all device cameras</string>
+ <string name="disable_keyguard_widgets">Disable keyguard widgets</string>
+ <string name="disable_keyguard_secure_camera">Disable keyguard secure camera</string>
+ <string name="keyguard_widgets_disabled">Keyguard widgets disabled</string>
+ <string name="keyguard_widgets_enabled">Keyguard widgets enabled</string>
+ <string name="keyguard_secure_camera_disabled">Keyguard secure camera disabled</string>
+ <string name="keyguard_secure_camera_enabled">Keyguard secure camera enabled</string>
<string name="camera_disabled">Device cameras disabled</string>
<string name="camera_enabled">Device cameras enabled</string>
<string name="password_controls_category">Password controls</string>
diff --git a/samples/ApiDemos/res/xml/device_admin_general.xml b/samples/ApiDemos/res/xml/device_admin_general.xml
index 61ccd32..3a1dd45 100644
--- a/samples/ApiDemos/res/xml/device_admin_general.xml
+++ b/samples/ApiDemos/res/xml/device_admin_general.xml
@@ -35,6 +35,14 @@
android:key="key_disable_camera"
android:title="@string/disable_camera" />
+ <CheckBoxPreference
+ android:key="key_disable_keyguard_widgets"
+ android:title="@string/disable_keyguard_widgets" />
+
+ <CheckBoxPreference
+ android:key="key_disable_keyguard_secure_camera"
+ android:title="@string/disable_keyguard_secure_camera" />
+
</PreferenceCategory>
</PreferenceScreen>
diff --git a/samples/ApiDemos/res/xml/device_admin_sample.xml b/samples/ApiDemos/res/xml/device_admin_sample.xml
index 2468919..4c8fc40 100644
--- a/samples/ApiDemos/res/xml/device_admin_sample.xml
+++ b/samples/ApiDemos/res/xml/device_admin_sample.xml
@@ -25,6 +25,7 @@
<expire-password />
<encrypted-storage />
<disable-camera />
+ <disable-keyguard-features />
</uses-policies>
</device-admin>
<!-- END_INCLUDE(meta_data) -->
diff --git a/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java b/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
index 324b8ce..db50185 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
@@ -68,6 +68,9 @@
// The following keys are used to find each preference item
private static final String KEY_ENABLE_ADMIN = "key_enable_admin";
private static final String KEY_DISABLE_CAMERA = "key_disable_camera";
+ private static final String KEY_DISABLE_KEYGUARD_WIDGETS = "key_disable_keyguard_widgets";
+ private static final String KEY_DISABLE_KEYGUARD_SECURE_CAMERA
+ = "key_disable_keyguard_secure_camera";
private static final String KEY_CATEGORY_QUALITY = "key_category_quality";
private static final String KEY_SET_PASSWORD = "key_set_password";
@@ -245,6 +248,8 @@
// UI elements
private CheckBoxPreference mEnableCheckbox;
private CheckBoxPreference mDisableCameraCheckbox;
+ private CheckBoxPreference mDisableKeyguardWidgetsCheckbox;
+ private CheckBoxPreference mDisableKeyguardSecureCameraCheckbox;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -254,6 +259,12 @@
mEnableCheckbox.setOnPreferenceChangeListener(this);
mDisableCameraCheckbox = (CheckBoxPreference) findPreference(KEY_DISABLE_CAMERA);
mDisableCameraCheckbox.setOnPreferenceChangeListener(this);
+ mDisableKeyguardWidgetsCheckbox =
+ (CheckBoxPreference) findPreference(KEY_DISABLE_KEYGUARD_WIDGETS);
+ mDisableKeyguardWidgetsCheckbox.setOnPreferenceChangeListener(this);
+ mDisableKeyguardSecureCameraCheckbox =
+ (CheckBoxPreference) findPreference(KEY_DISABLE_KEYGUARD_SECURE_CAMERA);
+ mDisableKeyguardSecureCameraCheckbox.setOnPreferenceChangeListener(this);
}
// At onResume time, reload UI with current values as required
@@ -265,10 +276,20 @@
if (mAdminActive) {
mDPM.setCameraDisabled(mDeviceAdminSample, mDisableCameraCheckbox.isChecked());
+ mDPM.setKeyguardDisabledFeatures(mDeviceAdminSample, createKeyguardDisabledFlag());
reloadSummaries();
}
}
+ int createKeyguardDisabledFlag() {
+ int flags = DevicePolicyManager.KEYGUARD_DISABLE_FEATURES_NONE;
+ flags |= mDisableKeyguardWidgetsCheckbox.isChecked() ?
+ DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL : 0;
+ flags |= mDisableKeyguardSecureCameraCheckbox.isChecked() ?
+ DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA : 0;
+ return flags;
+ }
+
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (super.onPreferenceChange(preference, newValue)) {
@@ -295,6 +316,10 @@
} else if (preference == mDisableCameraCheckbox) {
mDPM.setCameraDisabled(mDeviceAdminSample, value);
reloadSummaries();
+ } else if (preference == mDisableKeyguardWidgetsCheckbox
+ || preference == mDisableKeyguardSecureCameraCheckbox) {
+ mDPM.setKeyguardDisabledFeatures(mDeviceAdminSample, createKeyguardDisabledFlag());
+ reloadSummaries();
}
return true;
}
@@ -305,11 +330,25 @@
String cameraSummary = getString(mDPM.getCameraDisabled(mDeviceAdminSample)
? R.string.camera_disabled : R.string.camera_enabled);
mDisableCameraCheckbox.setSummary(cameraSummary);
+
+ int disabled = mDPM.getKeyguardDisabledFeatures(mDeviceAdminSample);
+
+ String keyguardWidgetSummary = getString(
+ (disabled & DevicePolicyManager.KEYGUARD_DISABLE_WIDGETS_ALL) != 0 ?
+ R.string.keyguard_widgets_disabled : R.string.keyguard_widgets_enabled);
+ mDisableKeyguardWidgetsCheckbox.setSummary(keyguardWidgetSummary);
+
+ String keyguardSecureCameraSummary = getString(
+ (disabled & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0 ?
+ R.string.keyguard_secure_camera_disabled : R.string.keyguard_secure_camera_enabled);
+ mDisableKeyguardSecureCameraCheckbox.setSummary(keyguardSecureCameraSummary);
}
/** Updates the device capabilities area (dis/enabling) as the admin is (de)activated */
private void enableDeviceCapabilitiesArea(boolean enabled) {
mDisableCameraCheckbox.setEnabled(enabled);
+ mDisableKeyguardWidgetsCheckbox.setEnabled(enabled);
+ mDisableKeyguardSecureCameraCheckbox.setEnabled(enabled);
}
}