Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f7cbf0e authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

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
parent a94afeb5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11811,6 +11811,7 @@ package android.net {
    method public deprecated boolean getBackgroundDataSetting();
    method public android.net.NetworkInfo getNetworkInfo(int);
    method public int getNetworkPreference();
    method public boolean isActiveNetworkMetered();
    method public static boolean isNetworkTypeValid(int);
    method public boolean requestRouteToHost(int, int);
    method public void setNetworkPreference(int);
+20 −4
Original line number Diff line number Diff line
@@ -373,9 +373,10 @@ 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 {
@@ -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;
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ interface IConnectivityManager
    NetworkState[] getAllNetworkState();

    NetworkQuotaInfo getActiveNetworkQuotaInfo();
    boolean isActiveNetworkMetered();

    boolean setRadios(boolean onOff);

+1 −0
Original line number Diff line number Diff line
@@ -50,5 +50,6 @@ interface INetworkPolicyManager {
    boolean getRestrictBackground();

    NetworkQuotaInfo getNetworkQuotaInfo(in NetworkState state);
    boolean isNetworkMetered(in NetworkState state);

}
+13 −0
Original line number Diff line number Diff line
@@ -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();
Loading