7575import android .util .Log ;
7676import android .util .LruCache ;
7777
78+ import com .android .internal .R ;
7879import com .android .internal .app .IBatteryStats ;
7980import com .android .internal .util .AsyncChannel ;
8081import com .android .internal .util .Protocol ;
@@ -112,6 +113,7 @@ public class WifiStateMachine extends StateMachine {
112113 private ConnectivityManager mCm ;
113114
114115 private final boolean mP2pSupported ;
116+ private final AtomicBoolean mP2pConnected = new AtomicBoolean (false );
115117 private final String mPrimaryDeviceType ;
116118
117119 /* Scan results handling */
@@ -595,16 +597,16 @@ public WifiStateMachine(Context context, String wlanInterface) {
595597 mScanIntent = PendingIntent .getBroadcast (mContext , SCAN_REQUEST , scanIntent , 0 );
596598
597599 mDefaultFrameworkScanIntervalMs = mContext .getResources ().getInteger (
598- com . android . internal . R .integer .config_wifi_framework_scan_interval );
600+ R .integer .config_wifi_framework_scan_interval );
599601
600602 mDriverStopDelayMs = mContext .getResources ().getInteger (
601- com . android . internal . R .integer .config_wifi_driver_stop_delay );
603+ R .integer .config_wifi_driver_stop_delay );
602604
603605 mBackgroundScanSupported = mContext .getResources ().getBoolean (
604- com . android . internal . R .bool .config_wifi_background_scan_support );
606+ R .bool .config_wifi_background_scan_support );
605607
606608 mPrimaryDeviceType = mContext .getResources ().getString (
607- com . android . internal . R .string .config_wifi_p2p_device_type );
609+ R .string .config_wifi_p2p_device_type );
608610
609611 mUserWantsSuspendOpt .set (Settings .Secure .getInt (mContext .getContentResolver (),
610612 Settings .Secure .WIFI_SUSPEND_OPTIMIZATIONS_ENABLED , 1 ) == 1 );
@@ -2011,6 +2013,10 @@ public boolean processMessage(Message message) {
20112013 replyToMessage (message , WifiManager .RSSI_PKTCNT_FETCH_FAILED ,
20122014 WifiManager .BUSY );
20132015 break ;
2016+ case WifiP2pService .P2P_CONNECTION_CHANGED :
2017+ NetworkInfo info = (NetworkInfo ) message .obj ;
2018+ mP2pConnected .set (info .isConnected ());
2019+ break ;
20142020 default :
20152021 loge ("Error! unhandled message" + message );
20162022 break ;
@@ -2408,7 +2414,7 @@ public void enter() {
24082414 mNetworkInfo .setIsAvailable (true );
24092415
24102416 int defaultInterval = mContext .getResources ().getInteger (
2411- com . android . internal . R .integer .config_wifi_supplicant_scan_interval );
2417+ R .integer .config_wifi_supplicant_scan_interval );
24122418
24132419 mSupplicantScanIntervalMs = Settings .Global .getLong (mContext .getContentResolver (),
24142420 Settings .Global .WIFI_SUPPLICANT_SCAN_INTERVAL_MS ,
@@ -3486,7 +3492,7 @@ public void enter() {
34863492 * The scans are useful to notify the user of the presence of an open network.
34873493 * Note that these are not wake up scans.
34883494 */
3489- if (mWifiConfigStore .getConfiguredNetworks ().size () == 0 ) {
3495+ if (! mP2pConnected . get () && mWifiConfigStore .getConfiguredNetworks ().size () == 0 ) {
34903496 sendMessageDelayed (obtainMessage (CMD_NO_NETWORKS_PERIODIC_SCAN ,
34913497 ++mPeriodicScanToken , 0 ), mSupplicantScanIntervalMs );
34923498 }
@@ -3497,6 +3503,7 @@ public boolean processMessage(Message message) {
34973503 boolean ret = HANDLED ;
34983504 switch (message .what ) {
34993505 case CMD_NO_NETWORKS_PERIODIC_SCAN :
3506+ if (mP2pConnected .get ()) break ;
35003507 if (message .arg1 == mPeriodicScanToken &&
35013508 mWifiConfigStore .getConfiguredNetworks ().size () == 0 ) {
35023509 sendMessage (CMD_START_SCAN );
@@ -3557,6 +3564,21 @@ public boolean processMessage(Message message) {
35573564 /* Handled in parent state */
35583565 ret = NOT_HANDLED ;
35593566 break ;
3567+ case WifiP2pService .P2P_CONNECTION_CHANGED :
3568+ NetworkInfo info = (NetworkInfo ) message .obj ;
3569+ mP2pConnected .set (info .isConnected ());
3570+ if (mP2pConnected .get ()) {
3571+ int defaultInterval = mContext .getResources ().getInteger (
3572+ R .integer .config_wifi_scan_interval_p2p_connected );
3573+ long scanIntervalMs = Settings .Global .getLong (mContext .getContentResolver (),
3574+ Settings .Global .WIFI_SCAN_INTERVAL_WHEN_P2P_CONNECTED_MS ,
3575+ defaultInterval );
3576+ mWifiNative .setScanInterval ((int ) scanIntervalMs /1000 );
3577+ } else if (mWifiConfigStore .getConfiguredNetworks ().size () == 0 ) {
3578+ if (DBG ) log ("Turn on scanning after p2p disconnected" );
3579+ sendMessageDelayed (obtainMessage (CMD_NO_NETWORKS_PERIODIC_SCAN ,
3580+ ++mPeriodicScanToken , 0 ), mSupplicantScanIntervalMs );
3581+ }
35603582 default :
35613583 ret = NOT_HANDLED ;
35623584 }
0 commit comments