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

Commit ce3d4b9c authored by Rebecca Silberstein's avatar Rebecca Silberstein Committed by android-build-merger
Browse files

Merge "Add error logging for softap commands" into nyc-dev

am: bf705b4a

* commit 'bf705b4a':
  Add error logging for softap commands

Change-Id: I8a2946f8c160114ab37be15f55838065e9dee961
parents 6e8111c5 bf705b4a
Loading
Loading
Loading
Loading
+68 −15
Original line number Diff line number Diff line
@@ -174,6 +174,16 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        public static final int StrictCleartext           = 617;
    }

    /**
     * String indicating a softap command.
     */
    static final String SOFT_AP_COMMAND = "softap";

    /**
     * String passed back to netd connector indicating softap command success.
     */
    static final String SOFT_AP_COMMAND_SUCCESS = "Ok";

    static final int DAEMON_MSG_MOBILE_CONN_REAL_TIME_INFO = 1;

    /**
@@ -1426,20 +1436,48 @@ 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) {
    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) {
                mConnector.execute("softap", "set", wlanIface);
                args = new Object[] {"set", wlanIface};
            } else {
                mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
                args = new Object[] {"set", wlanIface, wifiConfig.SSID,
                        "broadcast", Integer.toString(wifiConfig.apChannel),
                                   getSecurityType(wifiConfig),
                                   new SensitiveArg(wifiConfig.preSharedKey));
                        getSecurityType(wifiConfig), new SensitiveArg(wifiConfig.preSharedKey)};
            }
            mConnector.execute("softap", "startap");
            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();
        }
@@ -1460,8 +1498,12 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    @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 {
            mConnector.execute("softap", "fwreload", wlanIface, mode);
            executeOrLogWithMessage(SOFT_AP_COMMAND, args, NetdResponseCode.SoftapStatusResult,
                    SOFT_AP_COMMAND_SUCCESS, logMsg);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
@@ -1470,8 +1512,12 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    @Override
    public void stopAccessPoint(String wlanIface) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        Object[] args = {"stopap"};
        String logMsg = "stopAccessPoint Error stopping softap";

        try {
            mConnector.execute("softap", "stopap");
            executeOrLogWithMessage(SOFT_AP_COMMAND, args, NetdResponseCode.SoftapStatusResult,
                    SOFT_AP_COMMAND_SUCCESS, logMsg);
            wifiFirmwareReload(wlanIface, "STA");
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
@@ -1481,14 +1527,21 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    @Override
    public void setAccessPoint(WifiConfiguration wifiConfig, String wlanIface) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        Object[] args;
        String logMsg = "startAccessPoint Error setting up softap";
        try {
            if (wifiConfig == null) {
                mConnector.execute("softap", "set", wlanIface);
                args = new Object[] {"set", wlanIface};
            } else {
                mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
                                   "broadcast", "6", getSecurityType(wifiConfig),
                                   new SensitiveArg(wifiConfig.preSharedKey));
            }
                // TODO: understand why this is set to "6" instead of
                // Integer.toString(wifiConfig.apChannel) as in startAccessPoint
                // TODO: should startAccessPoint call this instead of repeating code?
                args = new Object[] {"set", wlanIface, wifiConfig.SSID,
                        "broadcast", "6",
                        getSecurityType(wifiConfig), new SensitiveArg(wifiConfig.preSharedKey)};
            }
            executeOrLogWithMessage(SOFT_AP_COMMAND, args, NetdResponseCode.SoftapStatusResult,
                    SOFT_AP_COMMAND_SUCCESS, logMsg);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }