Skip to content

Commit dd4c771

Browse files
isheriffAndroid (Google) Code Review
authored andcommitted
Merge "Disable p2p when airplane mode is turned on"
2 parents 1fe61d7 + 295da73 commit dd4c771

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub {
132132
/* User rejected to disable Wi-Fi in order to enable p2p */
133133
private static final int WIFI_DISABLE_USER_REJECT = BASE + 5;
134134

135+
/* Airplane mode changed */
136+
private static final int AIRPLANE_MODE_CHANGED = BASE + 6;
137+
135138
private final boolean mP2pSupported;
136139
private final String mDeviceType;
137140
private String mDeviceName;
@@ -168,6 +171,7 @@ public WifiP2pService(Context context) {
168171
// broadcasts
169172
IntentFilter filter = new IntentFilter();
170173
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
174+
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
171175
filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
172176
mContext.registerReceiver(new WifiStateReceiver(), filter);
173177

@@ -187,6 +191,8 @@ public void onReceive(Context context, Intent intent) {
187191
} else if (intent.getAction().equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
188192
mWifiApState = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE,
189193
WifiManager.WIFI_AP_STATE_DISABLED);
194+
} else if (intent.getAction().equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
195+
mP2pStateMachine.sendMessage(AIRPLANE_MODE_CHANGED);
190196
}
191197
}
192198
}
@@ -352,7 +358,10 @@ public boolean processMessage(Message message) {
352358
case WifiP2pManager.REQUEST_GROUP_INFO:
353359
replyToMessage(message, WifiP2pManager.RESPONSE_GROUP_INFO, mGroup);
354360
break;
355-
// Ignore
361+
case AIRPLANE_MODE_CHANGED:
362+
if (isAirplaneModeOn()) sendMessage(WifiP2pManager.DISABLE_P2P);
363+
break;
364+
// Ignore
356365
case WIFI_DISABLE_USER_ACCEPT:
357366
case WIFI_DISABLE_USER_REJECT:
358367
case GROUP_NEGOTIATION_TIMED_OUT:
@@ -1266,5 +1275,17 @@ private void clearNotification() {
12661275
}
12671276
}
12681277

1278+
private boolean isAirplaneSensitive() {
1279+
String airplaneModeRadios = Settings.System.getString(mContext.getContentResolver(),
1280+
Settings.System.AIRPLANE_MODE_RADIOS);
1281+
return airplaneModeRadios == null
1282+
|| airplaneModeRadios.contains(Settings.System.RADIO_WIFI);
1283+
}
1284+
1285+
private boolean isAirplaneModeOn() {
1286+
return isAirplaneSensitive() && Settings.System.getInt(mContext.getContentResolver(),
1287+
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
1288+
}
1289+
12691290
}
12701291
}

0 commit comments

Comments
 (0)