Loading services/core/java/com/android/server/NetworkManagementService.java +29 −43 Original line number Original line Diff line number Diff line Loading @@ -160,6 +160,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub private static final int MAX_UID_RANGES_PER_COMMAND = 10; private static final int MAX_UID_RANGES_PER_COMMAND = 10; private static final String[] EMPTY_STRING_ARRAY = new String[0]; /** /** * Name representing {@link #setGlobalAlert(long)} limit when delivered to * Name representing {@link #setGlobalAlert(long)} limit when delivered to * {@link INetworkManagementEventObserver#limitReached(String, String)}. * {@link INetworkManagementEventObserver#limitReached(String, String)}. Loading Loading @@ -1229,18 +1231,12 @@ public class NetworkManagementService extends INetworkManagementService.Stub @Override @Override public void startTethering(String[] dhcpRange) { public void startTethering(String[] dhcpRange) { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); // cmd is "tether start first_start first_stop second_start second_stop ..." // an odd number of addrs will fail // an odd number of addrs will fail final Command cmd = new Command("tether", "start"); for (String d : dhcpRange) { cmd.appendArg(d); } try { try { mConnector.execute(cmd); mNetdService.tetherStart(dhcpRange); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } } } Loading @@ -1248,9 +1244,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub public void stopTethering() { public void stopTethering() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { mConnector.execute("tether", "stop"); mNetdService.tetherStop(); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } } } Loading @@ -1258,25 +1254,21 @@ public class NetworkManagementService extends INetworkManagementService.Stub public boolean isTetheringStarted() { public boolean isTetheringStarted() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); final NativeDaemonEvent event; try { try { event = mConnector.execute("tether", "status"); final boolean isEnabled = mNetdService.tetherIsEnabled(); } catch (NativeDaemonConnectorException e) { return isEnabled; throw e.rethrowAsParcelableException(); } catch (RemoteException | ServiceSpecificException e) { throw new IllegalStateException(e); } } // 210 Tethering services started event.checkCode(TetherStatusResult); return event.getMessage().endsWith("started"); } } @Override @Override public void tetherInterface(String iface) { public void tetherInterface(String iface) { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { mConnector.execute("tether", "interface", "add", iface); mNetdService.tetherInterfaceAdd(iface); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } List<RouteInfo> routes = new ArrayList<>(); List<RouteInfo> routes = new ArrayList<>(); // The RouteInfo constructor truncates the LinkAddress to a network prefix, thus making it // The RouteInfo constructor truncates the LinkAddress to a network prefix, thus making it Loading @@ -1289,9 +1281,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub public void untetherInterface(String iface) { public void untetherInterface(String iface) { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { mConnector.execute("tether", "interface", "remove", iface); mNetdService.tetherInterfaceRemove(iface); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } finally { } finally { removeInterfaceFromLocalNetwork(iface); removeInterfaceFromLocalNetwork(iface); } } Loading @@ -1301,11 +1293,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub public String[] listTetheredInterfaces() { public String[] listTetheredInterfaces() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { return NativeDaemonEvent.filterMessageList( final List<String> result = mNetdService.tetherInterfaceList(); mConnector.executeForList("tether", "interface", "list"), return result.toArray(EMPTY_STRING_ARRAY); TetherInterfaceListResult); } catch (RemoteException | ServiceSpecificException e) { } catch (NativeDaemonConnectorException e) { throw new IllegalStateException(e); throw e.rethrowAsParcelableException(); } } } } Loading @@ -1314,16 +1305,11 @@ public class NetworkManagementService extends INetworkManagementService.Stub mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); int netId = (network != null) ? network.netId : ConnectivityManager.NETID_UNSET; int netId = (network != null) ? network.netId : ConnectivityManager.NETID_UNSET; final Command cmd = new Command("tether", "dns", "set", netId); for (String s : dns) { cmd.appendArg(NetworkUtils.numericToInetAddress(s).getHostAddress()); } try { try { mConnector.execute(cmd); mNetdService.tetherDnsSet(netId, dns); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } } } Loading @@ -1331,10 +1317,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub public String[] getDnsForwarders() { public String[] getDnsForwarders() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { return NativeDaemonEvent.filterMessageList( final List<String> result = mNetdService.tetherDnsList(); mConnector.executeForList("tether", "dns", "list"), TetherDnsFwdTgtListResult); return result.toArray(EMPTY_STRING_ARRAY); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } } } Loading Loading
services/core/java/com/android/server/NetworkManagementService.java +29 −43 Original line number Original line Diff line number Diff line Loading @@ -160,6 +160,8 @@ public class NetworkManagementService extends INetworkManagementService.Stub private static final int MAX_UID_RANGES_PER_COMMAND = 10; private static final int MAX_UID_RANGES_PER_COMMAND = 10; private static final String[] EMPTY_STRING_ARRAY = new String[0]; /** /** * Name representing {@link #setGlobalAlert(long)} limit when delivered to * Name representing {@link #setGlobalAlert(long)} limit when delivered to * {@link INetworkManagementEventObserver#limitReached(String, String)}. * {@link INetworkManagementEventObserver#limitReached(String, String)}. Loading Loading @@ -1229,18 +1231,12 @@ public class NetworkManagementService extends INetworkManagementService.Stub @Override @Override public void startTethering(String[] dhcpRange) { public void startTethering(String[] dhcpRange) { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); // cmd is "tether start first_start first_stop second_start second_stop ..." // an odd number of addrs will fail // an odd number of addrs will fail final Command cmd = new Command("tether", "start"); for (String d : dhcpRange) { cmd.appendArg(d); } try { try { mConnector.execute(cmd); mNetdService.tetherStart(dhcpRange); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } } } Loading @@ -1248,9 +1244,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub public void stopTethering() { public void stopTethering() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { mConnector.execute("tether", "stop"); mNetdService.tetherStop(); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } } } Loading @@ -1258,25 +1254,21 @@ public class NetworkManagementService extends INetworkManagementService.Stub public boolean isTetheringStarted() { public boolean isTetheringStarted() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); final NativeDaemonEvent event; try { try { event = mConnector.execute("tether", "status"); final boolean isEnabled = mNetdService.tetherIsEnabled(); } catch (NativeDaemonConnectorException e) { return isEnabled; throw e.rethrowAsParcelableException(); } catch (RemoteException | ServiceSpecificException e) { throw new IllegalStateException(e); } } // 210 Tethering services started event.checkCode(TetherStatusResult); return event.getMessage().endsWith("started"); } } @Override @Override public void tetherInterface(String iface) { public void tetherInterface(String iface) { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { mConnector.execute("tether", "interface", "add", iface); mNetdService.tetherInterfaceAdd(iface); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } List<RouteInfo> routes = new ArrayList<>(); List<RouteInfo> routes = new ArrayList<>(); // The RouteInfo constructor truncates the LinkAddress to a network prefix, thus making it // The RouteInfo constructor truncates the LinkAddress to a network prefix, thus making it Loading @@ -1289,9 +1281,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub public void untetherInterface(String iface) { public void untetherInterface(String iface) { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { mConnector.execute("tether", "interface", "remove", iface); mNetdService.tetherInterfaceRemove(iface); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } finally { } finally { removeInterfaceFromLocalNetwork(iface); removeInterfaceFromLocalNetwork(iface); } } Loading @@ -1301,11 +1293,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub public String[] listTetheredInterfaces() { public String[] listTetheredInterfaces() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { return NativeDaemonEvent.filterMessageList( final List<String> result = mNetdService.tetherInterfaceList(); mConnector.executeForList("tether", "interface", "list"), return result.toArray(EMPTY_STRING_ARRAY); TetherInterfaceListResult); } catch (RemoteException | ServiceSpecificException e) { } catch (NativeDaemonConnectorException e) { throw new IllegalStateException(e); throw e.rethrowAsParcelableException(); } } } } Loading @@ -1314,16 +1305,11 @@ public class NetworkManagementService extends INetworkManagementService.Stub mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); int netId = (network != null) ? network.netId : ConnectivityManager.NETID_UNSET; int netId = (network != null) ? network.netId : ConnectivityManager.NETID_UNSET; final Command cmd = new Command("tether", "dns", "set", netId); for (String s : dns) { cmd.appendArg(NetworkUtils.numericToInetAddress(s).getHostAddress()); } try { try { mConnector.execute(cmd); mNetdService.tetherDnsSet(netId, dns); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } } } Loading @@ -1331,10 +1317,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub public String[] getDnsForwarders() { public String[] getDnsForwarders() { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); try { try { return NativeDaemonEvent.filterMessageList( final List<String> result = mNetdService.tetherDnsList(); mConnector.executeForList("tether", "dns", "list"), TetherDnsFwdTgtListResult); return result.toArray(EMPTY_STRING_ARRAY); } catch (NativeDaemonConnectorException e) { } catch (RemoteException | ServiceSpecificException e) { throw e.rethrowAsParcelableException(); throw new IllegalStateException(e); } } } } Loading