diff --git a/samples/ApiDemos/res/layout/device_admin_sample.xml b/samples/ApiDemos/res/layout/device_admin_sample.xml
index f7273be0a..003674237 100644
--- a/samples/ApiDemos/res/layout/device_admin_sample.xml
+++ b/samples/ApiDemos/res/layout/device_admin_sample.xml
@@ -208,6 +208,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/ApiDemos/res/values/strings.xml b/samples/ApiDemos/res/values/strings.xml
index 2dcdd49c9..e00faff7c 100644
--- a/samples/ApiDemos/res/values/strings.xml
+++ b/samples/ApiDemos/res/values/strings.xml
@@ -512,6 +512,9 @@
Wipe Data
Max screen timeout
Set Timeout
+ Global proxyhost:port
+ No proxy for domain1,domain2
+ Set Global Proxy
diff --git a/samples/ApiDemos/res/xml/device_admin_sample.xml b/samples/ApiDemos/res/xml/device_admin_sample.xml
index 715800370..7b7551345 100644
--- a/samples/ApiDemos/res/xml/device_admin_sample.xml
+++ b/samples/ApiDemos/res/xml/device_admin_sample.xml
@@ -22,6 +22,7 @@
+
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 a28217297..e6cbc9b37 100644
--- a/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
+++ b/samples/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
@@ -42,6 +42,11 @@ import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.util.Arrays;
+import java.util.List;
+
/**
* Example of a do-nothing admin class. When enabled, it lets you control
* some of its policy and reports when there is interesting activity.
@@ -148,6 +153,10 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
private EditText mTimeout;
+ EditText mProxyHost;
+ EditText mProxyList;
+ Button mProxyButton;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -318,6 +327,11 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
mTimeout = (EditText) findViewById(R.id.timeout);
mTimeoutButton = (Button) findViewById(R.id.set_timeout);
mTimeoutButton.setOnClickListener(mSetTimeoutListener);
+
+ mProxyHost = (EditText) findViewById(R.id.proxyhost);
+ mProxyList = (EditText) findViewById(R.id.proxylist);
+ mProxyButton = (Button) findViewById(R.id.set_proxy);
+ mProxyButton.setOnClickListener(mSetProxyListener);
}
void updateButtonStates() {
@@ -614,5 +628,49 @@ public class DeviceAdminSample extends DeviceAdminReceiver {
}
}
};
+
+ private OnClickListener mSetProxyListener = new OnClickListener() {
+
+ public void onClick(View v) {
+ boolean active = mDPM.isAdminActive(mDeviceAdminSample);
+ String proxySpec = mProxyHost.getText().toString();
+ String proxyList = mProxyList.getText().toString();
+ Proxy instProxy;
+ List exclList;
+
+ if ((proxySpec.length() == 0) || (proxySpec == null)) {
+ instProxy = Proxy.NO_PROXY;
+ } else {
+ String[] proxyComponents = proxySpec.split(":");
+ if (proxyComponents.length != 2) {
+ Toast.makeText(Controller.this, "Wrong proxy specification.",
+ Toast.LENGTH_SHORT).show();
+ return;
+ }
+ instProxy = new Proxy(Proxy.Type.HTTP,
+ new InetSocketAddress(proxyComponents[0],
+ Integer.parseInt(proxyComponents[1])));
+ }
+ if ((proxyList == null) || (proxyList.length() == 0)) {
+ exclList = null;
+ } else {
+ String[] listDoms = proxyList.split(",");
+ if (listDoms.length == 0) {
+ Toast.makeText(Controller.this, "Wrong exclusion list format.",
+ Toast.LENGTH_SHORT).show();
+ }
+ exclList = Arrays.asList(listDoms);
+ }
+ if (active) {
+ mDPM.setGlobalProxy(mDeviceAdminSample, instProxy, exclList);
+ ComponentName proxyAdmin = mDPM.getGlobalProxyAdmin();
+ if ((proxyAdmin != null) && (proxyAdmin.equals(mDeviceAdminSample))) {
+ Toast.makeText(Controller.this, "Global Proxy set by device admin.",
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+ };
+
}
}
diff --git a/samples/CorpApp/Android.mk b/samples/CorpApp/Android.mk
new file mode 100644
index 000000000..37b98b03e
--- /dev/null
+++ b/samples/CorpApp/Android.mk
@@ -0,0 +1,17 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := samples
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CorpApp
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
+
diff --git a/samples/CorpApp/AndroidManifest.xml b/samples/CorpApp/AndroidManifest.xml
new file mode 100644
index 000000000..22a33755f
--- /dev/null
+++ b/samples/CorpApp/AndroidManifest.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/CorpApp/res/layout/corp_app_activity.xml b/samples/CorpApp/res/layout/corp_app_activity.xml
new file mode 100644
index 000000000..e21e73444
--- /dev/null
+++ b/samples/CorpApp/res/layout/corp_app_activity.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/CorpApp/res/values/strings.xml b/samples/CorpApp/res/values/strings.xml
new file mode 100644
index 000000000..18ef549e7
--- /dev/null
+++ b/samples/CorpApp/res/values/strings.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+ Corporate Demo App
+ Set Corp Global Proxy
+ Global Proxy successfully set
+ Global Proxy could not be set.
+ Waiting to set Global Proxy...
+ proxy.corpapp.com:8080
+ google.com,youtube.com
+ Sample Corp App Activity
+ Sample Corp App Device Admin
+ Corporate device admin sample demo
+
+
diff --git a/samples/CorpApp/res/xml/corp_device_admin.xml b/samples/CorpApp/res/xml/corp_device_admin.xml
new file mode 100644
index 000000000..f464b607f
--- /dev/null
+++ b/samples/CorpApp/res/xml/corp_device_admin.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/CorpApp/src/com/example/android/corpapp/CorpAppActivity.java b/samples/CorpApp/src/com/example/android/corpapp/CorpAppActivity.java
new file mode 100644
index 000000000..968fb5536
--- /dev/null
+++ b/samples/CorpApp/src/com/example/android/corpapp/CorpAppActivity.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.corpapp;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * A minimal Globl Proxy-setting corp app application.
+ */
+public class CorpAppActivity extends Activity {
+ /**
+ * Called with the activity is first created.
+ */
+
+ Button mSetButton;
+ TextView mStatusText;
+ String mProxyName;
+ String mProxyExclList;
+ String mSuccess;
+ String mFailure;
+
+ DevicePolicyManager mDPM;
+ ActivityManager mAM;
+ ComponentName mCorpDeviceAdmin;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
+ mAM = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
+ mCorpDeviceAdmin = new ComponentName(CorpAppActivity.this, CorpDeviceAdmin.class);
+
+ // Set the layout for this activity. You can find it
+ // in res/layout/corp_app_activity.xml
+ setContentView(R.layout.corp_app_activity);
+
+ mSetButton = (Button)findViewById(R.id.set_button);
+ mSetButton.setOnClickListener(mSetListener);
+ mStatusText = (Button)findViewById(R.id.status_text);
+
+ boolean active = mDPM.isAdminActive(mCorpDeviceAdmin);
+ mSetButton.setEnabled(active);
+ mProxyName = getResources().getString(R.string.corp_app_proxy_name);
+ mProxyExclList = getResources().getString(R.string.corp_app_proxy_excl_list);
+ mSuccess = getResources().getString(R.string.corp_app_status_success_text);
+ mFailure = getResources().getString(R.string.corp_app_status_failed_text);
+ }
+
+ private OnClickListener mSetListener = new OnClickListener() {
+ public void onClick(View v) {
+ String[] proxyComponents = mProxyName.split(":");
+ if (proxyComponents.length != 2) {
+ Toast.makeText(CorpAppActivity.this, "Wrong proxy specification.",
+ Toast.LENGTH_SHORT).show();
+ return;
+ }
+ Proxy instProxy = new Proxy(Proxy.Type.HTTP,
+ new InetSocketAddress(proxyComponents[0],
+ Integer.parseInt(proxyComponents[1])));
+ String[] listDoms = mProxyExclList.split(",");
+ if (listDoms.length == 0) {
+ Toast.makeText(CorpAppActivity.this, "Wrong exclusion list format.",
+ Toast.LENGTH_SHORT).show();
+ }
+ List exclList = Arrays.asList(listDoms);
+ boolean active = mDPM.isAdminActive(mCorpDeviceAdmin);
+ if (active) {
+ mDPM.setGlobalProxy(mCorpDeviceAdmin, instProxy, exclList);
+ ComponentName proxyAdmin = mDPM.getGlobalProxyAdmin();
+ if ((proxyAdmin != null) && (proxyAdmin.equals(mCorpDeviceAdmin))) {
+ Toast.makeText(CorpAppActivity.this, "Global Proxy set by device admin.",
+ Toast.LENGTH_SHORT).show();
+ mStatusText.setText(mSuccess);
+ } else {
+ Toast.makeText(CorpAppActivity.this, "Failed to set Global Proxy.",
+ Toast.LENGTH_SHORT).show();
+ mStatusText.setText(mFailure);
+ }
+ }
+ }
+ };
+
+}
+
diff --git a/samples/CorpApp/src/com/example/android/corpapp/CorpDeviceAdmin.java b/samples/CorpApp/src/com/example/android/corpapp/CorpDeviceAdmin.java
new file mode 100644
index 000000000..f1a83d638
--- /dev/null
+++ b/samples/CorpApp/src/com/example/android/corpapp/CorpDeviceAdmin.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.corpapp;
+
+import android.app.admin.DeviceAdminReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.widget.Toast;
+
+public class CorpDeviceAdmin extends DeviceAdminReceiver {
+
+ static SharedPreferences getSamplePreferences(Context context) {
+ return context.getSharedPreferences(DeviceAdminReceiver.class.getName(), 0);
+ }
+
+ void showToast(Context context, CharSequence msg) {
+ Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void onEnabled(Context context, Intent intent) {
+ showToast(context, "Sample Corp Device Admin: enabled");
+ }
+
+ @Override
+ public CharSequence onDisableRequested(Context context, Intent intent) {
+ return "Sample Corp Device Admin: disable requested";
+ }
+
+ @Override
+ public void onDisabled(Context context, Intent intent) {
+ showToast(context, "Sample Corp Device Admin: disabled");
+ }
+
+ @Override
+ public void onPasswordChanged(Context context, Intent intent) {
+ showToast(context, "Sample Corp Device Admin: pw changed");
+ }
+
+ @Override
+ public void onPasswordFailed(Context context, Intent intent) {
+ showToast(context, "Sample Corp Device Admin: pw failed");
+ }
+
+ @Override
+ public void onPasswordSucceeded(Context context, Intent intent) {
+ showToast(context, "Sample Corp Device Admin: pw succeeded");
+ }
+}