Skip to content

Commit 5bc09e2

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Disable notification scans when p2p is connected" into jb-mr1-dev
2 parents 3443602 + 3809f50 commit 5bc09e2

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

core/java/android/provider/Settings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5613,6 +5613,13 @@ public static final class Global extends NameValueTable {
56135613
public static final String WIFI_SUPPLICANT_SCAN_INTERVAL_MS =
56145614
"wifi_supplicant_scan_interval_ms";
56155615

5616+
/**
5617+
* The interval in milliseconds to scan at supplicant when p2p is connected
5618+
* @hide
5619+
*/
5620+
public static final String WIFI_SCAN_INTERVAL_WHEN_P2P_CONNECTED_MS =
5621+
"wifi_scan_interval_p2p_connected_ms";
5622+
56165623
/**
56175624
* Whether the Wi-Fi watchdog is enabled.
56185625
*/

core/res/res/values/config.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@
292292
<!-- Integer indicating wpa_supplicant scan interval in milliseconds -->
293293
<integer translatable="false" name="config_wifi_supplicant_scan_interval">15000</integer>
294294

295+
<!-- Integer indicating wpa_supplicant scan interval when p2p is connected in milliseconds -->
296+
<integer translatable="false" name="config_wifi_scan_interval_p2p_connected">60000</integer>
297+
295298
<!-- Integer indicating the framework scan interval in milliseconds. This is used in the scenario
296299
where the chipset does not support background scanning (config_wifi_background_scan_suport
297300
is false) to set up a periodic wake up scan so that the device can connect to a new access

core/res/res/values/symbols.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
<java-symbol type="integer" name="config_ntpTimeout" />
276276
<java-symbol type="integer" name="config_wifi_framework_scan_interval" />
277277
<java-symbol type="integer" name="config_wifi_supplicant_scan_interval" />
278+
<java-symbol type="integer" name="config_wifi_scan_interval_p2p_connected" />
278279
<java-symbol type="integer" name="db_connection_pool_size" />
279280
<java-symbol type="integer" name="db_journal_size_limit" />
280281
<java-symbol type="integer" name="db_wal_autocheckpoint" />

wifi/java/android/net/wifi/WifiStateMachine.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import android.util.Log;
7676
import android.util.LruCache;
7777

78+
import com.android.internal.R;
7879
import com.android.internal.app.IBatteryStats;
7980
import com.android.internal.util.AsyncChannel;
8081
import 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
}

wifi/java/android/net/wifi/p2p/WifiP2pService.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
137137
/* Idle time after a peer is gone when the group is torn down */
138138
private static final int GROUP_IDLE_TIME_S = 5;
139139

140-
/**
141-
* Delay between restarts upon failure to setup connection with supplicant
142-
*/
143-
private static final int P2P_RESTART_INTERVAL_MSECS = 5000;
144-
145-
/**
146-
* Number of times we attempt to restart p2p
147-
*/
148-
private static final int P2P_RESTART_TRIES = 5;
149-
150-
private int mP2pRestartCount = 0;
151-
152140
private static final int BASE = Protocol.BASE_WIFI_P2P_SERVICE;
153141

154142
/* Delayed message to timeout group creation */
@@ -159,6 +147,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
159147
/* User rejected a peer request */
160148
private static final int PEER_CONNECTION_USER_REJECT = BASE + 3;
161149

150+
/* Commands to the WifiStateMachine */
151+
public static final int P2P_CONNECTION_CHANGED = BASE + 11;
152+
162153
private final boolean mP2pSupported;
163154

164155
private WifiP2pDevice mThisDevice = new WifiP2pDevice();
@@ -1597,6 +1588,8 @@ private void sendP2pConnectionChangedBroadcast() {
15971588
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_INFO, new WifiP2pInfo(mWifiP2pInfo));
15981589
intent.putExtra(WifiP2pManager.EXTRA_NETWORK_INFO, new NetworkInfo(mNetworkInfo));
15991590
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
1591+
mWifiChannel.sendMessage(WifiP2pService.P2P_CONNECTION_CHANGED,
1592+
new NetworkInfo(mNetworkInfo));
16001593
}
16011594

16021595
private void sendP2pPersistentGroupsChangedBroadcast() {

0 commit comments

Comments
 (0)