API to report if active network is metered. am: d00b130332

Original change: undetermined

Change-Id: If4686b1c1508999712d17e992b938b41099cd911
This commit is contained in:
Jeff Sharkey
2021-05-31 12:28:33 +00:00
committed by Automerger Merge Worker
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();