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

Commit 5de073a6 authored by Christopher Wiley's avatar Christopher Wiley Committed by Mitchell Wills
Browse files

Remove WiFi related methods from NetworkManagementService

These are no longer necessary, since WiFi manages its own details.

Bug: 30041228
Change-Id: Ia3824da43367ae74d3f3a204318cfe5470d74957
Test: Compiles
(cherry picked from commit 212b95f5)
parent 079b2f34
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.net.Network;
import android.net.NetworkStats;
import android.net.RouteInfo;
import android.net.UidRange;
import android.net.wifi.WifiConfiguration;
import android.os.INetworkActivityListener;

/**
@@ -216,22 +215,6 @@ interface INetworkManagementService
     */
    void detachPppd(String tty);

    /**
     * Load firmware for operation in the given mode. Currently the three
     * modes supported are "AP", "STA" and "P2P".
     */
    void wifiFirmwareReload(String wlanIface, String mode);

    /**
     * Start Wifi Access Point
     */
    void startAccessPoint(in WifiConfiguration wifiConfig, String iface);

    /**
     * Stop Wifi Access Point
     */
    void stopAccessPoint(String iface);

    /**
     ** DATA USAGE RELATED
     **/
+5 −98
Original line number Diff line number Diff line
@@ -216,7 +216,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    private CountDownLatch mConnectedSignal = new CountDownLatch(1);

    private final RemoteCallbackList<INetworkManagementEventObserver> mObservers =
            new RemoteCallbackList<INetworkManagementEventObserver>();
            new RemoteCallbackList<>();

    private final NetworkStatsFactory mStatsFactory = new NetworkStatsFactory();

@@ -289,7 +289,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    private int mLastPowerStateFromWifi = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;

    private final RemoteCallbackList<INetworkActivityListener> mNetworkActivityListeners =
            new RemoteCallbackList<INetworkActivityListener>();
            new RemoteCallbackList<>();
    private boolean mNetworkActive;

    /**
@@ -1161,7 +1161,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub

    private ArrayList<String> readRouteList(String filename) {
        FileInputStream fstream = null;
        ArrayList<String> list = new ArrayList<String>();
        ArrayList<String> list = new ArrayList<>();

        try {
            fstream = new FileInputStream(filename);
@@ -1285,7 +1285,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
        List<RouteInfo> routes = new ArrayList<RouteInfo>();
        List<RouteInfo> routes = new ArrayList<>();
        // The RouteInfo constructor truncates the LinkAddress to a network prefix, thus making it
        // suitable to use as a route destination.
        routes.add(new RouteInfo(getInterfaceConfig(iface).getLinkAddress(), null, iface));
@@ -1345,7 +1345,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    }

    private List<InterfaceAddress> excludeLinkLocal(List<InterfaceAddress> addresses) {
        ArrayList<InterfaceAddress> filtered = new ArrayList<InterfaceAddress>(addresses.size());
        ArrayList<InterfaceAddress> filtered = new ArrayList<>(addresses.size());
        for (InterfaceAddress ia : addresses) {
            if (!ia.getAddress().isLinkLocalAddress())
                filtered.add(ia);
@@ -1458,99 +1458,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        }
    }

    /**
     * Private method used to call execute for a command given the provided arguments.
     *
     * This function checks the returned NativeDaemonEvent for the provided expected response code
     * and message.  If either of these is not correct, an error is logged.
     *
     * @param String command The command to execute.
     * @param Object[] args If needed, arguments for the command to execute.
     * @param int expectedResponseCode The code expected to be returned in the corresponding event.
     * @param String expectedResponseMessage The message expected in the returned event.
     * @param String logMsg The message to log as an error (TAG will be applied).
     */
    private void executeOrLogWithMessage(String command, Object[] args,
            int expectedResponseCode, String expectedResponseMessage, String logMsg)
            throws NativeDaemonConnectorException {
        NativeDaemonEvent event = mConnector.execute(command, args);
        if (event.getCode() != expectedResponseCode
                || !event.getMessage().equals(expectedResponseMessage)) {
            Log.e(TAG, logMsg + ": event = " + event);
        }
    }

    @Override
    public void startAccessPoint(WifiConfiguration wifiConfig, String wlanIface) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        Object[] args;
        String logMsg = "startAccessPoint Error setting up softap";
        try {
            if (wifiConfig == null) {
                args = new Object[] {"set", wlanIface};
            } else {
                args = new Object[] {"set", wlanIface, wifiConfig.SSID,
                        "broadcast", Integer.toString(wifiConfig.apChannel),
                        getSecurityType(wifiConfig), new SensitiveArg(wifiConfig.preSharedKey)};
            }
            executeOrLogWithMessage(SOFT_AP_COMMAND, args, NetdResponseCode.SoftapStatusResult,
                    SOFT_AP_COMMAND_SUCCESS, logMsg);

            logMsg = "startAccessPoint Error starting softap";
            args = new Object[] {"startap"};
            executeOrLogWithMessage(SOFT_AP_COMMAND, args, NetdResponseCode.SoftapStatusResult,
                    SOFT_AP_COMMAND_SUCCESS, logMsg);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
    }

    private static String getSecurityType(WifiConfiguration wifiConfig) {
        switch (wifiConfig.getAuthType()) {
            case KeyMgmt.WPA_PSK:
                return "wpa-psk";
            case KeyMgmt.WPA2_PSK:
                return "wpa2-psk";
            default:
                return "open";
        }
    }

    /* @param mode can be "AP", "STA" or "P2P" */
    @Override
    public void wifiFirmwareReload(String wlanIface, String mode) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        Object[] args = {"fwreload", wlanIface, mode};
        String logMsg = "wifiFirmwareReload Error reloading "
                + wlanIface + " fw in " + mode + " mode";
        try {
            executeOrLogWithMessage(SOFT_AP_COMMAND, args, NetdResponseCode.SoftapStatusResult,
                    SOFT_AP_COMMAND_SUCCESS, logMsg);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }

        // Ensure that before we return from this command, any asynchronous
        // notifications generated before the command completed have been
        // processed by all NetworkManagementEventObservers.
        mConnector.waitForCallbacks();
    }

    @Override
    public void stopAccessPoint(String wlanIface) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        Object[] args = {"stopap"};
        String logMsg = "stopAccessPoint Error stopping softap";

        try {
            executeOrLogWithMessage(SOFT_AP_COMMAND, args, NetdResponseCode.SoftapStatusResult,
                    SOFT_AP_COMMAND_SUCCESS, logMsg);
            wifiFirmwareReload(wlanIface, "STA");
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
    }

    @Override
    public void addIdleTimer(String iface, int timeout, final int type) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);