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

Commit 4bdcbf46 authored by Chiachang Wang's avatar Chiachang Wang Committed by Gerrit Code Review
Browse files

Merge "[IT4.21] Update the label type of idle timer"

parents 82ffaf2a 3ce298df
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -85,14 +85,14 @@ oneway interface INetworkManagementEventObserver {
    /**
    /**
     * Interface data activity status is changed.
     * Interface data activity status is changed.
     *
     *
     * @param networkType The legacy network type of the data activity change.
     * @param transportType The transport type of the data activity change.
     * @param active  True if the interface is actively transmitting data, false if it is idle.
     * @param active  True if the interface is actively transmitting data, false if it is idle.
     * @param tsNanos Elapsed realtime in nanos when the state of the network interface changed.
     * @param tsNanos Elapsed realtime in nanos when the state of the network interface changed.
     * @param uid Uid of this event. It represents the uid that was responsible for waking the
     * @param uid Uid of this event. It represents the uid that was responsible for waking the
     *            radio. For those events that are reported by system itself, not from specific uid,
     *            radio. For those events that are reported by system itself, not from specific uid,
     *            use -1 for the events which means no uid.
     *            use -1 for the events which means no uid.
     */
     */
    void interfaceClassDataActivityChanged(int networkType, boolean active, long tsNanos, int uid);
    void interfaceClassDataActivityChanged(int transportType, boolean active, long tsNanos, int uid);


    /**
    /**
     * Information about available DNS servers has been received.
     * Information about available DNS servers has been received.
+1 −1
Original line number Original line Diff line number Diff line
@@ -64,7 +64,7 @@ public class BaseNetworkObserver extends INetworkManagementEventObserver.Stub {
    }
    }


    @Override
    @Override
    public void interfaceClassDataActivityChanged(int networkType, boolean active, long tsNanos,
    public void interfaceClassDataActivityChanged(int transportType, boolean active, long tsNanos,
            int uid) {
            int uid) {
        // default no-op
        // default no-op
    }
    }
+21 −5
Original line number Original line Diff line number Diff line
@@ -1803,12 +1803,28 @@ public class ConnectivityService extends IConnectivityManager.Stub


    private INetworkManagementEventObserver mDataActivityObserver = new BaseNetworkObserver() {
    private INetworkManagementEventObserver mDataActivityObserver = new BaseNetworkObserver() {
        @Override
        @Override
        public void interfaceClassDataActivityChanged(int networkType, boolean active, long tsNanos,
        public void interfaceClassDataActivityChanged(int transportType, boolean active,
                int uid) {
                long tsNanos, int uid) {
            sendDataActivityBroadcast(networkType, active, tsNanos);
            sendDataActivityBroadcast(transportTypeToLegacyType(transportType), active, tsNanos);
        }
        }
    };
    };


    // This is deprecated and only to support legacy use cases.
    private int transportTypeToLegacyType(int type) {
        switch (type) {
            case NetworkCapabilities.TRANSPORT_CELLULAR:
                return ConnectivityManager.TYPE_MOBILE;
            case NetworkCapabilities.TRANSPORT_WIFI:
                return ConnectivityManager.TYPE_WIFI;
            case NetworkCapabilities.TRANSPORT_BLUETOOTH:
                return ConnectivityManager.TYPE_BLUETOOTH;
            case NetworkCapabilities.TRANSPORT_ETHERNET:
                return ConnectivityManager.TYPE_ETHERNET;
            default:
                loge("Unexpected transport in transportTypeToLegacyType: " + type);
        }
        return ConnectivityManager.TYPE_NONE;
    }
    /**
    /**
     * Ensures that the system cannot call a particular method.
     * Ensures that the system cannot call a particular method.
     */
     */
@@ -2392,13 +2408,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
            timeout = Settings.Global.getInt(mContext.getContentResolver(),
            timeout = Settings.Global.getInt(mContext.getContentResolver(),
                                             Settings.Global.DATA_ACTIVITY_TIMEOUT_MOBILE,
                                             Settings.Global.DATA_ACTIVITY_TIMEOUT_MOBILE,
                                             10);
                                             10);
            type = ConnectivityManager.TYPE_MOBILE;
            type = NetworkCapabilities.TRANSPORT_CELLULAR;
        } else if (networkAgent.networkCapabilities.hasTransport(
        } else if (networkAgent.networkCapabilities.hasTransport(
                NetworkCapabilities.TRANSPORT_WIFI)) {
                NetworkCapabilities.TRANSPORT_WIFI)) {
            timeout = Settings.Global.getInt(mContext.getContentResolver(),
            timeout = Settings.Global.getInt(mContext.getContentResolver(),
                                             Settings.Global.DATA_ACTIVITY_TIMEOUT_WIFI,
                                             Settings.Global.DATA_ACTIVITY_TIMEOUT_WIFI,
                                             15);
                                             15);
            type = ConnectivityManager.TYPE_WIFI;
            type = NetworkCapabilities.TRANSPORT_WIFI;
        } else {
        } else {
            return; // do not track any other networks
            return; // do not track any other networks
        }
        }
+3 −3
Original line number Original line Diff line number Diff line
@@ -7428,7 +7428,7 @@ public class ConnectivityServiceTest {
        mCellNetworkAgent.connect(true);
        mCellNetworkAgent.connect(true);
        networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
        networkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
        verify(mNetworkManagementService, times(1)).addIdleTimer(eq(MOBILE_IFNAME), anyInt(),
        verify(mNetworkManagementService, times(1)).addIdleTimer(eq(MOBILE_IFNAME), anyInt(),
                eq(ConnectivityManager.TYPE_MOBILE));
                eq(NetworkCapabilities.TRANSPORT_CELLULAR));


        mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
        mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
        final LinkProperties wifiLp = new LinkProperties();
        final LinkProperties wifiLp = new LinkProperties();
@@ -7442,7 +7442,7 @@ public class ConnectivityServiceTest {
        networkCallback.expectCallback(CallbackEntry.LOSING, mCellNetworkAgent);
        networkCallback.expectCallback(CallbackEntry.LOSING, mCellNetworkAgent);
        networkCallback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mWiFiNetworkAgent);
        networkCallback.expectCapabilitiesWith(NET_CAPABILITY_VALIDATED, mWiFiNetworkAgent);
        verify(mNetworkManagementService, times(1)).addIdleTimer(eq(WIFI_IFNAME), anyInt(),
        verify(mNetworkManagementService, times(1)).addIdleTimer(eq(WIFI_IFNAME), anyInt(),
                eq(ConnectivityManager.TYPE_WIFI));
                eq(NetworkCapabilities.TRANSPORT_WIFI));
        verify(mNetworkManagementService, times(1)).removeIdleTimer(eq(MOBILE_IFNAME));
        verify(mNetworkManagementService, times(1)).removeIdleTimer(eq(MOBILE_IFNAME));


        // Disconnect wifi and switch back to cell
        // Disconnect wifi and switch back to cell
@@ -7452,7 +7452,7 @@ public class ConnectivityServiceTest {
        assertNoCallbacks(networkCallback);
        assertNoCallbacks(networkCallback);
        verify(mNetworkManagementService, times(1)).removeIdleTimer(eq(WIFI_IFNAME));
        verify(mNetworkManagementService, times(1)).removeIdleTimer(eq(WIFI_IFNAME));
        verify(mNetworkManagementService, times(1)).addIdleTimer(eq(MOBILE_IFNAME), anyInt(),
        verify(mNetworkManagementService, times(1)).addIdleTimer(eq(MOBILE_IFNAME), anyInt(),
                eq(ConnectivityManager.TYPE_MOBILE));
                eq(NetworkCapabilities.TRANSPORT_CELLULAR));


        // reconnect wifi
        // reconnect wifi
        mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
        mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);