|
45 | 45 | import android.content.Context; |
46 | 46 | import android.content.Intent; |
47 | 47 | import android.content.IntentFilter; |
| 48 | +import android.content.pm.PackageManager; |
48 | 49 | import android.net.ConnectivityManager; |
49 | 50 | import android.net.DhcpInfo; |
50 | 51 | import android.net.DhcpInfoInternal; |
@@ -118,6 +119,8 @@ public class WifiStateMachine extends StateMachine { |
118 | 119 | private INetworkManagementService mNwService; |
119 | 120 | private ConnectivityManager mCm; |
120 | 121 |
|
| 122 | + private final boolean mP2pSupported; |
| 123 | + |
121 | 124 | /* Scan results handling */ |
122 | 125 | private List<ScanResult> mScanResults; |
123 | 126 | private static final Pattern scanResultPattern = Pattern.compile("\t+"); |
@@ -361,9 +364,9 @@ public class WifiStateMachine extends StateMachine { |
361 | 364 | /* Reset the WPS state machine */ |
362 | 365 | static final int CMD_RESET_WPS_STATE = BASE + 122; |
363 | 366 |
|
364 | | - /* Interaction with WifiP2pService */ |
365 | | - public static final int WIFI_ENABLE_PENDING = BASE + 131; |
366 | | - public static final int P2P_ENABLE_PROCEED = BASE + 132; |
| 367 | + /* P2p commands */ |
| 368 | + public static final int CMD_ENABLE_P2P = BASE + 131; |
| 369 | + public static final int CMD_DISABLE_P2P = BASE + 132; |
367 | 370 |
|
368 | 371 | private static final int CONNECT_MODE = 1; |
369 | 372 | private static final int SCAN_ONLY_MODE = 2; |
@@ -482,9 +485,6 @@ public class WifiStateMachine extends StateMachine { |
482 | 485 | /* Waiting for untether confirmation to stop soft Ap */ |
483 | 486 | private State mSoftApStoppingState = new SoftApStoppingState(); |
484 | 487 |
|
485 | | - /* Wait till p2p is disabled */ |
486 | | - private State mWaitForP2pDisableState = new WaitForP2pDisableState(); |
487 | | - |
488 | 488 | private class TetherStateChange { |
489 | 489 | ArrayList<String> available; |
490 | 490 | ArrayList<String> active; |
@@ -556,6 +556,9 @@ public WifiStateMachine(Context context, String wlanInterface) { |
556 | 556 | IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE); |
557 | 557 | mNwService = INetworkManagementService.Stub.asInterface(b); |
558 | 558 |
|
| 559 | + mP2pSupported = mContext.getPackageManager().hasSystemFeature( |
| 560 | + PackageManager.FEATURE_WIFI_DIRECT); |
| 561 | + |
559 | 562 | mWifiNative = new WifiNative(mInterfaceName); |
560 | 563 | mWifiConfigStore = new WifiConfigStore(context, mWifiNative); |
561 | 564 | mWifiMonitor = new WifiMonitor(this, mWifiNative); |
@@ -639,7 +642,6 @@ public void onReceive(Context context, Intent intent) { |
639 | 642 | addState(mTetheringState, mSoftApStartedState); |
640 | 643 | addState(mTetheredState, mSoftApStartedState); |
641 | 644 | addState(mSoftApStoppingState, mDefaultState); |
642 | | - addState(mWaitForP2pDisableState, mDefaultState); |
643 | 645 |
|
644 | 646 | setInitialState(mInitialState); |
645 | 647 |
|
@@ -1896,11 +1898,6 @@ public boolean processMessage(Message message) { |
1896 | 1898 | mReplyChannel.replyToMessage(message, WifiManager.CMD_WPS_COMPLETED, |
1897 | 1899 | new WpsResult(Status.FAILURE)); |
1898 | 1900 | break; |
1899 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
1900 | | - // turn off wifi and defer to be handled in DriverUnloadedState |
1901 | | - setWifiEnabled(false); |
1902 | | - deferMessage(message); |
1903 | | - break; |
1904 | 1901 | default: |
1905 | 1902 | loge("Error! unhandled message" + message); |
1906 | 1903 | break; |
@@ -2060,7 +2057,7 @@ public boolean processMessage(Message message) { |
2060 | 2057 | loge("Unable to change interface settings: " + ie); |
2061 | 2058 | } |
2062 | 2059 |
|
2063 | | - if(mWifiNative.startSupplicant()) { |
| 2060 | + if(mWifiNative.startSupplicant(mP2pSupported)) { |
2064 | 2061 | if (DBG) log("Supplicant start successful"); |
2065 | 2062 | mWifiMonitor.startMonitoring(); |
2066 | 2063 | transitionTo(mSupplicantStartingState); |
@@ -2172,11 +2169,7 @@ public boolean processMessage(Message message) { |
2172 | 2169 | if (DBG) log(getName() + message.toString() + "\n"); |
2173 | 2170 | switch (message.what) { |
2174 | 2171 | case CMD_LOAD_DRIVER: |
2175 | | - mWifiP2pChannel.sendMessage(WIFI_ENABLE_PENDING); |
2176 | | - transitionTo(mWaitForP2pDisableState); |
2177 | | - break; |
2178 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
2179 | | - mReplyChannel.replyToMessage(message, P2P_ENABLE_PROCEED); |
| 2172 | + transitionTo(mDriverLoadingState); |
2180 | 2173 | break; |
2181 | 2174 | default: |
2182 | 2175 | return NOT_HANDLED; |
@@ -2556,13 +2549,15 @@ public void enter() { |
2556 | 2549 | mWifiNative.status(); |
2557 | 2550 | transitionTo(mDisconnectedState); |
2558 | 2551 | } |
| 2552 | + |
| 2553 | + if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P); |
2559 | 2554 | } |
2560 | 2555 | @Override |
2561 | 2556 | public boolean processMessage(Message message) { |
2562 | 2557 | if (DBG) log(getName() + message.toString() + "\n"); |
2563 | 2558 | boolean eventLoggingEnabled = true; |
2564 | 2559 | switch(message.what) { |
2565 | | - case CMD_SET_SCAN_TYPE: |
| 2560 | + case CMD_SET_SCAN_TYPE: |
2566 | 2561 | mSetScanActive = (message.arg1 == SCAN_ACTIVE); |
2567 | 2562 | mWifiNative.setScanMode(mSetScanActive); |
2568 | 2563 | break; |
@@ -2675,6 +2670,8 @@ public void exit() { |
2675 | 2670 | mIsRunning = false; |
2676 | 2671 | updateBatteryWorkSource(null); |
2677 | 2672 | mScanResults = null; |
| 2673 | + |
| 2674 | + if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P); |
2678 | 2675 | } |
2679 | 2676 | } |
2680 | 2677 |
|
@@ -3348,7 +3345,6 @@ public boolean processMessage(Message message) { |
3348 | 3345 | case CMD_START_PACKET_FILTERING: |
3349 | 3346 | case CMD_STOP_PACKET_FILTERING: |
3350 | 3347 | case CMD_TETHER_STATE_CHANGE: |
3351 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
3352 | 3348 | deferMessage(message); |
3353 | 3349 | break; |
3354 | 3350 | case WifiStateMachine.CMD_RESPONSE_AP_CONFIG: |
@@ -3412,55 +3408,6 @@ public boolean processMessage(Message message) { |
3412 | 3408 | transitionTo(mTetheringState); |
3413 | 3409 | } |
3414 | 3410 | break; |
3415 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
3416 | | - // turn of soft Ap and defer to be handled in DriverUnloadedState |
3417 | | - setWifiApEnabled(null, false); |
3418 | | - deferMessage(message); |
3419 | | - break; |
3420 | | - default: |
3421 | | - return NOT_HANDLED; |
3422 | | - } |
3423 | | - EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what); |
3424 | | - return HANDLED; |
3425 | | - } |
3426 | | - } |
3427 | | - |
3428 | | - class WaitForP2pDisableState extends State { |
3429 | | - private int mSavedArg; |
3430 | | - @Override |
3431 | | - public void enter() { |
3432 | | - if (DBG) log(getName() + "\n"); |
3433 | | - EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); |
3434 | | - |
3435 | | - //Preserve the argument arg1 that has information used in DriverLoadingState |
3436 | | - mSavedArg = getCurrentMessage().arg1; |
3437 | | - } |
3438 | | - @Override |
3439 | | - public boolean processMessage(Message message) { |
3440 | | - if (DBG) log(getName() + message.toString() + "\n"); |
3441 | | - switch(message.what) { |
3442 | | - case WifiP2pService.WIFI_ENABLE_PROCEED: |
3443 | | - //restore argument from original message (CMD_LOAD_DRIVER) |
3444 | | - message.arg1 = mSavedArg; |
3445 | | - transitionTo(mDriverLoadingState); |
3446 | | - break; |
3447 | | - case CMD_LOAD_DRIVER: |
3448 | | - case CMD_UNLOAD_DRIVER: |
3449 | | - case CMD_START_SUPPLICANT: |
3450 | | - case CMD_STOP_SUPPLICANT: |
3451 | | - case CMD_START_AP: |
3452 | | - case CMD_STOP_AP: |
3453 | | - case CMD_START_DRIVER: |
3454 | | - case CMD_STOP_DRIVER: |
3455 | | - case CMD_SET_SCAN_MODE: |
3456 | | - case CMD_SET_SCAN_TYPE: |
3457 | | - case CMD_SET_HIGH_PERF_MODE: |
3458 | | - case CMD_SET_COUNTRY_CODE: |
3459 | | - case CMD_SET_FREQUENCY_BAND: |
3460 | | - case CMD_START_PACKET_FILTERING: |
3461 | | - case CMD_STOP_PACKET_FILTERING: |
3462 | | - deferMessage(message); |
3463 | | - break; |
3464 | 3411 | default: |
3465 | 3412 | return NOT_HANDLED; |
3466 | 3413 | } |
@@ -3510,7 +3457,6 @@ public boolean processMessage(Message message) { |
3510 | 3457 | case CMD_SET_FREQUENCY_BAND: |
3511 | 3458 | case CMD_START_PACKET_FILTERING: |
3512 | 3459 | case CMD_STOP_PACKET_FILTERING: |
3513 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
3514 | 3460 | deferMessage(message); |
3515 | 3461 | break; |
3516 | 3462 | default: |
@@ -3606,7 +3552,6 @@ public boolean processMessage(Message message) { |
3606 | 3552 | case CMD_SET_FREQUENCY_BAND: |
3607 | 3553 | case CMD_START_PACKET_FILTERING: |
3608 | 3554 | case CMD_STOP_PACKET_FILTERING: |
3609 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
3610 | 3555 | deferMessage(message); |
3611 | 3556 | break; |
3612 | 3557 | default: |
|
0 commit comments