Search in sources :

Example 6 with HandlerThread

use of android.os.HandlerThread in project android_frameworks_base by ParanoidAndroid.

the class StateMachineTest method testStateMachineSharedThread.

@MediumTest
public void testStateMachineSharedThread() throws Exception {
    if (DBG)
        tlog("testStateMachineSharedThread E");
    // Create and start the handler thread
    HandlerThread smThread = new HandlerThread("testStateMachineSharedThread");
    smThread.start();
    // Create the state machines
    StateMachineSharedThread[] sms = new StateMachineSharedThread[10];
    for (int i = 0; i < sms.length; i++) {
        sms[i] = new StateMachineSharedThread("smSharedThread", smThread.getLooper(), sms.length);
        sms[i].start();
    }
    synchronized (waitObject) {
        // Send messages to each of the state machines
        for (StateMachineSharedThread sm : sms) {
            for (int i = 1; i <= 4; i++) {
                sm.sendMessage(i);
            }
        }
        // Wait for the last state machine to notify its done
        try {
            waitObject.wait();
        } catch (InterruptedException e) {
            tloge("testStateMachineSharedThread: exception while waiting " + e.getMessage());
        }
    }
    for (StateMachineSharedThread sm : sms) {
        assertEquals(4, sm.getLogRecCount());
        for (int i = 0; i < sm.getLogRecSize(); i++) {
            LogRec lr = sm.getLogRec(i);
            assertEquals(i + 1, lr.getWhat());
            assertEquals(sm.mS1, lr.getState());
            assertEquals(sm.mS1, lr.getOriginalState());
        }
    }
    if (DBG)
        tlog("testStateMachineSharedThread X");
}
Also used : LogRec(com.android.internal.util.StateMachine.LogRec) HandlerThread(android.os.HandlerThread) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 7 with HandlerThread

use of android.os.HandlerThread in project android_frameworks_base by ParanoidAndroid.

the class NativeDaemonConnector method run.

@Override
public void run() {
    HandlerThread thread = new HandlerThread(TAG + ".CallbackHandler");
    thread.start();
    mCallbackHandler = new Handler(thread.getLooper(), this);
    while (true) {
        try {
            listenToSocket();
        } catch (Exception e) {
            loge("Error in NativeDaemonConnector: " + e);
            SystemClock.sleep(5000);
        }
    }
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) IOException(java.io.IOException)

Example 8 with HandlerThread

use of android.os.HandlerThread in project android_frameworks_base by ParanoidAndroid.

the class PowerManagerService method init.

/**
     * Initialize the power manager.
     * Must be called before any other functions within the power manager are called.
     */
public void init(Context context, LightsService ls, ActivityManagerService am, BatteryService bs, IBatteryStats bss, DisplayManagerService dm) {
    mContext = context;
    mLightsService = ls;
    mBatteryService = bs;
    mBatteryStats = bss;
    mDisplayManagerService = dm;
    mHandlerThread = new HandlerThread(TAG);
    mHandlerThread.start();
    mHandler = new PowerManagerHandler(mHandlerThread.getLooper());
    Watchdog.getInstance().addMonitor(this);
    // Forcibly turn the screen on at boot so that it is in a known power state.
    // We do this in init() rather than in the constructor because setting the
    // screen state requires a call into surface flinger which then needs to call back
    // into the activity manager to check permissions.  Unfortunately the
    // activity manager is not running when the constructor is called, so we
    // have to defer setting the screen state until this point.
    mDisplayBlanker.unblankAllDisplays();
}
Also used : HandlerThread(android.os.HandlerThread)

Example 9 with HandlerThread

use of android.os.HandlerThread in project android_frameworks_base by ParanoidAndroid.

the class WifiManager method init.

private void init() {
    synchronized (sThreadRefLock) {
        if (++sThreadRefCount == 1) {
            Messenger messenger = getWifiServiceMessenger();
            if (messenger == null) {
                sAsyncChannel = null;
                return;
            }
            sHandlerThread = new HandlerThread("WifiManager");
            sAsyncChannel = new AsyncChannel();
            sConnected = new CountDownLatch(1);
            sHandlerThread.start();
            Handler handler = new ServiceHandler(sHandlerThread.getLooper());
            sAsyncChannel.connect(mContext, handler, messenger);
            try {
                sConnected.await();
            } catch (InterruptedException e) {
                Log.e(TAG, "interrupted wait at init");
            }
        }
    }
}
Also used : HandlerThread(android.os.HandlerThread) Handler(android.os.Handler) AsyncChannel(com.android.internal.util.AsyncChannel) Messenger(android.os.Messenger) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 10 with HandlerThread

use of android.os.HandlerThread in project robotium by RobotiumTech.

the class ScreenshotTaker method initScreenShotSaver.

/**
	 * This method initializes the aysnc screenshot saving logic
	 */
private void initScreenShotSaver() {
    if (screenShotSaverThread == null || screenShotSaver == null) {
        screenShotSaverThread = new HandlerThread("ScreenShotSaver");
        screenShotSaverThread.start();
        screenShotSaver = new ScreenShotSaver(screenShotSaverThread);
    }
}
Also used : HandlerThread(android.os.HandlerThread)

Aggregations

HandlerThread (android.os.HandlerThread)292 Handler (android.os.Handler)128 Message (android.os.Message)26 IntentFilter (android.content.IntentFilter)24 Intent (android.content.Intent)22 Context (android.content.Context)20 Test (org.junit.Test)20 PowerManager (android.os.PowerManager)15 Runnable (java.lang.Runnable)15 ComponentName (android.content.ComponentName)14 View (android.view.View)14 PendingIntent (android.app.PendingIntent)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)12 Looper (android.os.Looper)11 RemoteException (android.os.RemoteException)11 MediaFormat (android.media.MediaFormat)10 Pair (android.util.Pair)10 SmallTest (android.test.suitebuilder.annotation.SmallTest)9 Uri (android.net.Uri)8 IOException (java.io.IOException)8