API to report if active network is metered.

Report to developers if active network is "metered" and define it
as the user being sensitive to heavy data usage.

Bug: 3001465
Change-Id: I855ca3cd3eb1de3c4814148d70ccf24957af898a
This commit is contained in:
Jeff Sharkey
2012-04-12 18:34:54 -07:00
parent 078d356a9b
commit d00b130332
3 changed files with 34 additions and 4 deletions

View File

@@ -373,10 +373,11 @@ public class ConnectivityManager {
}
/**
* Gets you info about the current data network.
* Call {@link NetworkInfo#isConnected()} on the returned {@link NetworkInfo}
* to check if the device has a data connection.
*/
* Returns details about the currently active data network. When connected,
* this network is the default route for outgoing connections. You should
* always check {@link NetworkInfo#isConnected()} before initiating network
* traffic. This may return {@code null} when no networks are available.
*/
public NetworkInfo getActiveNetworkInfo() {
try {
return mService.getActiveNetworkInfo();
@@ -856,4 +857,19 @@ public class ConnectivityManager {
} catch (RemoteException e) {}
return false;
}
/**
* Returns if the currently active data network is metered. A network is
* classified as metered when the user is sensitive to heavy data usage on
* that connection. You should check this before doing large data transfers,
* and warn the user or delay the operation until another network is
* available.
*/
public boolean isActiveNetworkMetered() {
try {
return mService.isActiveNetworkMetered();
} catch (RemoteException e) {
return false;
}
}
}

View File

@@ -51,6 +51,7 @@ interface IConnectivityManager
NetworkState[] getAllNetworkState();
NetworkQuotaInfo getActiveNetworkQuotaInfo();
boolean isActiveNetworkMetered();
boolean setRadios(boolean onOff);

View File

@@ -875,6 +875,19 @@ private NetworkStateTracker makeWimaxStateTracker() {
return null;
}
@Override
public boolean isActiveNetworkMetered() {
enforceAccessPermission();
final NetworkState state = getNetworkStateUnchecked(mActiveDefaultNetwork);
if (state != null) {
try {
return mPolicyManager.isNetworkMetered(state);
} catch (RemoteException e) {
}
}
return false;
}
public boolean setRadios(boolean turnOn) {
boolean result = true;
enforceChangePermission();