Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4c9df3d authored by Oscar Montemayor's avatar Oscar Montemayor Committed by Android (Google) Code Review
Browse files

Merge "Device Policy Manager changes to enable Global Proxy."

parents 8525f5dc 69238c6a
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -34339,6 +34339,17 @@
 visibility="public"
>
</method>
<method name="getGlobalProxyAdmin"
 return="android.content.ComponentName"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getMaximumFailedPasswordsForWipe"
 return="int"
 abstract="false"
@@ -34558,6 +34569,23 @@
<parameter name="flags" type="int">
</parameter>
</method>
<method name="setGlobalProxy"
 return="android.content.ComponentName"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="admin" type="android.content.ComponentName">
</parameter>
<parameter name="proxySpec" type="java.net.Proxy">
</parameter>
<parameter name="exclusionList" type="java.util.List&lt;java.lang.String&gt;">
</parameter>
</method>
<method name="setMaximumFailedPasswordsForWipe"
 return="void"
 abstract="false"
+14 −1
Original line number Diff line number Diff line
@@ -103,6 +103,16 @@ public final class DeviceAdminInfo implements Parcelable {
     */
    public static final int USES_POLICY_WIPE_DATA = 4;

    /**
     * A type of policy that this device admin can use: able to specify the
     * device Global Proxy, via {@link DevicePolicyManager#setGlobalProxy}.
     *
     * <p>To control this policy, the device admin must have a "set-global-proxy"
     * tag in the "uses-policies" section of its meta-data.
     * @hide
     */
    public static final int USES_POLICY_SETS_GLOBAL_PROXY = 5;

    /** @hide */
    public static class PolicyInfo {
        public final int ident;
@@ -138,6 +148,9 @@ public final class DeviceAdminInfo implements Parcelable {
        sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_FORCE_LOCK, "force-lock",
                com.android.internal.R.string.policylab_forceLock,
                com.android.internal.R.string.policydesc_forceLock));
        sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_SETS_GLOBAL_PROXY, "set-global-proxy",
                com.android.internal.R.string.policylab_setGlobalProxy,
                com.android.internal.R.string.policydesc_setGlobalProxy));
        
        for (int i=0; i<sPoliciesDisplayOrder.size(); i++) {
            PolicyInfo pi = sPoliciesDisplayOrder.get(i);
@@ -328,7 +341,7 @@ public final class DeviceAdminInfo implements Parcelable {
     * the given policy control.  The possible policy identifier inputs are:
     * {@link #USES_POLICY_LIMIT_PASSWORD}, {@link #USES_POLICY_WATCH_LOGIN},
     * {@link #USES_POLICY_RESET_PASSWORD}, {@link #USES_POLICY_FORCE_LOCK},
     * {@link #USES_POLICY_WIPE_DATA}.
     * {@link #USES_POLICY_WIPE_DATA}, {@link #USES_POLICY_SETS_GLOBAL_PROXY}.
     */
    public boolean usesPolicy(int policyIdent) {
        return (mUsesPolicies & (1<<policyIdent)) != 0;
+90 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.os.ServiceManager;
import android.util.Log;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.List;

/**
@@ -914,6 +916,93 @@ public class DevicePolicyManager {
        }
    }

    /**
     * Called by an application that is administering the device to set the
     * global proxy and exclusion list.
     * <p>
     * The calling device admin must have requested
     * {@link DeviceAdminInfo#USES_POLICY_SETS_GLOBAL_PROXY} to be able to call
     * this method; if it has not, a security exception will be thrown.
     * Only the first device admin can set the proxy. If a second admin attempts
     * to set the proxy, the {@link ComponentName} of the admin originally setting the
     * proxy will be returned. If successful in setting the proxy, null will
     * be returned.
     * The method can be called repeatedly by the device admin alrady setting the
     * proxy to update the proxy and exclusion list.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated
     *            with.
     * @param proxySpec the global proxy desired. Must be an HTTP Proxy.
     *            Pass Proxy.NO_PROXY to reset the proxy.
     * @param exclusionList a list of domains to be excluded from the global proxy.
     * @param proxyAdmins an empty, mutable list that will contain any proxy admins
     *            that define a global proxy.
     * @return returns null if the proxy was successfully set, or a {@link ComponentName}
     *            of the device admin that sets thew proxy otherwise.
     */
    public ComponentName setGlobalProxy(ComponentName admin, Proxy proxySpec,
            List<String> exclusionList ) {
        if (proxySpec == null) {
            throw new NullPointerException();
        }
        if (mService != null) {
            try {
                String hostSpec;
                String exclSpec;
                if (proxySpec.equals(Proxy.NO_PROXY)) {
                    hostSpec = null;
                    exclSpec = null;
                } else {
                    if (!proxySpec.type().equals(Proxy.Type.HTTP)) {
                        throw new IllegalArgumentException();
                    }
                    InetSocketAddress sa = (InetSocketAddress)proxySpec.address();
                    String hostName = sa.getHostName();
                    int port = sa.getPort();
                    StringBuilder hostBuilder = new StringBuilder();
                    hostSpec = hostBuilder.append(hostName)
                        .append(":").append(Integer.toString(port)).toString();
                    if (exclusionList == null) {
                        exclSpec = "";
                    } else {
                        StringBuilder listBuilder = new StringBuilder();
                        boolean firstDomain = true;
                        for (String exclDomain : exclusionList) {
                            if (!firstDomain) {
                                listBuilder = listBuilder.append(",");
                            } else {
                                firstDomain = false;
                            }
                            listBuilder = listBuilder.append(exclDomain.trim());
                        }
                        exclSpec = listBuilder.toString();
                    }
                    android.net.Proxy.validate(hostName, Integer.toString(port), exclSpec);
                }
                return mService.setGlobalProxy(admin, hostSpec, exclSpec);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
        }
        return null;
    }

    /**
     * Returns the component name setting the global proxy.
     * @return ComponentName object of the device admin that set the global proxy, or
     *            null if no admin has set the proxy.
     */
    public ComponentName getGlobalProxyAdmin() {
        if (mService != null) {
            try {
                return mService.getGlobalProxyAdmin();
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
        }
        return null;
    }

    /**
     * @hide
     */
@@ -1007,4 +1096,5 @@ public class DevicePolicyManager {
            }
        }
    }

}
+3 −0
Original line number Diff line number Diff line
@@ -67,6 +67,9 @@ interface IDevicePolicyManager {
    
    void wipeData(int flags);

    ComponentName setGlobalProxy(in ComponentName admin, String proxySpec, String exclusionList);
    ComponentName getGlobalProxyAdmin();
    
    void setActiveAdmin(in ComponentName policyReceiver);
    boolean isAdminActive(in ComponentName policyReceiver);
    List<ComponentName> getActiveAdmins();
+5 −0
Original line number Diff line number Diff line
@@ -1252,6 +1252,11 @@
    <!-- Description of policy access to wipe the user's data -->
    <string name="policydesc_wipeData">Perform a factory reset, deleting
        all of your data without any confirmation.</string>
    <string name="policylab_setGlobalProxy">Set the device global proxy</string>
    <!-- Description of policy access to wipe the user's data -->
    <string name="policydesc_setGlobalProxy">Set the device global proxy
        to be used while policy is enabled. Only the first device admin
        sets the effective global proxy.</string>

    <!-- The order of these is important, don't reorder without changing Contacts.java --> <skip />
    <!-- Phone number types from android.provider.Contacts. This could be used when adding a new phone number for a contact, for example. -->
Loading