blob: c3f3a5d47fe40d4244553e001a6ebbb44ec9225c [file] [log] [blame]
San Mehat873f2142010-01-14 10:25:07 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server;
18
Jeff Sharkey4529bb62011-12-14 10:31:54 -080019import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
Jeff Sharkey47eb1022011-08-25 17:48:52 -070020import static android.Manifest.permission.DUMP;
Jeff Sharkeyaf75c332011-11-18 12:41:12 -080021import static android.Manifest.permission.SHUTDOWN;
Jeff Sharkeyb5d55e32011-08-10 17:53:27 -070022import static android.net.NetworkStats.SET_DEFAULT;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070023import static android.net.NetworkStats.TAG_NONE;
24import static android.net.NetworkStats.UID_ALL;
Jeff Sharkeyae2c1812011-10-04 13:11:40 -070025import static android.net.TrafficStats.UID_TETHERING;
Jeff Sharkeyba2896e2011-11-30 18:13:54 -080026import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceGetCfgResult;
27import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceListResult;
28import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceRxThrottleResult;
29import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceTxThrottleResult;
30import static com.android.server.NetworkManagementService.NetdResponseCode.IpFwdStatusResult;
31import static com.android.server.NetworkManagementService.NetdResponseCode.TetherDnsFwdTgtListResult;
32import static com.android.server.NetworkManagementService.NetdResponseCode.TetherInterfaceListResult;
33import static com.android.server.NetworkManagementService.NetdResponseCode.TetherStatusResult;
34import static com.android.server.NetworkManagementService.NetdResponseCode.TetheringStatsResult;
35import static com.android.server.NetworkManagementService.NetdResponseCode.TtyListResult;
Jeff Sharkeya63ba592011-07-19 23:47:12 -070036import static com.android.server.NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED;
Jeff Sharkey1b5a2a92011-06-18 18:34:16 -070037
San Mehat873f2142010-01-14 10:25:07 -080038import android.content.Context;
San Mehat4d02d002010-01-22 16:07:46 -080039import android.net.INetworkManagementEventObserver;
Jeff Sharkeyeedcb952011-05-17 14:55:15 -070040import android.net.InterfaceConfiguration;
Robert Greenwalted126402011-01-28 15:34:55 -080041import android.net.LinkAddress;
Jeff Sharkeyeedcb952011-05-17 14:55:15 -070042import android.net.NetworkStats;
Robert Greenwalted126402011-01-28 15:34:55 -080043import android.net.NetworkUtils;
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -070044import android.net.RouteInfo;
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -080045import android.net.wifi.WifiConfiguration;
46import android.net.wifi.WifiConfiguration.KeyMgmt;
Jeff Sharkeyb24a7852012-05-01 15:19:37 -070047import android.os.Handler;
San Mehat873f2142010-01-14 10:25:07 -080048import android.os.INetworkManagementService;
Jeff Sharkey3df273e2011-12-15 15:47:12 -080049import android.os.RemoteCallbackList;
50import android.os.RemoteException;
Jeff Sharkey9a13f362011-04-26 16:25:36 -070051import android.os.SystemClock;
Marco Nelissen62dbb222010-02-18 10:56:30 -080052import android.os.SystemProperties;
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -080053import android.util.Log;
Joe Onorato8a9b2202010-02-26 18:56:32 -080054import android.util.Slog;
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -070055import android.util.SparseBooleanArray;
San Mehat873f2142010-01-14 10:25:07 -080056
Jeff Sharkey1059c3c2011-10-04 16:54:49 -070057import com.android.internal.net.NetworkStatsFactory;
Jeff Sharkeyba2896e2011-11-30 18:13:54 -080058import com.android.server.NativeDaemonConnector.Command;
Jeff Sharkeyb24a7852012-05-01 15:19:37 -070059import com.google.android.collect.Maps;
Jeff Sharkey4414cea2011-06-24 17:05:24 -070060
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -070061import java.io.BufferedReader;
62import java.io.DataInputStream;
San Mehat873f2142010-01-14 10:25:07 -080063import java.io.File;
Jeff Sharkey47eb1022011-08-25 17:48:52 -070064import java.io.FileDescriptor;
Jeff Sharkey9a13f362011-04-26 16:25:36 -070065import java.io.FileInputStream;
Jeff Sharkey9a13f362011-04-26 16:25:36 -070066import java.io.IOException;
Jeff Sharkey9a13f362011-04-26 16:25:36 -070067import java.io.InputStreamReader;
Jeff Sharkey47eb1022011-08-25 17:48:52 -070068import java.io.PrintWriter;
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -070069import java.net.Inet4Address;
Jeff Sharkeyeedcb952011-05-17 14:55:15 -070070import java.net.InetAddress;
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -070071import java.net.InterfaceAddress;
72import java.net.NetworkInterface;
73import java.net.SocketException;
Jeff Sharkeyeedcb952011-05-17 14:55:15 -070074import java.util.ArrayList;
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -070075import java.util.Collection;
Jeff Sharkeyb24a7852012-05-01 15:19:37 -070076import java.util.HashMap;
77import java.util.Map;
Jeff Sharkeyeedcb952011-05-17 14:55:15 -070078import java.util.NoSuchElementException;
79import java.util.StringTokenizer;
Robert Greenwalte5c3afb2010-09-22 14:32:35 -070080import java.util.concurrent.CountDownLatch;
fredc0f420372012-04-12 00:02:00 -070081import android.bluetooth.BluetoothTetheringDataTracker;
San Mehat873f2142010-01-14 10:25:07 -080082
83/**
84 * @hide
85 */
Jeff Sharkey8e9992a2011-08-23 18:37:23 -070086public class NetworkManagementService extends INetworkManagementService.Stub
87 implements Watchdog.Monitor {
Jeff Sharkeyeedcb952011-05-17 14:55:15 -070088 private static final String TAG = "NetworkManagementService";
Dianne Hackborncef65ee2010-09-30 18:27:22 -070089 private static final boolean DBG = false;
Kenny Root305bcbf2010-09-03 07:56:38 -070090 private static final String NETD_TAG = "NetdConnector";
91
Jeff Sharkeyba2896e2011-11-30 18:13:54 -080092 private static final String ADD = "add";
93 private static final String REMOVE = "remove";
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -070094
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -070095 private static final String DEFAULT = "default";
96 private static final String SECONDARY = "secondary";
97
Jeff Sharkey8e9992a2011-08-23 18:37:23 -070098 /**
99 * Name representing {@link #setGlobalAlert(long)} limit when delivered to
100 * {@link INetworkManagementEventObserver#limitReached(String, String)}.
101 */
102 public static final String LIMIT_GLOBAL_ALERT = "globalAlert";
103
San Mehat873f2142010-01-14 10:25:07 -0800104 class NetdResponseCode {
JP Abgrall12b933d2011-07-14 18:09:22 -0700105 /* Keep in sync with system/netd/ResponseCode.h */
San Mehat873f2142010-01-14 10:25:07 -0800106 public static final int InterfaceListResult = 110;
107 public static final int TetherInterfaceListResult = 111;
108 public static final int TetherDnsFwdTgtListResult = 112;
San Mehat72759df2010-01-19 13:50:37 -0800109 public static final int TtyListResult = 113;
San Mehat873f2142010-01-14 10:25:07 -0800110
111 public static final int TetherStatusResult = 210;
112 public static final int IpFwdStatusResult = 211;
San Mehated4fc8a2010-01-22 12:28:36 -0800113 public static final int InterfaceGetCfgResult = 213;
Robert Greenwalte3253922010-02-18 09:23:25 -0800114 public static final int SoftapStatusResult = 214;
San Mehat91cac642010-03-31 14:31:36 -0700115 public static final int InterfaceRxCounterResult = 216;
116 public static final int InterfaceTxCounterResult = 217;
117 public static final int InterfaceRxThrottleResult = 218;
118 public static final int InterfaceTxThrottleResult = 219;
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -0700119 public static final int QuotaCounterResult = 220;
120 public static final int TetheringStatsResult = 221;
Selim Gurun84c00c62012-02-27 15:42:38 -0800121 public static final int DnsProxyQueryResult = 222;
Robert Greenwalte3253922010-02-18 09:23:25 -0800122
123 public static final int InterfaceChange = 600;
JP Abgrall12b933d2011-07-14 18:09:22 -0700124 public static final int BandwidthControl = 601;
Haoyu Bai6b7358d2012-07-17 16:36:50 -0700125 public static final int InterfaceClassActivity = 613;
San Mehat873f2142010-01-14 10:25:07 -0800126 }
127
128 /**
129 * Binder context for this service
130 */
131 private Context mContext;
132
133 /**
134 * connector object for communicating with netd
135 */
136 private NativeDaemonConnector mConnector;
137
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700138 private final Handler mMainHandler = new Handler();
139
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700140 private Thread mThread;
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700141 private CountDownLatch mConnectedSignal = new CountDownLatch(1);
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700142
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800143 private final RemoteCallbackList<INetworkManagementEventObserver> mObservers =
144 new RemoteCallbackList<INetworkManagementEventObserver>();
San Mehat4d02d002010-01-22 16:07:46 -0800145
Jeff Sharkey1059c3c2011-10-04 16:54:49 -0700146 private final NetworkStatsFactory mStatsFactory = new NetworkStatsFactory();
147
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -0700148 private Object mQuotaLock = new Object();
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -0700149 /** Set of interfaces with active quotas. */
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700150 private HashMap<String, Long> mActiveQuotas = Maps.newHashMap();
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -0700151 /** Set of interfaces with active alerts. */
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700152 private HashMap<String, Long> mActiveAlerts = Maps.newHashMap();
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -0700153 /** Set of UIDs with active reject rules. */
154 private SparseBooleanArray mUidRejectOnQuota = new SparseBooleanArray();
155
Jeff Sharkeyfa23c5a2011-08-09 21:44:24 -0700156 private volatile boolean mBandwidthControlEnabled;
Jeff Sharkey350083e2011-06-29 10:45:16 -0700157
San Mehat873f2142010-01-14 10:25:07 -0800158 /**
159 * Constructs a new NetworkManagementService instance
160 *
161 * @param context Binder context for this service
162 */
Jeff Sharkey1059c3c2011-10-04 16:54:49 -0700163 private NetworkManagementService(Context context) {
San Mehat873f2142010-01-14 10:25:07 -0800164 mContext = context;
San Mehat4d02d002010-01-22 16:07:46 -0800165
Marco Nelissen62dbb222010-02-18 10:56:30 -0800166 if ("simulator".equals(SystemProperties.get("ro.product.device"))) {
167 return;
168 }
169
San Mehat873f2142010-01-14 10:25:07 -0800170 mConnector = new NativeDaemonConnector(
Robert Greenwalt5a0c3202012-05-22 16:07:46 -0700171 new NetdCallbackReceiver(), "netd", 10, NETD_TAG, 160);
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700172 mThread = new Thread(mConnector, NETD_TAG);
Jeff Sharkeyfa23c5a2011-08-09 21:44:24 -0700173
174 // Add ourself to the Watchdog monitors.
175 Watchdog.getInstance().addMonitor(this);
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700176 }
177
178 public static NetworkManagementService create(Context context) throws InterruptedException {
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700179 final NetworkManagementService service = new NetworkManagementService(context);
180 final CountDownLatch connectedSignal = service.mConnectedSignal;
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700181 if (DBG) Slog.d(TAG, "Creating NetworkManagementService");
182 service.mThread.start();
183 if (DBG) Slog.d(TAG, "Awaiting socket connection");
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700184 connectedSignal.await();
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700185 if (DBG) Slog.d(TAG, "Connected");
186 return service;
San Mehat873f2142010-01-14 10:25:07 -0800187 }
188
Jeff Sharkey350083e2011-06-29 10:45:16 -0700189 public void systemReady() {
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700190 prepareNativeDaemon();
191 if (DBG) Slog.d(TAG, "Prepared");
Jeff Sharkey350083e2011-06-29 10:45:16 -0700192 }
193
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800194 @Override
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800195 public void registerObserver(INetworkManagementEventObserver observer) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800196 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800197 mObservers.register(observer);
San Mehat4d02d002010-01-22 16:07:46 -0800198 }
199
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800200 @Override
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800201 public void unregisterObserver(INetworkManagementEventObserver observer) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800202 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800203 mObservers.unregister(observer);
San Mehat4d02d002010-01-22 16:07:46 -0800204 }
205
206 /**
Mike J. Chen6143f5f2011-06-23 15:17:51 -0700207 * Notify our observers of an interface status change
San Mehat4d02d002010-01-22 16:07:46 -0800208 */
Mike J. Chen6143f5f2011-06-23 15:17:51 -0700209 private void notifyInterfaceStatusChanged(String iface, boolean up) {
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800210 final int length = mObservers.beginBroadcast();
211 for (int i = 0; i < length; i++) {
San Mehat4d02d002010-01-22 16:07:46 -0800212 try {
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800213 mObservers.getBroadcastItem(i).interfaceStatusChanged(iface, up);
214 } catch (RemoteException e) {
Mike J. Chen6143f5f2011-06-23 15:17:51 -0700215 }
216 }
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800217 mObservers.finishBroadcast();
Mike J. Chen6143f5f2011-06-23 15:17:51 -0700218 }
219
220 /**
Mike J. Chenf59c7d02011-06-23 15:33:15 -0700221 * Notify our observers of an interface link state change
Mike J. Chen6143f5f2011-06-23 15:17:51 -0700222 * (typically, an Ethernet cable has been plugged-in or unplugged).
223 */
224 private void notifyInterfaceLinkStateChanged(String iface, boolean up) {
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800225 final int length = mObservers.beginBroadcast();
226 for (int i = 0; i < length; i++) {
Mike J. Chen6143f5f2011-06-23 15:17:51 -0700227 try {
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800228 mObservers.getBroadcastItem(i).interfaceLinkStateChanged(iface, up);
229 } catch (RemoteException e) {
San Mehat4d02d002010-01-22 16:07:46 -0800230 }
231 }
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800232 mObservers.finishBroadcast();
San Mehat4d02d002010-01-22 16:07:46 -0800233 }
234
235 /**
236 * Notify our observers of an interface addition.
237 */
238 private void notifyInterfaceAdded(String iface) {
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800239 final int length = mObservers.beginBroadcast();
240 for (int i = 0; i < length; i++) {
San Mehat4d02d002010-01-22 16:07:46 -0800241 try {
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800242 mObservers.getBroadcastItem(i).interfaceAdded(iface);
243 } catch (RemoteException e) {
San Mehat4d02d002010-01-22 16:07:46 -0800244 }
245 }
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800246 mObservers.finishBroadcast();
San Mehat4d02d002010-01-22 16:07:46 -0800247 }
248
249 /**
250 * Notify our observers of an interface removal.
251 */
252 private void notifyInterfaceRemoved(String iface) {
Jeff Sharkey89b8a212011-10-11 11:58:11 -0700253 // netd already clears out quota and alerts for removed ifaces; update
254 // our sanity-checking state.
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700255 mActiveAlerts.remove(iface);
256 mActiveQuotas.remove(iface);
Jeff Sharkey89b8a212011-10-11 11:58:11 -0700257
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800258 final int length = mObservers.beginBroadcast();
259 for (int i = 0; i < length; i++) {
San Mehat4d02d002010-01-22 16:07:46 -0800260 try {
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800261 mObservers.getBroadcastItem(i).interfaceRemoved(iface);
262 } catch (RemoteException e) {
San Mehat4d02d002010-01-22 16:07:46 -0800263 }
264 }
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800265 mObservers.finishBroadcast();
San Mehat4d02d002010-01-22 16:07:46 -0800266 }
267
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700268 /**
JP Abgrall12b933d2011-07-14 18:09:22 -0700269 * Notify our observers of a limit reached.
270 */
271 private void notifyLimitReached(String limitName, String iface) {
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800272 final int length = mObservers.beginBroadcast();
273 for (int i = 0; i < length; i++) {
JP Abgrall12b933d2011-07-14 18:09:22 -0700274 try {
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800275 mObservers.getBroadcastItem(i).limitReached(limitName, iface);
276 } catch (RemoteException e) {
JP Abgrall12b933d2011-07-14 18:09:22 -0700277 }
278 }
Jeff Sharkey3df273e2011-12-15 15:47:12 -0800279 mObservers.finishBroadcast();
JP Abgrall12b933d2011-07-14 18:09:22 -0700280 }
281
282 /**
Haoyu Baidb3c8672012-06-20 14:29:57 -0700283 * Notify our observers of a change in the data activity state of the interface
284 */
285 private void notifyInterfaceClassActivity(String label, boolean active) {
286 final int length = mObservers.beginBroadcast();
287 for (int i = 0; i < length; i++) {
288 try {
289 mObservers.getBroadcastItem(i).interfaceClassDataActivityChanged(label, active);
290 } catch (RemoteException e) {
291 }
292 }
293 mObservers.finishBroadcast();
294 }
295
296 /**
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700297 * Prepare native daemon once connected, enabling modules and pushing any
298 * existing in-memory rules.
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700299 */
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700300 private void prepareNativeDaemon() {
301 mBandwidthControlEnabled = false;
Robert Greenwalte5c3afb2010-09-22 14:32:35 -0700302
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700303 // only enable bandwidth control when support exists
304 final boolean hasKernelSupport = new File("/proc/net/xt_qtaguid/ctrl").exists();
305 if (hasKernelSupport) {
306 Slog.d(TAG, "enabling bandwidth control");
307 try {
308 mConnector.execute("bandwidth", "enable");
309 mBandwidthControlEnabled = true;
310 } catch (NativeDaemonConnectorException e) {
311 Log.wtf(TAG, "problem enabling bandwidth controls", e);
312 }
313 } else {
314 Slog.d(TAG, "not enabling bandwidth control");
315 }
316
317 SystemProperties.set(PROP_QTAGUID_ENABLED, mBandwidthControlEnabled ? "1" : "0");
318
319 // push any existing quota or UID rules
320 synchronized (mQuotaLock) {
321 int size = mActiveQuotas.size();
322 if (size > 0) {
323 Slog.d(TAG, "pushing " + size + " active quota rules");
324 final HashMap<String, Long> activeQuotas = mActiveQuotas;
325 mActiveQuotas = Maps.newHashMap();
326 for (Map.Entry<String, Long> entry : activeQuotas.entrySet()) {
327 setInterfaceQuota(entry.getKey(), entry.getValue());
328 }
329 }
330
331 size = mActiveAlerts.size();
332 if (size > 0) {
333 Slog.d(TAG, "pushing " + size + " active alert rules");
334 final HashMap<String, Long> activeAlerts = mActiveAlerts;
335 mActiveAlerts = Maps.newHashMap();
336 for (Map.Entry<String, Long> entry : activeAlerts.entrySet()) {
337 setInterfaceAlert(entry.getKey(), entry.getValue());
338 }
339 }
340
341 size = mUidRejectOnQuota.size();
342 if (size > 0) {
343 Slog.d(TAG, "pushing " + size + " active uid rules");
344 final SparseBooleanArray uidRejectOnQuota = mUidRejectOnQuota;
345 mUidRejectOnQuota = new SparseBooleanArray();
346 for (int i = 0; i < uidRejectOnQuota.size(); i++) {
347 setUidNetworkRules(uidRejectOnQuota.keyAt(i), uidRejectOnQuota.valueAt(i));
348 }
349 }
350 }
351 }
San Mehat4d02d002010-01-22 16:07:46 -0800352
San Mehat873f2142010-01-14 10:25:07 -0800353 //
354 // Netd Callback handling
355 //
356
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700357 private class NetdCallbackReceiver implements INativeDaemonConnectorCallbacks {
358 @Override
San Mehat873f2142010-01-14 10:25:07 -0800359 public void onDaemonConnected() {
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700360 // event is dispatched from internal NDC thread, so we prepare the
361 // daemon back on main thread.
362 if (mConnectedSignal != null) {
363 mConnectedSignal.countDown();
364 mConnectedSignal = null;
365 } else {
366 mMainHandler.post(new Runnable() {
367 @Override
368 public void run() {
369 prepareNativeDaemon();
370 }
371 });
372 }
San Mehat873f2142010-01-14 10:25:07 -0800373 }
Jeff Sharkeyfa23c5a2011-08-09 21:44:24 -0700374
Jeff Sharkeyb24a7852012-05-01 15:19:37 -0700375 @Override
San Mehat873f2142010-01-14 10:25:07 -0800376 public boolean onEvent(int code, String raw, String[] cooked) {
JP Abgrall12b933d2011-07-14 18:09:22 -0700377 switch (code) {
378 case NetdResponseCode.InterfaceChange:
379 /*
380 * a network interface change occured
381 * Format: "NNN Iface added <name>"
382 * "NNN Iface removed <name>"
383 * "NNN Iface changed <name> <up/down>"
384 * "NNN Iface linkstatus <name> <up/down>"
385 */
386 if (cooked.length < 4 || !cooked[1].equals("Iface")) {
387 throw new IllegalStateException(
388 String.format("Invalid event from daemon (%s)", raw));
389 }
390 if (cooked[2].equals("added")) {
391 notifyInterfaceAdded(cooked[3]);
392 return true;
393 } else if (cooked[2].equals("removed")) {
394 notifyInterfaceRemoved(cooked[3]);
395 return true;
396 } else if (cooked[2].equals("changed") && cooked.length == 5) {
397 notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
398 return true;
399 } else if (cooked[2].equals("linkstate") && cooked.length == 5) {
400 notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
401 return true;
402 }
Robert Greenwalte3253922010-02-18 09:23:25 -0800403 throw new IllegalStateException(
404 String.format("Invalid event from daemon (%s)", raw));
JP Abgrall12b933d2011-07-14 18:09:22 -0700405 // break;
406 case NetdResponseCode.BandwidthControl:
407 /*
408 * Bandwidth control needs some attention
409 * Format: "NNN limit alert <alertName> <ifaceName>"
410 */
411 if (cooked.length < 5 || !cooked[1].equals("limit")) {
412 throw new IllegalStateException(
413 String.format("Invalid event from daemon (%s)", raw));
414 }
415 if (cooked[2].equals("alert")) {
416 notifyLimitReached(cooked[3], cooked[4]);
417 return true;
418 }
419 throw new IllegalStateException(
420 String.format("Invalid event from daemon (%s)", raw));
421 // break;
Haoyu Baidb3c8672012-06-20 14:29:57 -0700422 case NetdResponseCode.InterfaceClassActivity:
423 /*
424 * An network interface class state changed (active/idle)
425 * Format: "NNN IfaceClass <active/idle> <label>"
426 */
427 if (cooked.length < 4 || !cooked[1].equals("IfaceClass")) {
428 throw new IllegalStateException(
429 String.format("Invalid event from daemon (%s)", raw));
430 }
431 boolean isActive = cooked[2].equals("active");
432 notifyInterfaceClassActivity(cooked[3], isActive);
433 return true;
434 // break;
JP Abgrall12b933d2011-07-14 18:09:22 -0700435 default: break;
Robert Greenwalte3253922010-02-18 09:23:25 -0800436 }
437 return false;
San Mehat873f2142010-01-14 10:25:07 -0800438 }
439 }
440
San Mehated4fc8a2010-01-22 12:28:36 -0800441
San Mehat873f2142010-01-14 10:25:07 -0800442 //
443 // INetworkManagementService members
444 //
445
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800446 @Override
447 public String[] listInterfaces() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800448 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700449 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800450 return NativeDaemonEvent.filterMessageList(
451 mConnector.executeForList("interface", "list"), InterfaceListResult);
Kenny Roota80ce062010-06-01 13:23:53 -0700452 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800453 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700454 }
San Mehated4fc8a2010-01-22 12:28:36 -0800455 }
456
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800457 @Override
458 public InterfaceConfiguration getInterfaceConfig(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800459 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800460
461 final NativeDaemonEvent event;
Kenny Roota80ce062010-06-01 13:23:53 -0700462 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800463 event = mConnector.execute("interface", "getcfg", iface);
Kenny Roota80ce062010-06-01 13:23:53 -0700464 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800465 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700466 }
San Mehated4fc8a2010-01-22 12:28:36 -0800467
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800468 event.checkCode(InterfaceGetCfgResult);
469
470 // Rsp: 213 xx:xx:xx:xx:xx:xx yyy.yyy.yyy.yyy zzz flag1 flag2 flag3
471 final StringTokenizer st = new StringTokenizer(event.getMessage());
San Mehated4fc8a2010-01-22 12:28:36 -0800472
Kenny Roota80ce062010-06-01 13:23:53 -0700473 InterfaceConfiguration cfg;
San Mehated4fc8a2010-01-22 12:28:36 -0800474 try {
Kenny Roota80ce062010-06-01 13:23:53 -0700475 cfg = new InterfaceConfiguration();
Jeff Sharkeyddba1062011-11-29 18:37:04 -0800476 cfg.setHardwareAddress(st.nextToken(" "));
Robert Greenwalted126402011-01-28 15:34:55 -0800477 InetAddress addr = null;
Robert Greenwalt2d2afd12011-02-01 15:30:46 -0800478 int prefixLength = 0;
Kenny Roota80ce062010-06-01 13:23:53 -0700479 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800480 addr = NetworkUtils.numericToInetAddress(st.nextToken());
Robert Greenwalte5903732011-02-22 16:00:42 -0800481 } catch (IllegalArgumentException iae) {
482 Slog.e(TAG, "Failed to parse ipaddr", iae);
Kenny Roota80ce062010-06-01 13:23:53 -0700483 }
484
485 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800486 prefixLength = Integer.parseInt(st.nextToken());
Robert Greenwalt2d2afd12011-02-01 15:30:46 -0800487 } catch (NumberFormatException nfe) {
488 Slog.e(TAG, "Failed to parse prefixLength", nfe);
Kenny Roota80ce062010-06-01 13:23:53 -0700489 }
Robert Greenwalt04808c22010-12-13 17:01:41 -0800490
Jeff Sharkeyddba1062011-11-29 18:37:04 -0800491 cfg.setLinkAddress(new LinkAddress(addr, prefixLength));
492 while (st.hasMoreTokens()) {
493 cfg.setFlag(st.nextToken());
494 }
Kenny Roota80ce062010-06-01 13:23:53 -0700495 } catch (NoSuchElementException nsee) {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800496 throw new IllegalStateException("Invalid response from daemon: " + event);
San Mehated4fc8a2010-01-22 12:28:36 -0800497 }
San Mehated4fc8a2010-01-22 12:28:36 -0800498 return cfg;
499 }
500
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800501 @Override
502 public void setInterfaceConfig(String iface, InterfaceConfiguration cfg) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800503 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkeyddba1062011-11-29 18:37:04 -0800504 LinkAddress linkAddr = cfg.getLinkAddress();
Robert Greenwalt2d2afd12011-02-01 15:30:46 -0800505 if (linkAddr == null || linkAddr.getAddress() == null) {
506 throw new IllegalStateException("Null LinkAddress given");
Robert Greenwalted126402011-01-28 15:34:55 -0800507 }
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800508
509 final Command cmd = new Command("interface", "setcfg", iface,
Robert Greenwalt2d2afd12011-02-01 15:30:46 -0800510 linkAddr.getAddress().getHostAddress(),
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800511 linkAddr.getNetworkPrefixLength());
512 for (String flag : cfg.getFlags()) {
513 cmd.appendArg(flag);
514 }
515
Kenny Roota80ce062010-06-01 13:23:53 -0700516 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800517 mConnector.execute(cmd);
Kenny Roota80ce062010-06-01 13:23:53 -0700518 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800519 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700520 }
San Mehat873f2142010-01-14 10:25:07 -0800521 }
522
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800523 @Override
524 public void setInterfaceDown(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800525 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800526 final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
Jeff Sharkeyddba1062011-11-29 18:37:04 -0800527 ifcg.setInterfaceDown();
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800528 setInterfaceConfig(iface, ifcg);
Irfan Sheriff7244c972011-08-05 20:40:45 -0700529 }
530
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800531 @Override
532 public void setInterfaceUp(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800533 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800534 final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
Jeff Sharkeyddba1062011-11-29 18:37:04 -0800535 ifcg.setInterfaceUp();
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800536 setInterfaceConfig(iface, ifcg);
Irfan Sheriff7244c972011-08-05 20:40:45 -0700537 }
538
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800539 @Override
540 public void setInterfaceIpv6PrivacyExtensions(String iface, boolean enable) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800541 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Irfan Sheriff73293612011-09-14 12:31:56 -0700542 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800543 mConnector.execute(
544 "interface", "ipv6privacyextensions", iface, enable ? "enable" : "disable");
Irfan Sheriff73293612011-09-14 12:31:56 -0700545 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800546 throw e.rethrowAsParcelableException();
Irfan Sheriff73293612011-09-14 12:31:56 -0700547 }
548 }
549
Irfan Sherifff5600612011-06-16 10:26:28 -0700550 /* TODO: This is right now a IPv4 only function. Works for wifi which loses its
551 IPv6 addresses on interface down, but we need to do full clean up here */
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800552 @Override
553 public void clearInterfaceAddresses(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800554 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Irfan Sherifff5600612011-06-16 10:26:28 -0700555 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800556 mConnector.execute("interface", "clearaddrs", iface);
Irfan Sherifff5600612011-06-16 10:26:28 -0700557 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800558 throw e.rethrowAsParcelableException();
Irfan Sherifff5600612011-06-16 10:26:28 -0700559 }
560 }
561
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800562 @Override
563 public void enableIpv6(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800564 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
repo sync7960d9f2011-09-29 12:40:02 -0700565 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800566 mConnector.execute("interface", "ipv6", iface, "enable");
repo sync7960d9f2011-09-29 12:40:02 -0700567 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800568 throw e.rethrowAsParcelableException();
repo sync7960d9f2011-09-29 12:40:02 -0700569 }
570 }
571
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800572 @Override
573 public void disableIpv6(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800574 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
repo sync7960d9f2011-09-29 12:40:02 -0700575 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800576 mConnector.execute("interface", "ipv6", iface, "disable");
repo sync7960d9f2011-09-29 12:40:02 -0700577 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800578 throw e.rethrowAsParcelableException();
repo sync7960d9f2011-09-29 12:40:02 -0700579 }
580 }
581
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800582 @Override
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700583 public void addRoute(String interfaceName, RouteInfo route) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800584 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700585 modifyRoute(interfaceName, ADD, route, DEFAULT);
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700586 }
587
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800588 @Override
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700589 public void removeRoute(String interfaceName, RouteInfo route) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800590 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700591 modifyRoute(interfaceName, REMOVE, route, DEFAULT);
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700592 }
593
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800594 @Override
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700595 public void addSecondaryRoute(String interfaceName, RouteInfo route) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800596 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700597 modifyRoute(interfaceName, ADD, route, SECONDARY);
598 }
599
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800600 @Override
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700601 public void removeSecondaryRoute(String interfaceName, RouteInfo route) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800602 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700603 modifyRoute(interfaceName, REMOVE, route, SECONDARY);
604 }
605
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800606 private void modifyRoute(String interfaceName, String action, RouteInfo route, String type) {
607 final Command cmd = new Command("interface", "route", action, interfaceName, type);
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700608
609 // create triplet: dest-ip-addr prefixlength gateway-ip-addr
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800610 final LinkAddress la = route.getDestination();
611 cmd.appendArg(la.getAddress().getHostAddress());
612 cmd.appendArg(la.getNetworkPrefixLength());
613
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700614 if (route.getGateway() == null) {
615 if (la.getAddress() instanceof Inet4Address) {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800616 cmd.appendArg("0.0.0.0");
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700617 } else {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800618 cmd.appendArg("::0");
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700619 }
620 } else {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800621 cmd.appendArg(route.getGateway().getHostAddress());
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700622 }
623
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800624 try {
625 mConnector.execute(cmd);
626 } catch (NativeDaemonConnectorException e) {
627 throw e.rethrowAsParcelableException();
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700628 }
629 }
630
631 private ArrayList<String> readRouteList(String filename) {
632 FileInputStream fstream = null;
633 ArrayList<String> list = new ArrayList<String>();
634
635 try {
636 fstream = new FileInputStream(filename);
637 DataInputStream in = new DataInputStream(fstream);
638 BufferedReader br = new BufferedReader(new InputStreamReader(in));
639 String s;
640
641 // throw away the title line
642
643 while (((s = br.readLine()) != null) && (s.length() != 0)) {
644 list.add(s);
645 }
646 } catch (IOException ex) {
647 // return current list, possibly empty
648 } finally {
649 if (fstream != null) {
650 try {
651 fstream.close();
652 } catch (IOException ex) {}
653 }
654 }
655
656 return list;
657 }
658
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800659 @Override
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700660 public RouteInfo[] getRoutes(String interfaceName) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800661 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700662 ArrayList<RouteInfo> routes = new ArrayList<RouteInfo>();
663
664 // v4 routes listed as:
665 // iface dest-addr gateway-addr flags refcnt use metric netmask mtu window IRTT
666 for (String s : readRouteList("/proc/net/route")) {
667 String[] fields = s.split("\t");
668
669 if (fields.length > 7) {
670 String iface = fields[0];
671
672 if (interfaceName.equals(iface)) {
673 String dest = fields[1];
674 String gate = fields[2];
675 String flags = fields[3]; // future use?
676 String mask = fields[7];
677 try {
678 // address stored as a hex string, ex: 0014A8C0
679 InetAddress destAddr =
680 NetworkUtils.intToInetAddress((int)Long.parseLong(dest, 16));
681 int prefixLength =
682 NetworkUtils.netmaskIntToPrefixLength(
683 (int)Long.parseLong(mask, 16));
684 LinkAddress linkAddress = new LinkAddress(destAddr, prefixLength);
685
686 // address stored as a hex string, ex 0014A8C0
687 InetAddress gatewayAddr =
688 NetworkUtils.intToInetAddress((int)Long.parseLong(gate, 16));
689
690 RouteInfo route = new RouteInfo(linkAddress, gatewayAddr);
691 routes.add(route);
692 } catch (Exception e) {
693 Log.e(TAG, "Error parsing route " + s + " : " + e);
694 continue;
695 }
696 }
697 }
698 }
699
700 // v6 routes listed as:
701 // dest-addr prefixlength ?? ?? gateway-addr ?? ?? ?? ?? iface
702 for (String s : readRouteList("/proc/net/ipv6_route")) {
703 String[]fields = s.split("\\s+");
704 if (fields.length > 9) {
705 String iface = fields[9].trim();
706 if (interfaceName.equals(iface)) {
707 String dest = fields[0];
708 String prefix = fields[1];
709 String gate = fields[4];
710
711 try {
712 // prefix length stored as a hex string, ex 40
713 int prefixLength = Integer.parseInt(prefix, 16);
714
715 // address stored as a 32 char hex string
716 // ex fe800000000000000000000000000000
717 InetAddress destAddr = NetworkUtils.hexToInet6Address(dest);
718 LinkAddress linkAddress = new LinkAddress(destAddr, prefixLength);
719
720 InetAddress gateAddr = NetworkUtils.hexToInet6Address(gate);
721
722 RouteInfo route = new RouteInfo(linkAddress, gateAddr);
723 routes.add(route);
724 } catch (Exception e) {
725 Log.e(TAG, "Error parsing route " + s + " : " + e);
726 continue;
727 }
728 }
729 }
730 }
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800731 return routes.toArray(new RouteInfo[routes.size()]);
Robert Greenwalt59b1a4e2011-05-10 15:05:02 -0700732 }
733
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800734 @Override
San Mehat873f2142010-01-14 10:25:07 -0800735 public void shutdown() {
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800736 // TODO: remove from aidl if nobody calls externally
737 mContext.enforceCallingOrSelfPermission(SHUTDOWN, TAG);
San Mehat873f2142010-01-14 10:25:07 -0800738
Joe Onorato8a9b2202010-02-26 18:56:32 -0800739 Slog.d(TAG, "Shutting down");
San Mehat873f2142010-01-14 10:25:07 -0800740 }
741
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800742 @Override
San Mehat873f2142010-01-14 10:25:07 -0800743 public boolean getIpForwardingEnabled() throws IllegalStateException{
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800744 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
San Mehat873f2142010-01-14 10:25:07 -0800745
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800746 final NativeDaemonEvent event;
Kenny Roota80ce062010-06-01 13:23:53 -0700747 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800748 event = mConnector.execute("ipfwd", "status");
Kenny Roota80ce062010-06-01 13:23:53 -0700749 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800750 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700751 }
San Mehat873f2142010-01-14 10:25:07 -0800752
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800753 // 211 Forwarding enabled
754 event.checkCode(IpFwdStatusResult);
755 return event.getMessage().endsWith("enabled");
San Mehat873f2142010-01-14 10:25:07 -0800756 }
757
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800758 @Override
759 public void setIpForwardingEnabled(boolean enable) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800760 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800761 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800762 mConnector.execute("ipfwd", enable ? "enable" : "disable");
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800763 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800764 throw e.rethrowAsParcelableException();
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800765 }
San Mehat873f2142010-01-14 10:25:07 -0800766 }
767
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800768 @Override
769 public void startTethering(String[] dhcpRange) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800770 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Robert Greenwaltbfb7bfa2010-03-24 16:03:21 -0700771 // cmd is "tether start first_start first_stop second_start second_stop ..."
772 // an odd number of addrs will fail
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800773
774 final Command cmd = new Command("tether", "start");
Robert Greenwaltbfb7bfa2010-03-24 16:03:21 -0700775 for (String d : dhcpRange) {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800776 cmd.appendArg(d);
Robert Greenwaltbfb7bfa2010-03-24 16:03:21 -0700777 }
Kenny Roota80ce062010-06-01 13:23:53 -0700778
779 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800780 mConnector.execute(cmd);
Kenny Roota80ce062010-06-01 13:23:53 -0700781 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800782 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700783 }
San Mehat873f2142010-01-14 10:25:07 -0800784 }
785
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800786 @Override
787 public void stopTethering() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800788 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700789 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800790 mConnector.execute("tether", "stop");
Kenny Roota80ce062010-06-01 13:23:53 -0700791 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800792 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700793 }
San Mehat873f2142010-01-14 10:25:07 -0800794 }
795
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800796 @Override
797 public boolean isTetheringStarted() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800798 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
San Mehat873f2142010-01-14 10:25:07 -0800799
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800800 final NativeDaemonEvent event;
Kenny Roota80ce062010-06-01 13:23:53 -0700801 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800802 event = mConnector.execute("tether", "status");
Kenny Roota80ce062010-06-01 13:23:53 -0700803 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800804 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700805 }
San Mehat873f2142010-01-14 10:25:07 -0800806
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800807 // 210 Tethering services started
808 event.checkCode(TetherStatusResult);
809 return event.getMessage().endsWith("started");
San Mehat873f2142010-01-14 10:25:07 -0800810 }
Matthew Xiefe19f122012-07-12 16:03:32 -0700811
812 // TODO(BT) Remove
fredc0f420372012-04-12 00:02:00 -0700813 public void startReverseTethering(String iface)
814 throws IllegalStateException {
815 if (DBG) Slog.d(TAG, "startReverseTethering in");
Matthew Xiefe19f122012-07-12 16:03:32 -0700816 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
fredc0f420372012-04-12 00:02:00 -0700817 // cmd is "tether start first_start first_stop second_start second_stop ..."
818 // an odd number of addrs will fail
819 String cmd = "tether start-reverse";
820 cmd += " " + iface;
821 if (DBG) Slog.d(TAG, "startReverseTethering cmd: " + cmd);
822 try {
823 mConnector.doCommand(cmd);
824 } catch (NativeDaemonConnectorException e) {
825 throw new IllegalStateException("Unable to communicate to native daemon");
826 }
827 BluetoothTetheringDataTracker.getInstance().startReverseTether(iface);
828
829 }
Matthew Xiefe19f122012-07-12 16:03:32 -0700830
831 // TODO(BT) Remove
fredc0f420372012-04-12 00:02:00 -0700832 public void stopReverseTethering() throws IllegalStateException {
Matthew Xiefe19f122012-07-12 16:03:32 -0700833 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
fredc0f420372012-04-12 00:02:00 -0700834 try {
835 mConnector.doCommand("tether stop-reverse");
836 } catch (NativeDaemonConnectorException e) {
837 throw new IllegalStateException("Unable to communicate to native daemon to stop tether");
838 }
839 BluetoothTetheringDataTracker.getInstance().stopReverseTether();
840 }
San Mehat873f2142010-01-14 10:25:07 -0800841
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800842 @Override
843 public void tetherInterface(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800844 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700845 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800846 mConnector.execute("tether", "interface", "add", iface);
Kenny Roota80ce062010-06-01 13:23:53 -0700847 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800848 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700849 }
San Mehat873f2142010-01-14 10:25:07 -0800850 }
851
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800852 @Override
San Mehat873f2142010-01-14 10:25:07 -0800853 public void untetherInterface(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800854 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700855 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800856 mConnector.execute("tether", "interface", "remove", iface);
Kenny Roota80ce062010-06-01 13:23:53 -0700857 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800858 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700859 }
San Mehat873f2142010-01-14 10:25:07 -0800860 }
861
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800862 @Override
863 public String[] listTetheredInterfaces() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800864 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700865 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800866 return NativeDaemonEvent.filterMessageList(
867 mConnector.executeForList("tether", "interface", "list"),
868 TetherInterfaceListResult);
Kenny Roota80ce062010-06-01 13:23:53 -0700869 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800870 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700871 }
San Mehat873f2142010-01-14 10:25:07 -0800872 }
873
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800874 @Override
875 public void setDnsForwarders(String[] dns) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800876 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800877
878 final Command cmd = new Command("tether", "dns", "set");
879 for (String s : dns) {
880 cmd.appendArg(NetworkUtils.numericToInetAddress(s).getHostAddress());
881 }
882
San Mehat873f2142010-01-14 10:25:07 -0800883 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800884 mConnector.execute(cmd);
885 } catch (NativeDaemonConnectorException e) {
886 throw e.rethrowAsParcelableException();
San Mehat873f2142010-01-14 10:25:07 -0800887 }
888 }
889
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800890 @Override
891 public String[] getDnsForwarders() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800892 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700893 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800894 return NativeDaemonEvent.filterMessageList(
895 mConnector.executeForList("tether", "dns", "list"), TetherDnsFwdTgtListResult);
Kenny Roota80ce062010-06-01 13:23:53 -0700896 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800897 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700898 }
San Mehat873f2142010-01-14 10:25:07 -0800899 }
900
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800901 private void modifyNat(String action, String internalInterface, String externalInterface)
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700902 throws SocketException {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800903 final Command cmd = new Command("nat", action, internalInterface, externalInterface);
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700904
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800905 final NetworkInterface internalNetworkInterface = NetworkInterface.getByName(
906 internalInterface);
Robert Greenwalte83d1812011-11-21 14:44:39 -0800907 if (internalNetworkInterface == null) {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800908 cmd.appendArg("0");
Robert Greenwalte83d1812011-11-21 14:44:39 -0800909 } else {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800910 Collection<InterfaceAddress> interfaceAddresses = internalNetworkInterface
911 .getInterfaceAddresses();
912 cmd.appendArg(interfaceAddresses.size());
Robert Greenwalte83d1812011-11-21 14:44:39 -0800913 for (InterfaceAddress ia : interfaceAddresses) {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800914 InetAddress addr = NetworkUtils.getNetworkPart(
915 ia.getAddress(), ia.getNetworkPrefixLength());
916 cmd.appendArg(addr.getHostAddress() + "/" + ia.getNetworkPrefixLength());
Robert Greenwalte83d1812011-11-21 14:44:39 -0800917 }
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700918 }
919
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800920 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800921 mConnector.execute(cmd);
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800922 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800923 throw e.rethrowAsParcelableException();
Jeff Sharkey31c6e482011-11-18 17:09:01 -0800924 }
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700925 }
926
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800927 @Override
928 public void enableNat(String internalInterface, String externalInterface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800929 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700930 try {
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700931 modifyNat("enable", internalInterface, externalInterface);
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800932 } catch (SocketException e) {
933 throw new IllegalStateException(e);
Kenny Roota80ce062010-06-01 13:23:53 -0700934 }
San Mehat873f2142010-01-14 10:25:07 -0800935 }
936
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800937 @Override
938 public void disableNat(String internalInterface, String externalInterface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800939 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700940 try {
Robert Greenwalt3b28e9a2011-11-02 14:37:19 -0700941 modifyNat("disable", internalInterface, externalInterface);
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800942 } catch (SocketException e) {
943 throw new IllegalStateException(e);
Kenny Roota80ce062010-06-01 13:23:53 -0700944 }
San Mehat873f2142010-01-14 10:25:07 -0800945 }
San Mehat72759df2010-01-19 13:50:37 -0800946
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800947 @Override
948 public String[] listTtys() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800949 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700950 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800951 return NativeDaemonEvent.filterMessageList(
952 mConnector.executeForList("list_ttys"), TtyListResult);
Kenny Roota80ce062010-06-01 13:23:53 -0700953 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800954 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700955 }
San Mehat72759df2010-01-19 13:50:37 -0800956 }
957
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800958 @Override
959 public void attachPppd(
960 String tty, String localAddr, String remoteAddr, String dns1Addr, String dns2Addr) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800961 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
San Mehat72759df2010-01-19 13:50:37 -0800962 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800963 mConnector.execute("pppd", "attach", tty,
Robert Greenwalte5903732011-02-22 16:00:42 -0800964 NetworkUtils.numericToInetAddress(localAddr).getHostAddress(),
965 NetworkUtils.numericToInetAddress(remoteAddr).getHostAddress(),
966 NetworkUtils.numericToInetAddress(dns1Addr).getHostAddress(),
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800967 NetworkUtils.numericToInetAddress(dns2Addr).getHostAddress());
Kenny Roota80ce062010-06-01 13:23:53 -0700968 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800969 throw e.rethrowAsParcelableException();
San Mehat72759df2010-01-19 13:50:37 -0800970 }
971 }
972
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800973 @Override
974 public void detachPppd(String tty) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800975 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700976 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800977 mConnector.execute("pppd", "detach", tty);
Kenny Roota80ce062010-06-01 13:23:53 -0700978 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800979 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -0700980 }
San Mehat72759df2010-01-19 13:50:37 -0800981 }
Robert Greenwaltce1200d2010-02-18 11:25:54 -0800982
Jeff Sharkeyaf75c332011-11-18 12:41:12 -0800983 @Override
984 public void startAccessPoint(
Irfan Sheriff90542752012-06-19 15:44:35 -0700985 WifiConfiguration wifiConfig, String wlanIface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -0800986 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -0700987 try {
Irfan Sheriffcb30b222011-07-29 20:54:52 -0700988 wifiFirmwareReload(wlanIface, "AP");
Kenny Roota80ce062010-06-01 13:23:53 -0700989 if (wifiConfig == null) {
Irfan Sheriff90542752012-06-19 15:44:35 -0700990 mConnector.execute("softap", "set", wlanIface);
Kenny Roota80ce062010-06-01 13:23:53 -0700991 } else {
Irfan Sheriff90542752012-06-19 15:44:35 -0700992 mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800993 getSecurityType(wifiConfig), wifiConfig.preSharedKey);
Kenny Roota80ce062010-06-01 13:23:53 -0700994 }
Jeff Sharkeyba2896e2011-11-30 18:13:54 -0800995 mConnector.execute("softap", "startap");
Kenny Roota80ce062010-06-01 13:23:53 -0700996 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -0800997 throw e.rethrowAsParcelableException();
Irfan Sheriff9ab518ad2010-03-12 15:48:17 -0800998 }
Irfan Sheriff5321aef2010-02-12 12:35:59 -0800999 }
1000
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001001 private static String getSecurityType(WifiConfiguration wifiConfig) {
Irfan Sheriffec8d23a2011-02-16 17:00:33 -08001002 switch (wifiConfig.getAuthType()) {
1003 case KeyMgmt.WPA_PSK:
1004 return "wpa-psk";
1005 case KeyMgmt.WPA2_PSK:
1006 return "wpa2-psk";
1007 default:
1008 return "open";
1009 }
1010 }
1011
Irfan Sheriffcb30b222011-07-29 20:54:52 -07001012 /* @param mode can be "AP", "STA" or "P2P" */
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001013 @Override
1014 public void wifiFirmwareReload(String wlanIface, String mode) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001015 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Irfan Sheriffcb30b222011-07-29 20:54:52 -07001016 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001017 mConnector.execute("softap", "fwreload", wlanIface, mode);
Irfan Sheriffcb30b222011-07-29 20:54:52 -07001018 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001019 throw e.rethrowAsParcelableException();
Irfan Sheriffcb30b222011-07-29 20:54:52 -07001020 }
1021 }
1022
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001023 @Override
1024 public void stopAccessPoint(String wlanIface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001025 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -07001026 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001027 mConnector.execute("softap", "stopap");
Irfan Sheriffcb30b222011-07-29 20:54:52 -07001028 wifiFirmwareReload(wlanIface, "STA");
Kenny Roota80ce062010-06-01 13:23:53 -07001029 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001030 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -07001031 }
Irfan Sheriff5321aef2010-02-12 12:35:59 -08001032 }
1033
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001034 @Override
Irfan Sheriff90542752012-06-19 15:44:35 -07001035 public void setAccessPoint(WifiConfiguration wifiConfig, String wlanIface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001036 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -07001037 try {
1038 if (wifiConfig == null) {
Irfan Sheriff90542752012-06-19 15:44:35 -07001039 mConnector.execute("softap", "set", wlanIface);
Kenny Roota80ce062010-06-01 13:23:53 -07001040 } else {
Irfan Sheriff90542752012-06-19 15:44:35 -07001041 mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001042 getSecurityType(wifiConfig), wifiConfig.preSharedKey);
Kenny Roota80ce062010-06-01 13:23:53 -07001043 }
1044 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001045 throw e.rethrowAsParcelableException();
Irfan Sheriffc2f54c22010-03-18 14:02:22 -07001046 }
1047 }
San Mehat91cac642010-03-31 14:31:36 -07001048
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07001049 @Override
Jeff Sharkeye8914c32012-05-01 16:26:09 -07001050 public NetworkStats getNetworkStatsSummaryDev() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001051 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkeye8914c32012-05-01 16:26:09 -07001052 return mStatsFactory.readNetworkStatsSummaryDev();
1053 }
1054
1055 @Override
1056 public NetworkStats getNetworkStatsSummaryXt() {
1057 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
1058 return mStatsFactory.readNetworkStatsSummaryXt();
Jeff Sharkeyae2c1812011-10-04 13:11:40 -07001059 }
1060
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07001061 @Override
Jeff Sharkey9a13f362011-04-26 16:25:36 -07001062 public NetworkStats getNetworkStatsDetail() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001063 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey1059c3c2011-10-04 16:54:49 -07001064 return mStatsFactory.readNetworkStatsDetail(UID_ALL);
San Mehat91cac642010-03-31 14:31:36 -07001065 }
1066
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07001067 @Override
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001068 public void setInterfaceQuota(String iface, long quotaBytes) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001069 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001070
Jeff Sharkey350083e2011-06-29 10:45:16 -07001071 // silently discard when control disabled
1072 // TODO: eventually migrate to be always enabled
1073 if (!mBandwidthControlEnabled) return;
1074
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001075 synchronized (mQuotaLock) {
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001076 if (mActiveQuotas.containsKey(iface)) {
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001077 throw new IllegalStateException("iface " + iface + " already has quota");
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001078 }
1079
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001080 try {
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001081 // TODO: support quota shared across interfaces
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001082 mConnector.execute("bandwidth", "setiquota", iface, quotaBytes);
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001083 mActiveQuotas.put(iface, quotaBytes);
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001084 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001085 throw e.rethrowAsParcelableException();
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001086 }
Ashish Sharma50fd36d2011-06-15 19:34:53 -07001087 }
1088 }
1089
1090 @Override
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001091 public void removeInterfaceQuota(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001092 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001093
Jeff Sharkey350083e2011-06-29 10:45:16 -07001094 // silently discard when control disabled
1095 // TODO: eventually migrate to be always enabled
1096 if (!mBandwidthControlEnabled) return;
1097
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001098 synchronized (mQuotaLock) {
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001099 if (!mActiveQuotas.containsKey(iface)) {
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001100 // TODO: eventually consider throwing
1101 return;
1102 }
1103
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001104 mActiveQuotas.remove(iface);
1105 mActiveAlerts.remove(iface);
Jeff Sharkey38ddeaa2011-11-08 13:04:22 -08001106
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001107 try {
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001108 // TODO: support quota shared across interfaces
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001109 mConnector.execute("bandwidth", "removeiquota", iface);
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001110 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001111 throw e.rethrowAsParcelableException();
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001112 }
1113 }
1114 }
1115
1116 @Override
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001117 public void setInterfaceAlert(String iface, long alertBytes) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001118 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001119
1120 // silently discard when control disabled
1121 // TODO: eventually migrate to be always enabled
1122 if (!mBandwidthControlEnabled) return;
1123
1124 // quick sanity check
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001125 if (!mActiveQuotas.containsKey(iface)) {
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001126 throw new IllegalStateException("setting alert requires existing quota on iface");
1127 }
1128
1129 synchronized (mQuotaLock) {
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001130 if (mActiveAlerts.containsKey(iface)) {
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001131 throw new IllegalStateException("iface " + iface + " already has alert");
1132 }
1133
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001134 try {
1135 // TODO: support alert shared across interfaces
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001136 mConnector.execute("bandwidth", "setinterfacealert", iface, alertBytes);
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001137 mActiveAlerts.put(iface, alertBytes);
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001138 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001139 throw e.rethrowAsParcelableException();
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001140 }
1141 }
1142 }
1143
1144 @Override
1145 public void removeInterfaceAlert(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001146 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001147
1148 // silently discard when control disabled
1149 // TODO: eventually migrate to be always enabled
1150 if (!mBandwidthControlEnabled) return;
1151
1152 synchronized (mQuotaLock) {
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001153 if (!mActiveAlerts.containsKey(iface)) {
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001154 // TODO: eventually consider throwing
1155 return;
1156 }
1157
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001158 try {
1159 // TODO: support alert shared across interfaces
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001160 mConnector.execute("bandwidth", "removeinterfacealert", iface);
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001161 mActiveAlerts.remove(iface);
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001162 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001163 throw e.rethrowAsParcelableException();
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001164 }
1165 }
1166 }
1167
1168 @Override
1169 public void setGlobalAlert(long alertBytes) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001170 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001171
1172 // silently discard when control disabled
1173 // TODO: eventually migrate to be always enabled
1174 if (!mBandwidthControlEnabled) return;
1175
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001176 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001177 mConnector.execute("bandwidth", "setglobalalert", alertBytes);
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001178 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001179 throw e.rethrowAsParcelableException();
Jeff Sharkey41ff7ec2011-07-25 15:21:22 -07001180 }
1181 }
1182
1183 @Override
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001184 public void setUidNetworkRules(int uid, boolean rejectOnQuotaInterfaces) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001185 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001186
Jeff Sharkey350083e2011-06-29 10:45:16 -07001187 // silently discard when control disabled
1188 // TODO: eventually migrate to be always enabled
1189 if (!mBandwidthControlEnabled) return;
1190
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001191 synchronized (mQuotaLock) {
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001192 final boolean oldRejectOnQuota = mUidRejectOnQuota.get(uid, false);
1193 if (oldRejectOnQuota == rejectOnQuotaInterfaces) {
1194 // TODO: eventually consider throwing
1195 return;
1196 }
1197
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001198 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001199 mConnector.execute("bandwidth",
1200 rejectOnQuotaInterfaces ? "addnaughtyapps" : "removenaughtyapps", uid);
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001201 if (rejectOnQuotaInterfaces) {
1202 mUidRejectOnQuota.put(uid, true);
1203 } else {
1204 mUidRejectOnQuota.delete(uid);
1205 }
1206 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001207 throw e.rethrowAsParcelableException();
Jeff Sharkeyb3f19ca2011-06-29 23:54:13 -07001208 }
Ashish Sharma50fd36d2011-06-15 19:34:53 -07001209 }
1210 }
1211
Jeff Sharkey63d27a92011-08-03 17:04:22 -07001212 @Override
1213 public boolean isBandwidthControlEnabled() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001214 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey63d27a92011-08-03 17:04:22 -07001215 return mBandwidthControlEnabled;
1216 }
1217
1218 @Override
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07001219 public NetworkStats getNetworkStatsUidDetail(int uid) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001220 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkey1059c3c2011-10-04 16:54:49 -07001221 return mStatsFactory.readNetworkStatsDetail(uid);
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07001222 }
1223
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -07001224 @Override
1225 public NetworkStats getNetworkStatsTethering(String[] ifacePairs) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001226 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -07001227
1228 if (ifacePairs.length % 2 != 0) {
1229 throw new IllegalArgumentException(
1230 "unexpected ifacePairs; length=" + ifacePairs.length);
1231 }
1232
1233 final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
1234 for (int i = 0; i < ifacePairs.length; i += 2) {
1235 final String ifaceIn = ifacePairs[i];
1236 final String ifaceOut = ifacePairs[i + 1];
1237 if (ifaceIn != null && ifaceOut != null) {
1238 stats.combineValues(getNetworkStatsTethering(ifaceIn, ifaceOut));
1239 }
1240 }
1241 return stats;
1242 }
1243
1244 private NetworkStats.Entry getNetworkStatsTethering(String ifaceIn, String ifaceOut) {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001245 final NativeDaemonEvent event;
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -07001246 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001247 event = mConnector.execute("bandwidth", "gettetherstats", ifaceIn, ifaceOut);
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -07001248 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001249 throw e.rethrowAsParcelableException();
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -07001250 }
1251
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001252 event.checkCode(TetheringStatsResult);
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -07001253
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001254 // 221 ifaceIn ifaceOut rx_bytes rx_packets tx_bytes tx_packets
1255 final StringTokenizer tok = new StringTokenizer(event.getMessage());
1256 tok.nextToken();
1257 tok.nextToken();
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -07001258
1259 try {
1260 final NetworkStats.Entry entry = new NetworkStats.Entry();
1261 entry.iface = ifaceIn;
Jeff Sharkey905b5892011-09-30 15:19:49 -07001262 entry.uid = UID_TETHERING;
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -07001263 entry.set = SET_DEFAULT;
1264 entry.tag = TAG_NONE;
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001265 entry.rxBytes = Long.parseLong(tok.nextToken());
1266 entry.rxPackets = Long.parseLong(tok.nextToken());
1267 entry.txBytes = Long.parseLong(tok.nextToken());
1268 entry.txPackets = Long.parseLong(tok.nextToken());
Jeff Sharkeycdd02c5d2011-09-16 01:52:49 -07001269 return entry;
1270 } catch (NumberFormatException e) {
1271 throw new IllegalStateException(
1272 "problem parsing tethering stats for " + ifaceIn + " " + ifaceOut + ": " + e);
1273 }
1274 }
1275
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001276 @Override
San Mehatf0db6e12010-04-07 15:22:10 -07001277 public void setInterfaceThrottle(String iface, int rxKbps, int txKbps) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001278 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Kenny Roota80ce062010-06-01 13:23:53 -07001279 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001280 mConnector.execute("interface", "setthrottle", iface, rxKbps, txKbps);
Kenny Roota80ce062010-06-01 13:23:53 -07001281 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001282 throw e.rethrowAsParcelableException();
Kenny Roota80ce062010-06-01 13:23:53 -07001283 }
San Mehat91cac642010-03-31 14:31:36 -07001284 }
1285
1286 private int getInterfaceThrottle(String iface, boolean rx) {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001287 final NativeDaemonEvent event;
San Mehat91cac642010-03-31 14:31:36 -07001288 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001289 event = mConnector.execute("interface", "getthrottle", iface, rx ? "rx" : "tx");
1290 } catch (NativeDaemonConnectorException e) {
1291 throw e.rethrowAsParcelableException();
San Mehat91cac642010-03-31 14:31:36 -07001292 }
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001293
1294 if (rx) {
1295 event.checkCode(InterfaceRxThrottleResult);
1296 } else {
1297 event.checkCode(InterfaceTxThrottleResult);
1298 }
1299
1300 try {
1301 return Integer.parseInt(event.getMessage());
1302 } catch (NumberFormatException e) {
1303 throw new IllegalStateException("unexpected response:" + event);
1304 }
San Mehat91cac642010-03-31 14:31:36 -07001305 }
1306
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001307 @Override
San Mehat91cac642010-03-31 14:31:36 -07001308 public int getInterfaceRxThrottle(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001309 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
San Mehat91cac642010-03-31 14:31:36 -07001310 return getInterfaceThrottle(iface, true);
1311 }
1312
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001313 @Override
San Mehat91cac642010-03-31 14:31:36 -07001314 public int getInterfaceTxThrottle(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001315 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
San Mehat91cac642010-03-31 14:31:36 -07001316 return getInterfaceThrottle(iface, false);
1317 }
Jeff Sharkey9a13f362011-04-26 16:25:36 -07001318
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001319 @Override
1320 public void setDefaultInterfaceForDns(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001321 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Mattias Falk7475c0c2011-04-04 16:10:36 +02001322 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001323 mConnector.execute("resolver", "setdefaultif", iface);
Mattias Falk7475c0c2011-04-04 16:10:36 +02001324 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001325 throw e.rethrowAsParcelableException();
Mattias Falk7475c0c2011-04-04 16:10:36 +02001326 }
1327 }
1328
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001329 @Override
1330 public void setDnsServersForInterface(String iface, String[] servers) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001331 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001332
1333 final Command cmd = new Command("resolver", "setifdns", iface);
1334 for (String s : servers) {
1335 InetAddress a = NetworkUtils.numericToInetAddress(s);
1336 if (a.isAnyLocalAddress() == false) {
1337 cmd.appendArg(a.getHostAddress());
Mattias Falk7475c0c2011-04-04 16:10:36 +02001338 }
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001339 }
1340
1341 try {
1342 mConnector.execute(cmd);
Mattias Falk7475c0c2011-04-04 16:10:36 +02001343 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001344 throw e.rethrowAsParcelableException();
Mattias Falk7475c0c2011-04-04 16:10:36 +02001345 }
1346 }
1347
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001348 @Override
1349 public void flushDefaultDnsCache() {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001350 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Mattias Falk7475c0c2011-04-04 16:10:36 +02001351 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001352 mConnector.execute("resolver", "flushdefaultif");
Mattias Falk7475c0c2011-04-04 16:10:36 +02001353 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001354 throw e.rethrowAsParcelableException();
Mattias Falk7475c0c2011-04-04 16:10:36 +02001355 }
1356 }
1357
Jeff Sharkeyaf75c332011-11-18 12:41:12 -08001358 @Override
1359 public void flushInterfaceDnsCache(String iface) {
Jeff Sharkey4529bb62011-12-14 10:31:54 -08001360 mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
Mattias Falk7475c0c2011-04-04 16:10:36 +02001361 try {
Jeff Sharkeyba2896e2011-11-30 18:13:54 -08001362 mConnector.execute("resolver", "flushif", iface);
Mattias Falk7475c0c2011-04-04 16:10:36 +02001363 } catch (NativeDaemonConnectorException e) {
Jeff Sharkey276642b2011-12-01 11:24:24 -08001364 throw e.rethrowAsParcelableException();
Mattias Falk7475c0c2011-04-04 16:10:36 +02001365 }
1366 }
Jeff Sharkeyfa23c5a2011-08-09 21:44:24 -07001367
1368 /** {@inheritDoc} */
1369 public void monitor() {
1370 if (mConnector != null) {
1371 mConnector.monitor();
1372 }
1373 }
Jeff Sharkey47eb1022011-08-25 17:48:52 -07001374
1375 @Override
1376 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1377 mContext.enforceCallingOrSelfPermission(DUMP, TAG);
1378
Robert Greenwalt470fd722012-01-18 12:51:15 -08001379 pw.println("NetworkManagementService NativeDaemonConnector Log:");
1380 mConnector.dump(fd, pw, args);
1381 pw.println();
1382
Jeff Sharkey47eb1022011-08-25 17:48:52 -07001383 pw.print("Bandwidth control enabled: "); pw.println(mBandwidthControlEnabled);
1384
1385 synchronized (mQuotaLock) {
Jeff Sharkeyb24a7852012-05-01 15:19:37 -07001386 pw.print("Active quota ifaces: "); pw.println(mActiveQuotas.toString());
1387 pw.print("Active alert ifaces: "); pw.println(mActiveAlerts.toString());
Jeff Sharkey47eb1022011-08-25 17:48:52 -07001388 }
1389
1390 synchronized (mUidRejectOnQuota) {
1391 pw.print("UID reject on quota ifaces: [");
1392 final int size = mUidRejectOnQuota.size();
1393 for (int i = 0; i < size; i++) {
1394 pw.print(mUidRejectOnQuota.keyAt(i));
1395 if (i < size - 1) pw.print(",");
1396 }
1397 pw.println("]");
1398 }
1399 }
San Mehat873f2142010-01-14 10:25:07 -08001400}