public class

WifiManager.MulticastLock

extends Object
java.lang.Object
   ↳ android.net.wifi.WifiManager.MulticastLock

Class Overview

Allows an application to receive Wifi Multicast packets. Normally the Wifi stack filters out packets not explicitly addressed to this device. Acquring a MulticastLock will cause the stack to receive packets addressed to multicast addresses. Processing these extra packets can cause a noticable battery drain and should be disabled when not needed.

Summary

Public Methods
void acquire()
Locks Wifi Multicast on until release() is called.
boolean isHeld()
Checks whether this MulticastLock is currently held.
void release()
Unlocks Wifi Multicast, restoring the filter of packets not addressed specifically to this device and saving power.
void setReferenceCounted(boolean refCounted)
Controls whether this is a reference-counted or non-reference- counted MulticastLock.
String toString()
Returns a string containing a concise, human-readable description of this object.
Protected Methods
void finalize()
Is called before the object's memory is being reclaimed by the VM.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void acquire ()

Since: API Level 4

Locks Wifi Multicast on until release() is called. If this MulticastLock is reference-counted each call to acquire will increment the reference count, and the wifi interface will receive multicast packets as long as the reference count is above zero. If this MulticastLock is not reference-counted, the first call to acquire will turn on the multicast packets, but subsequent calls will be ignored. Only one call to release() will be required, regardless of the number of times that acquire is called. Note that other applications may also lock Wifi Multicast on. Only they can relinquish their lock. Also note that applications cannot leave Multicast locked on. When an app exits or crashes, any Multicast locks will be released.

public boolean isHeld ()

Since: API Level 4

Checks whether this MulticastLock is currently held.

Returns
  • true if this MulticastLock is held, false otherwise

public void release ()

Since: API Level 4

Unlocks Wifi Multicast, restoring the filter of packets not addressed specifically to this device and saving power. If this MulticastLock is reference-counted, each call to release will decrement the reference count, and the multicast packets will only stop being received when the reference count reaches zero. If the reference count goes below zero (that is, if release is called a greater number of times than acquire()), an exception is thrown. If this MulticastLock is not reference-counted, the first call to release (after the radio was multicast locked using acquire()) will unlock the multicast, and subsequent calls will be ignored. Note that if any other Wifi Multicast Locks are still outstanding this release call will not have an immediate effect. Only when all applications have released all their Multicast Locks will the Multicast filter be turned back on. Also note that when an app exits or crashes all of its Multicast Locks will be automatically released.

public void setReferenceCounted (boolean refCounted)

Since: API Level 4

Controls whether this is a reference-counted or non-reference- counted MulticastLock. Reference-counted MulticastLocks keep track of the number of calls to acquire() and release(), and only stop the reception of multicast packets when every call to acquire() has been balanced with a call to release(). Non-reference- counted MulticastLocks allow the reception of multicast packets whenever acquire() is called and stop accepting multicast packets whenever release() is called.

Parameters
refCounted true if this MulticastLock should keep a reference count

public String toString ()

Since: API Level 4

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's hashCode(), that is, it is equivalent to the following expression:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a printable representation of this object.

Protected Methods

protected void finalize ()

Since: API Level 4

Is called before the object's memory is being reclaimed by the VM. This can only happen once the VM has detected, during a run of the garbage collector, that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override finalize() as required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize() will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection.

Throws
Throwable