summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorMichael Plass <mplass@google.com>2018-05-22 11:58:18 -0700
committerMichael Plass <mplass@google.com>2018-05-31 16:12:03 -0700
commit2f2f41dca22a9463af648bd823e4620bff4bb5bd (patch)
tree66d20ab416067ec51b42b1f8d63080c08e08678e /service
parentc231fb2d5b30ef8faa41399d0feed9b6448e85f9 (diff)
Restrict wifi p2p broadcasts
Only apps with appropriate permissions should receive broadcasts that carry device or peer information. Bug: 77228252 Test: Unit tests Test: CtsVerifier Wi-Fi Direct tests Test: Manually exercise Wi-Fi Direct settings Change-Id: I58a57a82023a1b4f4a65548ef90665fb7ff6a751
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java30
1 files changed, 26 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
index c089c9c09..a0409bf79 100644
--- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
+++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
@@ -127,6 +127,13 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
private static final Boolean RELOAD = true;
private static final Boolean NO_RELOAD = false;
+ private static final String[] RECEIVER_PERMISSIONS_FOR_BROADCAST = {
+ android.Manifest.permission.ACCESS_COARSE_LOCATION,
+ android.Manifest.permission.ACCESS_NETWORK_STATE,
+ android.Manifest.permission.ACCESS_WIFI_STATE,
+ android.Manifest.permission.CHANGE_WIFI_STATE
+ };
+
// Two minutes comes from the wpa_supplicant setting
private static final int GROUP_CREATING_WAIT_TIME_MS = 120 * 1000;
private static int sGroupCreatingTimeoutIndex = 0;
@@ -1190,6 +1197,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
mNetworkInfo.setIsAvailable(true);
sendP2pConnectionChangedBroadcast();
initializeP2pSettings();
+ refreshBroadcasts();
}
@Override
@@ -1201,7 +1209,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
transitionTo(mP2pDisabledState);
break;
case ENABLE_P2P:
- // Nothing to do
+ refreshBroadcasts();
break;
case DISABLE_P2P:
if (mPeers.clear()) {
@@ -2537,14 +2545,17 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_DEVICE, new WifiP2pDevice(mThisDevice));
- mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
+ // Formerly sticky
+ mContext.sendBroadcastAsUserMultiplePermissions(intent, UserHandle.ALL,
+ RECEIVER_PERMISSIONS_FOR_BROADCAST);
}
private void sendPeersChangedBroadcast() {
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
intent.putExtra(WifiP2pManager.EXTRA_P2P_DEVICE_LIST, new WifiP2pDeviceList(mPeers));
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
- mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+ mContext.sendBroadcastAsUserMultiplePermissions(intent, UserHandle.ALL,
+ RECEIVER_PERMISSIONS_FOR_BROADCAST);
}
private void sendP2pConnectionChangedBroadcast() {
@@ -2555,7 +2566,9 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_INFO, new WifiP2pInfo(mWifiP2pInfo));
intent.putExtra(WifiP2pManager.EXTRA_NETWORK_INFO, new NetworkInfo(mNetworkInfo));
intent.putExtra(WifiP2pManager.EXTRA_WIFI_P2P_GROUP, new WifiP2pGroup(mGroup));
- mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
+ // Formerly sticky
+ mContext.sendBroadcastAsUserMultiplePermissions(intent, UserHandle.ALL,
+ RECEIVER_PERMISSIONS_FOR_BROADCAST);
if (mWifiChannel != null) {
mWifiChannel.sendMessage(WifiP2pServiceImpl.P2P_CONNECTION_CHANGED,
new NetworkInfo(mNetworkInfo));
@@ -2571,6 +2584,15 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
}
+ /**
+ * These broadcasts were formerly sticky; send them again after critical changes to ease
+ * transition.
+ */
+ private void refreshBroadcasts() {
+ sendThisDeviceChangedBroadcast();
+ sendP2pConnectionChangedBroadcast();
+ }
+
private void startDhcpServer(String intf) {
InterfaceConfiguration ifcg = null;
try {