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

Commit 78e23609 authored by Irfan Sheriff's avatar Irfan Sheriff Committed by Android Git Automerger
Browse files

am 7a6a4bf1: Merge "P2p fixes" into jb-dev

* commit '7a6a4bf1':
  P2p fixes
parents 9edbb235 7a6a4bf1
Loading
Loading
Loading
Loading
+13 −11
Original line number Diff line number Diff line
@@ -442,8 +442,8 @@ public class WifiNative {
        return doBooleanCommand("SET p2p_ssid_postfix " + postfix);
    }

    public boolean setP2pGroupIdle(String iface, int time) {
        return doBooleanCommand("SET interface=" + iface + " p2p_group_idle " + time);
    public boolean setP2pGroupIdle(int time) {
        return doBooleanCommand("SET p2p_group_idle " + time);
    }

    public void setPowerSave(boolean enabled) {
@@ -467,7 +467,7 @@ public class WifiNative {
     * P2P connection over STA
     */
    public boolean setConcurrencyPriority(String s) {
        return doBooleanCommand("P2P_SET conc_priority " + s);
        return doBooleanCommand("P2P_SET conc_pref " + s);
    }

    public boolean p2pFind() {
@@ -536,8 +536,9 @@ public class WifiNative {
        /* Persist unless there is an explicit request to not do so*/
        //if (config.persist != WifiP2pConfig.Persist.NO) args.add("persistent");

        if (joinExistingGroup) args.add("join");

        if (joinExistingGroup) {
            args.add("join");
        } else {
            //TODO: This can be adapted based on device plugged in state and
            //device battery state
            int groupOwnerIntent = config.groupOwnerIntent;
@@ -545,6 +546,7 @@ public class WifiNative {
                groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT;
            }
            args.add("go_intent=" + groupOwnerIntent);
        }

        String command = "P2P_CONNECT ";
        for (String s : args) command += s + " ";
+7 −78
Original line number Diff line number Diff line
@@ -50,19 +50,10 @@ public class WifiP2pProvDiscEvent {
    /**
     * @param string formats supported include
     *
     *  P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
     *  pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
     *  group_capab=0x0
     *
     *  P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27
     *  P2P-PROV-DISC-PBC-RESP 02:12:47:f2:5a:36
     *
     *  P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
     *  pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
     *  group_capab=0x0
     *
     *  P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 p2p_dev_addr=42:fc:89:e1:e2:27
     *  pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
     *  group_capab=0x0
     *  P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27
     *  P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607
     *
     *  Note: The events formats can be looked up in the wpa_supplicant code
     * @hide
@@ -80,51 +71,12 @@ public class WifiP2pProvDiscEvent {
        else if (tokens[0].endsWith("SHOW-PIN")) event = SHOW_PIN;
        else throw new IllegalArgumentException("Malformed event " + string);

        device = new WifiP2pDevice();

        for (String token : tokens) {
            String[] nameValue = token.split("=");
            if (nameValue.length != 2) {
                //mac address without key is device address
                if (token.matches("(([0-9a-f]{2}:){5}[0-9a-f]{2})")) {
                    device.deviceAddress = token;
                } else if (token.matches("[0-9]+")) {
                    pin = token;
                } else {
                    //ignore;
                }
                continue;
            }

            if (nameValue[0].equals("p2p_dev_addr")) {
                device.deviceAddress = nameValue[1];
                continue;
            }

            if (nameValue[0].equals("pri_dev_type")) {
                device.primaryDeviceType = nameValue[1];
                continue;
            }

            if (nameValue[0].equals("name")) {
                device.deviceName = trimQuotes(nameValue[1]);
                continue;
            }

            if (nameValue[0].equals("config_methods")) {
                device.wpsConfigMethodsSupported = parseHex(nameValue[1]);
                continue;
            }

            if (nameValue[0].equals("dev_capab")) {
                device.deviceCapability = parseHex(nameValue[1]);
                continue;
            }
        device = new WifiP2pDevice();
        device.deviceAddress = tokens[1];

            if (nameValue[0].equals("group_capab")) {
                device.groupCapability = parseHex(nameValue[1]);
                continue;
            }
        if (event == SHOW_PIN) {
            pin = tokens[2];
        }
    }

@@ -135,27 +87,4 @@ public class WifiP2pProvDiscEvent {
        sbuf.append("\n pin: ").append(pin);
        return sbuf.toString();
    }

    private String trimQuotes(String str) {
        str = str.trim();
        if (str.startsWith("'") && str.endsWith("'")) {
            return str.substring(1, str.length()-1);
        }
        return str;
    }

    //supported formats: 0x1abc, 0X1abc, 1abc
    private int parseHex(String hexString) {
        int num = 0;
        if (hexString.startsWith("0x") || hexString.startsWith("0X")) {
            hexString = hexString.substring(2);
        }

        try {
            num = Integer.parseInt(hexString, 16);
        } catch(NumberFormatException e) {
            Log.e(TAG, "Failed to parse hex string " + hexString);
        }
        return num;
    }
}
+29 −18
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ import java.util.HashMap;
import java.util.List;

/**
 * WifiP2pService inclues a state machine to perform Wi-Fi p2p operations. Applications
 * WifiP2pService includes a state machine to perform Wi-Fi p2p operations. Applications
 * communicate with this service to issue device discovery and connectivity requests
 * through the WifiP2pManager interface. The state machine communicates with the wifi
 * driver through wpa_supplicant and handles the event responses through WifiMonitor.
@@ -432,9 +432,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
                    loge("Unexpected group creation, remove " + mGroup);
                    mWifiNative.p2pGroupRemove(mGroup.getInterface());
                    break;
                // A group formation failure is always followed by
                // a group removed event. Flushing things at group formation
                // failure causes supplicant issues. Ignore right now.
                case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
                    loge("Unexpected group failure, flush peers");
                    mWifiNative.p2pFlush();
                    break;
                default:
                    loge("Unhandled message " + message);
@@ -839,6 +840,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
                   break;
                case WifiP2pManager.CREATE_GROUP:
                   mAutonomousGroup = true;
                   // An autonomous GO requires group idle settings to be reset
                   mWifiNative.setP2pGroupIdle(0);
                   if (mWifiNative.p2pGroupAdd()) {
                        replyToMessage(message, WifiP2pManager.CREATE_GROUP_SUCCEEDED);
                    } else {
@@ -860,6 +863,11 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
            if (DBG) logd(getName());
            sendMessageDelayed(obtainMessage(GROUP_CREATING_TIMED_OUT,
                    ++mGroupCreatingTimeoutIndex, 0), GROUP_CREATING_WAIT_TIME_MS);

            // Set default group idle settings
            if (!mAutonomousGroup) {
                mWifiNative.setP2pGroupIdle(GROUP_IDLE_TIME_S);
            }
        }

        @Override
@@ -882,7 +890,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
                    //Do a supplicant p2p_cancel which only cancels an ongoing
                    //group negotiation. This will fail for a pending provision
                    //discovery or for a pending user action, but at the framework
                    //level, we always treat cancel as succeded and enter
                    //level, we always treat cancel as succeeded and enter
                    //an inactive state
                    mWifiNative.p2pCancelConnect();
                    handleGroupCreationFailure();
@@ -1034,11 +1042,16 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
                    transitionTo(mGroupCreatedState);
                    break;
                case WifiMonitor.P2P_GO_NEGOTIATION_FAILURE_EVENT:
                case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
                case WifiMonitor.P2P_GROUP_REMOVED_EVENT:
                    if (DBG) logd(getName() + " go failure");
                    handleGroupCreationFailure();
                    transitionTo(mInactiveState);
                    break;
                // A group formation failure is always followed by
                // a group removed event. Flushing things at group formation
                // failure causes supplicant issues. Ignore right now.
                case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
                    break;
                default:
                    return NOT_HANDLED;
            }
@@ -1061,10 +1074,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
                setWifiP2pInfoOnGroupFormation(SERVER_ADDRESS);
                sendP2pConnectionChangedBroadcast();
            }

            if (!mAutonomousGroup) {
                mWifiNative.setP2pGroupIdle(mGroup.getInterface(), GROUP_IDLE_TIME_S);
            }
        }

        @Override
@@ -1155,6 +1164,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {

                    mGroup = null;
                    mWifiNative.p2pFlush();
                    mServiceDiscReqId = null;
                    if (changed) sendP2pPeersChangedBroadcast();
                    transitionTo(mInactiveState);
                    break;
@@ -1540,9 +1550,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
        // DIRECT-XY-DEVICENAME (XY is randomly generated)
        mWifiNative.setP2pSsidPostfix("-" + mThisDevice.deviceName);
        mWifiNative.setDeviceType(mThisDevice.primaryDeviceType);
        //The supplicant default is to support everything, but a bug necessitates
        //the framework to specify this explicitly
        mWifiNative.setConfigMethods("keypad display push_button");
        // Supplicant defaults to using virtual display with display
        // which refers to a remote display. Use physical_display
        mWifiNative.setConfigMethods("virtual_push_button physical_display keypad");
        // STA has higher priority over P2P
        mWifiNative.setConcurrencyPriority("sta");

@@ -1567,11 +1577,12 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
        /* After cancelling group formation, new connections on existing peers can fail
         * at supplicant. Flush and restart discovery */
        mWifiNative.p2pFlush();
        mServiceDiscReqId = null;
        sendMessage(WifiP2pManager.DISCOVER_PEERS);
    }

    //State machine initiated requests can have replyTo set to null indicating
    //there are no recepients, we ignore those reply actions
    //there are no recipients, we ignore those reply actions
    private void replyToMessage(Message msg, int what) {
        if (msg.replyTo == null) return;
        Message dstMsg = obtainMessage(msg);
@@ -1650,7 +1661,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
        mServiceDiscReqId = null;
    }

    /* TODO: We could track individual service adds seperately and avoid
    /* TODO: We could track individual service adds separately and avoid
     * having to do update all service requests on every new request
     */
    private boolean addServiceRequest(Messenger m, WifiP2pServiceRequest req) {