Loading cmds/svc/src/com/android/commands/svc/DataCommand.java +2 −13 Original line number Diff line number Diff line Loading @@ -36,9 +36,7 @@ public class DataCommand extends Svc.Command { return shortHelp() + "\n" + "\n" + "usage: svc data [enable|disable]\n" + " Turn mobile data on or off.\n\n" + " svc data prefer\n" + " Set mobile as the preferred data network\n"; + " Turn mobile data on or off.\n\n"; } public void run(String[] args) { Loading @@ -51,15 +49,6 @@ public class DataCommand extends Svc.Command { } else if ("disable".equals(args[1])) { flag = false; validCommand = true; } else if ("prefer".equals(args[1])) { IConnectivityManager connMgr = IConnectivityManager.Stub.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE)); try { connMgr.setNetworkPreference(ConnectivityManager.TYPE_MOBILE); } catch (RemoteException e) { System.err.println("Failed to set preferred network: " + e); } return; } if (validCommand) { ITelephony phoneMgr Loading cmds/svc/src/com/android/commands/svc/WifiCommand.java +2 −13 Original line number Diff line number Diff line Loading @@ -36,9 +36,7 @@ public class WifiCommand extends Svc.Command { return shortHelp() + "\n" + "\n" + "usage: svc wifi [enable|disable]\n" + " Turn Wi-Fi on or off.\n\n" + " svc wifi prefer\n" + " Set Wi-Fi as the preferred data network\n"; + " Turn Wi-Fi on or off.\n\n"; } public void run(String[] args) { Loading @@ -51,15 +49,6 @@ public class WifiCommand extends Svc.Command { } else if ("disable".equals(args[1])) { flag = false; validCommand = true; } else if ("prefer".equals(args[1])) { IConnectivityManager connMgr = IConnectivityManager.Stub.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE)); try { connMgr.setNetworkPreference(ConnectivityManager.TYPE_WIFI); } catch (RemoteException e) { System.err.println("Failed to set preferred network: " + e); } return; } if (validCommand) { IWifiManager wifiMgr Loading core/java/android/net/ConnectivityManager.java +102 −29 Original line number Diff line number Diff line Loading @@ -534,39 +534,33 @@ public class ConnectivityManager { /** * Specifies the preferred network type. When the device has more * than one type available the preferred network type will be used. * Note that this made sense when we only had 2 network types, * but with more and more default networks we need an array to list * their ordering. This will be deprecated soon. * * @param preference the network type to prefer over all others. It is * unspecified what happens to the old preferred network in the * overall ordering. * @Deprecated Functionality has been removed as it no longer makes sense, * with many more than two networks - we'd need an array to express * preference. Instead we use dynamic network properties of * the networks to describe their precedence. */ public void setNetworkPreference(int preference) { try { mService.setNetworkPreference(preference); } catch (RemoteException e) { } } /** * Retrieves the current preferred network type. * Note that this made sense when we only had 2 network types, * but with more and more default networks we need an array to list * their ordering. This will be deprecated soon. * * @return an integer representing the preferred network type * * <p>This method requires the caller to hold the permission * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. * @Deprecated Functionality has been removed as it no longer makes sense, * with many more than two networks - we'd need an array to express * preference. Instead we use dynamic network properties of * the networks to describe their precedence. */ public int getNetworkPreference() { try { return mService.getNetworkPreference(); } catch (RemoteException e) { return -1; } } /** * Returns details about the currently active default data network. When Loading Loading @@ -723,13 +717,14 @@ public class ConnectivityManager { * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. * {@hide} */ public boolean setRadios(boolean turnOn) { try { return mService.setRadios(turnOn); } catch (RemoteException e) { return false; } } // TODO - check for any callers and remove // public boolean setRadios(boolean turnOn) { // try { // return mService.setRadios(turnOn); // } catch (RemoteException e) { // return false; // } // } /** * Tells a given networkType to set its radio power state as directed. Loading @@ -743,13 +738,14 @@ public class ConnectivityManager { * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. * {@hide} */ public boolean setRadio(int networkType, boolean turnOn) { try { return mService.setRadio(networkType, turnOn); } catch (RemoteException e) { return false; } } // TODO - check for any callers and remove // public boolean setRadio(int networkType, boolean turnOn) { // try { // return mService.setRadio(networkType, turnOn); // } catch (RemoteException e) { // return false; // } // } /** * Tells the underlying networking system that the caller wants to Loading Loading @@ -1594,4 +1590,81 @@ public class ConnectivityManager { mService.registerNetworkFactory(messenger); } catch (RemoteException e) { } } /** {@hide} */ public void registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp, NetworkCapabilities nc, int score) { try { mService.registerNetworkAgent(messenger, ni, lp, nc, score); } catch (RemoteException e) { } } /** Interface for NetworkRequest callbacks {@hide} */ public static class NetworkCallbacks { public static final int PRECHECK = 1; public static final int AVAILABLE = 2; public static final int LOSING = 3; public static final int LOST = 4; public static final int UNAVAIL = 5; public static final int CAP_CHANGED = 6; public static final int PROP_CHANGED = 7; public static final int CANCELED = 8; /** * @hide * Called whenever the framework connects to a network that it may use to * satisfy this request */ public void onPreCheck(NetworkRequest networkRequest, Network network) {} /** * Called when the framework connects and has validated the new network. */ public void onAvailable(NetworkRequest networkRequest, Network network) {} /** * Called when the framework is losing the network. Often paired with an * onAvailable call with the new replacement network for graceful handover. * This may not be called if we have a hard loss (loss without warning). * This may be followed by either an onLost call or an onAvailable call for this * network depending on if we lose or regain it. */ public void onLosing(NetworkRequest networkRequest, Network network, int maxSecToLive) {} /** * Called when the framework has a hard loss of the network or when the * graceful failure ends. Note applications should only request this callback * if the application is willing to track the Available and Lost callbacks * together, else the application may think it has no network when it * really does (A Avail, B Avail, A Lost.. still have B). */ public void onLost(NetworkRequest networkRequest, Network network) {} /** * Called if no network is found in the given timeout time. If no timeout is given, * this will not be called. */ public void onUnavailable(NetworkRequest networkRequest) {} /** * Called when the network the framework connected to for this request * changes capabilities but still satisfies the stated need. */ public void onCapabilitiesChanged(NetworkRequest networkRequest, Network network, NetworkCapabilities networkCapabilities) {} /** * Called when the network the framework connected to for this request * changes properties. */ public void onPropertiesChanged(NetworkRequest networkRequest, Network network, LinkProperties linkProperties) {} /** * Called when a CancelRequest call concludes and the registered callbacks will * no longer be used. */ public void onCanceled(NetworkRequest networkRequest) {} } } core/java/android/net/ConnectivityServiceProtocol.java +65 −4 Original line number Diff line number Diff line Loading @@ -23,15 +23,41 @@ import static com.android.internal.util.Protocol.BASE_CONNECTIVITY_SERVICE; * @hide */ public class ConnectivityServiceProtocol { private ConnectivityServiceProtocol() {} private static final int BASE = BASE_CONNECTIVITY_SERVICE; private ConnectivityServiceProtocol() {} /** * This is a contract between ConnectivityService and various bearers. * A NetworkFactory is an abstract entity that creates NetworkAgent objects. * The bearers register with ConnectivityService using * ConnectivityManager.registerNetworkFactory, where they pass in a Messenger * to be used to deliver the following Messages. */ public static class NetworkFactoryProtocol { private NetworkFactoryProtocol() {} /** * Pass a network request to the transport * Pass a network request to the bearer. If the bearer believes it can * satisfy the request it should connect to the network and create a * NetworkAgent. Once the NetworkAgent is fully functional it will * register itself with ConnectivityService using registerNetworkAgent. * If the bearer cannot immediately satisfy the request (no network, * user disabled the radio, lower-scored network) it should remember * any NetworkRequests it may be able to satisfy in the future. It may * disregard any that it will never be able to service, for example * those requiring a different bearer. * msg.obj = NetworkRequest * msg.arg1 = score - the score of the any network currently satisfying this * request. If this bearer knows in advance it cannot * exceed this score it should not try to connect, holding the request * for the future. * Note that subsequent events may give a different (lower * or higher) score for this request, transmitted to each * NetworkFactory through additional CMD_REQUEST_NETWORK msgs * with the same NetworkRequest but an updated score. * Also, network conditions may change for this bearer * allowing for a better score in the future. */ public static final int CMD_REQUEST_NETWORK = BASE; Loading @@ -42,7 +68,42 @@ public class ConnectivityServiceProtocol { public static final int CMD_CANCEL_REQUEST = BASE + 1; } public static class NetworkAgentProtocol { private NetworkAgentProtocol() {} /** * TODO - move to NetworkMonitor and document */ public static class NetworkMonitorProtocol { private NetworkMonitorProtocol() {} /** * Inform NetworkMonitor that their network is connected. * Initiates Network Validation. */ public static final int CMD_NETWORK_CONNECTED = BASE + 200; /** * Inform ConnectivityService that the network is validated. * obj = NetworkAgent */ public static final int EVENT_NETWORK_VALIDATED = BASE + 201; /** * Inform NetworkMonitor to linger a network. The Monitor should * start a timer and/or start watching for zero live connections while * moving towards LINGER_COMPLETE. After the Linger period expires * (or other events mark the end of the linger state) the LINGER_COMPLETE * event should be sent to ConnectivityService and ConnectivityService * will shut down the network, telling the corresponding NetworkAgent * to disconnect. If a CMD_NETWORK_CONNECTED happens before the LINGER completes * it indicates further desire to keep the network alive and so * the LINGER is aborted. * TODO - figure out who manages/does this simple state machine */ public static final int CMD_NETWORK_LINGER = BASE + 202; /** * Inform ConnectivityService that the network LINGER period has * expired. * obj = NetworkAgent */ public static final int EVENT_NETWORK_LINGER_COMPLETE = BASE + 203; } } core/java/android/net/IConnectivityManager.aidl +5 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.net; import android.net.LinkQualityInfo; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.NetworkQuotaInfo; import android.net.NetworkState; Loading @@ -41,10 +42,6 @@ interface IConnectivityManager // Keep this in sync with framework/native/services/connectivitymanager/ConnectivityManager.h void markSocketAsUser(in ParcelFileDescriptor socket, int uid); void setNetworkPreference(int pref); int getNetworkPreference(); NetworkInfo getActiveNetworkInfo(); NetworkInfo getActiveNetworkInfoForUid(int uid); NetworkInfo getNetworkInfo(int networkType); Loading @@ -62,10 +59,6 @@ interface IConnectivityManager NetworkQuotaInfo getActiveNetworkQuotaInfo(); boolean isActiveNetworkMetered(); boolean setRadios(boolean onOff); boolean setRadio(int networkType, boolean turnOn); int startUsingNetworkFeature(int networkType, in String feature, in IBinder binder); Loading Loading @@ -147,9 +140,12 @@ interface IConnectivityManager LinkQualityInfo[] getAllLinkQualityInfo(); void setProvisioningNotificationVisible(boolean visible, int networkType, in String extraInfo, in String url); void setProvisioningNotificationVisible(boolean visible, int networkType, in String extraInfo, in String url); void setAirplaneMode(boolean enable); void registerNetworkFactory(in Messenger messenger); void registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp, in NetworkCapabilities nc, int score); } Loading
cmds/svc/src/com/android/commands/svc/DataCommand.java +2 −13 Original line number Diff line number Diff line Loading @@ -36,9 +36,7 @@ public class DataCommand extends Svc.Command { return shortHelp() + "\n" + "\n" + "usage: svc data [enable|disable]\n" + " Turn mobile data on or off.\n\n" + " svc data prefer\n" + " Set mobile as the preferred data network\n"; + " Turn mobile data on or off.\n\n"; } public void run(String[] args) { Loading @@ -51,15 +49,6 @@ public class DataCommand extends Svc.Command { } else if ("disable".equals(args[1])) { flag = false; validCommand = true; } else if ("prefer".equals(args[1])) { IConnectivityManager connMgr = IConnectivityManager.Stub.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE)); try { connMgr.setNetworkPreference(ConnectivityManager.TYPE_MOBILE); } catch (RemoteException e) { System.err.println("Failed to set preferred network: " + e); } return; } if (validCommand) { ITelephony phoneMgr Loading
cmds/svc/src/com/android/commands/svc/WifiCommand.java +2 −13 Original line number Diff line number Diff line Loading @@ -36,9 +36,7 @@ public class WifiCommand extends Svc.Command { return shortHelp() + "\n" + "\n" + "usage: svc wifi [enable|disable]\n" + " Turn Wi-Fi on or off.\n\n" + " svc wifi prefer\n" + " Set Wi-Fi as the preferred data network\n"; + " Turn Wi-Fi on or off.\n\n"; } public void run(String[] args) { Loading @@ -51,15 +49,6 @@ public class WifiCommand extends Svc.Command { } else if ("disable".equals(args[1])) { flag = false; validCommand = true; } else if ("prefer".equals(args[1])) { IConnectivityManager connMgr = IConnectivityManager.Stub.asInterface(ServiceManager.getService(Context.CONNECTIVITY_SERVICE)); try { connMgr.setNetworkPreference(ConnectivityManager.TYPE_WIFI); } catch (RemoteException e) { System.err.println("Failed to set preferred network: " + e); } return; } if (validCommand) { IWifiManager wifiMgr Loading
core/java/android/net/ConnectivityManager.java +102 −29 Original line number Diff line number Diff line Loading @@ -534,39 +534,33 @@ public class ConnectivityManager { /** * Specifies the preferred network type. When the device has more * than one type available the preferred network type will be used. * Note that this made sense when we only had 2 network types, * but with more and more default networks we need an array to list * their ordering. This will be deprecated soon. * * @param preference the network type to prefer over all others. It is * unspecified what happens to the old preferred network in the * overall ordering. * @Deprecated Functionality has been removed as it no longer makes sense, * with many more than two networks - we'd need an array to express * preference. Instead we use dynamic network properties of * the networks to describe their precedence. */ public void setNetworkPreference(int preference) { try { mService.setNetworkPreference(preference); } catch (RemoteException e) { } } /** * Retrieves the current preferred network type. * Note that this made sense when we only had 2 network types, * but with more and more default networks we need an array to list * their ordering. This will be deprecated soon. * * @return an integer representing the preferred network type * * <p>This method requires the caller to hold the permission * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}. * @Deprecated Functionality has been removed as it no longer makes sense, * with many more than two networks - we'd need an array to express * preference. Instead we use dynamic network properties of * the networks to describe their precedence. */ public int getNetworkPreference() { try { return mService.getNetworkPreference(); } catch (RemoteException e) { return -1; } } /** * Returns details about the currently active default data network. When Loading Loading @@ -723,13 +717,14 @@ public class ConnectivityManager { * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. * {@hide} */ public boolean setRadios(boolean turnOn) { try { return mService.setRadios(turnOn); } catch (RemoteException e) { return false; } } // TODO - check for any callers and remove // public boolean setRadios(boolean turnOn) { // try { // return mService.setRadios(turnOn); // } catch (RemoteException e) { // return false; // } // } /** * Tells a given networkType to set its radio power state as directed. Loading @@ -743,13 +738,14 @@ public class ConnectivityManager { * {@link android.Manifest.permission#CHANGE_NETWORK_STATE}. * {@hide} */ public boolean setRadio(int networkType, boolean turnOn) { try { return mService.setRadio(networkType, turnOn); } catch (RemoteException e) { return false; } } // TODO - check for any callers and remove // public boolean setRadio(int networkType, boolean turnOn) { // try { // return mService.setRadio(networkType, turnOn); // } catch (RemoteException e) { // return false; // } // } /** * Tells the underlying networking system that the caller wants to Loading Loading @@ -1594,4 +1590,81 @@ public class ConnectivityManager { mService.registerNetworkFactory(messenger); } catch (RemoteException e) { } } /** {@hide} */ public void registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp, NetworkCapabilities nc, int score) { try { mService.registerNetworkAgent(messenger, ni, lp, nc, score); } catch (RemoteException e) { } } /** Interface for NetworkRequest callbacks {@hide} */ public static class NetworkCallbacks { public static final int PRECHECK = 1; public static final int AVAILABLE = 2; public static final int LOSING = 3; public static final int LOST = 4; public static final int UNAVAIL = 5; public static final int CAP_CHANGED = 6; public static final int PROP_CHANGED = 7; public static final int CANCELED = 8; /** * @hide * Called whenever the framework connects to a network that it may use to * satisfy this request */ public void onPreCheck(NetworkRequest networkRequest, Network network) {} /** * Called when the framework connects and has validated the new network. */ public void onAvailable(NetworkRequest networkRequest, Network network) {} /** * Called when the framework is losing the network. Often paired with an * onAvailable call with the new replacement network for graceful handover. * This may not be called if we have a hard loss (loss without warning). * This may be followed by either an onLost call or an onAvailable call for this * network depending on if we lose or regain it. */ public void onLosing(NetworkRequest networkRequest, Network network, int maxSecToLive) {} /** * Called when the framework has a hard loss of the network or when the * graceful failure ends. Note applications should only request this callback * if the application is willing to track the Available and Lost callbacks * together, else the application may think it has no network when it * really does (A Avail, B Avail, A Lost.. still have B). */ public void onLost(NetworkRequest networkRequest, Network network) {} /** * Called if no network is found in the given timeout time. If no timeout is given, * this will not be called. */ public void onUnavailable(NetworkRequest networkRequest) {} /** * Called when the network the framework connected to for this request * changes capabilities but still satisfies the stated need. */ public void onCapabilitiesChanged(NetworkRequest networkRequest, Network network, NetworkCapabilities networkCapabilities) {} /** * Called when the network the framework connected to for this request * changes properties. */ public void onPropertiesChanged(NetworkRequest networkRequest, Network network, LinkProperties linkProperties) {} /** * Called when a CancelRequest call concludes and the registered callbacks will * no longer be used. */ public void onCanceled(NetworkRequest networkRequest) {} } }
core/java/android/net/ConnectivityServiceProtocol.java +65 −4 Original line number Diff line number Diff line Loading @@ -23,15 +23,41 @@ import static com.android.internal.util.Protocol.BASE_CONNECTIVITY_SERVICE; * @hide */ public class ConnectivityServiceProtocol { private ConnectivityServiceProtocol() {} private static final int BASE = BASE_CONNECTIVITY_SERVICE; private ConnectivityServiceProtocol() {} /** * This is a contract between ConnectivityService and various bearers. * A NetworkFactory is an abstract entity that creates NetworkAgent objects. * The bearers register with ConnectivityService using * ConnectivityManager.registerNetworkFactory, where they pass in a Messenger * to be used to deliver the following Messages. */ public static class NetworkFactoryProtocol { private NetworkFactoryProtocol() {} /** * Pass a network request to the transport * Pass a network request to the bearer. If the bearer believes it can * satisfy the request it should connect to the network and create a * NetworkAgent. Once the NetworkAgent is fully functional it will * register itself with ConnectivityService using registerNetworkAgent. * If the bearer cannot immediately satisfy the request (no network, * user disabled the radio, lower-scored network) it should remember * any NetworkRequests it may be able to satisfy in the future. It may * disregard any that it will never be able to service, for example * those requiring a different bearer. * msg.obj = NetworkRequest * msg.arg1 = score - the score of the any network currently satisfying this * request. If this bearer knows in advance it cannot * exceed this score it should not try to connect, holding the request * for the future. * Note that subsequent events may give a different (lower * or higher) score for this request, transmitted to each * NetworkFactory through additional CMD_REQUEST_NETWORK msgs * with the same NetworkRequest but an updated score. * Also, network conditions may change for this bearer * allowing for a better score in the future. */ public static final int CMD_REQUEST_NETWORK = BASE; Loading @@ -42,7 +68,42 @@ public class ConnectivityServiceProtocol { public static final int CMD_CANCEL_REQUEST = BASE + 1; } public static class NetworkAgentProtocol { private NetworkAgentProtocol() {} /** * TODO - move to NetworkMonitor and document */ public static class NetworkMonitorProtocol { private NetworkMonitorProtocol() {} /** * Inform NetworkMonitor that their network is connected. * Initiates Network Validation. */ public static final int CMD_NETWORK_CONNECTED = BASE + 200; /** * Inform ConnectivityService that the network is validated. * obj = NetworkAgent */ public static final int EVENT_NETWORK_VALIDATED = BASE + 201; /** * Inform NetworkMonitor to linger a network. The Monitor should * start a timer and/or start watching for zero live connections while * moving towards LINGER_COMPLETE. After the Linger period expires * (or other events mark the end of the linger state) the LINGER_COMPLETE * event should be sent to ConnectivityService and ConnectivityService * will shut down the network, telling the corresponding NetworkAgent * to disconnect. If a CMD_NETWORK_CONNECTED happens before the LINGER completes * it indicates further desire to keep the network alive and so * the LINGER is aborted. * TODO - figure out who manages/does this simple state machine */ public static final int CMD_NETWORK_LINGER = BASE + 202; /** * Inform ConnectivityService that the network LINGER period has * expired. * obj = NetworkAgent */ public static final int EVENT_NETWORK_LINGER_COMPLETE = BASE + 203; } }
core/java/android/net/IConnectivityManager.aidl +5 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.net; import android.net.LinkQualityInfo; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.NetworkQuotaInfo; import android.net.NetworkState; Loading @@ -41,10 +42,6 @@ interface IConnectivityManager // Keep this in sync with framework/native/services/connectivitymanager/ConnectivityManager.h void markSocketAsUser(in ParcelFileDescriptor socket, int uid); void setNetworkPreference(int pref); int getNetworkPreference(); NetworkInfo getActiveNetworkInfo(); NetworkInfo getActiveNetworkInfoForUid(int uid); NetworkInfo getNetworkInfo(int networkType); Loading @@ -62,10 +59,6 @@ interface IConnectivityManager NetworkQuotaInfo getActiveNetworkQuotaInfo(); boolean isActiveNetworkMetered(); boolean setRadios(boolean onOff); boolean setRadio(int networkType, boolean turnOn); int startUsingNetworkFeature(int networkType, in String feature, in IBinder binder); Loading Loading @@ -147,9 +140,12 @@ interface IConnectivityManager LinkQualityInfo[] getAllLinkQualityInfo(); void setProvisioningNotificationVisible(boolean visible, int networkType, in String extraInfo, in String url); void setProvisioningNotificationVisible(boolean visible, int networkType, in String extraInfo, in String url); void setAirplaneMode(boolean enable); void registerNetworkFactory(in Messenger messenger); void registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp, in NetworkCapabilities nc, int score); }