diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 58daf39fc..65bfba353 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -790,6 +790,10 @@
Require encryption
Activate encryption
+ Trust Agent Features
+ Enabled Component Name
+ Enabled Features (comma-separated)
+
Current password meets policy requirements
Current password does not meet policy requirements
diff --git a/samples/ApiDemos/res/xml/device_admin_general.xml b/samples/ApiDemos/res/xml/device_admin_general.xml
index cfd0048be..1d0084e6a 100644
--- a/samples/ApiDemos/res/xml/device_admin_general.xml
+++ b/samples/ApiDemos/res/xml/device_admin_general.xml
@@ -57,4 +57,19 @@
+
+
+
+
+
+
+
+
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 82df9037a..71badcdf7 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
@@ -26,7 +26,9 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.os.PersistableBundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
@@ -41,6 +43,8 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -71,6 +75,8 @@ public class DeviceAdminSample extends PreferenceActivity {
private static final String KEY_DISABLE_NOTIFICATIONS = "key_disable_notifications";
private static final String KEY_DISABLE_UNREDACTED = "key_disable_unredacted";
private static final String KEY_DISABLE_TRUST_AGENTS = "key_disable_trust_agents";
+ private static final String KEY_TRUST_AGENT_COMPONENT = "key_trust_agent_component";
+ private static final String KEY_TRUST_AGENT_FEATURES = "key_trust_agent_features";
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";
@@ -274,6 +280,8 @@ public class DeviceAdminSample extends PreferenceActivity {
private CheckBoxPreference mDisableKeyguardNotificationCheckbox;
private CheckBoxPreference mDisableKeyguardTrustAgentCheckbox;
private CheckBoxPreference mDisableKeyguardUnredactedCheckbox;
+ private EditTextPreference mTrustAgentComponent;
+ private EditTextPreference mTrustAgentFeatures;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -304,6 +312,14 @@ public class DeviceAdminSample extends PreferenceActivity {
mDisableKeyguardTrustAgentCheckbox =
(CheckBoxPreference) findPreference(KEY_DISABLE_TRUST_AGENTS);
mDisableKeyguardTrustAgentCheckbox.setOnPreferenceChangeListener(this);
+
+ mTrustAgentComponent =
+ (EditTextPreference) findPreference(KEY_TRUST_AGENT_COMPONENT);
+ mTrustAgentComponent.setOnPreferenceChangeListener(this);
+
+ mTrustAgentFeatures =
+ (EditTextPreference) findPreference(KEY_TRUST_AGENT_FEATURES);
+ mTrustAgentFeatures.setOnPreferenceChangeListener(this);
}
// At onResume time, reload UI with current values as required
@@ -340,8 +356,8 @@ public class DeviceAdminSample extends PreferenceActivity {
if (super.onPreferenceChange(preference, newValue)) {
return true;
}
- boolean value = (Boolean) newValue;
if (preference == mEnableCheckbox) {
+ boolean value = (Boolean) newValue;
if (value != mAdminActive) {
if (value) {
// Launch the activity to have the user enable our admin.
@@ -359,6 +375,7 @@ public class DeviceAdminSample extends PreferenceActivity {
}
}
} else if (preference == mDisableCameraCheckbox) {
+ boolean value = (Boolean) newValue;
mDPM.setCameraDisabled(mDeviceAdminSample, value);
// Delay update because the change is only applied after exiting this method.
postReloadSummaries();
@@ -366,20 +383,39 @@ public class DeviceAdminSample extends PreferenceActivity {
|| preference == mDisableKeyguardSecureCameraCheckbox
|| preference == mDisableKeyguardNotificationCheckbox
|| preference == mDisableKeyguardUnredactedCheckbox
- || preference == mDisableKeyguardTrustAgentCheckbox) {
- // Delay update because the change is only applied after exiting this method.
- getView().post(new Runnable() {
- @Override
- public void run() {
- mDPM.setKeyguardDisabledFeatures(mDeviceAdminSample,
- createKeyguardDisabledFlag());
- }
- });
+ || preference == mDisableKeyguardTrustAgentCheckbox
+ || preference == mTrustAgentComponent
+ || preference == mTrustAgentFeatures) {
+ postUpdateDpmDisableFeatures();
postReloadSummaries();
}
return true;
}
+ private void postUpdateDpmDisableFeatures() {
+ getView().post(new Runnable() {
+ @Override
+ public void run() {
+ mDPM.setKeyguardDisabledFeatures(mDeviceAdminSample,
+ createKeyguardDisabledFlag());
+ String component = mTrustAgentComponent.getText();
+ if (component != null) {
+ ComponentName agent = ComponentName.unflattenFromString(component);
+ if (agent != null) {
+ String featureString = mTrustAgentFeatures.getText();
+ if (featureString != null) {
+ PersistableBundle bundle = new PersistableBundle();
+ bundle.putStringArray("features", featureString.split(","));
+ mDPM.setTrustAgentConfiguration(mDeviceAdminSample, agent, bundle);
+ }
+ } else {
+ Log.w(TAG, "Invalid component: " + component);
+ }
+ }
+ }
+ });
+ }
+
@Override
protected void reloadSummaries() {
super.reloadSummaries();
@@ -416,6 +452,17 @@ public class DeviceAdminSample extends PreferenceActivity {
R.string.keyguard_trust_agents_disabled
: R.string.keyguard_trust_agents_enabled);
mDisableKeyguardTrustAgentCheckbox.setSummary(keyguardEnableTrustAgentSummary);
+
+ final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
+ final boolean trustDisabled =
+ (disabled & DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS) != 0;
+ String component = prefs.getString(mTrustAgentComponent.getKey(), null);
+ mTrustAgentComponent.setSummary(component);
+ mTrustAgentComponent.setEnabled(trustDisabled);
+
+ String features = prefs.getString(mTrustAgentFeatures.getKey(), null);
+ mTrustAgentFeatures.setSummary(features);
+ mTrustAgentFeatures.setEnabled(trustDisabled);
}
/** Updates the device capabilities area (dis/enabling) as the admin is (de)activated */
@@ -426,6 +473,8 @@ public class DeviceAdminSample extends PreferenceActivity {
mDisableKeyguardNotificationCheckbox.setEnabled(enabled);
mDisableKeyguardUnredactedCheckbox.setEnabled(enabled);
mDisableKeyguardTrustAgentCheckbox.setEnabled(enabled);
+ mTrustAgentComponent.setEnabled(enabled);
+ mTrustAgentFeatures.setEnabled(enabled);
}
}