|
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 |
|
@@ -1892,11 +1894,6 @@ public boolean processMessage(Message message) { |
1892 | 1894 | mReplyChannel.replyToMessage(message, WifiManager.CMD_WPS_COMPLETED, |
1893 | 1895 | new WpsResult(Status.FAILURE)); |
1894 | 1896 | break; |
1895 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
1896 | | - // turn off wifi and defer to be handled in DriverUnloadedState |
1897 | | - setWifiEnabled(false); |
1898 | | - deferMessage(message); |
1899 | | - break; |
1900 | 1897 | default: |
1901 | 1898 | loge("Error! unhandled message" + message); |
1902 | 1899 | break; |
@@ -2056,7 +2053,7 @@ public boolean processMessage(Message message) { |
2056 | 2053 | loge("Unable to change interface settings: " + ie); |
2057 | 2054 | } |
2058 | 2055 |
|
2059 | | - if(mWifiNative.startSupplicant()) { |
| 2056 | + if(mWifiNative.startSupplicant(mP2pSupported)) { |
2060 | 2057 | if (DBG) log("Supplicant start successful"); |
2061 | 2058 | mWifiMonitor.startMonitoring(); |
2062 | 2059 | transitionTo(mSupplicantStartingState); |
@@ -2168,11 +2165,7 @@ public boolean processMessage(Message message) { |
2168 | 2165 | if (DBG) log(getName() + message.toString() + "\n"); |
2169 | 2166 | switch (message.what) { |
2170 | 2167 | case CMD_LOAD_DRIVER: |
2171 | | - mWifiP2pChannel.sendMessage(WIFI_ENABLE_PENDING); |
2172 | | - transitionTo(mWaitForP2pDisableState); |
2173 | | - break; |
2174 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
2175 | | - mReplyChannel.replyToMessage(message, P2P_ENABLE_PROCEED); |
| 2168 | + transitionTo(mDriverLoadingState); |
2176 | 2169 | break; |
2177 | 2170 | default: |
2178 | 2171 | return NOT_HANDLED; |
@@ -2549,13 +2542,15 @@ public void enter() { |
2549 | 2542 | mWifiNative.status(); |
2550 | 2543 | transitionTo(mDisconnectedState); |
2551 | 2544 | } |
| 2545 | + |
| 2546 | + if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_ENABLE_P2P); |
2552 | 2547 | } |
2553 | 2548 | @Override |
2554 | 2549 | public boolean processMessage(Message message) { |
2555 | 2550 | if (DBG) log(getName() + message.toString() + "\n"); |
2556 | 2551 | boolean eventLoggingEnabled = true; |
2557 | 2552 | switch(message.what) { |
2558 | | - case CMD_SET_SCAN_TYPE: |
| 2553 | + case CMD_SET_SCAN_TYPE: |
2559 | 2554 | mSetScanActive = (message.arg1 == SCAN_ACTIVE); |
2560 | 2555 | mWifiNative.setScanMode(mSetScanActive); |
2561 | 2556 | break; |
@@ -2668,6 +2663,8 @@ public void exit() { |
2668 | 2663 | mIsRunning = false; |
2669 | 2664 | updateBatteryWorkSource(null); |
2670 | 2665 | mScanResults = null; |
| 2666 | + |
| 2667 | + if (mP2pSupported) mWifiP2pChannel.sendMessage(WifiStateMachine.CMD_DISABLE_P2P); |
2671 | 2668 | } |
2672 | 2669 | } |
2673 | 2670 |
|
@@ -3341,7 +3338,6 @@ public boolean processMessage(Message message) { |
3341 | 3338 | case CMD_START_PACKET_FILTERING: |
3342 | 3339 | case CMD_STOP_PACKET_FILTERING: |
3343 | 3340 | case CMD_TETHER_STATE_CHANGE: |
3344 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
3345 | 3341 | deferMessage(message); |
3346 | 3342 | break; |
3347 | 3343 | case WifiStateMachine.CMD_RESPONSE_AP_CONFIG: |
@@ -3405,55 +3401,6 @@ public boolean processMessage(Message message) { |
3405 | 3401 | transitionTo(mTetheringState); |
3406 | 3402 | } |
3407 | 3403 | break; |
3408 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
3409 | | - // turn of soft Ap and defer to be handled in DriverUnloadedState |
3410 | | - setWifiApEnabled(null, false); |
3411 | | - deferMessage(message); |
3412 | | - break; |
3413 | | - default: |
3414 | | - return NOT_HANDLED; |
3415 | | - } |
3416 | | - EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what); |
3417 | | - return HANDLED; |
3418 | | - } |
3419 | | - } |
3420 | | - |
3421 | | - class WaitForP2pDisableState extends State { |
3422 | | - private int mSavedArg; |
3423 | | - @Override |
3424 | | - public void enter() { |
3425 | | - if (DBG) log(getName() + "\n"); |
3426 | | - EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName()); |
3427 | | - |
3428 | | - //Preserve the argument arg1 that has information used in DriverLoadingState |
3429 | | - mSavedArg = getCurrentMessage().arg1; |
3430 | | - } |
3431 | | - @Override |
3432 | | - public boolean processMessage(Message message) { |
3433 | | - if (DBG) log(getName() + message.toString() + "\n"); |
3434 | | - switch(message.what) { |
3435 | | - case WifiP2pService.WIFI_ENABLE_PROCEED: |
3436 | | - //restore argument from original message (CMD_LOAD_DRIVER) |
3437 | | - message.arg1 = mSavedArg; |
3438 | | - transitionTo(mDriverLoadingState); |
3439 | | - break; |
3440 | | - case CMD_LOAD_DRIVER: |
3441 | | - case CMD_UNLOAD_DRIVER: |
3442 | | - case CMD_START_SUPPLICANT: |
3443 | | - case CMD_STOP_SUPPLICANT: |
3444 | | - case CMD_START_AP: |
3445 | | - case CMD_STOP_AP: |
3446 | | - case CMD_START_DRIVER: |
3447 | | - case CMD_STOP_DRIVER: |
3448 | | - case CMD_SET_SCAN_MODE: |
3449 | | - case CMD_SET_SCAN_TYPE: |
3450 | | - case CMD_SET_HIGH_PERF_MODE: |
3451 | | - case CMD_SET_COUNTRY_CODE: |
3452 | | - case CMD_SET_FREQUENCY_BAND: |
3453 | | - case CMD_START_PACKET_FILTERING: |
3454 | | - case CMD_STOP_PACKET_FILTERING: |
3455 | | - deferMessage(message); |
3456 | | - break; |
3457 | 3404 | default: |
3458 | 3405 | return NOT_HANDLED; |
3459 | 3406 | } |
@@ -3503,7 +3450,6 @@ public boolean processMessage(Message message) { |
3503 | 3450 | case CMD_SET_FREQUENCY_BAND: |
3504 | 3451 | case CMD_START_PACKET_FILTERING: |
3505 | 3452 | case CMD_STOP_PACKET_FILTERING: |
3506 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
3507 | 3453 | deferMessage(message); |
3508 | 3454 | break; |
3509 | 3455 | default: |
@@ -3599,7 +3545,6 @@ public boolean processMessage(Message message) { |
3599 | 3545 | case CMD_SET_FREQUENCY_BAND: |
3600 | 3546 | case CMD_START_PACKET_FILTERING: |
3601 | 3547 | case CMD_STOP_PACKET_FILTERING: |
3602 | | - case WifiP2pService.P2P_ENABLE_PENDING: |
3603 | 3548 | deferMessage(message); |
3604 | 3549 | break; |
3605 | 3550 | default: |
|
0 commit comments