public abstract class UEventObserver extends Object
Subclass UEventObserver, implementing onUEvent(UEvent event), then call startObserving() with a match string. The UEvent thread will then call your onUEvent() method when a UEvent occurs that contains your match string.
Call stopObserving() to stop receiving UEvents.
There is only one UEvent thread per process, even if that process has multiple UEventObserver subclass instances. The UEvent thread starts when the startObserving() is called for the first time in that process. Once started the UEvent thread will not stop (although it can stop notifying UEventObserver's via stopObserving()).
Modifier and Type | Class and Description |
---|---|
static class |
UEventObserver.UEvent
Representation of a UEvent.
|
Constructor and Description |
---|
UEventObserver() |
Modifier and Type | Method and Description |
---|---|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
abstract void |
onUEvent(UEventObserver.UEvent event)
Subclasses of UEventObserver should override this method to handle
UEvents.
|
void |
startObserving(String match)
Begin observation of UEvents.
|
void |
stopObserving()
End observation of UEvents.
|
protected void finalize() throws Throwable
Object
finalize
method to dispose of
system resources or to perform other cleanup.
The general contract of finalize
is that it is invoked
if and when the JavaTM virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize
method may take any action, including
making this object available again to other threads; the usual purpose
of finalize
, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize
method of class Object
performs no
special action; it simply returns normally. Subclasses of
Object
may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize
method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize
method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize
method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize
method causes
the finalization of this object to be halted, but is otherwise
ignored.
public final void startObserving(String match)
This method will cause the UEvent thread to start if this is the first invocation of startObserving in this process.
Once called, the UEvent thread will call onUEvent() when an incoming UEvent matches the specified string.
This method can be called multiple times to register multiple matches. Only one call to stopObserving is required even with multiple registered matches.
match
- A substring of the UEvent to match. Try to be as specific
as possible to avoid incurring unintended additional cost from processing
irrelevant messages. Netlink messages can be moderately high bandwidth and
are expensive to parse. For example, some devices may send one netlink message
for each vsync period.public final void stopObserving()
This process's UEvent thread will never call onUEvent() on this UEventObserver after this call. Repeated calls have no effect.
public abstract void onUEvent(UEventObserver.UEvent event)