Is CHANGE_WIFI_MULTICAST_STATE permission and using WifiManager.MulticastLock to receive multicast packets on Android?

I have a test application that I am using to demonstrate whether multicast traffic turns into an Android device. I see behavior that appears to contradict the Google documentation here and here , which implies two prerequisites for the application to receive multicast traffic:

  • Get MulticastLock
  • Add CHANGE_WIFI_MULTICAST_STATE permission to app manifest

My application can receive multicast traffic without any of these items. Below is a piece of code that sets up a multicast socket to receive data.

MulticastSocket multicastReceiveSocket = new MulticastSocket( 18200 );
multicastReceiveSocket.joinGroup( InetAddress.getByName( "232.232.232.232" ) );

byte[] buffer = new byte[ 65536 ];
DatagramPacket packet = new DatagramPacket( buffer, buffer.length );
multicastReceiveSocket.receive( packet );

      

Should this be happening? Should I receive multicast packets without any two preconditions? I noticed that the MulticastLock documentation says:

Typically, the Wifi stack filters out packets not explicitly addressed to this device.

Does this mean that the behavior may differ from one device to another? I am testing my app on a Samsung Galaxy Note4 (model SM-N910T) running Android 4.4.4. Any clarification on this point would be greatly appreciated.

+3


source to share


3 answers


WifiManager.MulticastLock, when purchased, will change the state of the Wifi interface on the device (gobe) so that all applications can receive multicast traffic. your app will need CHANGE_WIFI_MULTICAST_STATE permission if your app wants to acquire this lock.

In your case, if multicast traffic is received without acquiring this block, it should mean that either

(1) some other application has acquired this blocking, thanks to which the interface now processes / filters and delivers multicast packets as well.

or



(2) the device manufacturer ignored this Android iPhone when designing the device, and the interface always provides all multicast traffic.

The API description does not force vendors to only allow multicast traffic when an application has acquired this block.

Regardless, applications must obtain this block if they want to receive multicast traffic reliably.

+2


source


The MultiCastLock class is used to receive multicast signals (other than AP probes) using a Wi-Fi manager. These packets can be other devices connected to Wi-Fi enabled devices and similar packets caught by your Wi-Fi card.



Here, what you are describing is quite different. You just listen to a specific socket and collect data packets that flow inside your connected network.

0


source


Like other sad things on Android, it depends on the device.

I could just start getting UDP BroadCast packets on Motorola XT890 (RAZRi) with Android 4.4.2 KitKat after adding this permission and getting the multicast blocking.

With Samsung and Nexus devices, this was not necessary.

Apparently other Motorola devices also have this problem:

Moto G tolerance receives UDP packets over WIFI network

0


source







All Articles