Add an API hint for metered multipath traffic.

This allows an application that knows how to provide seamless
network connectivity (e.g., using QUIC multipath) to find out if
doing so is desired.

(cherry picked from commit 48a2a32bdd)

Test: builds, boots, runtest frameworks-net passes.
Bug: 34630278
Change-Id: Ic7fd0b9e1cd879fdfaf84009d7125391895e9087
This commit is contained in:
Lorenzo Colitti
2017-01-24 18:08:41 +09:00
parent 3145827105
commit e454b43d3f
5 changed files with 151 additions and 5 deletions

View File

@@ -3406,6 +3406,75 @@ public class ConnectivityManager {
}
}
/**
* It is acceptable to briefly use multipath data to provide seamless connectivity for
* time-sensitive user-facing operations when the system default network is temporarily
* unresponsive. The amount of data should be limited (less than one megabyte), and the
* operation should be infrequent to ensure that data usage is limited.
*
* An example of such an operation might be a time-sensitive foreground activity, such as a
* voice command, that the user is performing while walking out of range of a Wi-Fi network.
*/
public static final int MULTIPATH_PREFERENCE_HANDOVER = 1 << 0;
/**
* It is acceptable to use small amounts of multipath data on an ongoing basis to provide
* a backup channel for traffic that is primarily going over another network.
*
* An example might be maintaining backup connections to peers or servers for the purpose of
* fast fallback if the default network is temporarily unresponsive or disconnects. The traffic
* on backup paths should be negligible compared to the traffic on the main path.
*/
public static final int MULTIPATH_PREFERENCE_RELIABILITY = 1 << 1;
/**
* It is acceptable to use metered data to improve network latency and performance.
*/
public static final int MULTIPATH_PREFERENCE_PERFORMANCE = 1 << 2;
/**
* Return value to use for unmetered networks. On such networks we currently set all the flags
* to true.
* @hide
*/
public static final int MULTIPATH_PREFERENCE_UNMETERED =
MULTIPATH_PREFERENCE_HANDOVER |
MULTIPATH_PREFERENCE_RELIABILITY |
MULTIPATH_PREFERENCE_PERFORMANCE;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, value = {
MULTIPATH_PREFERENCE_HANDOVER,
MULTIPATH_PREFERENCE_RELIABILITY,
MULTIPATH_PREFERENCE_PERFORMANCE,
})
public @interface MultipathPreference {
}
/**
* Provides a hint to the calling application on whether it is desirable to use the
* multinetwork APIs (e.g., {@link Network#openConnection}, {@link Network#bindSocket}, etc.)
* for multipath data transfer on this network when it is not the system default network.
* Applications desiring to use multipath network protocols should call this method before
* each such operation.
* <p>
* This method requires the caller to hold the permission
* {@link android.Manifest.permission#ACCESS_NETWORK_STATE}.
*
* @param network The network on which the application desires to use multipath data.
* If {@code null}, this method will return the a preference that will generally
* apply to metered networks.
* @return a bitwise OR of zero or more of the {@code MULTIPATH_PREFERENCE_*} constants.
*/
public @MultipathPreference int getMultipathPreference(Network network) {
try {
return mService.getMultipathPreference(network);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Resets all connectivity manager settings back to factory defaults.
* @hide

View File

@@ -161,6 +161,8 @@ interface IConnectivityManager
void setAcceptUnvalidated(in Network network, boolean accept, boolean always);
void setAvoidUnvalidated(in Network network);
int getMultipathPreference(in Network Network);
int getRestoreDefaultNetworkDelay(int networkType);
boolean addVpnAddress(String address, int prefixLength);