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

Commit 72718229 authored by Deepthi Gowri's avatar Deepthi Gowri Committed by Steve Kondik
Browse files

wifi: LTECoex changes for SAP/P2P

Restart sap/P2P GO with safe channel list received from android
telephony layer, whenever sap/P2P GO is operating on an channel
interfering with LTE.

Change-Id: I3f5da86374dcb542ab4f11ac755eca0b2dc067c1
CRs-Fixed: 510273
parent 50db7bc3
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -404,4 +404,19 @@ interface INetworkManagementService
    * address from a custom routing table denoted by routeId
    */
   boolean delSrcRoute(in byte[] ip, int routeId);

   /**
     * Set SAP Channel Range
    */
    void setChannelRange(int startchannel, int endchannel, int band);

    /**
     * Get SAP Current Operating Channel
    */
    int getSapOperatingChannel();

    /**
     * Get SAP Auto Channel Selection
    */
    int getSapAutoChannelSelection();
}
+81 −0
Original line number Diff line number Diff line
@@ -1082,6 +1082,87 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        }
    }

     /*Set SAP Channel Range*/
    public void setChannelRange(int startchannel, int endchannel, int band)
            throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(
           android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
        mContext.enforceCallingOrSelfPermission(
           android.Manifest.permission.CHANGE_WIFI_STATE, "NetworkManagementService");
        try {
            Slog.d(TAG, "Set SAP Channel Range");
            mConnector.execute(
            "softap", "qccmd", "set", "setchannelrange=", startchannel, " ", endchannel, " ", band);
        } catch (NativeDaemonConnectorException e) {
              throw new IllegalStateException(
                   "Error communicating to native daemon to set channel range", e);
        }
    }

     /*Get SAP Operating Channel*/
    public int getSapOperatingChannel() throws IllegalStateException{
        mContext.enforceCallingOrSelfPermission(
            android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
        mContext.enforceCallingOrSelfPermission(
            android.Manifest.permission.CHANGE_WIFI_STATE, "NetworkManagementService");
        int channel=0;
        try {
            final NativeDaemonEvent OperChanResp;
            Slog.d(TAG, "getSapOperatingChannel");
            OperChanResp = mConnector.execute("softap", "qccmd", "get", "channel");
            Slog.d(TAG, "getSapOperatingChannel--OperChanResp" + OperChanResp);

            //Resp Pattern : 200 8 success channel=6
            final StringTokenizer tok = new StringTokenizer(OperChanResp.getMessage());
            tok.nextToken();
            String temp = (tok.hasMoreTokens()) ? tok.nextToken() : null;
            if (temp != null) {
                 final StringTokenizer tok1 = new StringTokenizer(temp, "=");
                 String temp1 = (tok1.hasMoreTokens()) ? tok1.nextToken() : null;
                 String temp2 = (tok1.hasMoreTokens()) ? tok1.nextToken() : null;
                 if (temp2 != null)
                      channel = Integer.parseInt(temp2);
            }
            Slog.d(TAG, "softap qccmd get channel =" + channel);
            return channel;
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException(
                     "Error communicating to native daemon to getSapOperatingChannel", e);
        }
    }

     /*Get SAP Auto Channel Selection*/
    public int getSapAutoChannelSelection() throws IllegalStateException{
        mContext.enforceCallingOrSelfPermission(
            android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
        mContext.enforceCallingOrSelfPermission(
            android.Manifest.permission.CHANGE_WIFI_STATE, "NetworkManagementService");
        int autochannel=0;
        try {
            final NativeDaemonEvent OperChanResp;
            Slog.d(TAG, "getSapAutoChannelSelection");
            OperChanResp = mConnector.execute("softap", "qccmd", "get", "autochannel");

            //Resp Pattern : 200 9 success autochannel=0
            final StringTokenizer tok = new StringTokenizer(OperChanResp.getMessage());
            tok.nextToken();
            String temp = (tok.hasMoreTokens()) ? tok.nextToken() : null;
            if (temp != null) {
                 final StringTokenizer tok1 = new StringTokenizer(temp, "=");
                 String temp1 = (tok1.hasMoreTokens()) ? tok1.nextToken() : null;
                 String temp2 = (tok1.hasMoreTokens()) ? tok1.nextToken() : null;
                 if (temp2 != null)
                      autochannel = Integer.parseInt(temp2);
            }
            Slog.d(TAG, "getSapAutoChannelSelection--OperChanResp" + OperChanResp);
            Slog.d(TAG, "softap qccmd get autochannel =" + autochannel);
            return autochannel;
        } catch (NativeDaemonConnectorException e) {
              throw new IllegalStateException(
                  "Error communicating to native daemon to getSapOperatingChannel", e);
        }
    }

    @Override
    public void setAccessPoint(WifiConfiguration wifiConfig, String wlanIface) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+21 −0
Original line number Diff line number Diff line
@@ -838,6 +838,27 @@ public class WifiNative {

    public native static boolean setMode(int mode);

    /**Create P2P GO on the operating frequency*/
    public boolean p2pGroupAddOnSpecifiedFreq(int freq) {
        return doBooleanCommand("P2P_GROUP_ADD" + " freq=" + freq);
    }

    /**Set Channel preferrence eg., p2p_pref_chan=81:1,81:2,81:3,81:4,81:5,81:6*/
    public boolean setPreferredChannel(int startChannel, int endChannel) {
      int i = 0;
      if ((startChannel == 0) || (endChannel == 0)) return false;
          StringBuffer strBuf = new StringBuffer();
          String command = "SET p2p_pref_chan ";
          for (i = startChannel; i<=endChannel; i++) {
              strBuf.append("81:" + i);
              strBuf.append(",");
          }
       strBuf.deleteCharAt(strBuf.length() - 1);
       command += strBuf;
       Log.d(mTAG, "setPreferredChannel Command that goes to Supplicant is=" + command);
       return doBooleanCommand(command) && doBooleanCommand("SAVE_CONFIG");
    }

    /* Set the current mode of miracast operation.
     *  0 = disabled
     *  1 = operating as source
+92 −1
Original line number Diff line number Diff line
@@ -70,6 +70,9 @@ import android.provider.Settings;
import android.util.LruCache;
import android.text.TextUtils;

import android.util.Log;
import android.text.TextUtils;
import android.util.LruCache;
import com.android.internal.R;
import com.android.internal.app.IBatteryStats;
import com.android.internal.util.AsyncChannel;
@@ -101,6 +104,7 @@ import java.util.regex.Pattern;
 */
public class WifiStateMachine extends StateMachine {

    private static final String TAG = "WifiStateMachine";
    private static final String NETWORKTYPE = "WIFI";
    private static final boolean DBG = false;

@@ -155,6 +159,8 @@ public class WifiStateMachine extends StateMachine {
    private PowerManager.WakeLock mSuspendWakeLock;

    private List<WifiChannel> mSupportedChannels;
    private int startSafeChannel = 0;
    private int endSafeChannel = 0;

    /**
     * Interval in milliseconds between polling for RSSI
@@ -527,6 +533,8 @@ public class WifiStateMachine extends StateMachine {
    private static final int DRIVER_STOP_REQUEST = 0;
    private static final String ACTION_DELAYED_DRIVER_STOP =
        "com.android.server.WifiManager.action.DELAYED_DRIVER_STOP";
    private static final String ACTION_SAFE_WIFI_CHANNELS_CHANGED =
           "qualcomm.intent.action.SAFE_WIFI_CHANNELS_CHANGED";

    /**
     * Keep track of whether WIFI is running.
@@ -612,6 +620,10 @@ public class WifiStateMachine extends StateMachine {
                }
            },new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));

       IntentFilter filter = new IntentFilter();
       filter.addAction(ACTION_SAFE_WIFI_CHANNELS_CHANGED);
       mContext.registerReceiver(WifiStateReceiver, filter);

       mContext.registerReceiver(
                new BroadcastReceiver() {
                    @Override
@@ -716,6 +728,32 @@ public class WifiStateMachine extends StateMachine {
        mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
    }

    private BroadcastReceiver WifiStateReceiver = new BroadcastReceiver() {

         public void onReceive(Context context, Intent intent) {
             if (intent.getAction().equals(
                 ACTION_SAFE_WIFI_CHANNELS_CHANGED)) {
                 startSafeChannel = intent.getIntExtra("start_safe_channel", -1);
                 endSafeChannel = intent.getIntExtra("end_safe_channel", -1);
                 Log.d(TAG, "Received WIFI_CHANNELS_CHANGED broadcast");
                 int state = syncGetWifiApState();
                 if (state == WIFI_AP_STATE_ENABLED) {
                     int autochannel = getSapAutoChannelSelection();
                     Log.d(TAG,"autochannel=" + autochannel);
                     if (1 == autochannel){
                         int currentChannel = getSapOperatingChannel();
                         if (currentChannel >= 0 &&
                            (currentChannel < startSafeChannel ||
                             currentChannel > endSafeChannel)) {
                             Log.e(TAG, "Operating on restricted channel! Restart SAP");
                             restartSoftApIfOn();
                         }
                     }
                 }
              }
           }
    };

    /*********************************************************
     * Methods exposed for public use
     ********************************************************/
@@ -803,6 +841,42 @@ public class WifiStateMachine extends StateMachine {
        return ret;
    }

    /**
     * Function to set Channel range.
    */
    public void setChannelRange(int startchannel, int endchannel, int band) {
       try {
              Log.e(TAG, "setChannelRange");
              mNwService.setChannelRange(startchannel, endchannel, band);
           } catch(Exception e) {
             loge("Exception in setChannelRange");
           }
    }

    /**
    *  Function to get SAP operating Channel
    */
    public int getSapOperatingChannel() {
        try {
            return mNwService.getSapOperatingChannel();
        } catch(Exception e) {
              loge("Exception in getSapOperatingChannel");
              return -1;
        }
    }

    /**
    *  Function to get Auto Channel selection
    */
    public int getSapAutoChannelSelection() {
        try {
            return mNwService.getSapAutoChannelSelection();
        } catch (Exception e) {
             loge("Exception in getSapOperatingChannel");
             return -1;
        }
    }

    /**
     * TODO: doc
     */
@@ -1928,6 +2002,10 @@ public class WifiStateMachine extends StateMachine {
                    loge("Exception in softap start " + e);
                    try {
                        mNwService.stopAccessPoint(mInterfaceName);
                        if (startSafeChannel!=0) {
                           Log.e(TAG, "Calling setChannelRange ---startSoftApWithConfig()");
                           setChannelRange(startSafeChannel, endSafeChannel, 0);
                        }
                        mNwService.startAccessPoint(config, mInterfaceName);
                    } catch (Exception e1) {
                        loge("Exception in softap re-start " + e1);
@@ -3622,6 +3700,10 @@ public class WifiStateMachine extends StateMachine {
                final WifiConfiguration config = (WifiConfiguration) message.obj;

                if (config == null) {
                   if (startSafeChannel!=0) {
                       Log.e(TAG, "Calling setChannelRange ---CMD_START_AP SoftApStartingState()");
                       setChannelRange(startSafeChannel, endSafeChannel , 0);
                   }
                    mWifiApConfigChannel.sendMessage(CMD_REQUEST_AP_CONFIG);
                } else {
                    mWifiApConfigChannel.sendMessage(CMD_SET_AP_CONFIG, config);
@@ -3859,4 +3941,13 @@ public class WifiStateMachine extends StateMachine {
        msg.arg2 = srcMsg.arg2;
        return msg;
    }


    private void restartSoftApIfOn() {
        Log.e(TAG, "Disabling wifi ap");
        setHostApRunning(null, false);
        Log.e(TAG, "Enabling wifi ap");
        setHostApRunning(null, true);
        Log.e(TAG, "Restart softap Done");
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ public class WifiP2pGroup implements Parcelable {
    /** The passphrase used for WPA2-PSK */
    private String mPassphrase;

    /** GO operating Frequency*/
    private int mGoOperFreq;

    private String mInterface;

    /** The network id in the wpa_supplicant */
@@ -116,6 +119,7 @@ public class WifiP2pGroup implements Parcelable {
            //freq and psk are unused right now
            //int freq = Integer.parseInt(match.group(2));
            //String psk = match.group(3);
            mGoOperFreq = Integer.parseInt(match.group(2));
            mPassphrase = match.group(4);
            mOwner = new WifiP2pDevice(match.group(5));
            if (match.group(6) != null) {
@@ -228,6 +232,18 @@ public class WifiP2pGroup implements Parcelable {
        return Collections.unmodifiableCollection(mClients);
    }

    /** @hide */
    public int setGoOperatingFrequency(int GoOperFreq) {
        return mGoOperFreq = GoOperFreq;
    }

    /** @hide
    * This is used to fetch the GO operating frequency
    */
    public int getGoOperatingFrequency() {
        return mGoOperFreq;
    }

    /** @hide */
    public void setPassphrase(String passphrase) {
        mPassphrase = passphrase;
@@ -290,6 +306,7 @@ public class WifiP2pGroup implements Parcelable {
            mPassphrase = source.getPassphrase();
            mInterface = source.getInterface();
            mNetId = source.getNetworkId();
            mGoOperFreq = source.getGoOperatingFrequency();
        }
    }

@@ -305,6 +322,7 @@ public class WifiP2pGroup implements Parcelable {
        dest.writeString(mPassphrase);
        dest.writeString(mInterface);
        dest.writeInt(mNetId);
        dest.writeInt(mGoOperFreq);
    }

    /** Implement the Parcelable interface */
@@ -322,6 +340,7 @@ public class WifiP2pGroup implements Parcelable {
                group.setPassphrase(in.readString());
                group.setInterface(in.readString());
                group.setNetworkId(in.readInt());
                group.setGoOperatingFrequency(in.readInt());
                return group;
            }

Loading