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

Commit c006f1ae authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Policy and rules work for ConnectivityManager.

Teach ConnectivityManager about UID-specific rules derived from policy,
such as rejecting network traffic on "paid" interfaces.  Calls that
return NetworkInfo now filter based on any REJECT rules in effect for
the calling UID.  (Added uid parameter if callers that still want all
interfaces.)

Changed NetworkPolicyManager to derive rules based on current policy
combined with PowerManager and ActivityManager status, which it passes
to ConnectivityService for eventual enforcement through netd.  When
rules change the usability of a NetworkInfo for a specific UID, it also
dispatches CONNECTIVITY_ACTION broadcasts to that UID.  Combined paid
and background policy together to match current working definition.

Change-Id: I797ea49439fcc487cfe2cbc16703d4b91ceb9af6
parent b145112e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ LOCAL_SRC_FILES += \
	core/java/android/net/IConnectivityManager.aidl \
	core/java/android/net/INetworkManagementEventObserver.aidl \
	core/java/android/net/IThrottleManager.aidl \
	core/java/android/net/INetworkPolicyListener.aidl \
	core/java/android/net/INetworkPolicyManager.aidl \
	core/java/android/nfc/ILlcpConnectionlessSocket.aidl \
	core/java/android/nfc/ILlcpServiceSocket.aidl \
+1 −0
Original line number Diff line number Diff line
@@ -11041,6 +11041,7 @@ package android.net {
    method public static android.net.NetworkInfo.DetailedState valueOf(java.lang.String);
    method public static final android.net.NetworkInfo.DetailedState[] values();
    enum_constant public static final android.net.NetworkInfo.DetailedState AUTHENTICATING;
    enum_constant public static final android.net.NetworkInfo.DetailedState BLOCKED;
    enum_constant public static final android.net.NetworkInfo.DetailedState CONNECTED;
    enum_constant public static final android.net.NetworkInfo.DetailedState CONNECTING;
    enum_constant public static final android.net.NetworkInfo.DetailedState DISCONNECTED;
+18 −18
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.os.Binder;
import android.os.RemoteException;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Class that answers queries about the state of network connectivity. It also
@@ -40,8 +39,9 @@ import java.net.UnknownHostException;
 * state of the available networks</li>
 * </ol>
 */
public class ConnectivityManager
{
public class ConnectivityManager {
    private static final String TAG = "ConnectivityManager";

    /**
     * A change in network connectivity has occurred. A connection has either
     * been established or lost. The NetworkInfo for the affected network is
@@ -109,7 +109,7 @@ public class ConnectivityManager
     * The lookup key for an int that provides information about
     * our connection to the internet at large.  0 indicates no connection,
     * 100 indicates a great connection.  Retrieve it with
     * {@link android.content.Intent@getIntExtra(String)}.
     * {@link android.content.Intent#getIntExtra(String, int)}.
     * {@hide}
     */
    public static final String EXTRA_INET_CONDITION = "inetCondition";
@@ -120,13 +120,12 @@ public class ConnectivityManager
     * <p>
     * If an application uses the network in the background, it should listen
     * for this broadcast and stop using the background data if the value is
     * false.
     * {@code false}.
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_BACKGROUND_DATA_SETTING_CHANGED =
            "android.net.conn.BACKGROUND_DATA_SETTING_CHANGED";


    /**
     * Broadcast Action: The network connection may not be good
     * uses {@code ConnectivityManager.EXTRA_INET_CONDITION} and
@@ -255,7 +254,7 @@ public class ConnectivityManager

    public static final int DEFAULT_NETWORK_PREFERENCE = TYPE_WIFI;

    private IConnectivityManager mService;
    private final IConnectivityManager mService;

    static public boolean isNetworkTypeValid(int networkType) {
        return networkType >= 0 && networkType <= MAX_NETWORK_TYPE;
@@ -284,6 +283,15 @@ public class ConnectivityManager
        }
    }

    /** {@hide} */
    public NetworkInfo getActiveNetworkInfoForUid(int uid) {
        try {
            return mService.getActiveNetworkInfoForUid(uid);
        } catch (RemoteException e) {
            return null;
        }
    }

    public NetworkInfo getNetworkInfo(int networkType) {
        try {
            return mService.getNetworkInfo(networkType);
@@ -300,7 +308,7 @@ public class ConnectivityManager
        }
    }

    /** @hide */
    /** {@hide} */
    public LinkProperties getActiveLinkProperties() {
        try {
            return mService.getActiveLinkProperties();
@@ -309,7 +317,7 @@ public class ConnectivityManager
        }
    }

    /** @hide */
    /** {@hide} */
    public LinkProperties getLinkProperties(int networkType) {
        try {
            return mService.getLinkProperties(networkType);
@@ -478,20 +486,12 @@ public class ConnectivityManager
        }
    }

    /**
     * Don't allow use of default constructor.
     */
    @SuppressWarnings({"UnusedDeclaration"})
    private ConnectivityManager() {
    }

    /**
     * {@hide}
     */
    public ConnectivityManager(IConnectivityManager service) {
        if (service == null) {
            throw new IllegalArgumentException(
                "ConnectivityManager() cannot be constructed with null service");
            throw new IllegalArgumentException("missing IConnectivityManager");
        }
        mService = service;
    }
+1 −3
Original line number Diff line number Diff line
@@ -33,13 +33,11 @@ interface IConnectivityManager
    int getNetworkPreference();

    NetworkInfo getActiveNetworkInfo();

    NetworkInfo getActiveNetworkInfoForUid(int uid);
    NetworkInfo getNetworkInfo(int networkType);

    NetworkInfo[] getAllNetworkInfo();

    LinkProperties getActiveLinkProperties();

    LinkProperties getLinkProperties(int networkType);

    boolean setRadios(boolean onOff);
+24 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 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 android.net;

/** {@hide} */
oneway interface INetworkPolicyListener {

    void onRulesChanged(int uid, int uidRules);

}
Loading