FileDocCategorySizeDatePackage
UEventObserver.javaAPI DocAndroid 5.1 API8321Thu Mar 12 22:22:10 GMT 2015android.os

UEventObserver

public abstract class UEventObserver extends Object
UEventObserver is an abstract class that receives UEvent's from the kernel.

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 UEvent's.

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()).

hide

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static UEventThread
sThread
Constructors Summary
public UEventObserver()


        
        
         
         

      
    
Methods Summary
protected voidfinalize()

        try {
            stopObserving();
        } finally {
            super.finalize();
        }
    
private static android.os.UEventObserver$UEventThreadgetThread()

        synchronized (UEventObserver.class) {
            if (sThread == null) {
                sThread = new UEventThread();
                sThread.start();
            }
            return sThread;
        }
    
private static native voidnativeAddMatch(java.lang.String match)

private static native voidnativeRemoveMatch(java.lang.String match)

private static native voidnativeSetup()

private static native java.lang.StringnativeWaitForNextEvent()

public abstract voidonUEvent(android.os.UEventObserver$UEvent event)
Subclasses of UEventObserver should override this method to handle UEvents.

private static android.os.UEventObserver$UEventThreadpeekThread()

        synchronized (UEventObserver.class) {
            return sThread;
        }
    
public final voidstartObserving(java.lang.String match)
Begin observation of UEvent's.

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.

param
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.

        if (match == null || match.isEmpty()) {
            throw new IllegalArgumentException("match substring must be non-empty");
        }

        final UEventThread t = getThread();
        t.addObserver(match, this);
    
public final voidstopObserving()
End observation of UEvent's.

This process's UEvent thread will never call onUEvent() on this UEventObserver after this call. Repeated calls have no effect.

        final UEventThread t = getThread();
        if (t != null) {
            t.removeObserver(this);
        }