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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ interface IConnectivityManager
|
||||
NetworkState[] getAllNetworkState();
|
||||
|
||||
NetworkQuotaInfo getActiveNetworkQuotaInfo();
|
||||
boolean isActiveNetworkMetered();
|
||||
|
||||
boolean setRadios(boolean onOff);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user