Merge changes I88fee389,Ib0d4e8c6
* changes: Remove the unused ITetheringStatsProvider. Remove unused methods from NetworkManagementService.
This commit is contained in:
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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;
|
|
||||||
|
|
||||||
import android.net.NetworkStats;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for NetworkManagementService to query tethering statistics and set data limits.
|
|
||||||
*
|
|
||||||
* TODO: this does not really need to be an interface since Tethering runs in the same process
|
|
||||||
* as NetworkManagementService. Consider refactoring Tethering to use direct access to
|
|
||||||
* NetworkManagementService instead of using INetworkManagementService, and then deleting this
|
|
||||||
* interface.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
interface ITetheringStatsProvider {
|
|
||||||
// Returns cumulative statistics for all tethering sessions since boot, on all upstreams.
|
|
||||||
// @code {how} is one of the NetworkStats.STATS_PER_* constants. If {@code how} is
|
|
||||||
// {@code STATS_PER_IFACE}, the provider should not include any traffic that is already
|
|
||||||
// counted by kernel interface counters.
|
|
||||||
NetworkStats getTetherStats(int how);
|
|
||||||
|
|
||||||
// Sets the interface quota for the specified upstream interface. This is defined as the number
|
|
||||||
// of bytes, starting from zero and counting from now, after which data should stop being
|
|
||||||
// forwarded to/from the specified upstream. A value of QUOTA_UNLIMITED means there is no limit.
|
|
||||||
void setInterfaceQuota(String iface, long quotaBytes);
|
|
||||||
|
|
||||||
// Indicates that no data usage limit is set.
|
|
||||||
const int QUOTA_UNLIMITED = -1;
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,6 @@ package android.os;
|
|||||||
|
|
||||||
import android.net.InterfaceConfiguration;
|
import android.net.InterfaceConfiguration;
|
||||||
import android.net.INetworkManagementEventObserver;
|
import android.net.INetworkManagementEventObserver;
|
||||||
import android.net.ITetheringStatsProvider;
|
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
import android.net.NetworkStats;
|
import android.net.NetworkStats;
|
||||||
import android.net.RouteInfo;
|
import android.net.RouteInfo;
|
||||||
@@ -142,14 +141,6 @@ interface INetworkManagementService
|
|||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
void startTethering(in String[] dhcpRanges);
|
void startTethering(in String[] dhcpRanges);
|
||||||
|
|
||||||
/**
|
|
||||||
* Start tethering services with the specified dhcp server range and
|
|
||||||
* DNS proxy config.
|
|
||||||
* {@code boolean} is used to control legacy DNS proxy server.
|
|
||||||
* {@code String[]} is a set of start end pairs defining the ranges.
|
|
||||||
*/
|
|
||||||
void startTetheringWithConfiguration(boolean usingLegacyDnsProxy, in String[] dhcpRanges);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop currently running tethering services
|
* Stop currently running tethering services
|
||||||
*/
|
*/
|
||||||
@@ -180,23 +171,6 @@ interface INetworkManagementService
|
|||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
String[] listTetheredInterfaces();
|
String[] listTetheredInterfaces();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the list of DNS forwarders (in order of priority)
|
|
||||||
*/
|
|
||||||
String[] getDnsForwarders();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables unidirectional packet forwarding from {@code fromIface} to
|
|
||||||
* {@code toIface}.
|
|
||||||
*/
|
|
||||||
void startInterfaceForwarding(String fromIface, String toIface);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disables unidirectional packet forwarding from {@code fromIface} to
|
|
||||||
* {@code toIface}.
|
|
||||||
*/
|
|
||||||
void stopInterfaceForwarding(String fromIface, String toIface);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables Network Address Translation between two interfaces.
|
* Enables Network Address Translation between two interfaces.
|
||||||
* The address and netmask of the external interface is used for
|
* The address and netmask of the external interface is used for
|
||||||
@@ -211,42 +185,10 @@ interface INetworkManagementService
|
|||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage
|
||||||
void disableNat(String internalInterface, String externalInterface);
|
void disableNat(String internalInterface, String externalInterface);
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a {@code ITetheringStatsProvider} to provide tethering statistics.
|
|
||||||
* All registered providers will be called in order, and their results will be added together.
|
|
||||||
* Netd is always registered as a tethering stats provider.
|
|
||||||
*/
|
|
||||||
void registerTetheringStatsProvider(ITetheringStatsProvider provider, String name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unregisters a previously-registered {@code ITetheringStatsProvider}.
|
|
||||||
*/
|
|
||||||
void unregisterTetheringStatsProvider(ITetheringStatsProvider provider);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reports that a tethering provider has reached a data limit.
|
|
||||||
*
|
|
||||||
* Currently triggers a global alert, which causes NetworkStatsService to poll counters and
|
|
||||||
* re-evaluate data usage.
|
|
||||||
*
|
|
||||||
* This does not take an interface name because:
|
|
||||||
* 1. The tethering offload stats provider cannot reliably determine the interface on which the
|
|
||||||
* limit was reached, because the HAL does not provide it.
|
|
||||||
* 2. Firing an interface-specific alert instead of a global alert isn't really useful since in
|
|
||||||
* all cases of interest, the system responds to both in the same way - it polls stats, and
|
|
||||||
* then notifies NetworkPolicyManagerService of the fact.
|
|
||||||
*/
|
|
||||||
void tetherLimitReached(ITetheringStatsProvider provider);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
** DATA USAGE RELATED
|
** DATA USAGE RELATED
|
||||||
**/
|
**/
|
||||||
|
|
||||||
/**
|
|
||||||
* Return summary of network statistics all tethering interfaces.
|
|
||||||
*/
|
|
||||||
NetworkStats getNetworkStatsTethering(int how);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set quota for an interface.
|
* Set quota for an interface.
|
||||||
*/
|
*/
|
||||||
@@ -267,11 +209,6 @@ interface INetworkManagementService
|
|||||||
*/
|
*/
|
||||||
void removeInterfaceAlert(String iface);
|
void removeInterfaceAlert(String iface);
|
||||||
|
|
||||||
/**
|
|
||||||
* Set alert across all interfaces.
|
|
||||||
*/
|
|
||||||
void setGlobalAlert(long alertBytes);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Control network activity of a UID over interfaces with a quota limit.
|
* Control network activity of a UID over interfaces with a quota limit.
|
||||||
*/
|
*/
|
||||||
@@ -289,7 +226,6 @@ interface INetworkManagementService
|
|||||||
|
|
||||||
void setFirewallEnabled(boolean enabled);
|
void setFirewallEnabled(boolean enabled);
|
||||||
boolean isFirewallEnabled();
|
boolean isFirewallEnabled();
|
||||||
void setFirewallInterfaceRule(String iface, boolean allow);
|
|
||||||
void setFirewallUidRule(int chain, int uid, int rule);
|
void setFirewallUidRule(int chain, int uid, int rule);
|
||||||
void setFirewallUidRules(int chain, in int[] uids, in int[] rules);
|
void setFirewallUidRules(int chain, in int[] uids, in int[] rules);
|
||||||
void setFirewallChainEnabled(int chain, boolean enable);
|
void setFirewallChainEnabled(int chain, boolean enable);
|
||||||
@@ -304,9 +240,5 @@ interface INetworkManagementService
|
|||||||
*/
|
*/
|
||||||
void denyProtect(int uid);
|
void denyProtect(int uid);
|
||||||
|
|
||||||
void addInterfaceToLocalNetwork(String iface, in List<RouteInfo> routes);
|
|
||||||
void removeInterfaceFromLocalNetwork(String iface);
|
|
||||||
int removeRoutesFromLocalNetwork(in List<RouteInfo> routes);
|
|
||||||
|
|
||||||
boolean isNetworkRestricted(int uid);
|
boolean isNetworkRestricted(int uid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ import static android.net.NetworkPolicyManager.FIREWALL_CHAIN_NAME_RESTRICTED;
|
|||||||
import static android.net.NetworkPolicyManager.FIREWALL_CHAIN_NAME_STANDBY;
|
import static android.net.NetworkPolicyManager.FIREWALL_CHAIN_NAME_STANDBY;
|
||||||
import static android.net.NetworkPolicyManager.FIREWALL_RULE_DEFAULT;
|
import static android.net.NetworkPolicyManager.FIREWALL_RULE_DEFAULT;
|
||||||
|
|
||||||
import static com.android.net.module.util.NetworkStatsUtils.LIMIT_GLOBAL_ALERT;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -46,15 +44,12 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.INetd;
|
import android.net.INetd;
|
||||||
import android.net.INetdUnsolicitedEventListener;
|
import android.net.INetdUnsolicitedEventListener;
|
||||||
import android.net.INetworkManagementEventObserver;
|
import android.net.INetworkManagementEventObserver;
|
||||||
import android.net.ITetheringStatsProvider;
|
|
||||||
import android.net.InetAddresses;
|
import android.net.InetAddresses;
|
||||||
import android.net.InterfaceConfiguration;
|
import android.net.InterfaceConfiguration;
|
||||||
import android.net.InterfaceConfigurationParcel;
|
import android.net.InterfaceConfigurationParcel;
|
||||||
import android.net.IpPrefix;
|
import android.net.IpPrefix;
|
||||||
import android.net.LinkAddress;
|
import android.net.LinkAddress;
|
||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.NetworkStack;
|
|
||||||
import android.net.NetworkStats;
|
|
||||||
import android.net.RouteInfo;
|
import android.net.RouteInfo;
|
||||||
import android.net.util.NetdService;
|
import android.net.util.NetdService;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
@@ -80,26 +75,18 @@ import com.android.internal.annotations.GuardedBy;
|
|||||||
import com.android.internal.app.IBatteryStats;
|
import com.android.internal.app.IBatteryStats;
|
||||||
import com.android.internal.util.DumpUtils;
|
import com.android.internal.util.DumpUtils;
|
||||||
import com.android.internal.util.HexDump;
|
import com.android.internal.util.HexDump;
|
||||||
import com.android.internal.util.Preconditions;
|
|
||||||
import com.android.net.module.util.NetdUtils;
|
import com.android.net.module.util.NetdUtils;
|
||||||
import com.android.net.module.util.NetdUtils.ModifyOperation;
|
import com.android.net.module.util.NetdUtils.ModifyOperation;
|
||||||
|
import com.android.net.module.util.PermissionUtils;
|
||||||
|
|
||||||
import com.google.android.collect.Maps;
|
import com.google.android.collect.Maps;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InterfaceAddress;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
@@ -129,13 +116,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
private static final String TAG = "NetworkManagement";
|
private static final String TAG = "NetworkManagement";
|
||||||
private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
|
private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
|
||||||
private static final int MAX_UID_RANGES_PER_COMMAND = 10;
|
|
||||||
|
|
||||||
static final int DAEMON_MSG_MOBILE_CONN_REAL_TIME_INFO = 1;
|
|
||||||
|
|
||||||
static final boolean MODIFY_OPERATION_ADD = true;
|
|
||||||
static final boolean MODIFY_OPERATION_REMOVE = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binder context for this service
|
* Binder context for this service
|
||||||
*/
|
*/
|
||||||
@@ -154,10 +134,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
private final RemoteCallbackList<INetworkManagementEventObserver> mObservers =
|
private final RemoteCallbackList<INetworkManagementEventObserver> mObservers =
|
||||||
new RemoteCallbackList<>();
|
new RemoteCallbackList<>();
|
||||||
|
|
||||||
@GuardedBy("mTetheringStatsProviders")
|
|
||||||
private final HashMap<ITetheringStatsProvider, String>
|
|
||||||
mTetheringStatsProviders = Maps.newHashMap();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If both locks need to be held, then they should be obtained in the order:
|
* If both locks need to be held, then they should be obtained in the order:
|
||||||
* first {@link #mQuotaLock} and then {@link #mRulesLock}.
|
* first {@link #mQuotaLock} and then {@link #mRulesLock}.
|
||||||
@@ -182,35 +158,35 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
private SparseIntArray mUidCleartextPolicy = new SparseIntArray();
|
private SparseIntArray mUidCleartextPolicy = new SparseIntArray();
|
||||||
/** Set of UIDs that are to be blocked/allowed by firewall controller. */
|
/** Set of UIDs that are to be blocked/allowed by firewall controller. */
|
||||||
@GuardedBy("mRulesLock")
|
@GuardedBy("mRulesLock")
|
||||||
private SparseIntArray mUidFirewallRules = new SparseIntArray();
|
private final SparseIntArray mUidFirewallRules = new SparseIntArray();
|
||||||
/**
|
/**
|
||||||
* Set of UIDs that are to be blocked/allowed by firewall controller. This set of Ids matches
|
* Set of UIDs that are to be blocked/allowed by firewall controller. This set of Ids matches
|
||||||
* to application idles.
|
* to application idles.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mRulesLock")
|
@GuardedBy("mRulesLock")
|
||||||
private SparseIntArray mUidFirewallStandbyRules = new SparseIntArray();
|
private final SparseIntArray mUidFirewallStandbyRules = new SparseIntArray();
|
||||||
/**
|
/**
|
||||||
* Set of UIDs that are to be blocked/allowed by firewall controller. This set of Ids matches
|
* Set of UIDs that are to be blocked/allowed by firewall controller. This set of Ids matches
|
||||||
* to device idles.
|
* to device idles.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mRulesLock")
|
@GuardedBy("mRulesLock")
|
||||||
private SparseIntArray mUidFirewallDozableRules = new SparseIntArray();
|
private final SparseIntArray mUidFirewallDozableRules = new SparseIntArray();
|
||||||
/**
|
/**
|
||||||
* Set of UIDs that are to be blocked/allowed by firewall controller. This set of Ids matches
|
* Set of UIDs that are to be blocked/allowed by firewall controller. This set of Ids matches
|
||||||
* to device on power-save mode.
|
* to device on power-save mode.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mRulesLock")
|
@GuardedBy("mRulesLock")
|
||||||
private SparseIntArray mUidFirewallPowerSaveRules = new SparseIntArray();
|
private final SparseIntArray mUidFirewallPowerSaveRules = new SparseIntArray();
|
||||||
/**
|
/**
|
||||||
* Contains the per-UID firewall rules that are used when Restricted Networking Mode is enabled.
|
* Contains the per-UID firewall rules that are used when Restricted Networking Mode is enabled.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mRulesLock")
|
@GuardedBy("mRulesLock")
|
||||||
private SparseIntArray mUidFirewallRestrictedRules = new SparseIntArray();
|
private final SparseIntArray mUidFirewallRestrictedRules = new SparseIntArray();
|
||||||
/**
|
/**
|
||||||
* Contains the per-UID firewall rules that are used when Low Power Standby is enabled.
|
* Contains the per-UID firewall rules that are used when Low Power Standby is enabled.
|
||||||
*/
|
*/
|
||||||
@GuardedBy("mRulesLock")
|
@GuardedBy("mRulesLock")
|
||||||
private SparseIntArray mUidFirewallLowPowerStandbyRules = new SparseIntArray();
|
private final SparseIntArray mUidFirewallLowPowerStandbyRules = new SparseIntArray();
|
||||||
/** Set of states for the child firewall chains. True if the chain is active. */
|
/** Set of states for the child firewall chains. True if the chain is active. */
|
||||||
@GuardedBy("mRulesLock")
|
@GuardedBy("mRulesLock")
|
||||||
final SparseBooleanArray mFirewallChainStates = new SparseBooleanArray();
|
final SparseBooleanArray mFirewallChainStates = new SparseBooleanArray();
|
||||||
@@ -236,17 +212,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
mNetdUnsolicitedEventListener = new NetdUnsolicitedEventListener();
|
mNetdUnsolicitedEventListener = new NetdUnsolicitedEventListener();
|
||||||
|
|
||||||
mDeps.registerLocalService(new LocalService());
|
mDeps.registerLocalService(new LocalService());
|
||||||
|
|
||||||
synchronized (mTetheringStatsProviders) {
|
|
||||||
mTetheringStatsProviders.put(new NetdTetheringStatsProvider(), "netd");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private NetworkManagementService() {
|
|
||||||
mContext = null;
|
|
||||||
mDaemonHandler = null;
|
|
||||||
mDeps = null;
|
|
||||||
mNetdUnsolicitedEventListener = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NetworkManagementService create(Context context, Dependencies deps)
|
static NetworkManagementService create(Context context, Dependencies deps)
|
||||||
@@ -289,19 +254,19 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerObserver(INetworkManagementEventObserver observer) {
|
public void registerObserver(INetworkManagementEventObserver observer) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
mObservers.register(observer);
|
mObservers.register(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterObserver(INetworkManagementEventObserver observer) {
|
public void unregisterObserver(INetworkManagementEventObserver observer) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
mObservers.unregister(observer);
|
mObservers.unregister(observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
private interface NetworkManagementEventCallback {
|
private interface NetworkManagementEventCallback {
|
||||||
public void sendCallback(INetworkManagementEventObserver o) throws RemoteException;
|
void sendCallback(INetworkManagementEventObserver o) throws RemoteException;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeForAllObservers(NetworkManagementEventCallback eventCallback) {
|
private void invokeForAllObservers(NetworkManagementEventCallback eventCallback) {
|
||||||
@@ -367,35 +332,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
type, isActive, tsNanos, uid));
|
type, isActive, tsNanos, uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerTetheringStatsProvider(ITetheringStatsProvider provider, String name) {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
Objects.requireNonNull(provider);
|
|
||||||
synchronized(mTetheringStatsProviders) {
|
|
||||||
mTetheringStatsProviders.put(provider, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unregisterTetheringStatsProvider(ITetheringStatsProvider provider) {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
synchronized(mTetheringStatsProviders) {
|
|
||||||
mTetheringStatsProviders.remove(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tetherLimitReached(ITetheringStatsProvider provider) {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
synchronized(mTetheringStatsProviders) {
|
|
||||||
if (!mTetheringStatsProviders.containsKey(provider)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// No current code examines the interface parameter in a global alert. Just pass null.
|
|
||||||
mDaemonHandler.post(() -> notifyLimitReached(LIMIT_GLOBAL_ALERT, null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sync the state of the given chain with the native daemon.
|
// Sync the state of the given chain with the native daemon.
|
||||||
private void syncFirewallChainLocked(int chain, String name) {
|
private void syncFirewallChainLocked(int chain, String name) {
|
||||||
SparseIntArray rules;
|
SparseIntArray rules;
|
||||||
@@ -665,7 +601,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
public String[] listInterfaces() {
|
public String[] listInterfaces() {
|
||||||
// TODO: Remove CONNECTIVITY_INTERNAL after bluetooth tethering has no longer called these
|
// TODO: Remove CONNECTIVITY_INTERNAL after bluetooth tethering has no longer called these
|
||||||
// APIs.
|
// APIs.
|
||||||
NetworkStack.checkNetworkStackPermissionOr(mContext, CONNECTIVITY_INTERNAL);
|
PermissionUtils.enforceNetworkStackPermissionOr(mContext, CONNECTIVITY_INTERNAL);
|
||||||
try {
|
try {
|
||||||
return mNetdService.interfaceGetList();
|
return mNetdService.interfaceGetList();
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -717,7 +653,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
public InterfaceConfiguration getInterfaceConfig(String iface) {
|
public InterfaceConfiguration getInterfaceConfig(String iface) {
|
||||||
// TODO: Remove CONNECTIVITY_INTERNAL after bluetooth tethering has no longer called these
|
// TODO: Remove CONNECTIVITY_INTERNAL after bluetooth tethering has no longer called these
|
||||||
// APIs.
|
// APIs.
|
||||||
NetworkStack.checkNetworkStackPermissionOr(mContext, CONNECTIVITY_INTERNAL);
|
PermissionUtils.enforceNetworkStackPermissionOr(mContext, CONNECTIVITY_INTERNAL);
|
||||||
final InterfaceConfigurationParcel result;
|
final InterfaceConfigurationParcel result;
|
||||||
try {
|
try {
|
||||||
result = mNetdService.interfaceGetCfg(iface);
|
result = mNetdService.interfaceGetCfg(iface);
|
||||||
@@ -737,7 +673,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
public void setInterfaceConfig(String iface, InterfaceConfiguration cfg) {
|
public void setInterfaceConfig(String iface, InterfaceConfiguration cfg) {
|
||||||
// TODO: Remove CONNECTIVITY_INTERNAL after bluetooth tethering has no longer called these
|
// TODO: Remove CONNECTIVITY_INTERNAL after bluetooth tethering has no longer called these
|
||||||
// APIs.
|
// APIs.
|
||||||
NetworkStack.checkNetworkStackPermissionOr(mContext, CONNECTIVITY_INTERNAL);
|
PermissionUtils.enforceNetworkStackPermissionOr(mContext, CONNECTIVITY_INTERNAL);
|
||||||
LinkAddress linkAddr = cfg.getLinkAddress();
|
LinkAddress linkAddr = cfg.getLinkAddress();
|
||||||
if (linkAddr == null || linkAddr.getAddress() == null) {
|
if (linkAddr == null || linkAddr.getAddress() == null) {
|
||||||
throw new IllegalStateException("Null LinkAddress given");
|
throw new IllegalStateException("Null LinkAddress given");
|
||||||
@@ -754,7 +690,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInterfaceDown(String iface) {
|
public void setInterfaceDown(String iface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
|
final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
|
||||||
ifcg.setInterfaceDown();
|
ifcg.setInterfaceDown();
|
||||||
setInterfaceConfig(iface, ifcg);
|
setInterfaceConfig(iface, ifcg);
|
||||||
@@ -762,7 +698,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInterfaceUp(String iface) {
|
public void setInterfaceUp(String iface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
|
final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
|
||||||
ifcg.setInterfaceUp();
|
ifcg.setInterfaceUp();
|
||||||
setInterfaceConfig(iface, ifcg);
|
setInterfaceConfig(iface, ifcg);
|
||||||
@@ -770,7 +706,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInterfaceIpv6PrivacyExtensions(String iface, boolean enable) {
|
public void setInterfaceIpv6PrivacyExtensions(String iface, boolean enable) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
mNetdService.interfaceSetIPv6PrivacyExtensions(iface, enable);
|
mNetdService.interfaceSetIPv6PrivacyExtensions(iface, enable);
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -782,7 +718,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
IPv6 addresses on interface down, but we need to do full clean up here */
|
IPv6 addresses on interface down, but we need to do full clean up here */
|
||||||
@Override
|
@Override
|
||||||
public void clearInterfaceAddresses(String iface) {
|
public void clearInterfaceAddresses(String iface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
mNetdService.interfaceClearAddrs(iface);
|
mNetdService.interfaceClearAddrs(iface);
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -792,7 +728,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableIpv6(String iface) {
|
public void enableIpv6(String iface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
mNetdService.interfaceSetEnableIPv6(iface, true);
|
mNetdService.interfaceSetEnableIPv6(iface, true);
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -802,7 +738,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setIPv6AddrGenMode(String iface, int mode) throws ServiceSpecificException {
|
public void setIPv6AddrGenMode(String iface, int mode) throws ServiceSpecificException {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
mNetdService.setIPv6AddrGenMode(iface, mode);
|
mNetdService.setIPv6AddrGenMode(iface, mode);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
@@ -812,7 +748,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disableIpv6(String iface) {
|
public void disableIpv6(String iface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
mNetdService.interfaceSetEnableIPv6(iface, false);
|
mNetdService.interfaceSetEnableIPv6(iface, false);
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -822,44 +758,16 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addRoute(int netId, RouteInfo route) {
|
public void addRoute(int netId, RouteInfo route) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
NetdUtils.modifyRoute(mNetdService, ModifyOperation.ADD, netId, route);
|
NetdUtils.modifyRoute(mNetdService, ModifyOperation.ADD, netId, route);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeRoute(int netId, RouteInfo route) {
|
public void removeRoute(int netId, RouteInfo route) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
NetdUtils.modifyRoute(mNetdService, ModifyOperation.REMOVE, netId, route);
|
NetdUtils.modifyRoute(mNetdService, ModifyOperation.REMOVE, netId, route);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<String> readRouteList(String filename) {
|
|
||||||
FileInputStream fstream = null;
|
|
||||||
ArrayList<String> list = new ArrayList<>();
|
|
||||||
|
|
||||||
try {
|
|
||||||
fstream = new FileInputStream(filename);
|
|
||||||
DataInputStream in = new DataInputStream(fstream);
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
||||||
String s;
|
|
||||||
|
|
||||||
// throw away the title line
|
|
||||||
|
|
||||||
while (((s = br.readLine()) != null) && (s.length() != 0)) {
|
|
||||||
list.add(s);
|
|
||||||
}
|
|
||||||
} catch (IOException ex) {
|
|
||||||
// return current list, possibly empty
|
|
||||||
} finally {
|
|
||||||
if (fstream != null) {
|
|
||||||
try {
|
|
||||||
fstream.close();
|
|
||||||
} catch (IOException ex) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
// TODO: remove from aidl if nobody calls externally
|
// TODO: remove from aidl if nobody calls externally
|
||||||
@@ -870,11 +778,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getIpForwardingEnabled() throws IllegalStateException{
|
public boolean getIpForwardingEnabled() throws IllegalStateException{
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final boolean isEnabled = mNetdService.ipfwdEnabled();
|
return mNetdService.ipfwdEnabled();
|
||||||
return isEnabled;
|
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
@@ -882,7 +789,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setIpForwardingEnabled(boolean enable) {
|
public void setIpForwardingEnabled(boolean enable) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
mNetdService.ipfwdEnableForwarding("tethering");
|
mNetdService.ipfwdEnableForwarding("tethering");
|
||||||
@@ -896,14 +803,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startTethering(String[] dhcpRange) {
|
public void startTethering(String[] dhcpRange) {
|
||||||
startTetheringWithConfiguration(true, dhcpRange);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startTetheringWithConfiguration(boolean usingLegacyDnsProxy, String[] dhcpRange) {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
try {
|
try {
|
||||||
NetdUtils.tetherStart(mNetdService, usingLegacyDnsProxy, dhcpRange);
|
NetdUtils.tetherStart(mNetdService, true /* usingLegacyDnsProxy */, dhcpRange);
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
@@ -911,7 +813,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopTethering() {
|
public void stopTethering() {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
mNetdService.tetherStop();
|
mNetdService.tetherStop();
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -921,11 +823,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTetheringStarted() {
|
public boolean isTetheringStarted() {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final boolean isEnabled = mNetdService.tetherIsEnabled();
|
return mNetdService.tetherIsEnabled();
|
||||||
return isEnabled;
|
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
@@ -933,7 +833,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tetherInterface(String iface) {
|
public void tetherInterface(String iface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
final LinkAddress addr = getInterfaceConfig(iface).getLinkAddress();
|
final LinkAddress addr = getInterfaceConfig(iface).getLinkAddress();
|
||||||
final IpPrefix dest = new IpPrefix(addr.getAddress(), addr.getPrefixLength());
|
final IpPrefix dest = new IpPrefix(addr.getAddress(), addr.getPrefixLength());
|
||||||
@@ -945,7 +845,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void untetherInterface(String iface) {
|
public void untetherInterface(String iface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
NetdUtils.untetherInterface(mNetdService, iface);
|
NetdUtils.untetherInterface(mNetdService, iface);
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -955,7 +855,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] listTetheredInterfaces() {
|
public String[] listTetheredInterfaces() {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
return mNetdService.tetherInterfaceList();
|
return mNetdService.tetherInterfaceList();
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -963,52 +863,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getDnsForwarders() {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
try {
|
|
||||||
return mNetdService.tetherDnsList();
|
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<InterfaceAddress> excludeLinkLocal(List<InterfaceAddress> addresses) {
|
|
||||||
ArrayList<InterfaceAddress> filtered = new ArrayList<>(addresses.size());
|
|
||||||
for (InterfaceAddress ia : addresses) {
|
|
||||||
if (!ia.getAddress().isLinkLocalAddress())
|
|
||||||
filtered.add(ia);
|
|
||||||
}
|
|
||||||
return filtered;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void modifyInterfaceForward(boolean add, String fromIface, String toIface) {
|
|
||||||
try {
|
|
||||||
if (add) {
|
|
||||||
mNetdService.ipfwdAddInterfaceForward(fromIface, toIface);
|
|
||||||
} else {
|
|
||||||
mNetdService.ipfwdRemoveInterfaceForward(fromIface, toIface);
|
|
||||||
}
|
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startInterfaceForwarding(String fromIface, String toIface) {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
modifyInterfaceForward(true, fromIface, toIface);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stopInterfaceForwarding(String fromIface, String toIface) {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
modifyInterfaceForward(false, fromIface, toIface);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enableNat(String internalInterface, String externalInterface) {
|
public void enableNat(String internalInterface, String externalInterface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
mNetdService.tetherAddForward(internalInterface, externalInterface);
|
mNetdService.tetherAddForward(internalInterface, externalInterface);
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -1018,7 +875,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disableNat(String internalInterface, String externalInterface) {
|
public void disableNat(String internalInterface, String externalInterface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
try {
|
try {
|
||||||
mNetdService.tetherRemoveForward(internalInterface, externalInterface);
|
mNetdService.tetherRemoveForward(internalInterface, externalInterface);
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
@@ -1028,7 +885,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInterfaceQuota(String iface, long quotaBytes) {
|
public void setInterfaceQuota(String iface, long quotaBytes) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
synchronized (mQuotaLock) {
|
synchronized (mQuotaLock) {
|
||||||
if (mActiveQuotas.containsKey(iface)) {
|
if (mActiveQuotas.containsKey(iface)) {
|
||||||
@@ -1043,23 +900,12 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (mTetheringStatsProviders) {
|
|
||||||
for (ITetheringStatsProvider provider : mTetheringStatsProviders.keySet()) {
|
|
||||||
try {
|
|
||||||
provider.setInterfaceQuota(iface, quotaBytes);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Problem setting tethering data limit on provider " +
|
|
||||||
mTetheringStatsProviders.get(provider) + ": " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeInterfaceQuota(String iface) {
|
public void removeInterfaceQuota(String iface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
synchronized (mQuotaLock) {
|
synchronized (mQuotaLock) {
|
||||||
if (!mActiveQuotas.containsKey(iface)) {
|
if (!mActiveQuotas.containsKey(iface)) {
|
||||||
@@ -1076,23 +922,12 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
} catch (RemoteException | ServiceSpecificException e) {
|
} catch (RemoteException | ServiceSpecificException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (mTetheringStatsProviders) {
|
|
||||||
for (ITetheringStatsProvider provider : mTetheringStatsProviders.keySet()) {
|
|
||||||
try {
|
|
||||||
provider.setInterfaceQuota(iface, ITetheringStatsProvider.QUOTA_UNLIMITED);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Problem removing tethering data limit on provider " +
|
|
||||||
mTetheringStatsProviders.get(provider) + ": " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInterfaceAlert(String iface, long alertBytes) {
|
public void setInterfaceAlert(String iface, long alertBytes) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
// quick validity check
|
// quick validity check
|
||||||
if (!mActiveQuotas.containsKey(iface)) {
|
if (!mActiveQuotas.containsKey(iface)) {
|
||||||
@@ -1116,7 +951,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeInterfaceAlert(String iface) {
|
public void removeInterfaceAlert(String iface) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
synchronized (mQuotaLock) {
|
synchronized (mQuotaLock) {
|
||||||
if (!mActiveAlerts.containsKey(iface)) {
|
if (!mActiveAlerts.containsKey(iface)) {
|
||||||
@@ -1134,19 +969,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setGlobalAlert(long alertBytes) {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
|
|
||||||
try {
|
|
||||||
mNetdService.bandwidthSetGlobalAlert(alertBytes);
|
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setUidOnMeteredNetworkList(int uid, boolean allowlist, boolean enable) {
|
private void setUidOnMeteredNetworkList(int uid, boolean allowlist, boolean enable) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
synchronized (mQuotaLock) {
|
synchronized (mQuotaLock) {
|
||||||
boolean oldEnable;
|
boolean oldEnable;
|
||||||
@@ -1256,7 +1080,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void setUidCleartextNetworkPolicy(int uid, int policy) {
|
public void setUidCleartextNetworkPolicy(int uid, int policy) {
|
||||||
if (mDeps.getCallingUid() != uid) {
|
if (mDeps.getCallingUid() != uid) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (mQuotaLock) {
|
synchronized (mQuotaLock) {
|
||||||
@@ -1293,27 +1117,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class NetdTetheringStatsProvider extends ITetheringStatsProvider.Stub {
|
|
||||||
@Override
|
|
||||||
public NetworkStats getTetherStats(int how) {
|
|
||||||
// Remove the implementation of NetdTetheringStatsProvider#getTetherStats
|
|
||||||
// since all callers are migrated to use INetd#tetherGetStats directly.
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInterfaceQuota(String iface, long quotaBytes) {
|
|
||||||
// Do nothing. netd is already informed of quota changes in setInterfaceQuota.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NetworkStats getNetworkStatsTethering(int how) {
|
|
||||||
// Remove the implementation of getNetworkStatsTethering since all callers are migrated
|
|
||||||
// to use INetd#tetherGetStats directly.
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFirewallEnabled(boolean enabled) {
|
public void setFirewallEnabled(boolean enabled) {
|
||||||
enforceSystemUid();
|
enforceSystemUid();
|
||||||
@@ -1332,18 +1135,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
return mFirewallEnabled;
|
return mFirewallEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFirewallInterfaceRule(String iface, boolean allow) {
|
|
||||||
enforceSystemUid();
|
|
||||||
Preconditions.checkState(mFirewallEnabled);
|
|
||||||
try {
|
|
||||||
mNetdService.firewallSetInterfaceRule(iface,
|
|
||||||
allow ? INetd.FIREWALL_RULE_ALLOW : INetd.FIREWALL_RULE_DENY);
|
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFirewallChainEnabled(int chain, boolean enable) {
|
public void setFirewallChainEnabled(int chain, boolean enable) {
|
||||||
enforceSystemUid();
|
enforceSystemUid();
|
||||||
@@ -1620,22 +1411,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
pw.println("]");
|
pw.println("]");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyInterfaceInNetwork(boolean add, int netId, String iface) {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
try {
|
|
||||||
if (add) {
|
|
||||||
mNetdService.networkAddInterface(netId, iface);
|
|
||||||
} else {
|
|
||||||
mNetdService.networkRemoveInterface(netId, iface);
|
|
||||||
}
|
|
||||||
} catch (RemoteException | ServiceSpecificException e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void allowProtect(int uid) {
|
public void allowProtect(int uid) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mNetdService.networkSetProtectAllow(uid);
|
mNetdService.networkSetProtectAllow(uid);
|
||||||
@@ -1646,7 +1424,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void denyProtect(int uid) {
|
public void denyProtect(int uid) {
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
PermissionUtils.enforceNetworkStackPermission(mContext);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mNetdService.networkSetProtectDeny(uid);
|
mNetdService.networkSetProtectDeny(uid);
|
||||||
@@ -1655,24 +1433,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addInterfaceToLocalNetwork(String iface, List<RouteInfo> routes) {
|
|
||||||
modifyInterfaceInNetwork(MODIFY_OPERATION_ADD, INetd.LOCAL_NET_ID, iface);
|
|
||||||
// modifyInterfaceInNetwork already check calling permission.
|
|
||||||
NetdUtils.addRoutesToLocalNetwork(mNetdService, iface, routes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeInterfaceFromLocalNetwork(String iface) {
|
|
||||||
modifyInterfaceInNetwork(MODIFY_OPERATION_REMOVE, INetd.LOCAL_NET_ID, iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeRoutesFromLocalNetwork(List<RouteInfo> routes) {
|
|
||||||
NetworkStack.checkNetworkStackPermission(mContext);
|
|
||||||
return NetdUtils.removeRoutesFromLocalNetwork(mNetdService, routes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNetworkRestricted(int uid) {
|
public boolean isNetworkRestricted(int uid) {
|
||||||
mContext.enforceCallingOrSelfPermission(OBSERVE_NETWORK_POLICY, TAG);
|
mContext.enforceCallingOrSelfPermission(OBSERVE_NETWORK_POLICY, TAG);
|
||||||
|
|||||||
Reference in New Issue
Block a user