summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/mdm
diff options
context:
space:
mode:
authorDave Tharp <dtharp@codeaurora.org>2015-04-09 15:32:21 -0700
committerWebTech Code Review <code-review@localhost>2015-04-10 14:00:49 -0700
commit81729beff2ec0cf0af4288f7c73e4f3eb3d57d7b (patch)
tree896e244bf9d919f0810638868a403beb5524dc35 /src/com/android/browser/mdm
parent076032992467d6b0016e9c5f4ca3c8fe4ebdeeb7 (diff)
downloadandroid_packages_apps_Gello-81729beff2ec0cf0af4288f7c73e4f3eb3d57d7b.tar.gz
android_packages_apps_Gello-81729beff2ec0cf0af4288f7c73e4f3eb3d57d7b.tar.bz2
android_packages_apps_Gello-81729beff2ec0cf0af4288f7c73e4f3eb3d57d7b.zip
MDM Proxy Mode Restriction Triggering
Implemented triggering mechanism to transport MDM proxy settings to native code. Also modified unit tests to set mode to NULL instead of MODE_NONE. There's a subtle difference. Change-Id: I89f3873eb0398b4a4ac65553ed3c0ecf1b343399
Diffstat (limited to 'src/com/android/browser/mdm')
-rw-r--r--src/com/android/browser/mdm/ProxyRestriction.java65
-rw-r--r--src/com/android/browser/mdm/tests/ProxyRestrictionsTest.java8
2 files changed, 43 insertions, 30 deletions
diff --git a/src/com/android/browser/mdm/ProxyRestriction.java b/src/com/android/browser/mdm/ProxyRestriction.java
index a252b3d3..99606d5a 100644
--- a/src/com/android/browser/mdm/ProxyRestriction.java
+++ b/src/com/android/browser/mdm/ProxyRestriction.java
@@ -30,10 +30,13 @@
package com.android.browser.mdm;
+import android.content.Intent;
+import android.net.Proxy;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
+import com.android.browser.Browser;
import com.android.browser.PreferenceKeys;
import org.chromium.net.ProxyChangeListener;
@@ -59,15 +62,6 @@ public class ProxyRestriction extends Restriction implements PreferenceKeys {
}
@Override
- public void enable(boolean enable) {
- super.enable(enable);
- // Ensure any previously set proxy restriction is revoked
- if (!enable) {
- ProxyChangeListener.setMdmProxy(null, null);
- }
- }
-
- @Override
public void enforce(Bundle restrictions) {
String proxyMode = restrictions.getString(ProxyChangeListener.PROXY_MODE);
@@ -75,24 +69,23 @@ public class ProxyRestriction extends Restriction implements PreferenceKeys {
// choose the proxy settings on their own.
if (proxyMode == null) {
Log.v(TAG, "enforce: proxyMode is null, disabling.");
- enable(false);
+ saveProxyConfig(false, null, null, -1, null, null);
}
// If policy is to not use the proxy and always connect directly, then all other options
// are ignored.
else if (proxyMode.equals(ProxyChangeListener.MODE_DIRECT)) {
Log.v(TAG, "enforce: proxyMode is MODE_DIRECT, enabling and passing to ProxyChangeListener.");
- enable(true);
- ProxyChangeListener.setMdmProxy(proxyMode, null);
+ saveProxyConfig(true, proxyMode, null, -1, null, null);
}
// If you choose to use system proxy settings or auto detect the proxy server,
// all other options are ignored.
else if (proxyMode.equals(ProxyChangeListener.MODE_SYSTEM) ||
proxyMode.equals(ProxyChangeListener.MODE_AUTO_DETECT)) {
- // TODO We will go ahead and configure here, but will throttle the enable in ProxyModeListener
- enable(true);
- ProxyChangeListener.setMdmProxy(proxyMode, null);
+
+ // TODO: We will go ahead and configure here, but will throttle the enable in ProxyModeListener
+ saveProxyConfig(true, proxyMode, null, -1, null, null);
}
// If you choose fixed server proxy mode, you can specify further options in 'Address or URL
@@ -105,15 +98,15 @@ public class ProxyRestriction extends Restriction implements PreferenceKeys {
host = proxyServerUri.getHost();
// Bail out if host is not present
if (host == null) {
- Log.e(TAG, "enforce: host - nul while processing MODE_FIXED_SERVERS");
- enable(false);
+ Log.e(TAG, "enforce: host == null while processing MODE_FIXED_SERVERS");
+ saveProxyConfig(false, null, null, -1, null, null);
return;
}
port = proxyServerUri.getPort();
} catch (Exception e) {
// Bail out if ProxyServer string is missing
Log.e(TAG,"enforce: Exception caught while processing MODE_FIXED_SERVERS");
- enable(false);
+ saveProxyConfig(false, null, null, -1, null, null);
return;
}
String proxyBypassList = restrictions.getString(ProxyChangeListener.PROXY_BYPASS_LIST);
@@ -122,7 +115,7 @@ public class ProxyRestriction extends Restriction implements PreferenceKeys {
Log.v(TAG," - port : " + port);
Log.v(TAG," - bypassList : " + (proxyBypassList != null ? proxyBypassList.toString() : "NULL"));
- saveProxyConfig(proxyMode, host, port, null, proxyBypassList);
+ saveProxyConfig(true, proxyMode, host, port, null, proxyBypassList);
}
// This policy only takes effect if you have selected manual proxy settings at 'Choose how
@@ -133,19 +126,39 @@ public class ProxyRestriction extends Restriction implements PreferenceKeys {
// Bail out if ProxyPacUrl string is missing
if (proxyPacUrl == null) {
Log.v(TAG, "enforce: MODE_PAC_SCRIPT. proxyPacUrl is null. disabling");
- enable(false);
+ saveProxyConfig(false, null, null, -1, null, null);
+
} else {
Log.v(TAG, "enforce: MODE_PAC_SCRIPT. proxyPacUrl ["+proxyPacUrl.toString() +
"]. sending and enabling");
- saveProxyConfig(proxyMode, null, -1, proxyPacUrl, null);
+ saveProxyConfig(true, proxyMode, null, -1, proxyPacUrl, null);
}
}
}
- private void saveProxyConfig(String proxyMode, String host, int port, String proxyPacUrl, String proxyBypassList) {
- ProxyChangeListener.setMdmProxy(proxyMode, new ProxyConfig(host, port, proxyPacUrl,
- (proxyBypassList != null) ? proxyBypassList.split(",") : new String[0]));
- enable(true);
- }
+ private void saveProxyConfig(boolean isEnabled, String proxyMode, String host,
+ int port, String proxyPacUrl, String proxyBypassList) {
+ if (isEnabled) {
+ String[] bypass = (proxyBypassList != null) ? proxyBypassList.split(",") : new String[0];
+
+ ProxyConfig cfg = null;
+ // If all components of the cfg are null or invalid, just send a null instead of
+ // of a completely invalid cfg. We don't check port, since it's meaningless without host.
+ if (host != null || proxyPacUrl != null || proxyBypassList != null) {
+ cfg = new ProxyConfig(host, port, proxyPacUrl, bypass);
+ }
+
+ ProxyChangeListener.setMdmProxy(proxyMode, cfg);
+ enable(true);
+ }
+ else {
+ // Ensure any previously set proxy restriction is revoked
+ ProxyChangeListener.setMdmProxy(null, null);
+ enable(false);
+ }
+
+ Intent proxySignal = new Intent(ProxyChangeListener.MDM_PROXY_CHANGE_ACTION);
+ Browser.getContext().sendBroadcast(proxySignal);
+ }
}
diff --git a/src/com/android/browser/mdm/tests/ProxyRestrictionsTest.java b/src/com/android/browser/mdm/tests/ProxyRestrictionsTest.java
index 211c6b42..d8c9de14 100644
--- a/src/com/android/browser/mdm/tests/ProxyRestrictionsTest.java
+++ b/src/com/android/browser/mdm/tests/ProxyRestrictionsTest.java
@@ -127,7 +127,7 @@ public class ProxyRestrictionsTest extends ActivityInstrumentationTestCase2<Brow
Log.v(TAG, "== Testing " + mode + " ==");
// Clear any restrictions
- setProxyRestrictions(ProxyChangeListener.MODE_DIRECT, null, null, null);
+ setProxyRestrictions(null, null, null, null);
// set the restrictions
setProxyRestrictions(mode, null, null, null);
@@ -149,7 +149,7 @@ public class ProxyRestrictionsTest extends ActivityInstrumentationTestCase2<Brow
Log.v(TAG, "== Testing " + mode + " ==");
// Clear any restrictions
- setProxyRestrictions(ProxyChangeListener.MODE_DIRECT, null, null, null);
+ setProxyRestrictions(null, null, null, null);
// set the restrictions
setProxyRestrictions(mode, null, null, null);
@@ -176,7 +176,7 @@ public class ProxyRestrictionsTest extends ActivityInstrumentationTestCase2<Brow
String configuredMode;
// Clear any restrictions
- setProxyRestrictions(ProxyChangeListener.MODE_DIRECT, null, null, null);
+ setProxyRestrictions(null, null, null, null);
// Test that mode didn't get set if no proxy server is set
setProxyRestrictions(mode, null, null, null);
@@ -228,7 +228,7 @@ public class ProxyRestrictionsTest extends ActivityInstrumentationTestCase2<Brow
Log.v(TAG, "== Testing " + mode + " ==");
// Clear any restrictions
- setProxyRestrictions(ProxyChangeListener.MODE_DIRECT, null, null, null);
+ setProxyRestrictions(null, null, null, null);
// set the restrictions without pac url
setProxyRestrictions(mode, null, null, null);