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

Commit 43d2a170 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Move "metered" persistence to WifiConfiguration.

For a long time we've had a nasty tangled dependency between Wi-Fi
and NPMS, since they both persisted different details for configured
networks.  As part of preparing for new carrier data plan APIs, move
the tracking of meteredness over to WifiConfiguration.

This also cleans up how meteredness is communicated through
NetworkAgents to rely completely on NET_CAPABILITY_NOT_METERED by
removing the metered flag on NetworkInfo, which has caused confusion
and staleness.

Migrates any existing user-configured metered networks over to
WifiConfiguration once the device finishes booting.

Remove support for NetworkQuotaInfo, since this information can no
longer be made available to apps.  Frustratingly, some apps are
using it, so keep the object around returning stub values, and shame
them in the logs.

Bug: 63391323
Test: builds, boots, Wi-Fi policy is upgraded
Exempt-From-Owner-Approval: Bug 63673347
Change-Id: I64f865ddeb65cfcd330f8d2a847368abdf960a07
parent 183f9ac2
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -1720,14 +1720,8 @@ public class ConnectivityManager {
        // ignored
    }

    /**
     * Return quota status for the current active network, or {@code null} if no
     * network is active. Quota status can change rapidly, so these values
     * shouldn't be cached.
     *
     * @hide
     */
    @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
    /** {@hide} */
    @Deprecated
    public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
        try {
            return mService.getActiveNetworkQuotaInfo();
+1 −1
Original line number Diff line number Diff line
@@ -63,9 +63,9 @@ interface INetworkPolicyManager {
    int getRestrictBackgroundByCaller();

    void setDeviceIdleMode(boolean enabled);
    void setWifiMeteredOverride(String networkId, int meteredOverride);

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

    void factoryReset(String subscriber);
}
+1 −31
Original line number Diff line number Diff line
@@ -16,8 +16,8 @@

package android.net;

import android.os.Parcelable;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.annotations.VisibleForTesting;

@@ -121,7 +121,6 @@ public class NetworkInfo implements Parcelable {
    private boolean mIsFailover;
    private boolean mIsAvailable;
    private boolean mIsRoaming;
    private boolean mIsMetered;

    /**
     * @hide
@@ -154,7 +153,6 @@ public class NetworkInfo implements Parcelable {
                mIsFailover = source.mIsFailover;
                mIsAvailable = source.mIsAvailable;
                mIsRoaming = source.mIsRoaming;
                mIsMetered = source.mIsMetered;
            }
        }
    }
@@ -326,31 +324,6 @@ public class NetworkInfo implements Parcelable {
        }
    }

    /**
     * Returns if this network is metered. A network is classified as metered
     * when the user is sensitive to heavy data usage on that connection due to
     * monetary costs, data limitations or battery/performance issues. You
     * should check this before doing large data transfers, and warn the user or
     * delay the operation until another network is available.
     *
     * @return {@code true} if large transfers should be avoided, otherwise
     *         {@code false}.
     * @hide
     */
    public boolean isMetered() {
        synchronized (this) {
            return mIsMetered;
        }
    }

    /** {@hide} */
    @VisibleForTesting
    public void setMetered(boolean isMetered) {
        synchronized (this) {
            mIsMetered = isMetered;
        }
    }

    /**
     * Reports the current coarse-grained state of the network.
     * @return the coarse-grained state
@@ -434,7 +407,6 @@ public class NetworkInfo implements Parcelable {
            append(", failover: ").append(mIsFailover).
            append(", available: ").append(mIsAvailable).
            append(", roaming: ").append(mIsRoaming).
            append(", metered: ").append(mIsMetered).
            append("]");
            return builder.toString();
        }
@@ -457,7 +429,6 @@ public class NetworkInfo implements Parcelable {
            dest.writeInt(mIsFailover ? 1 : 0);
            dest.writeInt(mIsAvailable ? 1 : 0);
            dest.writeInt(mIsRoaming ? 1 : 0);
            dest.writeInt(mIsMetered ? 1 : 0);
            dest.writeString(mReason);
            dest.writeString(mExtraInfo);
        }
@@ -476,7 +447,6 @@ public class NetworkInfo implements Parcelable {
            netInfo.mIsFailover = in.readInt() != 0;
            netInfo.mIsAvailable = in.readInt() != 0;
            netInfo.mIsRoaming = in.readInt() != 0;
            netInfo.mIsMetered = in.readInt() != 0;
            netInfo.mReason = in.readString();
            netInfo.mExtraInfo = in.readString();
            return netInfo;
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
    public long limitBytes;
    public long lastWarningSnooze;
    public long lastLimitSnooze;
    public boolean metered;
    @Deprecated public boolean metered;
    public boolean inferred;

    private static final long DEFAULT_MTU = 1500;
+11 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.DebugUtils;
@@ -400,4 +402,13 @@ public class NetworkPolicyManager {
    public static boolean isProcStateAllowedWhileOnRestrictBackground(int procState) {
        return procState <= ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
    }

    public static String resolveNetworkId(WifiConfiguration config) {
        return WifiInfo.removeDoubleQuotes(config.isPasspoint()
                ? config.providerFriendlyName : config.SSID);
    }

    public static String resolveNetworkId(String ssid) {
        return WifiInfo.removeDoubleQuotes(ssid);
    }
}
Loading