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

Commit 1f12cb52 authored by Vinit Deshapnde's avatar Vinit Deshapnde
Browse files

Introduce network link quality statistics

This change starts tracking traffic quality data for WiFi and mobile
networks. The quality is tracked based on incidental traffic, and not
on specific measurements. Theoretical bandwidths are hard-coded, as
well as sampling interval; although sampling interval can be changed
by setting a system policy.

Bugs filed to remove shortcomings of this change -

10342372 Change LinkInfo name to something better
10342318 Move hardcoded values of MobileLinkInfo to resources
         so they can be updated without changing code

Bug: 10006249

Change-Id: I83d8c7594da20fe53abbd5e1f909b1f606b035bb
parent 2241d45c
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.bluetooth;

import android.net.BaseNetworkStateTracker;
import android.os.IBinder;
import android.os.ServiceManager;
import android.os.INetworkManagementService;
@@ -54,7 +55,7 @@ import java.util.concurrent.atomic.AtomicReference;
 *
 * @hide
 */
public class BluetoothTetheringDataTracker implements NetworkStateTracker {
public class BluetoothTetheringDataTracker extends BaseNetworkStateTracker {
    private static final String NETWORKTYPE = "BLUETOOTH_TETHER";
    private static final String TAG = "BluetoothTethering";
    private static final boolean DBG = true;
@@ -66,18 +67,12 @@ public class BluetoothTetheringDataTracker implements NetworkStateTracker {
    private AtomicBoolean mDefaultRouteSet = new AtomicBoolean(false);

    private final Object mLinkPropertiesLock = new Object();
    private LinkProperties mLinkProperties;

    private LinkCapabilities mLinkCapabilities;

    private final Object mNetworkInfoLock = new Object();
    private NetworkInfo mNetworkInfo;

    private BluetoothPan mBluetoothPan;
    private static String mRevTetheredIface;
    /* For sending events to connectivity service handler */
    private Handler mCsHandler;
    protected Context mContext;
    private static BluetoothTetheringDataTracker sInstance;
    private BtdtHandler mBtdtHandler;
    private AtomicReference<AsyncChannel> mAsyncChannel = new AtomicReference<AsyncChannel>(null);
+35 −5
Original line number Diff line number Diff line
@@ -57,6 +57,10 @@ public abstract class BaseNetworkStateTracker implements NetworkStateTracker {
        mLinkCapabilities = new LinkCapabilities();
    }

    protected BaseNetworkStateTracker() {
        // By default, let the sub classes construct everything
    }

    @Deprecated
    protected Handler getTargetHandler() {
        return mTarget;
@@ -73,29 +77,36 @@ public abstract class BaseNetworkStateTracker implements NetworkStateTracker {
    }

    @Override
    public final void startMonitoring(Context context, Handler target) {
    public void startMonitoring(Context context, Handler target) {
        mContext = Preconditions.checkNotNull(context);
        mTarget = Preconditions.checkNotNull(target);
        startMonitoringInternal();
    }

    protected abstract void startMonitoringInternal();
    protected void startMonitoringInternal() {

    }

    @Override
    public final NetworkInfo getNetworkInfo() {
    public NetworkInfo getNetworkInfo() {
        return new NetworkInfo(mNetworkInfo);
    }

    @Override
    public final LinkProperties getLinkProperties() {
    public LinkProperties getLinkProperties() {
        return new LinkProperties(mLinkProperties);
    }

    @Override
    public final LinkCapabilities getLinkCapabilities() {
    public LinkCapabilities getLinkCapabilities() {
        return new LinkCapabilities(mLinkCapabilities);
    }

    @Override
    public LinkInfo getLinkInfo() {
        return null;
    }

    @Override
    public void captivePortalCheckComplete() {
        // not implemented
@@ -176,4 +187,23 @@ public abstract class BaseNetworkStateTracker implements NetworkStateTracker {
    public void supplyMessenger(Messenger messenger) {
        // not supported on this network
    }

    @Override
    public String getNetworkInterfaceName() {
        if (mLinkProperties != null) {
            return mLinkProperties.getInterfaceName();
        } else {
            return null;
        }
    }

    @Override
    public void startSampling(SamplingDataTracker.SamplingSnapshot s) {
        // nothing to do
    }

    @Override
    public void stopSampling(SamplingDataTracker.SamplingSnapshot s) {
        // nothing to do
    }
}
+39 −0
Original line number Diff line number Diff line
@@ -1442,4 +1442,43 @@ public class ConnectivityManager {
        }
        return null;
    }

    /**
     * get the information about a specific network link
     * @hide
     */
    public LinkInfo getLinkInfo(int networkType) {
        try {
            LinkInfo li = mService.getLinkInfo(networkType);
            return li;
        } catch (RemoteException e) {
            return null;
        }
    }

    /**
     * get the information of currently active network link
     * @hide
     */
    public LinkInfo getActiveLinkInfo() {
        try {
            LinkInfo li = mService.getActiveLinkInfo();
            return li;
        } catch (RemoteException e) {
            return null;
        }
    }

    /**
     * get the information of all network links
     * @hide
     */
    public LinkInfo[] getAllLinkInfo() {
        try {
            LinkInfo[] li = mService.getAllLinkInfo();
            return li;
        } catch (RemoteException e) {
            return null;
        }
    }
}
+1 −5
Original line number Diff line number Diff line
@@ -29,18 +29,14 @@ import android.util.Slog;
 *
 * {@hide}
 */
public class DummyDataStateTracker implements NetworkStateTracker {
public class DummyDataStateTracker extends BaseNetworkStateTracker {

    private static final String TAG = "DummyDataStateTracker";
    private static final boolean DBG = true;
    private static final boolean VDBG = false;

    private NetworkInfo mNetworkInfo;
    private boolean mTeardownRequested = false;
    private Handler mTarget;
    private Context mContext;
    private LinkProperties mLinkProperties;
    private LinkCapabilities mLinkCapabilities;
    private boolean mPrivateDnsRouteSet = false;
    private boolean mDefaultRouteSet = false;

+1 −5
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 * ConnectivityService.
 * @hide
 */
public class EthernetDataTracker implements NetworkStateTracker {
public class EthernetDataTracker extends BaseNetworkStateTracker {
    private static final String NETWORKTYPE = "ETHERNET";
    private static final String TAG = "Ethernet";

@@ -46,15 +46,11 @@ public class EthernetDataTracker implements NetworkStateTracker {
    private AtomicBoolean mDefaultRouteSet = new AtomicBoolean(false);

    private static boolean mLinkUp;
    private LinkProperties mLinkProperties;
    private LinkCapabilities mLinkCapabilities;
    private NetworkInfo mNetworkInfo;
    private InterfaceObserver mInterfaceObserver;
    private String mHwAddr;

    /* For sending events to connectivity service handler */
    private Handler mCsHandler;
    private Context mContext;

    private static EthernetDataTracker sInstance;
    private static String sIfaceMatch = "";
Loading