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

Commit 48c47471 authored by Vinit Deshapnde's avatar Vinit Deshapnde
Browse files

More elaborate logs to debug missing APs

Bug: 10375978

Change-Id: Ic9bb8f3a7a0684143e4e77f8da0d2c833293c94a
parent 1f809c77
Loading
Loading
Loading
Loading
+54 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.net.wifi.WifiConfiguration.Status;
import android.net.wifi.NetworkUpdateResult;
import static android.net.wifi.WifiConfiguration.INVALID_NETWORK_ID;
import android.os.Environment;
import android.os.FileObserver;
import android.os.Message;
import android.os.Handler;
import android.os.HandlerThread;
@@ -42,12 +43,16 @@ import android.util.Log;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
@@ -111,6 +116,8 @@ class WifiConfigStore {
    private static final String TAG = "WifiConfigStore";
    private static final boolean DBG = true;

    private static final String SUPPLICANT_CONFIG_FILE = "/data/misc/wifi/wpa_supplicant.conf";

    /* configured networks with network id as the key */
    private HashMap<Integer, WifiConfiguration> mConfiguredNetworks =
            new HashMap<Integer, WifiConfiguration>();
@@ -147,6 +154,7 @@ class WifiConfigStore {
    private static final String EOS = "eos";

    private final LocalLog mLocalLog;
    WpaConfigFileObserver mFileObserver;

    private WifiNative mWifiNative;
    private final KeyStore mKeyStore = KeyStore.getInstance();
@@ -156,10 +164,27 @@ class WifiConfigStore {
        mWifiNative = wn;

        if (DBG) {
            mLocalLog = new LocalLog(1024);                         // takes about 64 K
            mWifiNative.setLocalLog(mLocalLog);
            mLocalLog = mWifiNative.getLocalLog();
            mFileObserver = new WpaConfigFileObserver();
            mFileObserver.startWatching();
        }
    }

    class WpaConfigFileObserver extends FileObserver {

        public WpaConfigFileObserver() {
            super(SUPPLICANT_CONFIG_FILE, CLOSE_WRITE);
        }

        @Override
        public void onEvent(int event, String path) {
            if (event == CLOSE_WRITE) {
                File file = new File(SUPPLICANT_CONFIG_FILE);
                localLog("wpa_supplicant.conf changed; new size = " + file.length());
            }
        }
    }


    /**
     * Fetch the list of configured networks
@@ -636,6 +661,7 @@ class WifiConfigStore {
            try {
                config.networkId = Integer.parseInt(result[0]);
            } catch(NumberFormatException e) {
                loge("Failed to read network-id '" + result[0] + "'");
                continue;
            }
            if (result.length > 3) {
@@ -663,6 +689,31 @@ class WifiConfigStore {
        sendConfiguredNetworksChangedBroadcast();

        localLog("loadConfiguredNetworks loaded " + mNetworkIds.size() + " networks");

        if (mNetworkIds.size() == 0) {
            // no networks? Lets log if the wpa_supplicant.conf file contents
            BufferedReader reader = null;
            try {
                reader = new BufferedReader(new FileReader(SUPPLICANT_CONFIG_FILE));
                localLog("--- Begin wpa_supplicant.conf Contents ---");
                for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                    localLog(line);
                }
                localLog("--- End wpa_supplicant.conf Contents ---");
            } catch (FileNotFoundException e) {
                localLog("Could not open " + SUPPLICANT_CONFIG_FILE + ", " + e);
            } catch (IOException e) {
                localLog("Could not read " + SUPPLICANT_CONFIG_FILE + ", " + e);
            } finally {
                try {
                    if (reader != null) {
                        reader.close();
                    }
                } catch (IOException e) {
                    // Just ignore the fact that we couldn't close
                }
            }
        }
    }

    /* Mark all networks except specified netId as disabled */
+36 −17
Original line number Diff line number Diff line
@@ -93,10 +93,17 @@ public class WifiNative {
    }


    private LocalLog mLocalLog;
    private static final LocalLog mLocalLog = new LocalLog(1024);
    private int mCmdId;

    public void setLocalLog(LocalLog l) {
        mLocalLog = l;
    public LocalLog getLocalLog() {
        return mLocalLog;
    }

    private int getNewCmdId() {
        synchronized (mLocalLog) {
            return mCmdId++;
        }
    }

    private void localLog(String s) {
@@ -105,10 +112,12 @@ public class WifiNative {
    }

    public boolean connectToSupplicant() {
        localLog(mInterfacePrefix + "connectToSupplicant");
        return connectToSupplicantNative();
    }

    public void closeSupplicantConnection() {
        localLog(mInterfacePrefix + "closeSupplicantConnection");
        closeSupplicantConnectionNative();
    }

@@ -118,15 +127,32 @@ public class WifiNative {

    private boolean doBooleanCommand(String command) {
        if (DBG) Log.d(mTAG, "doBoolean: " + command);
        return doBooleanCommandNative(mInterfacePrefix + command);
        int cmdId = getNewCmdId();
        localLog(cmdId + "->" + mInterfacePrefix + command);
        boolean result = doBooleanCommandNative(mInterfacePrefix + command);
        localLog(cmdId + "<-" + result);
        return result;
    }

    private int doIntCommand(String command) {
        if (DBG) Log.d(mTAG, "doInt: " + command);
        return doIntCommandNative(mInterfacePrefix + command);
        int cmdId = getNewCmdId();
        localLog(cmdId + "->" + mInterfacePrefix + command);
        int result = doIntCommandNative(mInterfacePrefix + command);
        localLog(cmdId + "<-" + result);
        return result;
    }

    private String doStringCommand(String command) {
        if (DBG) Log.d(mTAG, "doString: " + command);
        int cmdId = getNewCmdId();
        localLog(cmdId + "->" + mInterfacePrefix + command);
        String result = doStringCommandNative(mInterfacePrefix + command);
        localLog(cmdId + "<-" + result);
        return result;
    }

    private String doStringCommandWithoutLogging(String command) {
        if (DBG) Log.d(mTAG, "doString: " + command);
        return doStringCommandNative(mInterfacePrefix + command);
    }
@@ -157,48 +183,42 @@ public class WifiNative {
    }

    public String listNetworks() {
        localLog("LIST_NETWORKS");
        return doStringCommand("LIST_NETWORKS");
    }

    public int addNetwork() {
        localLog("ADD_NETWORK");
        return doIntCommand("ADD_NETWORK");
    }

    public boolean setNetworkVariable(int netId, String name, String value) {
        if (TextUtils.isEmpty(name) || TextUtils.isEmpty(value)) return false;
        localLog("SET_NETWORK " + netId + " " + name + "=" + value);
        return doBooleanCommand("SET_NETWORK " + netId + " " + name + " " + value);
    }

    public String getNetworkVariable(int netId, String name) {
        if (TextUtils.isEmpty(name)) return null;
        return doStringCommand("GET_NETWORK " + netId + " " + name);

        // GET_NETWORK will likely flood the logs ...
        return doStringCommandWithoutLogging("GET_NETWORK " + netId + " " + name);
    }

    public boolean removeNetwork(int netId) {
        localLog("REMOVE_NETWORK " + netId);
        return doBooleanCommand("REMOVE_NETWORK " + netId);
    }

    public boolean enableNetwork(int netId, boolean disableOthers) {
        if (disableOthers) {
            localLog("SELECT_NETWORK " + netId);
            return doBooleanCommand("SELECT_NETWORK " + netId);
        } else {
            localLog("ENABLE_NETWORK " + netId);
            return doBooleanCommand("ENABLE_NETWORK " + netId);
        }
    }

    public boolean disableNetwork(int netId) {
        localLog("DISABLE_NETWORK " + netId);
        return doBooleanCommand("DISABLE_NETWORK " + netId);
    }

    public boolean reconnect() {
        localLog("RECONNECT");
        return doBooleanCommand("RECONNECT");
    }

@@ -242,7 +262,7 @@ public class WifiNative {
     * MASK=<N> see wpa_supplicant/src/common/wpa_ctrl.h for details
     */
    public String scanResults(int sid) {
        return doStringCommand("BSS RANGE=" + sid + "- MASK=0x21987");
        return doStringCommandWithoutLogging("BSS RANGE=" + sid + "- MASK=0x21987");
    }

    /**
@@ -401,7 +421,6 @@ public class WifiNative {
    }

    public boolean saveConfig() {
        localLog("SAVE_CONFIG");
        return doBooleanCommand("SAVE_CONFIG");
    }

@@ -456,7 +475,7 @@ public class WifiNative {
     * FREQUENCY=0
     */
    public String signalPoll() {
        return doStringCommand("SIGNAL_POLL");
        return doStringCommandWithoutLogging("SIGNAL_POLL");
    }

    /** Example outout:
+1 −1
Original line number Diff line number Diff line
@@ -723,7 +723,7 @@ public class WifiStateMachine extends StateMachine {

        setInitialState(mInitialState);

        setLogRecSize(300);
        setLogRecSize(2000);
        setLogOnlyTransitions(false);
        if (DBG) setDbg(true);