Loading core/java/android/net/ConnectivityManager.java +17 −0 Original line number Diff line number Diff line Loading @@ -928,6 +928,23 @@ public class ConnectivityManager { } } /** * Get the set of tethered dhcp ranges. * * @return an array of 0 or more Strings of tethered dhcp ranges. * * <p>This method requires the call to hold the permission * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. * {@hide} */ public String[] getTetheredDhcpRanges() { try { return mService.getTetheredDhcpRanges(); } catch (RemoteException e) { return new String[0]; } } /** * Get the set of tethered interfaces. * Loading core/java/android/net/IConnectivityManager.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ interface IConnectivityManager String[] getTetherableIfaces(); String[] getTetheredDhcpRanges(); String[] getTetheredIfaces(); String[] getTetheringErroredIfaces(); Loading services/java/com/android/server/ConnectivityService.java +5 −0 Original line number Diff line number Diff line Loading @@ -3297,6 +3297,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { return mTethering.getTetherableIfaces(); } public String[] getTetheredDhcpRanges() { enforceConnectivityInternalPermission(); return mTethering.getTetheredDhcpRanges(); } public String[] getTetheredIfaces() { enforceTetherAccessPermission(); return mTethering.getTetheredIfaces(); Loading services/java/com/android/server/connectivity/Tethering.java +6 −1 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ public class Tethering extends BaseNetworkObserver { // USB is 192.168.42.1 and 255.255.255.0 // Wifi is 192.168.43.1 and 255.255.255.0 // P2P is 192.168.49.1 and 255.255.255.0 // BT is limited to max default of 5 connections. 192.168.44.1 to 192.168.48.1 // with 255.255.255.0 Loading @@ -117,7 +118,7 @@ public class Tethering extends BaseNetworkObserver { "192.168.42.2", "192.168.42.254", "192.168.43.2", "192.168.43.254", "192.168.44.2", "192.168.44.254", "192.168.45.2", "192.168.45.254", "192.168.46.2", "192.168.46.254", "192.168.47.2", "192.168.47.254", "192.168.48.2", "192.168.48.254", "192.168.48.2", "192.168.48.254", "192.168.49.2", "192.168.49.254", }; private String[] mDefaultDnsServers; Loading Loading @@ -699,6 +700,10 @@ public class Tethering extends BaseNetworkObserver { return retVal; } public String[] getTetheredDhcpRanges() { return mDhcpRange; } public String[] getErroredIfaces() { ArrayList<String> list = new ArrayList<String>(); synchronized (mPublicSync) { Loading wifi/java/android/net/wifi/p2p/WifiP2pService.java +23 −5 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { INetworkManagementService mNwService; private DhcpStateMachine mDhcpStateMachine; private ConnectivityManager mCm; private P2pStateMachine mP2pStateMachine; private AsyncChannel mReplyChannel = new AsyncChannel(); Loading Loading @@ -226,9 +227,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub { /* clients(application) information list. */ private HashMap<Messenger, ClientInfo> mClientInfoList = new HashMap<Messenger, ClientInfo>(); /* Is chosen as a unique range to avoid conflict with the range defined in Tethering.java */ private static final String[] DHCP_RANGE = {"192.168.49.2", "192.168.49.254"}; private static final String SERVER_ADDRESS = "192.168.49.1"; /** Loading Loading @@ -2058,8 +2056,15 @@ public class WifiP2pService extends IWifiP2pManager.Stub { mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } private void checkAndSetConnectivityInstance() { if (mCm == null) { mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); } } private void startDhcpServer(String intf) { InterfaceConfiguration ifcg = null; checkAndSetConnectivityInstance(); try { ifcg = mNwService.getInterfaceConfig(intf); ifcg.setLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress( Loading @@ -2067,17 +2072,30 @@ public class WifiP2pService extends IWifiP2pManager.Stub { ifcg.setInterfaceUp(); mNwService.setInterfaceConfig(intf, ifcg); /* This starts the dnsmasq server */ mNwService.startTethering(DHCP_RANGE); String[] tetheringDhcpRanges = mCm.getTetheredDhcpRanges(); if (mNwService.isTetheringStarted()) { if (DBG) logd("Stop exist tethering and will restart it"); mNwService.stopTethering(); mNwService.tetherInterface(intf); } mNwService.startTethering(tetheringDhcpRanges); } catch (Exception e) { loge("Error configuring interface " + intf + ", :" + e); return; } logd("Started Dhcp server on " + intf); } private void stopDhcpServer(String intf) { try { for (String temp : mNwService.listTetheredInterfaces()) { logd("List all interfaces " + temp); if (temp.compareTo(intf) != 0 ) { logd("Found other tethering interface so keep tethering alive"); mNwService.untetherInterface(intf); return; } } mNwService.stopTethering(); } catch (Exception e) { loge("Error stopping Dhcp server" + e); Loading Loading
core/java/android/net/ConnectivityManager.java +17 −0 Original line number Diff line number Diff line Loading @@ -928,6 +928,23 @@ public class ConnectivityManager { } } /** * Get the set of tethered dhcp ranges. * * @return an array of 0 or more Strings of tethered dhcp ranges. * * <p>This method requires the call to hold the permission * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. * {@hide} */ public String[] getTetheredDhcpRanges() { try { return mService.getTetheredDhcpRanges(); } catch (RemoteException e) { return new String[0]; } } /** * Get the set of tethered interfaces. * Loading
core/java/android/net/IConnectivityManager.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ interface IConnectivityManager String[] getTetherableIfaces(); String[] getTetheredDhcpRanges(); String[] getTetheredIfaces(); String[] getTetheringErroredIfaces(); Loading
services/java/com/android/server/ConnectivityService.java +5 −0 Original line number Diff line number Diff line Loading @@ -3297,6 +3297,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { return mTethering.getTetherableIfaces(); } public String[] getTetheredDhcpRanges() { enforceConnectivityInternalPermission(); return mTethering.getTetheredDhcpRanges(); } public String[] getTetheredIfaces() { enforceTetherAccessPermission(); return mTethering.getTetheredIfaces(); Loading
services/java/com/android/server/connectivity/Tethering.java +6 −1 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ public class Tethering extends BaseNetworkObserver { // USB is 192.168.42.1 and 255.255.255.0 // Wifi is 192.168.43.1 and 255.255.255.0 // P2P is 192.168.49.1 and 255.255.255.0 // BT is limited to max default of 5 connections. 192.168.44.1 to 192.168.48.1 // with 255.255.255.0 Loading @@ -117,7 +118,7 @@ public class Tethering extends BaseNetworkObserver { "192.168.42.2", "192.168.42.254", "192.168.43.2", "192.168.43.254", "192.168.44.2", "192.168.44.254", "192.168.45.2", "192.168.45.254", "192.168.46.2", "192.168.46.254", "192.168.47.2", "192.168.47.254", "192.168.48.2", "192.168.48.254", "192.168.48.2", "192.168.48.254", "192.168.49.2", "192.168.49.254", }; private String[] mDefaultDnsServers; Loading Loading @@ -699,6 +700,10 @@ public class Tethering extends BaseNetworkObserver { return retVal; } public String[] getTetheredDhcpRanges() { return mDhcpRange; } public String[] getErroredIfaces() { ArrayList<String> list = new ArrayList<String>(); synchronized (mPublicSync) { Loading
wifi/java/android/net/wifi/p2p/WifiP2pService.java +23 −5 Original line number Diff line number Diff line Loading @@ -109,6 +109,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { INetworkManagementService mNwService; private DhcpStateMachine mDhcpStateMachine; private ConnectivityManager mCm; private P2pStateMachine mP2pStateMachine; private AsyncChannel mReplyChannel = new AsyncChannel(); Loading Loading @@ -226,9 +227,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub { /* clients(application) information list. */ private HashMap<Messenger, ClientInfo> mClientInfoList = new HashMap<Messenger, ClientInfo>(); /* Is chosen as a unique range to avoid conflict with the range defined in Tethering.java */ private static final String[] DHCP_RANGE = {"192.168.49.2", "192.168.49.254"}; private static final String SERVER_ADDRESS = "192.168.49.1"; /** Loading Loading @@ -2058,8 +2056,15 @@ public class WifiP2pService extends IWifiP2pManager.Stub { mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } private void checkAndSetConnectivityInstance() { if (mCm == null) { mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); } } private void startDhcpServer(String intf) { InterfaceConfiguration ifcg = null; checkAndSetConnectivityInstance(); try { ifcg = mNwService.getInterfaceConfig(intf); ifcg.setLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress( Loading @@ -2067,17 +2072,30 @@ public class WifiP2pService extends IWifiP2pManager.Stub { ifcg.setInterfaceUp(); mNwService.setInterfaceConfig(intf, ifcg); /* This starts the dnsmasq server */ mNwService.startTethering(DHCP_RANGE); String[] tetheringDhcpRanges = mCm.getTetheredDhcpRanges(); if (mNwService.isTetheringStarted()) { if (DBG) logd("Stop exist tethering and will restart it"); mNwService.stopTethering(); mNwService.tetherInterface(intf); } mNwService.startTethering(tetheringDhcpRanges); } catch (Exception e) { loge("Error configuring interface " + intf + ", :" + e); return; } logd("Started Dhcp server on " + intf); } private void stopDhcpServer(String intf) { try { for (String temp : mNwService.listTetheredInterfaces()) { logd("List all interfaces " + temp); if (temp.compareTo(intf) != 0 ) { logd("Found other tethering interface so keep tethering alive"); mNwService.untetherInterface(intf); return; } } mNwService.stopTethering(); } catch (Exception e) { loge("Error stopping Dhcp server" + e); Loading