Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 17 | package com.android.server.connectivity; |
| 18 | |
| 19 | import android.app.Notification; |
| 20 | import android.app.NotificationManager; |
| 21 | import android.app.PendingIntent; |
| 22 | import android.content.BroadcastReceiver; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 23 | import android.content.Context; |
| 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 26 | import android.content.pm.PackageManager; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 27 | import android.content.res.Resources; |
Mike Lockwood | c4308f0 | 2011-03-01 08:04:54 -0800 | [diff] [blame] | 28 | import android.hardware.usb.UsbManager; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 29 | import android.net.ConnectivityManager; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 30 | import android.net.IConnectivityManager; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 31 | import android.net.INetworkManagementEventObserver; |
Jeff Sharkey | 367d15a | 2011-09-22 14:59:51 -0700 | [diff] [blame] | 32 | import android.net.INetworkStatsService; |
Jeff Sharkey | cdd02c5d | 2011-09-16 01:52:49 -0700 | [diff] [blame] | 33 | import android.net.InterfaceConfiguration; |
Robert Greenwalt | ed12640 | 2011-01-28 15:34:55 -0800 | [diff] [blame] | 34 | import android.net.LinkAddress; |
Robert Greenwalt | 05d8936 | 2011-01-23 16:04:05 -0800 | [diff] [blame] | 35 | import android.net.LinkProperties; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 36 | import android.net.NetworkInfo; |
Robert Greenwalt | e590373 | 2011-02-22 16:00:42 -0800 | [diff] [blame] | 37 | import android.net.NetworkUtils; |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 38 | import android.net.RouteInfo; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 39 | import android.os.Binder; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 40 | import android.os.INetworkManagementService; |
Robert Greenwalt | dfadaea | 2010-03-11 15:03:08 -0800 | [diff] [blame] | 41 | import android.os.Looper; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 42 | import android.os.Message; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 43 | import android.os.RemoteException; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 44 | import android.os.UserHandle; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 45 | import android.provider.Settings; |
| 46 | import android.util.Log; |
| 47 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 48 | import com.android.internal.telephony.Phone; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 49 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 50 | import com.android.internal.util.IState; |
| 51 | import com.android.internal.util.State; |
| 52 | import com.android.internal.util.StateMachine; |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 53 | import com.android.server.IoThread; |
Lorenzo Colitti | 132fe8d | 2013-10-31 23:30:47 +0900 | [diff] [blame] | 54 | import com.android.server.net.BaseNetworkObserver; |
Jeff Sharkey | cdd02c5d | 2011-09-16 01:52:49 -0700 | [diff] [blame] | 55 | import com.google.android.collect.Lists; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 56 | |
| 57 | import java.io.FileDescriptor; |
| 58 | import java.io.PrintWriter; |
Robert Greenwalt | 04808c2 | 2010-12-13 17:01:41 -0800 | [diff] [blame] | 59 | import java.net.InetAddress; |
Robert Greenwalt | 4f74d55 | 2011-12-19 16:59:31 -0800 | [diff] [blame] | 60 | import java.net.Inet4Address; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 61 | import java.util.ArrayList; |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 62 | import java.util.Collection; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 63 | import java.util.HashMap; |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 64 | import java.util.Iterator; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 65 | import java.util.Set; |
Jeff Sharkey | cdd02c5d | 2011-09-16 01:52:49 -0700 | [diff] [blame] | 66 | |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 67 | /** |
| 68 | * @hide |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 69 | * |
| 70 | * Timeout |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 71 | * |
| 72 | * TODO - look for parent classes and code sharing |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 73 | */ |
Lorenzo Colitti | 132fe8d | 2013-10-31 23:30:47 +0900 | [diff] [blame] | 74 | public class Tethering extends BaseNetworkObserver { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 75 | |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 76 | private Context mContext; |
Robert Greenwalt | 924cc94 | 2010-06-28 10:26:19 -0700 | [diff] [blame] | 77 | private final static String TAG = "Tethering"; |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 78 | private final static boolean DBG = true; |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 79 | private final static boolean VDBG = false; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 80 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 81 | // TODO - remove both of these - should be part of interface inspection/selection stuff |
| 82 | private String[] mTetherableUsbRegexs; |
| 83 | private String[] mTetherableWifiRegexs; |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 84 | private String[] mTetherableBluetoothRegexs; |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 85 | private Collection<Integer> mUpstreamIfaceTypes; |
| 86 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 87 | // used to synchronize public access to members |
| 88 | private Object mPublicSync; |
| 89 | |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 90 | private static final Integer MOBILE_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE); |
| 91 | private static final Integer HIPRI_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE_HIPRI); |
| 92 | private static final Integer DUN_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE_DUN); |
| 93 | |
| 94 | // if we have to connect to mobile, what APN type should we use? Calculated by examining the |
| 95 | // upstream type list and the DUN_REQUIRED secure-setting |
| 96 | private int mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_NONE; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 97 | |
Jeff Sharkey | 367d15a | 2011-09-22 14:59:51 -0700 | [diff] [blame] | 98 | private final INetworkManagementService mNMService; |
| 99 | private final INetworkStatsService mStatsService; |
Robert Greenwalt | 3b28e9a | 2011-11-02 14:37:19 -0700 | [diff] [blame] | 100 | private final IConnectivityManager mConnService; |
Robert Greenwalt | 7eae250 | 2010-04-20 15:51:20 -0700 | [diff] [blame] | 101 | private Looper mLooper; |
Robert Greenwalt | dfadaea | 2010-03-11 15:03:08 -0800 | [diff] [blame] | 102 | |
Robert Greenwalt | 030f5e1 | 2010-03-10 16:41:03 -0800 | [diff] [blame] | 103 | private HashMap<String, TetherInterfaceSM> mIfaces; // all tethered/tetherable ifaces |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 104 | |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 105 | private BroadcastReceiver mStateReceiver; |
| 106 | |
Robert Greenwalt | bfb7bfa | 2010-03-24 16:03:21 -0700 | [diff] [blame] | 107 | private static final String USB_NEAR_IFACE_ADDR = "192.168.42.129"; |
Robert Greenwalt | b979f79 | 2011-02-11 17:01:02 -0800 | [diff] [blame] | 108 | private static final int USB_PREFIX_LENGTH = 24; |
Robert Greenwalt | bfb7bfa | 2010-03-24 16:03:21 -0700 | [diff] [blame] | 109 | |
Jaikumar Ganesh | 707952e | 2010-09-13 19:04:54 -0700 | [diff] [blame] | 110 | // USB is 192.168.42.1 and 255.255.255.0 |
| 111 | // Wifi is 192.168.43.1 and 255.255.255.0 |
| 112 | // BT is limited to max default of 5 connections. 192.168.44.1 to 192.168.48.1 |
| 113 | // with 255.255.255.0 |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 114 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 115 | private String[] mDhcpRange; |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 116 | private static final String[] DHCP_DEFAULT_RANGE = { |
| 117 | "192.168.42.2", "192.168.42.254", "192.168.43.2", "192.168.43.254", |
| 118 | "192.168.44.2", "192.168.44.254", "192.168.45.2", "192.168.45.254", |
| 119 | "192.168.46.2", "192.168.46.254", "192.168.47.2", "192.168.47.254", |
| 120 | "192.168.48.2", "192.168.48.254", |
| 121 | }; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 122 | |
Robert Greenwalt | bb4fd0b | 2011-12-09 15:36:50 -0800 | [diff] [blame] | 123 | private String[] mDefaultDnsServers; |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 124 | private static final String DNS_DEFAULT_SERVER1 = "8.8.8.8"; |
Robert Greenwalt | df255c2 | 2010-10-07 15:32:08 -0700 | [diff] [blame] | 125 | private static final String DNS_DEFAULT_SERVER2 = "8.8.4.4"; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 126 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 127 | private StateMachine mTetherMasterSM; |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 128 | |
| 129 | private Notification mTetheredNotification; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 130 | |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 131 | private boolean mRndisEnabled; // track the RNDIS function enabled state |
| 132 | private boolean mUsbTetherRequested; // true if USB tethering should be started |
| 133 | // when RNDIS is enabled |
Robert Greenwalt | 030f5e1 | 2010-03-10 16:41:03 -0800 | [diff] [blame] | 134 | |
Jeff Sharkey | 367d15a | 2011-09-22 14:59:51 -0700 | [diff] [blame] | 135 | public Tethering(Context context, INetworkManagementService nmService, |
Robert Greenwalt | 3b28e9a | 2011-11-02 14:37:19 -0700 | [diff] [blame] | 136 | INetworkStatsService statsService, IConnectivityManager connService, Looper looper) { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 137 | mContext = context; |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 138 | mNMService = nmService; |
Jeff Sharkey | 367d15a | 2011-09-22 14:59:51 -0700 | [diff] [blame] | 139 | mStatsService = statsService; |
Robert Greenwalt | 3b28e9a | 2011-11-02 14:37:19 -0700 | [diff] [blame] | 140 | mConnService = connService; |
Robert Greenwalt | dfadaea | 2010-03-11 15:03:08 -0800 | [diff] [blame] | 141 | mLooper = looper; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 142 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 143 | mPublicSync = new Object(); |
| 144 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 145 | mIfaces = new HashMap<String, TetherInterfaceSM>(); |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 146 | |
Robert Greenwalt | 7eae250 | 2010-04-20 15:51:20 -0700 | [diff] [blame] | 147 | // make our own thread so we don't anr the system |
Dianne Hackborn | 8d044e8 | 2013-04-30 17:24:15 -0700 | [diff] [blame] | 148 | mLooper = IoThread.get().getLooper(); |
Robert Greenwalt | dfadaea | 2010-03-11 15:03:08 -0800 | [diff] [blame] | 149 | mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 150 | mTetherMasterSM.start(); |
| 151 | |
Robert Greenwalt | bb51d9f | 2010-03-12 10:23:35 -0800 | [diff] [blame] | 152 | mStateReceiver = new StateReceiver(); |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 153 | IntentFilter filter = new IntentFilter(); |
Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 154 | filter.addAction(UsbManager.ACTION_USB_STATE); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 155 | filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); |
Robert Greenwalt | c13368b | 2013-07-18 14:24:42 -0700 | [diff] [blame] | 156 | filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); |
Robert Greenwalt | bb51d9f | 2010-03-12 10:23:35 -0800 | [diff] [blame] | 157 | mContext.registerReceiver(mStateReceiver, filter); |
| 158 | |
| 159 | filter = new IntentFilter(); |
Robert Greenwalt | 030f5e1 | 2010-03-10 16:41:03 -0800 | [diff] [blame] | 160 | filter.addAction(Intent.ACTION_MEDIA_SHARED); |
| 161 | filter.addAction(Intent.ACTION_MEDIA_UNSHARED); |
Robert Greenwalt | bb51d9f | 2010-03-12 10:23:35 -0800 | [diff] [blame] | 162 | filter.addDataScheme("file"); |
| 163 | mContext.registerReceiver(mStateReceiver, filter); |
| 164 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 165 | mDhcpRange = context.getResources().getStringArray( |
| 166 | com.android.internal.R.array.config_tether_dhcp_range); |
Robert Greenwalt | bfb7bfa | 2010-03-24 16:03:21 -0700 | [diff] [blame] | 167 | if ((mDhcpRange.length == 0) || (mDhcpRange.length % 2 ==1)) { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 168 | mDhcpRange = DHCP_DEFAULT_RANGE; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Robert Greenwalt | 49348e7 | 2011-10-21 16:54:26 -0700 | [diff] [blame] | 171 | // load device config info |
| 172 | updateConfiguration(); |
| 173 | |
| 174 | // TODO - remove and rely on real notifications of the current iface |
Robert Greenwalt | bb4fd0b | 2011-12-09 15:36:50 -0800 | [diff] [blame] | 175 | mDefaultDnsServers = new String[2]; |
| 176 | mDefaultDnsServers[0] = DNS_DEFAULT_SERVER1; |
| 177 | mDefaultDnsServers[1] = DNS_DEFAULT_SERVER2; |
Robert Greenwalt | 49348e7 | 2011-10-21 16:54:26 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void updateConfiguration() { |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 181 | String[] tetherableUsbRegexs = mContext.getResources().getStringArray( |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 182 | com.android.internal.R.array.config_tether_usb_regexs); |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 183 | String[] tetherableWifiRegexs = mContext.getResources().getStringArray( |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 184 | com.android.internal.R.array.config_tether_wifi_regexs); |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 185 | String[] tetherableBluetoothRegexs = mContext.getResources().getStringArray( |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 186 | com.android.internal.R.array.config_tether_bluetooth_regexs); |
Robert Greenwalt | 49348e7 | 2011-10-21 16:54:26 -0700 | [diff] [blame] | 187 | |
| 188 | int ifaceTypes[] = mContext.getResources().getIntArray( |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 189 | com.android.internal.R.array.config_tether_upstream_types); |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 190 | Collection<Integer> upstreamIfaceTypes = new ArrayList(); |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 191 | for (int i : ifaceTypes) { |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 192 | upstreamIfaceTypes.add(new Integer(i)); |
| 193 | } |
| 194 | |
| 195 | synchronized (mPublicSync) { |
| 196 | mTetherableUsbRegexs = tetherableUsbRegexs; |
| 197 | mTetherableWifiRegexs = tetherableWifiRegexs; |
| 198 | mTetherableBluetoothRegexs = tetherableBluetoothRegexs; |
| 199 | mUpstreamIfaceTypes = upstreamIfaceTypes; |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // check if the upstream type list needs to be modified due to secure-settings |
| 203 | checkDunRequired(); |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 204 | } |
| 205 | |
Mike J. Chen | 6143f5f | 2011-06-23 15:17:51 -0700 | [diff] [blame] | 206 | public void interfaceStatusChanged(String iface, boolean up) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 207 | if (VDBG) Log.d(TAG, "interfaceStatusChanged " + iface + ", " + up); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 208 | boolean found = false; |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 209 | boolean usb = false; |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 210 | synchronized (mPublicSync) { |
| 211 | if (isWifi(iface)) { |
| 212 | found = true; |
| 213 | } else if (isUsb(iface)) { |
| 214 | found = true; |
| 215 | usb = true; |
| 216 | } else if (isBluetooth(iface)) { |
| 217 | found = true; |
| 218 | } |
| 219 | if (found == false) return; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 220 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 221 | TetherInterfaceSM sm = mIfaces.get(iface); |
Mike J. Chen | 6143f5f | 2011-06-23 15:17:51 -0700 | [diff] [blame] | 222 | if (up) { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 223 | if (sm == null) { |
Robert Greenwalt | dfadaea | 2010-03-11 15:03:08 -0800 | [diff] [blame] | 224 | sm = new TetherInterfaceSM(iface, mLooper, usb); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 225 | mIfaces.put(iface, sm); |
| 226 | sm.start(); |
| 227 | } |
| 228 | } else { |
Mike Lockwood | 485861c | 2011-07-27 13:52:32 -0400 | [diff] [blame] | 229 | if (isUsb(iface)) { |
| 230 | // ignore usb0 down after enabling RNDIS |
| 231 | // we will handle disconnect in interfaceRemoved instead |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 232 | if (VDBG) Log.d(TAG, "ignore interface down for " + iface); |
Mike Lockwood | 485861c | 2011-07-27 13:52:32 -0400 | [diff] [blame] | 233 | } else if (sm != null) { |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 234 | sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 235 | mIfaces.remove(iface); |
| 236 | } |
| 237 | } |
| 238 | } |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Mike J. Chen | f59c7d0 | 2011-06-23 15:33:15 -0700 | [diff] [blame] | 241 | public void interfaceLinkStateChanged(String iface, boolean up) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 242 | if (VDBG) Log.d(TAG, "interfaceLinkStateChanged " + iface + ", " + up); |
Irfan Sheriff | 23eb297 | 2011-07-22 15:21:10 -0700 | [diff] [blame] | 243 | interfaceStatusChanged(iface, up); |
Mike J. Chen | f59c7d0 | 2011-06-23 15:33:15 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 246 | private boolean isUsb(String iface) { |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 247 | synchronized (mPublicSync) { |
| 248 | for (String regex : mTetherableUsbRegexs) { |
| 249 | if (iface.matches(regex)) return true; |
| 250 | } |
| 251 | return false; |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 252 | } |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | public boolean isWifi(String iface) { |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 256 | synchronized (mPublicSync) { |
| 257 | for (String regex : mTetherableWifiRegexs) { |
| 258 | if (iface.matches(regex)) return true; |
| 259 | } |
| 260 | return false; |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 261 | } |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 264 | public boolean isBluetooth(String iface) { |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 265 | synchronized (mPublicSync) { |
| 266 | for (String regex : mTetherableBluetoothRegexs) { |
| 267 | if (iface.matches(regex)) return true; |
| 268 | } |
| 269 | return false; |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 270 | } |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 271 | } |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 272 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 273 | public void interfaceAdded(String iface) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 274 | if (VDBG) Log.d(TAG, "interfaceAdded " + iface); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 275 | boolean found = false; |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 276 | boolean usb = false; |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 277 | synchronized (mPublicSync) { |
| 278 | if (isWifi(iface)) { |
| 279 | found = true; |
| 280 | } |
| 281 | if (isUsb(iface)) { |
| 282 | found = true; |
| 283 | usb = true; |
| 284 | } |
| 285 | if (isBluetooth(iface)) { |
| 286 | found = true; |
| 287 | } |
| 288 | if (found == false) { |
| 289 | if (VDBG) Log.d(TAG, iface + " is not a tetherable iface, ignoring"); |
| 290 | return; |
| 291 | } |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 292 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 293 | TetherInterfaceSM sm = mIfaces.get(iface); |
| 294 | if (sm != null) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 295 | if (VDBG) Log.d(TAG, "active iface (" + iface + ") reported as added, ignoring"); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 296 | return; |
| 297 | } |
Robert Greenwalt | dfadaea | 2010-03-11 15:03:08 -0800 | [diff] [blame] | 298 | sm = new TetherInterfaceSM(iface, mLooper, usb); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 299 | mIfaces.put(iface, sm); |
| 300 | sm.start(); |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 301 | } |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 304 | public void interfaceRemoved(String iface) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 305 | if (VDBG) Log.d(TAG, "interfaceRemoved " + iface); |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 306 | synchronized (mPublicSync) { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 307 | TetherInterfaceSM sm = mIfaces.get(iface); |
| 308 | if (sm == null) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 309 | if (VDBG) { |
Robert Greenwalt | 924cc94 | 2010-06-28 10:26:19 -0700 | [diff] [blame] | 310 | Log.e(TAG, "attempting to remove unknown iface (" + iface + "), ignoring"); |
| 311 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 312 | return; |
| 313 | } |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 314 | sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 315 | mIfaces.remove(iface); |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 319 | public int tether(String iface) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 320 | if (DBG) Log.d(TAG, "Tethering " + iface); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 321 | TetherInterfaceSM sm = null; |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 322 | synchronized (mPublicSync) { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 323 | sm = mIfaces.get(iface); |
| 324 | } |
| 325 | if (sm == null) { |
| 326 | Log.e(TAG, "Tried to Tether an unknown iface :" + iface + ", ignoring"); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 327 | return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 328 | } |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 329 | if (!sm.isAvailable() && !sm.isErrored()) { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 330 | Log.e(TAG, "Tried to Tether an unavailable iface :" + iface + ", ignoring"); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 331 | return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 332 | } |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 333 | sm.sendMessage(TetherInterfaceSM.CMD_TETHER_REQUESTED); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 334 | return ConnectivityManager.TETHER_ERROR_NO_ERROR; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 337 | public int untether(String iface) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 338 | if (DBG) Log.d(TAG, "Untethering " + iface); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 339 | TetherInterfaceSM sm = null; |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 340 | synchronized (mPublicSync) { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 341 | sm = mIfaces.get(iface); |
| 342 | } |
| 343 | if (sm == null) { |
| 344 | Log.e(TAG, "Tried to Untether an unknown iface :" + iface + ", ignoring"); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 345 | return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 346 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 347 | if (sm.isErrored()) { |
| 348 | Log.e(TAG, "Tried to Untethered an errored iface :" + iface + ", ignoring"); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 349 | return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 350 | } |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 351 | sm.sendMessage(TetherInterfaceSM.CMD_TETHER_UNREQUESTED); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 352 | return ConnectivityManager.TETHER_ERROR_NO_ERROR; |
| 353 | } |
| 354 | |
| 355 | public int getLastTetherError(String iface) { |
| 356 | TetherInterfaceSM sm = null; |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 357 | synchronized (mPublicSync) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 358 | sm = mIfaces.get(iface); |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 359 | if (sm == null) { |
| 360 | Log.e(TAG, "Tried to getLastTetherError on an unknown iface :" + iface + |
| 361 | ", ignoring"); |
| 362 | return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE; |
| 363 | } |
| 364 | return sm.getLastError(); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 365 | } |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 368 | // TODO - move all private methods used only by the state machine into the state machine |
| 369 | // to clarify what needs synchronized protection. |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 370 | private void sendTetherStateChangedBroadcast() { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 371 | try { |
Robert Greenwalt | 3b28e9a | 2011-11-02 14:37:19 -0700 | [diff] [blame] | 372 | if (!mConnService.isTetheringSupported()) return; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 373 | } catch (RemoteException e) { |
| 374 | return; |
| 375 | } |
| 376 | |
| 377 | ArrayList<String> availableList = new ArrayList<String>(); |
| 378 | ArrayList<String> activeList = new ArrayList<String>(); |
| 379 | ArrayList<String> erroredList = new ArrayList<String>(); |
| 380 | |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 381 | boolean wifiTethered = false; |
| 382 | boolean usbTethered = false; |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 383 | boolean bluetoothTethered = false; |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 384 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 385 | synchronized (mPublicSync) { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 386 | Set ifaces = mIfaces.keySet(); |
| 387 | for (Object iface : ifaces) { |
| 388 | TetherInterfaceSM sm = mIfaces.get(iface); |
| 389 | if (sm != null) { |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 390 | if (sm.isErrored()) { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 391 | erroredList.add((String)iface); |
| 392 | } else if (sm.isAvailable()) { |
| 393 | availableList.add((String)iface); |
| 394 | } else if (sm.isTethered()) { |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 395 | if (isUsb((String)iface)) { |
| 396 | usbTethered = true; |
| 397 | } else if (isWifi((String)iface)) { |
| 398 | wifiTethered = true; |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 399 | } else if (isBluetooth((String)iface)) { |
| 400 | bluetoothTethered = true; |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 401 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 402 | activeList.add((String)iface); |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | } |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 407 | Intent broadcast = new Intent(ConnectivityManager.ACTION_TETHER_STATE_CHANGED); |
Robert Greenwalt | 98c79e5 | 2011-07-28 11:51:11 -0700 | [diff] [blame] | 408 | broadcast.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING | |
| 409 | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 410 | broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_AVAILABLE_TETHER, |
| 411 | availableList); |
| 412 | broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER, activeList); |
| 413 | broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ERRORED_TETHER, |
| 414 | erroredList); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 415 | mContext.sendStickyBroadcastAsUser(broadcast, UserHandle.ALL); |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 416 | if (DBG) { |
Robert Greenwalt | 924cc94 | 2010-06-28 10:26:19 -0700 | [diff] [blame] | 417 | Log.d(TAG, "sendTetherStateChangedBroadcast " + availableList.size() + ", " + |
| 418 | activeList.size() + ", " + erroredList.size()); |
| 419 | } |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 420 | |
| 421 | if (usbTethered) { |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 422 | if (wifiTethered || bluetoothTethered) { |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 423 | showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_general); |
| 424 | } else { |
| 425 | showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_usb); |
| 426 | } |
| 427 | } else if (wifiTethered) { |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 428 | if (bluetoothTethered) { |
| 429 | showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_general); |
| 430 | } else { |
| 431 | showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_wifi); |
| 432 | } |
| 433 | } else if (bluetoothTethered) { |
| 434 | showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_bluetooth); |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 435 | } else { |
| 436 | clearTetheredNotification(); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | private void showTetheredNotification(int icon) { |
| 441 | NotificationManager notificationManager = |
| 442 | (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 443 | if (notificationManager == null) { |
| 444 | return; |
| 445 | } |
| 446 | |
Robert Greenwalt | db3fe9e | 2010-03-18 16:28:30 -0700 | [diff] [blame] | 447 | if (mTetheredNotification != null) { |
| 448 | if (mTetheredNotification.icon == icon) { |
| 449 | return; |
| 450 | } |
Robert Greenwalt | 3cab6b0 | 2012-10-04 16:44:26 -0700 | [diff] [blame] | 451 | notificationManager.cancelAsUser(null, mTetheredNotification.icon, |
| 452 | UserHandle.ALL); |
Robert Greenwalt | db3fe9e | 2010-03-18 16:28:30 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 455 | Intent intent = new Intent(); |
| 456 | intent.setClassName("com.android.settings", "com.android.settings.TetherSettings"); |
| 457 | intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); |
| 458 | |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 459 | PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, intent, 0, |
| 460 | null, UserHandle.CURRENT); |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 461 | |
| 462 | Resources r = Resources.getSystem(); |
| 463 | CharSequence title = r.getText(com.android.internal.R.string.tethered_notification_title); |
| 464 | CharSequence message = r.getText(com.android.internal.R.string. |
| 465 | tethered_notification_message); |
| 466 | |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 467 | if (mTetheredNotification == null) { |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 468 | mTetheredNotification = new Notification(); |
| 469 | mTetheredNotification.when = 0; |
| 470 | } |
| 471 | mTetheredNotification.icon = icon; |
| 472 | mTetheredNotification.defaults &= ~Notification.DEFAULT_SOUND; |
| 473 | mTetheredNotification.flags = Notification.FLAG_ONGOING_EVENT; |
| 474 | mTetheredNotification.tickerText = title; |
| 475 | mTetheredNotification.setLatestEventInfo(mContext, title, message, pi); |
| 476 | |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 477 | notificationManager.notifyAsUser(null, mTetheredNotification.icon, |
| 478 | mTetheredNotification, UserHandle.ALL); |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | private void clearTetheredNotification() { |
| 482 | NotificationManager notificationManager = |
| 483 | (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE); |
| 484 | if (notificationManager != null && mTetheredNotification != null) { |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 485 | notificationManager.cancelAsUser(null, mTetheredNotification.icon, |
| 486 | UserHandle.ALL); |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 487 | mTetheredNotification = null; |
| 488 | } |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 489 | } |
| 490 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 491 | private class StateReceiver extends BroadcastReceiver { |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 492 | public void onReceive(Context content, Intent intent) { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 493 | String action = intent.getAction(); |
Mike Lockwood | 770126a | 2010-12-09 22:30:37 -0800 | [diff] [blame] | 494 | if (action.equals(UsbManager.ACTION_USB_STATE)) { |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 495 | synchronized (Tethering.this.mPublicSync) { |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 496 | boolean usbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false); |
| 497 | mRndisEnabled = intent.getBooleanExtra(UsbManager.USB_FUNCTION_RNDIS, false); |
| 498 | // start tethering if we have a request pending |
| 499 | if (usbConnected && mRndisEnabled && mUsbTetherRequested) { |
| 500 | tetherUsb(true); |
| 501 | } |
| 502 | mUsbTetherRequested = false; |
| 503 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 504 | } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { |
Robert Greenwalt | adfb0d0 | 2012-06-14 15:50:32 -0700 | [diff] [blame] | 505 | NetworkInfo networkInfo = (NetworkInfo)intent.getParcelableExtra( |
| 506 | ConnectivityManager.EXTRA_NETWORK_INFO); |
| 507 | if (networkInfo != null && |
| 508 | networkInfo.getDetailedState() != NetworkInfo.DetailedState.FAILED) { |
| 509 | if (VDBG) Log.d(TAG, "Tethering got CONNECTIVITY_ACTION"); |
| 510 | mTetherMasterSM.sendMessage(TetherMasterSM.CMD_UPSTREAM_CHANGED); |
| 511 | } |
Robert Greenwalt | c13368b | 2013-07-18 14:24:42 -0700 | [diff] [blame] | 512 | } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) { |
| 513 | updateConfiguration(); |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 518 | private void tetherUsb(boolean enable) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 519 | if (VDBG) Log.d(TAG, "tetherUsb " + enable); |
Mike Lockwood | 3c2a2f6 | 2011-06-08 15:10:26 -0700 | [diff] [blame] | 520 | |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 521 | String[] ifaces = new String[0]; |
| 522 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 523 | ifaces = mNMService.listInterfaces(); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 524 | } catch (Exception e) { |
Mike Lockwood | 3c2a2f6 | 2011-06-08 15:10:26 -0700 | [diff] [blame] | 525 | Log.e(TAG, "Error listing Interfaces", e); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 526 | return; |
| 527 | } |
| 528 | for (String iface : ifaces) { |
Robert Greenwalt | a599fe7c | 2010-03-08 18:30:14 -0800 | [diff] [blame] | 529 | if (isUsb(iface)) { |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 530 | int result = (enable ? tether(iface) : untether(iface)); |
| 531 | if (result == ConnectivityManager.TETHER_ERROR_NO_ERROR) { |
| 532 | return; |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | } |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 536 | Log.e(TAG, "unable start or stop USB tethering"); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | // configured when we start tethering and unconfig'd on error or conclusion |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 540 | private boolean configureUsbIface(boolean enabled) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 541 | if (VDBG) Log.d(TAG, "configureUsbIface(" + enabled + ")"); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 542 | |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 543 | // toggle the USB interfaces |
| 544 | String[] ifaces = new String[0]; |
Mike Lockwood | 3c2a2f6 | 2011-06-08 15:10:26 -0700 | [diff] [blame] | 545 | try { |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 546 | ifaces = mNMService.listInterfaces(); |
| 547 | } catch (Exception e) { |
| 548 | Log.e(TAG, "Error listing Interfaces", e); |
| 549 | return false; |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 550 | } |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 551 | for (String iface : ifaces) { |
| 552 | if (isUsb(iface)) { |
| 553 | InterfaceConfiguration ifcg = null; |
| 554 | try { |
| 555 | ifcg = mNMService.getInterfaceConfig(iface); |
| 556 | if (ifcg != null) { |
| 557 | InetAddress addr = NetworkUtils.numericToInetAddress(USB_NEAR_IFACE_ADDR); |
Jeff Sharkey | ddba106 | 2011-11-29 18:37:04 -0800 | [diff] [blame] | 558 | ifcg.setLinkAddress(new LinkAddress(addr, USB_PREFIX_LENGTH)); |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 559 | if (enabled) { |
Jeff Sharkey | ddba106 | 2011-11-29 18:37:04 -0800 | [diff] [blame] | 560 | ifcg.setInterfaceUp(); |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 561 | } else { |
Jeff Sharkey | ddba106 | 2011-11-29 18:37:04 -0800 | [diff] [blame] | 562 | ifcg.setInterfaceDown(); |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 563 | } |
Jeff Sharkey | ddba106 | 2011-11-29 18:37:04 -0800 | [diff] [blame] | 564 | ifcg.clearFlag("running"); |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 565 | mNMService.setInterfaceConfig(iface, ifcg); |
| 566 | } |
| 567 | } catch (Exception e) { |
| 568 | Log.e(TAG, "Error configuring interface " + iface, e); |
| 569 | return false; |
| 570 | } |
| 571 | } |
| 572 | } |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 573 | |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 574 | return true; |
| 575 | } |
| 576 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 577 | // TODO - return copies so people can't tamper |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 578 | public String[] getTetherableUsbRegexs() { |
| 579 | return mTetherableUsbRegexs; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 580 | } |
| 581 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 582 | public String[] getTetherableWifiRegexs() { |
| 583 | return mTetherableWifiRegexs; |
| 584 | } |
| 585 | |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 586 | public String[] getTetherableBluetoothRegexs() { |
| 587 | return mTetherableBluetoothRegexs; |
| 588 | } |
| 589 | |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 590 | public int setUsbTethering(boolean enable) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 591 | if (VDBG) Log.d(TAG, "setUsbTethering(" + enable + ")"); |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 592 | UsbManager usbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE); |
| 593 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 594 | synchronized (mPublicSync) { |
Mike Lockwood | 6c2260b | 2011-07-19 13:04:47 -0700 | [diff] [blame] | 595 | if (enable) { |
| 596 | if (mRndisEnabled) { |
| 597 | tetherUsb(true); |
| 598 | } else { |
| 599 | mUsbTetherRequested = true; |
| 600 | usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, false); |
| 601 | } |
| 602 | } else { |
| 603 | tetherUsb(false); |
| 604 | if (mRndisEnabled) { |
| 605 | usbManager.setCurrentFunction(null, false); |
| 606 | } |
| 607 | mUsbTetherRequested = false; |
| 608 | } |
| 609 | } |
| 610 | return ConnectivityManager.TETHER_ERROR_NO_ERROR; |
| 611 | } |
| 612 | |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 613 | public int[] getUpstreamIfaceTypes() { |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 614 | int values[]; |
| 615 | synchronized (mPublicSync) { |
Robert Greenwalt | c13368b | 2013-07-18 14:24:42 -0700 | [diff] [blame] | 616 | updateConfiguration(); // TODO - remove? |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 617 | values = new int[mUpstreamIfaceTypes.size()]; |
| 618 | Iterator<Integer> iterator = mUpstreamIfaceTypes.iterator(); |
| 619 | for (int i=0; i < mUpstreamIfaceTypes.size(); i++) { |
| 620 | values[i] = iterator.next(); |
| 621 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 622 | } |
| 623 | return values; |
Robert Greenwalt | c9d5fb7 | 2010-02-25 12:29:30 -0800 | [diff] [blame] | 624 | } |
| 625 | |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 626 | public void checkDunRequired() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 627 | int secureSetting = Settings.Global.getInt(mContext.getContentResolver(), |
| 628 | Settings.Global.TETHER_DUN_REQUIRED, 2); |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 629 | synchronized (mPublicSync) { |
| 630 | // 2 = not set, 0 = DUN not required, 1 = DUN required |
| 631 | if (secureSetting != 2) { |
| 632 | int requiredApn = (secureSetting == 1 ? |
| 633 | ConnectivityManager.TYPE_MOBILE_DUN : |
| 634 | ConnectivityManager.TYPE_MOBILE_HIPRI); |
| 635 | if (requiredApn == ConnectivityManager.TYPE_MOBILE_DUN) { |
| 636 | while (mUpstreamIfaceTypes.contains(MOBILE_TYPE)) { |
| 637 | mUpstreamIfaceTypes.remove(MOBILE_TYPE); |
| 638 | } |
| 639 | while (mUpstreamIfaceTypes.contains(HIPRI_TYPE)) { |
| 640 | mUpstreamIfaceTypes.remove(HIPRI_TYPE); |
| 641 | } |
| 642 | if (mUpstreamIfaceTypes.contains(DUN_TYPE) == false) { |
| 643 | mUpstreamIfaceTypes.add(DUN_TYPE); |
| 644 | } |
| 645 | } else { |
| 646 | while (mUpstreamIfaceTypes.contains(DUN_TYPE)) { |
| 647 | mUpstreamIfaceTypes.remove(DUN_TYPE); |
| 648 | } |
| 649 | if (mUpstreamIfaceTypes.contains(MOBILE_TYPE) == false) { |
| 650 | mUpstreamIfaceTypes.add(MOBILE_TYPE); |
| 651 | } |
| 652 | if (mUpstreamIfaceTypes.contains(HIPRI_TYPE) == false) { |
| 653 | mUpstreamIfaceTypes.add(HIPRI_TYPE); |
| 654 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 655 | } |
| 656 | } |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 657 | if (mUpstreamIfaceTypes.contains(DUN_TYPE)) { |
| 658 | mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_DUN; |
| 659 | } else { |
| 660 | mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_HIPRI; |
| 661 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 662 | } |
Robert Greenwalt | c9d5fb7 | 2010-02-25 12:29:30 -0800 | [diff] [blame] | 663 | } |
| 664 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 665 | // TODO review API - maybe return ArrayList<String> here and below? |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 666 | public String[] getTetheredIfaces() { |
| 667 | ArrayList<String> list = new ArrayList<String>(); |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 668 | synchronized (mPublicSync) { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 669 | Set keys = mIfaces.keySet(); |
| 670 | for (Object key : keys) { |
| 671 | TetherInterfaceSM sm = mIfaces.get(key); |
| 672 | if (sm.isTethered()) { |
| 673 | list.add((String)key); |
| 674 | } |
| 675 | } |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 676 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 677 | String[] retVal = new String[list.size()]; |
| 678 | for (int i=0; i < list.size(); i++) { |
| 679 | retVal[i] = list.get(i); |
| 680 | } |
| 681 | return retVal; |
| 682 | } |
| 683 | |
| 684 | public String[] getTetherableIfaces() { |
| 685 | ArrayList<String> list = new ArrayList<String>(); |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 686 | synchronized (mPublicSync) { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 687 | Set keys = mIfaces.keySet(); |
| 688 | for (Object key : keys) { |
| 689 | TetherInterfaceSM sm = mIfaces.get(key); |
| 690 | if (sm.isAvailable()) { |
| 691 | list.add((String)key); |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | String[] retVal = new String[list.size()]; |
| 696 | for (int i=0; i < list.size(); i++) { |
| 697 | retVal[i] = list.get(i); |
| 698 | } |
| 699 | return retVal; |
| 700 | } |
| 701 | |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 702 | public String[] getErroredIfaces() { |
| 703 | ArrayList<String> list = new ArrayList<String>(); |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 704 | synchronized (mPublicSync) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 705 | Set keys = mIfaces.keySet(); |
| 706 | for (Object key : keys) { |
| 707 | TetherInterfaceSM sm = mIfaces.get(key); |
| 708 | if (sm.isErrored()) { |
| 709 | list.add((String)key); |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | String[] retVal = new String[list.size()]; |
| 714 | for (int i= 0; i< list.size(); i++) { |
| 715 | retVal[i] = list.get(i); |
| 716 | } |
| 717 | return retVal; |
| 718 | } |
| 719 | |
Kazuhiro Ondo | 1ccb10e | 2011-06-22 21:10:34 -0500 | [diff] [blame] | 720 | //TODO: Temporary handling upstream change triggered without |
| 721 | // CONNECTIVITY_ACTION. Only to accomodate interface |
| 722 | // switch during HO. |
| 723 | // @see bug/4455071 |
| 724 | public void handleTetherIfaceChange() { |
| 725 | mTetherMasterSM.sendMessage(TetherMasterSM.CMD_UPSTREAM_CHANGED); |
| 726 | } |
| 727 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 728 | class TetherInterfaceSM extends StateMachine { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 729 | // notification from the master SM that it's not in tether mode |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 730 | static final int CMD_TETHER_MODE_DEAD = 1; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 731 | // request from the user that it wants to tether |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 732 | static final int CMD_TETHER_REQUESTED = 2; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 733 | // request from the user that it wants to untether |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 734 | static final int CMD_TETHER_UNREQUESTED = 3; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 735 | // notification that this interface is down |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 736 | static final int CMD_INTERFACE_DOWN = 4; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 737 | // notification that this interface is up |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 738 | static final int CMD_INTERFACE_UP = 5; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 739 | // notification from the master SM that it had an error turning on cellular dun |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 740 | static final int CMD_CELL_DUN_ERROR = 6; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 741 | // notification from the master SM that it had trouble enabling IP Forwarding |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 742 | static final int CMD_IP_FORWARDING_ENABLE_ERROR = 7; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 743 | // notification from the master SM that it had trouble disabling IP Forwarding |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 744 | static final int CMD_IP_FORWARDING_DISABLE_ERROR = 8; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 745 | // notification from the master SM that it had trouble staring tethering |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 746 | static final int CMD_START_TETHERING_ERROR = 9; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 747 | // notification from the master SM that it had trouble stopping tethering |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 748 | static final int CMD_STOP_TETHERING_ERROR = 10; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 749 | // notification from the master SM that it had trouble setting the DNS forwarders |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 750 | static final int CMD_SET_DNS_FORWARDERS_ERROR = 11; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 751 | // the upstream connection has changed |
Wink Saville | 951749b | 2010-03-19 09:03:13 -0700 | [diff] [blame] | 752 | static final int CMD_TETHER_CONNECTION_CHANGED = 12; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 753 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 754 | private State mDefaultState; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 755 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 756 | private State mInitialState; |
| 757 | private State mStartingState; |
| 758 | private State mTetheredState; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 759 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 760 | private State mUnavailableState; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 761 | |
| 762 | private boolean mAvailable; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 763 | private boolean mTethered; |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 764 | int mLastError; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 765 | |
| 766 | String mIfaceName; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 767 | String mMyUpstreamIfaceName; // may change over time |
| 768 | |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 769 | boolean mUsb; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 770 | |
Robert Greenwalt | dfadaea | 2010-03-11 15:03:08 -0800 | [diff] [blame] | 771 | TetherInterfaceSM(String name, Looper looper, boolean usb) { |
| 772 | super(name, looper); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 773 | mIfaceName = name; |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 774 | mUsb = usb; |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 775 | setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 776 | |
| 777 | mInitialState = new InitialState(); |
| 778 | addState(mInitialState); |
| 779 | mStartingState = new StartingState(); |
| 780 | addState(mStartingState); |
| 781 | mTetheredState = new TetheredState(); |
| 782 | addState(mTetheredState); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 783 | mUnavailableState = new UnavailableState(); |
| 784 | addState(mUnavailableState); |
| 785 | |
| 786 | setInitialState(mInitialState); |
| 787 | } |
| 788 | |
| 789 | public String toString() { |
| 790 | String res = new String(); |
| 791 | res += mIfaceName + " - "; |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 792 | IState current = getCurrentState(); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 793 | if (current == mInitialState) res += "InitialState"; |
| 794 | if (current == mStartingState) res += "StartingState"; |
| 795 | if (current == mTetheredState) res += "TetheredState"; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 796 | if (current == mUnavailableState) res += "UnavailableState"; |
| 797 | if (mAvailable) res += " - Available"; |
| 798 | if (mTethered) res += " - Tethered"; |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 799 | res += " - lastError =" + mLastError; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 800 | return res; |
| 801 | } |
| 802 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 803 | public int getLastError() { |
| 804 | synchronized (Tethering.this.mPublicSync) { |
| 805 | return mLastError; |
| 806 | } |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 809 | private void setLastError(int error) { |
| 810 | synchronized (Tethering.this.mPublicSync) { |
| 811 | mLastError = error; |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 812 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 813 | if (isErrored()) { |
| 814 | if (mUsb) { |
| 815 | // note everything's been unwound by this point so nothing to do on |
| 816 | // further error.. |
| 817 | Tethering.this.configureUsbIface(false); |
| 818 | } |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 819 | } |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 823 | public boolean isAvailable() { |
| 824 | synchronized (Tethering.this.mPublicSync) { |
| 825 | return mAvailable; |
| 826 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 827 | } |
| 828 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 829 | private void setAvailable(boolean available) { |
| 830 | synchronized (Tethering.this.mPublicSync) { |
| 831 | mAvailable = available; |
| 832 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 833 | } |
| 834 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 835 | public boolean isTethered() { |
| 836 | synchronized (Tethering.this.mPublicSync) { |
| 837 | return mTethered; |
| 838 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 839 | } |
| 840 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 841 | private void setTethered(boolean tethered) { |
| 842 | synchronized (Tethering.this.mPublicSync) { |
| 843 | mTethered = tethered; |
| 844 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 847 | public boolean isErrored() { |
| 848 | synchronized (Tethering.this.mPublicSync) { |
| 849 | return (mLastError != ConnectivityManager.TETHER_ERROR_NO_ERROR); |
| 850 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 851 | } |
| 852 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 853 | class InitialState extends State { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 854 | @Override |
| 855 | public void enter() { |
| 856 | setAvailable(true); |
| 857 | setTethered(false); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 858 | sendTetherStateChangedBroadcast(); |
| 859 | } |
| 860 | |
| 861 | @Override |
| 862 | public boolean processMessage(Message message) { |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 863 | if (DBG) Log.d(TAG, "InitialState.processMessage what=" + message.what); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 864 | boolean retValue = true; |
| 865 | switch (message.what) { |
| 866 | case CMD_TETHER_REQUESTED: |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 867 | setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 868 | mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_REQUESTED, |
| 869 | TetherInterfaceSM.this); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 870 | transitionTo(mStartingState); |
| 871 | break; |
| 872 | case CMD_INTERFACE_DOWN: |
| 873 | transitionTo(mUnavailableState); |
| 874 | break; |
| 875 | default: |
| 876 | retValue = false; |
| 877 | break; |
| 878 | } |
| 879 | return retValue; |
| 880 | } |
| 881 | } |
| 882 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 883 | class StartingState extends State { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 884 | @Override |
| 885 | public void enter() { |
| 886 | setAvailable(false); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 887 | if (mUsb) { |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 888 | if (!Tethering.this.configureUsbIface(true)) { |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 889 | mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED, |
| 890 | TetherInterfaceSM.this); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 891 | setLastError(ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR); |
| 892 | |
Wink Saville | 951749b | 2010-03-19 09:03:13 -0700 | [diff] [blame] | 893 | transitionTo(mInitialState); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 894 | return; |
| 895 | } |
| 896 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 897 | sendTetherStateChangedBroadcast(); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 898 | |
Wink Saville | 951749b | 2010-03-19 09:03:13 -0700 | [diff] [blame] | 899 | // Skipping StartingState |
| 900 | transitionTo(mTetheredState); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 901 | } |
| 902 | @Override |
| 903 | public boolean processMessage(Message message) { |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 904 | if (DBG) Log.d(TAG, "StartingState.processMessage what=" + message.what); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 905 | boolean retValue = true; |
| 906 | switch (message.what) { |
| 907 | // maybe a parent class? |
| 908 | case CMD_TETHER_UNREQUESTED: |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 909 | mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED, |
| 910 | TetherInterfaceSM.this); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 911 | if (mUsb) { |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 912 | if (!Tethering.this.configureUsbIface(false)) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 913 | setLastErrorAndTransitionToInitialState( |
| 914 | ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 915 | break; |
| 916 | } |
| 917 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 918 | transitionTo(mInitialState); |
| 919 | break; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 920 | case CMD_CELL_DUN_ERROR: |
| 921 | case CMD_IP_FORWARDING_ENABLE_ERROR: |
| 922 | case CMD_IP_FORWARDING_DISABLE_ERROR: |
| 923 | case CMD_START_TETHERING_ERROR: |
| 924 | case CMD_STOP_TETHERING_ERROR: |
| 925 | case CMD_SET_DNS_FORWARDERS_ERROR: |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 926 | setLastErrorAndTransitionToInitialState( |
| 927 | ConnectivityManager.TETHER_ERROR_MASTER_ERROR); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 928 | break; |
| 929 | case CMD_INTERFACE_DOWN: |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 930 | mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED, |
| 931 | TetherInterfaceSM.this); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 932 | transitionTo(mUnavailableState); |
| 933 | break; |
| 934 | default: |
| 935 | retValue = false; |
| 936 | } |
| 937 | return retValue; |
| 938 | } |
| 939 | } |
| 940 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 941 | class TetheredState extends State { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 942 | @Override |
| 943 | public void enter() { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 944 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 945 | mNMService.tetherInterface(mIfaceName); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 946 | } catch (Exception e) { |
Robert Greenwalt | 3b28e9a | 2011-11-02 14:37:19 -0700 | [diff] [blame] | 947 | Log.e(TAG, "Error Tethering: " + e.toString()); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 948 | setLastError(ConnectivityManager.TETHER_ERROR_TETHER_IFACE_ERROR); |
| 949 | |
Wink Saville | 951749b | 2010-03-19 09:03:13 -0700 | [diff] [blame] | 950 | transitionTo(mInitialState); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 951 | return; |
| 952 | } |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 953 | if (DBG) Log.d(TAG, "Tethered " + mIfaceName); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 954 | setAvailable(false); |
| 955 | setTethered(true); |
| 956 | sendTetherStateChangedBroadcast(); |
| 957 | } |
Robert Greenwalt | 731026c | 2011-11-01 21:59:44 -0700 | [diff] [blame] | 958 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 959 | private void cleanupUpstream() { |
Robert Greenwalt | 731026c | 2011-11-01 21:59:44 -0700 | [diff] [blame] | 960 | if (mMyUpstreamIfaceName != null) { |
| 961 | // note that we don't care about errors here. |
| 962 | // sometimes interfaces are gone before we get |
| 963 | // to remove their rules, which generates errors. |
| 964 | // just do the best we can. |
| 965 | try { |
| 966 | // about to tear down NAT; gather remaining statistics |
| 967 | mStatsService.forceUpdate(); |
| 968 | } catch (Exception e) { |
| 969 | if (VDBG) Log.e(TAG, "Exception in forceUpdate: " + e.toString()); |
| 970 | } |
| 971 | try { |
| 972 | mNMService.disableNat(mIfaceName, mMyUpstreamIfaceName); |
| 973 | } catch (Exception e) { |
| 974 | if (VDBG) Log.e(TAG, "Exception in disableNat: " + e.toString()); |
| 975 | } |
| 976 | mMyUpstreamIfaceName = null; |
| 977 | } |
| 978 | return; |
| 979 | } |
| 980 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 981 | @Override |
| 982 | public boolean processMessage(Message message) { |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 983 | if (DBG) Log.d(TAG, "TetheredState.processMessage what=" + message.what); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 984 | boolean retValue = true; |
| 985 | boolean error = false; |
| 986 | switch (message.what) { |
| 987 | case CMD_TETHER_UNREQUESTED: |
| 988 | case CMD_INTERFACE_DOWN: |
Robert Greenwalt | 731026c | 2011-11-01 21:59:44 -0700 | [diff] [blame] | 989 | cleanupUpstream(); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 990 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 991 | mNMService.untetherInterface(mIfaceName); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 992 | } catch (Exception e) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 993 | setLastErrorAndTransitionToInitialState( |
| 994 | ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 995 | break; |
| 996 | } |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 997 | mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED, |
| 998 | TetherInterfaceSM.this); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 999 | if (message.what == CMD_TETHER_UNREQUESTED) { |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 1000 | if (mUsb) { |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1001 | if (!Tethering.this.configureUsbIface(false)) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1002 | setLastError( |
| 1003 | ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 1004 | } |
| 1005 | } |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1006 | transitionTo(mInitialState); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1007 | } else if (message.what == CMD_INTERFACE_DOWN) { |
| 1008 | transitionTo(mUnavailableState); |
| 1009 | } |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 1010 | if (DBG) Log.d(TAG, "Untethered " + mIfaceName); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1011 | break; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1012 | case CMD_TETHER_CONNECTION_CHANGED: |
| 1013 | String newUpstreamIfaceName = (String)(message.obj); |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1014 | if ((mMyUpstreamIfaceName == null && newUpstreamIfaceName == null) || |
| 1015 | (mMyUpstreamIfaceName != null && |
| 1016 | mMyUpstreamIfaceName.equals(newUpstreamIfaceName))) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 1017 | if (VDBG) Log.d(TAG, "Connection changed noop - dropping"); |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1018 | break; |
| 1019 | } |
Robert Greenwalt | 731026c | 2011-11-01 21:59:44 -0700 | [diff] [blame] | 1020 | cleanupUpstream(); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1021 | if (newUpstreamIfaceName != null) { |
| 1022 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1023 | mNMService.enableNat(mIfaceName, newUpstreamIfaceName); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1024 | } catch (Exception e) { |
Robert Greenwalt | 3b28e9a | 2011-11-02 14:37:19 -0700 | [diff] [blame] | 1025 | Log.e(TAG, "Exception enabling Nat: " + e.toString()); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1026 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1027 | mNMService.untetherInterface(mIfaceName); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1028 | } catch (Exception ee) {} |
| 1029 | |
| 1030 | setLastError(ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR); |
| 1031 | transitionTo(mInitialState); |
| 1032 | return true; |
| 1033 | } |
| 1034 | } |
| 1035 | mMyUpstreamIfaceName = newUpstreamIfaceName; |
| 1036 | break; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1037 | case CMD_CELL_DUN_ERROR: |
| 1038 | case CMD_IP_FORWARDING_ENABLE_ERROR: |
| 1039 | case CMD_IP_FORWARDING_DISABLE_ERROR: |
| 1040 | case CMD_START_TETHERING_ERROR: |
| 1041 | case CMD_STOP_TETHERING_ERROR: |
| 1042 | case CMD_SET_DNS_FORWARDERS_ERROR: |
| 1043 | error = true; |
| 1044 | // fall through |
| 1045 | case CMD_TETHER_MODE_DEAD: |
Robert Greenwalt | 731026c | 2011-11-01 21:59:44 -0700 | [diff] [blame] | 1046 | cleanupUpstream(); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1047 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1048 | mNMService.untetherInterface(mIfaceName); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1049 | } catch (Exception e) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1050 | setLastErrorAndTransitionToInitialState( |
| 1051 | ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1052 | break; |
| 1053 | } |
| 1054 | if (error) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1055 | setLastErrorAndTransitionToInitialState( |
| 1056 | ConnectivityManager.TETHER_ERROR_MASTER_ERROR); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1057 | break; |
| 1058 | } |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 1059 | if (DBG) Log.d(TAG, "Tether lost upstream connection " + mIfaceName); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1060 | sendTetherStateChangedBroadcast(); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 1061 | if (mUsb) { |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1062 | if (!Tethering.this.configureUsbIface(false)) { |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1063 | setLastError(ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR); |
Robert Greenwalt | 65ae29b | 2010-02-18 11:25:54 -0800 | [diff] [blame] | 1064 | } |
| 1065 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1066 | transitionTo(mInitialState); |
| 1067 | break; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1068 | default: |
| 1069 | retValue = false; |
| 1070 | break; |
| 1071 | } |
| 1072 | return retValue; |
| 1073 | } |
| 1074 | } |
| 1075 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 1076 | class UnavailableState extends State { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1077 | @Override |
| 1078 | public void enter() { |
| 1079 | setAvailable(false); |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1080 | setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1081 | setTethered(false); |
| 1082 | sendTetherStateChangedBroadcast(); |
| 1083 | } |
| 1084 | @Override |
| 1085 | public boolean processMessage(Message message) { |
| 1086 | boolean retValue = true; |
| 1087 | switch (message.what) { |
| 1088 | case CMD_INTERFACE_UP: |
| 1089 | transitionTo(mInitialState); |
| 1090 | break; |
| 1091 | default: |
| 1092 | retValue = false; |
| 1093 | break; |
| 1094 | } |
| 1095 | return retValue; |
| 1096 | } |
| 1097 | } |
| 1098 | |
Robert Greenwalt | 5a73506 | 2010-03-02 17:25:02 -0800 | [diff] [blame] | 1099 | void setLastErrorAndTransitionToInitialState(int error) { |
| 1100 | setLastError(error); |
| 1101 | transitionTo(mInitialState); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1104 | } |
| 1105 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 1106 | class TetherMasterSM extends StateMachine { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1107 | // an interface SM has requested Tethering |
| 1108 | static final int CMD_TETHER_MODE_REQUESTED = 1; |
| 1109 | // an interface SM has unrequested Tethering |
| 1110 | static final int CMD_TETHER_MODE_UNREQUESTED = 2; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1111 | // upstream connection change - do the right thing |
| 1112 | static final int CMD_UPSTREAM_CHANGED = 3; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1113 | // we received notice that the cellular DUN connection is up |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1114 | static final int CMD_CELL_CONNECTION_RENEW = 4; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1115 | // we don't have a valid upstream conn, check again after a delay |
Wink Saville | 951749b | 2010-03-19 09:03:13 -0700 | [diff] [blame] | 1116 | static final int CMD_RETRY_UPSTREAM = 5; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1117 | |
| 1118 | // This indicates what a timeout event relates to. A state that |
| 1119 | // sends itself a delayed timeout event and handles incoming timeout events |
| 1120 | // should inc this when it is entered and whenever it sends a new timeout event. |
| 1121 | // We do not flush the old ones. |
| 1122 | private int mSequenceNumber; |
| 1123 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 1124 | private State mInitialState; |
| 1125 | private State mTetherModeAliveState; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1126 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 1127 | private State mSetIpForwardingEnabledErrorState; |
| 1128 | private State mSetIpForwardingDisabledErrorState; |
| 1129 | private State mStartTetheringErrorState; |
| 1130 | private State mStopTetheringErrorState; |
| 1131 | private State mSetDnsForwardersErrorState; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1132 | |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1133 | private ArrayList<TetherInterfaceSM> mNotifyList; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1134 | |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1135 | private int mCurrentConnectionSequence; |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1136 | private int mMobileApnReserved = ConnectivityManager.TYPE_NONE; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1137 | |
Robert Greenwalt | b37f0c6 | 2010-03-25 14:50:34 -0700 | [diff] [blame] | 1138 | private String mUpstreamIfaceName = null; |
| 1139 | |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1140 | private static final int UPSTREAM_SETTLE_TIME_MS = 10000; |
| 1141 | private static final int CELL_CONNECTION_RENEW_MS = 40000; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1142 | |
Robert Greenwalt | dfadaea | 2010-03-11 15:03:08 -0800 | [diff] [blame] | 1143 | TetherMasterSM(String name, Looper looper) { |
| 1144 | super(name, looper); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1145 | |
| 1146 | //Add states |
| 1147 | mInitialState = new InitialState(); |
| 1148 | addState(mInitialState); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1149 | mTetherModeAliveState = new TetherModeAliveState(); |
| 1150 | addState(mTetherModeAliveState); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1151 | |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1152 | mSetIpForwardingEnabledErrorState = new SetIpForwardingEnabledErrorState(); |
| 1153 | addState(mSetIpForwardingEnabledErrorState); |
| 1154 | mSetIpForwardingDisabledErrorState = new SetIpForwardingDisabledErrorState(); |
| 1155 | addState(mSetIpForwardingDisabledErrorState); |
| 1156 | mStartTetheringErrorState = new StartTetheringErrorState(); |
| 1157 | addState(mStartTetheringErrorState); |
| 1158 | mStopTetheringErrorState = new StopTetheringErrorState(); |
| 1159 | addState(mStopTetheringErrorState); |
| 1160 | mSetDnsForwardersErrorState = new SetDnsForwardersErrorState(); |
| 1161 | addState(mSetDnsForwardersErrorState); |
| 1162 | |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1163 | mNotifyList = new ArrayList<TetherInterfaceSM>(); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1164 | setInitialState(mInitialState); |
| 1165 | } |
| 1166 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 1167 | class TetherMasterUtilState extends State { |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1168 | protected final static boolean TRY_TO_SETUP_MOBILE_CONNECTION = true; |
| 1169 | protected final static boolean WAIT_FOR_NETWORK_TO_SETTLE = false; |
| 1170 | |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1171 | @Override |
| 1172 | public boolean processMessage(Message m) { |
| 1173 | return false; |
| 1174 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1175 | protected String enableString(int apnType) { |
| 1176 | switch (apnType) { |
| 1177 | case ConnectivityManager.TYPE_MOBILE_DUN: |
| 1178 | return Phone.FEATURE_ENABLE_DUN_ALWAYS; |
| 1179 | case ConnectivityManager.TYPE_MOBILE: |
| 1180 | case ConnectivityManager.TYPE_MOBILE_HIPRI: |
| 1181 | return Phone.FEATURE_ENABLE_HIPRI; |
| 1182 | } |
| 1183 | return null; |
| 1184 | } |
| 1185 | protected boolean turnOnUpstreamMobileConnection(int apnType) { |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1186 | boolean retValue = true; |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1187 | if (apnType == ConnectivityManager.TYPE_NONE) return false; |
| 1188 | if (apnType != mMobileApnReserved) turnOffUpstreamMobileConnection(); |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1189 | int result = PhoneConstants.APN_REQUEST_FAILED; |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1190 | String enableString = enableString(apnType); |
| 1191 | if (enableString == null) return false; |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1192 | try { |
Robert Greenwalt | 3b28e9a | 2011-11-02 14:37:19 -0700 | [diff] [blame] | 1193 | result = mConnService.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1194 | enableString, new Binder()); |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1195 | } catch (Exception e) { |
| 1196 | } |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1197 | switch (result) { |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1198 | case PhoneConstants.APN_ALREADY_ACTIVE: |
| 1199 | case PhoneConstants.APN_REQUEST_STARTED: |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1200 | mMobileApnReserved = apnType; |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1201 | Message m = obtainMessage(CMD_CELL_CONNECTION_RENEW); |
| 1202 | m.arg1 = ++mCurrentConnectionSequence; |
| 1203 | sendMessageDelayed(m, CELL_CONNECTION_RENEW_MS); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1204 | break; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 1205 | case PhoneConstants.APN_REQUEST_FAILED: |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1206 | default: |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1207 | retValue = false; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1208 | break; |
| 1209 | } |
| 1210 | |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1211 | return retValue; |
| 1212 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1213 | protected boolean turnOffUpstreamMobileConnection() { |
Robert Greenwalt | c9dac11 | 2012-02-28 12:25:34 -0800 | [diff] [blame] | 1214 | // ignore pending renewal requests |
| 1215 | ++mCurrentConnectionSequence; |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1216 | if (mMobileApnReserved != ConnectivityManager.TYPE_NONE) { |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1217 | try { |
Robert Greenwalt | 3b28e9a | 2011-11-02 14:37:19 -0700 | [diff] [blame] | 1218 | mConnService.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1219 | enableString(mMobileApnReserved)); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1220 | } catch (Exception e) { |
| 1221 | return false; |
| 1222 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1223 | mMobileApnReserved = ConnectivityManager.TYPE_NONE; |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1224 | } |
| 1225 | return true; |
| 1226 | } |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1227 | protected boolean turnOnMasterTetherSettings() { |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1228 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1229 | mNMService.setIpForwardingEnabled(true); |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1230 | } catch (Exception e) { |
Wink Saville | 951749b | 2010-03-19 09:03:13 -0700 | [diff] [blame] | 1231 | transitionTo(mSetIpForwardingEnabledErrorState); |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1232 | return false; |
| 1233 | } |
| 1234 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1235 | mNMService.startTethering(mDhcpRange); |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1236 | } catch (Exception e) { |
Robert Greenwalt | 547e4e7 | 2011-01-14 17:24:03 -0800 | [diff] [blame] | 1237 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1238 | mNMService.stopTethering(); |
| 1239 | mNMService.startTethering(mDhcpRange); |
Robert Greenwalt | 547e4e7 | 2011-01-14 17:24:03 -0800 | [diff] [blame] | 1240 | } catch (Exception ee) { |
| 1241 | transitionTo(mStartTetheringErrorState); |
| 1242 | return false; |
| 1243 | } |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1244 | } |
| 1245 | try { |
Robert Greenwalt | bb4fd0b | 2011-12-09 15:36:50 -0800 | [diff] [blame] | 1246 | mNMService.setDnsForwarders(mDefaultDnsServers); |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1247 | } catch (Exception e) { |
Wink Saville | 951749b | 2010-03-19 09:03:13 -0700 | [diff] [blame] | 1248 | transitionTo(mSetDnsForwardersErrorState); |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1249 | return false; |
| 1250 | } |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1251 | return true; |
| 1252 | } |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1253 | protected boolean turnOffMasterTetherSettings() { |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1254 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1255 | mNMService.stopTethering(); |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1256 | } catch (Exception e) { |
| 1257 | transitionTo(mStopTetheringErrorState); |
| 1258 | return false; |
| 1259 | } |
| 1260 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1261 | mNMService.setIpForwardingEnabled(false); |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1262 | } catch (Exception e) { |
| 1263 | transitionTo(mSetIpForwardingDisabledErrorState); |
| 1264 | return false; |
| 1265 | } |
| 1266 | transitionTo(mInitialState); |
| 1267 | return true; |
| 1268 | } |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1269 | |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1270 | protected void chooseUpstreamType(boolean tryCell) { |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1271 | int upType = ConnectivityManager.TYPE_NONE; |
| 1272 | String iface = null; |
| 1273 | |
Robert Greenwalt | c13368b | 2013-07-18 14:24:42 -0700 | [diff] [blame] | 1274 | updateConfiguration(); // TODO - remove? |
Robert Greenwalt | 49348e7 | 2011-10-21 16:54:26 -0700 | [diff] [blame] | 1275 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 1276 | synchronized (mPublicSync) { |
| 1277 | if (VDBG) { |
| 1278 | Log.d(TAG, "chooseUpstreamType has upstream iface types:"); |
| 1279 | for (Integer netType : mUpstreamIfaceTypes) { |
| 1280 | Log.d(TAG, " " + netType); |
| 1281 | } |
Robert Greenwalt | 49348e7 | 2011-10-21 16:54:26 -0700 | [diff] [blame] | 1282 | } |
Robert Greenwalt | 49348e7 | 2011-10-21 16:54:26 -0700 | [diff] [blame] | 1283 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 1284 | for (Integer netType : mUpstreamIfaceTypes) { |
| 1285 | NetworkInfo info = null; |
| 1286 | try { |
| 1287 | info = mConnService.getNetworkInfo(netType.intValue()); |
| 1288 | } catch (RemoteException e) { } |
| 1289 | if ((info != null) && info.isConnected()) { |
| 1290 | upType = netType.intValue(); |
| 1291 | break; |
| 1292 | } |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1293 | } |
| 1294 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1295 | |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 1296 | if (DBG) { |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1297 | Log.d(TAG, "chooseUpstreamType(" + tryCell + "), preferredApn =" |
| 1298 | + mPreferredUpstreamMobileApn + ", got type=" + upType); |
| 1299 | } |
| 1300 | |
| 1301 | // if we're on DUN, put our own grab on it |
| 1302 | if (upType == ConnectivityManager.TYPE_MOBILE_DUN || |
| 1303 | upType == ConnectivityManager.TYPE_MOBILE_HIPRI) { |
| 1304 | turnOnUpstreamMobileConnection(upType); |
Robert Greenwalt | c9dac11 | 2012-02-28 12:25:34 -0800 | [diff] [blame] | 1305 | } else if (upType != ConnectivityManager.TYPE_NONE) { |
| 1306 | /* If we've found an active upstream connection that's not DUN/HIPRI |
| 1307 | * we should stop any outstanding DUN/HIPRI start requests. |
| 1308 | * |
| 1309 | * If we found NONE we don't want to do this as we want any previous |
| 1310 | * requests to keep trying to bring up something we can use. |
| 1311 | */ |
| 1312 | turnOffUpstreamMobileConnection(); |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | if (upType == ConnectivityManager.TYPE_NONE) { |
| 1316 | boolean tryAgainLater = true; |
| 1317 | if ((tryCell == TRY_TO_SETUP_MOBILE_CONNECTION) && |
| 1318 | (turnOnUpstreamMobileConnection(mPreferredUpstreamMobileApn) == true)) { |
| 1319 | // we think mobile should be coming up - don't set a retry |
| 1320 | tryAgainLater = false; |
Robert Greenwalt | 77e638d | 2010-03-22 10:35:53 -0700 | [diff] [blame] | 1321 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1322 | if (tryAgainLater) { |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1323 | sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS); |
| 1324 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1325 | } else { |
| 1326 | LinkProperties linkProperties = null; |
| 1327 | try { |
Robert Greenwalt | 3b28e9a | 2011-11-02 14:37:19 -0700 | [diff] [blame] | 1328 | linkProperties = mConnService.getLinkProperties(upType); |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1329 | } catch (RemoteException e) { } |
Robert Greenwalt | bb4fd0b | 2011-12-09 15:36:50 -0800 | [diff] [blame] | 1330 | if (linkProperties != null) { |
Lorenzo Colitti | 13c9fde | 2013-03-15 04:22:37 +0900 | [diff] [blame] | 1331 | // Find the interface with the default IPv4 route. It may be the |
| 1332 | // interface described by linkProperties, or one of the interfaces |
| 1333 | // stacked on top of it. |
| 1334 | Log.i(TAG, "Finding IPv4 upstream interface on: " + linkProperties); |
| 1335 | RouteInfo ipv4Default = RouteInfo.selectBestRoute( |
| 1336 | linkProperties.getAllRoutes(), Inet4Address.ANY); |
| 1337 | if (ipv4Default != null) { |
| 1338 | iface = ipv4Default.getInterface(); |
| 1339 | Log.i(TAG, "Found interface " + ipv4Default.getInterface()); |
| 1340 | } else { |
| 1341 | Log.i(TAG, "No IPv4 upstream interface, giving up."); |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | if (iface != null) { |
Robert Greenwalt | bb4fd0b | 2011-12-09 15:36:50 -0800 | [diff] [blame] | 1346 | String[] dnsServers = mDefaultDnsServers; |
| 1347 | Collection<InetAddress> dnses = linkProperties.getDnses(); |
| 1348 | if (dnses != null) { |
Robert Greenwalt | 4f74d55 | 2011-12-19 16:59:31 -0800 | [diff] [blame] | 1349 | // we currently only handle IPv4 |
| 1350 | ArrayList<InetAddress> v4Dnses = |
| 1351 | new ArrayList<InetAddress>(dnses.size()); |
| 1352 | for (InetAddress dnsAddress : dnses) { |
| 1353 | if (dnsAddress instanceof Inet4Address) { |
| 1354 | v4Dnses.add(dnsAddress); |
| 1355 | } |
| 1356 | } |
| 1357 | if (v4Dnses.size() > 0) { |
| 1358 | dnsServers = NetworkUtils.makeStrings(v4Dnses); |
| 1359 | } |
Robert Greenwalt | bb4fd0b | 2011-12-09 15:36:50 -0800 | [diff] [blame] | 1360 | } |
| 1361 | try { |
| 1362 | mNMService.setDnsForwarders(dnsServers); |
| 1363 | } catch (Exception e) { |
| 1364 | transitionTo(mSetDnsForwardersErrorState); |
| 1365 | } |
| 1366 | } |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1367 | } |
Robert Greenwalt | b37f0c6 | 2010-03-25 14:50:34 -0700 | [diff] [blame] | 1368 | notifyTetheredOfNewUpstreamIface(iface); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1369 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1370 | |
Robert Greenwalt | b37f0c6 | 2010-03-25 14:50:34 -0700 | [diff] [blame] | 1371 | protected void notifyTetheredOfNewUpstreamIface(String ifaceName) { |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 1372 | if (DBG) Log.d(TAG, "notifying tethered with iface =" + ifaceName); |
Robert Greenwalt | b37f0c6 | 2010-03-25 14:50:34 -0700 | [diff] [blame] | 1373 | mUpstreamIfaceName = ifaceName; |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1374 | for (TetherInterfaceSM sm : mNotifyList) { |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1375 | sm.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED, |
| 1376 | ifaceName); |
| 1377 | } |
| 1378 | } |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1379 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1380 | |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1381 | class InitialState extends TetherMasterUtilState { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1382 | @Override |
Robert Greenwalt | c9d5fb7 | 2010-02-25 12:29:30 -0800 | [diff] [blame] | 1383 | public void enter() { |
Robert Greenwalt | c9d5fb7 | 2010-02-25 12:29:30 -0800 | [diff] [blame] | 1384 | } |
| 1385 | @Override |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1386 | public boolean processMessage(Message message) { |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 1387 | if (DBG) Log.d(TAG, "MasterInitialState.processMessage what=" + message.what); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1388 | boolean retValue = true; |
| 1389 | switch (message.what) { |
| 1390 | case CMD_TETHER_MODE_REQUESTED: |
| 1391 | TetherInterfaceSM who = (TetherInterfaceSM)message.obj; |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1392 | if (VDBG) Log.d(TAG, "Tether Mode requested by " + who); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1393 | mNotifyList.add(who); |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1394 | transitionTo(mTetherModeAliveState); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1395 | break; |
| 1396 | case CMD_TETHER_MODE_UNREQUESTED: |
| 1397 | who = (TetherInterfaceSM)message.obj; |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1398 | if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1399 | int index = mNotifyList.indexOf(who); |
| 1400 | if (index != -1) { |
| 1401 | mNotifyList.remove(who); |
| 1402 | } |
| 1403 | break; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1404 | default: |
| 1405 | retValue = false; |
| 1406 | break; |
| 1407 | } |
| 1408 | return retValue; |
| 1409 | } |
| 1410 | } |
| 1411 | |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1412 | class TetherModeAliveState extends TetherMasterUtilState { |
Robert Greenwalt | 19b9ab4 | 2011-01-10 11:58:31 -0800 | [diff] [blame] | 1413 | boolean mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1414 | @Override |
| 1415 | public void enter() { |
Robert Greenwalt | 4f74d55 | 2011-12-19 16:59:31 -0800 | [diff] [blame] | 1416 | turnOnMasterTetherSettings(); // may transition us out |
| 1417 | |
Robert Greenwalt | 19b9ab4 | 2011-01-10 11:58:31 -0800 | [diff] [blame] | 1418 | mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE; // better try something first pass |
| 1419 | // or crazy tests cases will fail |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1420 | chooseUpstreamType(mTryCell); |
| 1421 | mTryCell = !mTryCell; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1422 | } |
| 1423 | @Override |
| 1424 | public void exit() { |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1425 | turnOffUpstreamMobileConnection(); |
Robert Greenwalt | b37f0c6 | 2010-03-25 14:50:34 -0700 | [diff] [blame] | 1426 | notifyTetheredOfNewUpstreamIface(null); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1427 | } |
| 1428 | @Override |
| 1429 | public boolean processMessage(Message message) { |
Robert Greenwalt | fd1be2b | 2011-11-11 12:30:19 -0800 | [diff] [blame] | 1430 | if (DBG) Log.d(TAG, "TetherModeAliveState.processMessage what=" + message.what); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1431 | boolean retValue = true; |
| 1432 | switch (message.what) { |
| 1433 | case CMD_TETHER_MODE_REQUESTED: |
| 1434 | TetherInterfaceSM who = (TetherInterfaceSM)message.obj; |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1435 | if (VDBG) Log.d(TAG, "Tether Mode requested by " + who); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1436 | mNotifyList.add(who); |
Robert Greenwalt | b37f0c6 | 2010-03-25 14:50:34 -0700 | [diff] [blame] | 1437 | who.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED, |
| 1438 | mUpstreamIfaceName); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1439 | break; |
| 1440 | case CMD_TETHER_MODE_UNREQUESTED: |
| 1441 | who = (TetherInterfaceSM)message.obj; |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1442 | if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1443 | int index = mNotifyList.indexOf(who); |
| 1444 | if (index != -1) { |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1445 | if (DBG) Log.d(TAG, "TetherModeAlive removing notifyee " + who); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1446 | mNotifyList.remove(index); |
| 1447 | if (mNotifyList.isEmpty()) { |
Robert Greenwalt | d70a3d4 | 2010-02-23 18:15:29 -0800 | [diff] [blame] | 1448 | turnOffMasterTetherSettings(); // transitions appropriately |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1449 | } else { |
| 1450 | if (DBG) { |
| 1451 | Log.d(TAG, "TetherModeAlive still has " + mNotifyList.size() + |
| 1452 | " live requests:"); |
| 1453 | for (Object o : mNotifyList) Log.d(TAG, " " + o); |
| 1454 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1455 | } |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1456 | } else { |
| 1457 | Log.e(TAG, "TetherModeAliveState UNREQUESTED has unknown who: " + who); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1458 | } |
| 1459 | break; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1460 | case CMD_UPSTREAM_CHANGED: |
Robert Greenwalt | 05d8936 | 2011-01-23 16:04:05 -0800 | [diff] [blame] | 1461 | // need to try DUN immediately if Wifi goes down |
| 1462 | mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1463 | chooseUpstreamType(mTryCell); |
| 1464 | mTryCell = !mTryCell; |
| 1465 | break; |
| 1466 | case CMD_CELL_CONNECTION_RENEW: |
| 1467 | // make sure we're still using a requested connection - may have found |
| 1468 | // wifi or something since then. |
Robert Greenwalt | 1039872 | 2010-12-17 15:20:36 -0800 | [diff] [blame] | 1469 | if (mCurrentConnectionSequence == message.arg1) { |
Wink Saville | c9acde9 | 2011-09-21 11:05:43 -0700 | [diff] [blame] | 1470 | if (VDBG) { |
Robert Greenwalt | 924cc94 | 2010-06-28 10:26:19 -0700 | [diff] [blame] | 1471 | Log.d(TAG, "renewing mobile connection - requeuing for another " + |
| 1472 | CELL_CONNECTION_RENEW_MS + "ms"); |
| 1473 | } |
Robert Greenwalt | ccf83af1 | 2011-06-02 17:30:47 -0700 | [diff] [blame] | 1474 | turnOnUpstreamMobileConnection(mMobileApnReserved); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1475 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1476 | break; |
Kazuhiro Ondo | 01758e8 | 2011-04-30 20:10:57 -0500 | [diff] [blame] | 1477 | case CMD_RETRY_UPSTREAM: |
| 1478 | chooseUpstreamType(mTryCell); |
| 1479 | mTryCell = !mTryCell; |
| 1480 | break; |
Kazuhiro Ondo | 01758e8 | 2011-04-30 20:10:57 -0500 | [diff] [blame] | 1481 | default: |
| 1482 | retValue = false; |
| 1483 | break; |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1484 | } |
| 1485 | return retValue; |
| 1486 | } |
| 1487 | } |
| 1488 | |
Wink Saville | 64c42ca | 2011-04-18 14:55:10 -0700 | [diff] [blame] | 1489 | class ErrorState extends State { |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1490 | int mErrorNotification; |
| 1491 | @Override |
| 1492 | public boolean processMessage(Message message) { |
| 1493 | boolean retValue = true; |
| 1494 | switch (message.what) { |
| 1495 | case CMD_TETHER_MODE_REQUESTED: |
| 1496 | TetherInterfaceSM who = (TetherInterfaceSM)message.obj; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1497 | who.sendMessage(mErrorNotification); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1498 | break; |
| 1499 | default: |
| 1500 | retValue = false; |
| 1501 | } |
| 1502 | return retValue; |
| 1503 | } |
| 1504 | void notify(int msgType) { |
| 1505 | mErrorNotification = msgType; |
| 1506 | for (Object o : mNotifyList) { |
| 1507 | TetherInterfaceSM sm = (TetherInterfaceSM)o; |
Robert Greenwalt | 6a1967c | 2010-03-17 11:19:57 -0700 | [diff] [blame] | 1508 | sm.sendMessage(msgType); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | } |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1513 | class SetIpForwardingEnabledErrorState extends ErrorState { |
| 1514 | @Override |
| 1515 | public void enter() { |
| 1516 | Log.e(TAG, "Error in setIpForwardingEnabled"); |
| 1517 | notify(TetherInterfaceSM.CMD_IP_FORWARDING_ENABLE_ERROR); |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | class SetIpForwardingDisabledErrorState extends ErrorState { |
| 1522 | @Override |
| 1523 | public void enter() { |
| 1524 | Log.e(TAG, "Error in setIpForwardingDisabled"); |
| 1525 | notify(TetherInterfaceSM.CMD_IP_FORWARDING_DISABLE_ERROR); |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | class StartTetheringErrorState extends ErrorState { |
| 1530 | @Override |
| 1531 | public void enter() { |
| 1532 | Log.e(TAG, "Error in startTethering"); |
| 1533 | notify(TetherInterfaceSM.CMD_START_TETHERING_ERROR); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1534 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1535 | mNMService.setIpForwardingEnabled(false); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1536 | } catch (Exception e) {} |
| 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | class StopTetheringErrorState extends ErrorState { |
| 1541 | @Override |
| 1542 | public void enter() { |
| 1543 | Log.e(TAG, "Error in stopTethering"); |
| 1544 | notify(TetherInterfaceSM.CMD_STOP_TETHERING_ERROR); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1545 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1546 | mNMService.setIpForwardingEnabled(false); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1547 | } catch (Exception e) {} |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | class SetDnsForwardersErrorState extends ErrorState { |
| 1552 | @Override |
| 1553 | public void enter() { |
| 1554 | Log.e(TAG, "Error in setDnsForwarders"); |
| 1555 | notify(TetherInterfaceSM.CMD_SET_DNS_FORWARDERS_ERROR); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1556 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1557 | mNMService.stopTethering(); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1558 | } catch (Exception e) {} |
| 1559 | try { |
Chia-chi Yeh | c933830 | 2011-05-11 16:35:13 -0700 | [diff] [blame] | 1560 | mNMService.setIpForwardingEnabled(false); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1561 | } catch (Exception e) {} |
| 1562 | } |
| 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1567 | if (mContext.checkCallingOrSelfPermission( |
| 1568 | android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { |
| 1569 | pw.println("Permission Denial: can't dump ConnectivityService.Tether " + |
| 1570 | "from from pid=" + Binder.getCallingPid() + ", uid=" + |
| 1571 | Binder.getCallingUid()); |
| 1572 | return; |
| 1573 | } |
| 1574 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 1575 | synchronized (mPublicSync) { |
| 1576 | pw.println("mUpstreamIfaceTypes: "); |
| 1577 | for (Integer netType : mUpstreamIfaceTypes) { |
| 1578 | pw.println(" " + netType); |
| 1579 | } |
Robert Greenwalt | 49348e7 | 2011-10-21 16:54:26 -0700 | [diff] [blame] | 1580 | |
Robert Greenwalt | b445362 | 2011-11-03 16:01:40 -0700 | [diff] [blame] | 1581 | pw.println(); |
| 1582 | pw.println("Tether state:"); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1583 | for (Object o : mIfaces.values()) { |
Robert Greenwalt | 68ea9b0 | 2012-05-10 16:58:16 -0700 | [diff] [blame] | 1584 | pw.println(" " + o); |
Robert Greenwalt | 2a091d7 | 2010-02-11 18:18:40 -0800 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | pw.println(); |
| 1588 | return; |
Robert Greenwalt | d0e18ff | 2010-01-26 11:40:34 -0800 | [diff] [blame] | 1589 | } |
| 1590 | } |