Search in sources :

Example 66 with HandlerThread

use of android.os.HandlerThread in project simple-stack by Zhuinden.

the class MainScopeListener method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    handlerThread = new HandlerThread("LOOPER_SCHEDULER");
    handlerThread.start();
    synchronized (handlerThread) {
        looperScheduler.setScheduler(AndroidSchedulers.from(handlerThread.getLooper()));
    }
    databaseManager.openDatabase();
}
Also used : HandlerThread(android.os.HandlerThread)

Example 67 with HandlerThread

use of android.os.HandlerThread in project simple-stack by Zhuinden.

the class MainScopeListener method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    handlerThread = new HandlerThread("LOOPER_SCHEDULER");
    handlerThread.start();
    synchronized (handlerThread) {
        looperScheduler.setScheduler(AndroidSchedulers.from(handlerThread.getLooper()));
    }
    databaseManager.openDatabase();
}
Also used : HandlerThread(android.os.HandlerThread)

Example 68 with HandlerThread

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

the class IntentService method onCreate.

@Override
public void onCreate() {
    // TODO: It would be nice to have an option to hold a partial wakelock
    // during processing, and to have a static startService(Context, Intent)
    // method that would launch the service & hand off a wakelock.
    super.onCreate();
    HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");
    thread.start();
    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);
}
Also used : HandlerThread(android.os.HandlerThread)

Example 69 with HandlerThread

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

the class HandlerThreadTest method testHandlerThread.

@MediumTest
public void testHandlerThread() throws Exception {
    HandlerThread th1 = new HandlerThread("HandlerThreadTest") {

        protected void onLooperPrepared() {
            synchronized (HandlerThreadTest.this) {
                mDidSetup = true;
                mLooperTid = Process.myTid();
                HandlerThreadTest.this.notify();
            }
        }
    };
    assertFalse(th1.isAlive());
    assertNull(th1.getLooper());
    th1.start();
    assertTrue(th1.isAlive());
    assertNotNull(th1.getLooper());
    // and fill in the values we expect.
    synchronized (this) {
        while (!mDidSetup) {
            try {
                wait();
            } catch (InterruptedException e) {
            }
        }
    }
    // Make sure that the process was set.
    assertNotSame(-1, mLooperTid);
    // Make sure that the onLooperPrepared() was called on a different thread.
    assertNotSame(Process.myTid(), mLooperTid);
    final Handler h1 = new Handler(th1.getLooper()) {

        public void handleMessage(Message msg) {
            assertEquals(TEST_WHAT, msg.what);
            // Ensure that we are running on the same thread in which the looper was setup on.
            assertEquals(mLooperTid, Process.myTid());
            mGotMessageWhat = msg.what;
            mGotMessage = true;
            synchronized (this) {
                notifyAll();
            }
        }
    };
    Message msg = h1.obtainMessage(TEST_WHAT);
    synchronized (h1) {
        // wait until we have the lock before sending the message.
        h1.sendMessage(msg);
        try {
            // wait for the message to be handled
            h1.wait();
        } catch (InterruptedException e) {
        }
    }
    assertTrue(mGotMessage);
    assertEquals(TEST_WHAT, mGotMessageWhat);
}
Also used : HandlerThread(android.os.HandlerThread) Message(android.os.Message) Handler(android.os.Handler) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 70 with HandlerThread

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

the class CameraDeviceBinderTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    /**
         * Workaround for mockito and JB-MR2 incompatibility
         *
         * Avoid java.lang.IllegalArgumentException: dexcache == null
         * https://code.google.com/p/dexmaker/issues/detail?id=2
         */
    System.setProperty("dexmaker.dexcache", getContext().getCacheDir().toString());
    mUtils = new CameraBinderTestUtils(getContext());
    // This cannot be set in the constructor, since the onCreate isn't
    // called yet
    mCameraId = MediaFrameworkIntegrationTestRunner.mCameraId;
    ICameraDeviceCallbacks.Stub dummyCallbacks = new DummyCameraDeviceCallbacks();
    String clientPackageName = getContext().getPackageName();
    mMockCb = spy(dummyCallbacks);
    mCameraUser = mUtils.getCameraService().connectDevice(mMockCb, mCameraId, clientPackageName, ICameraService.USE_CALLING_UID);
    assertNotNull(String.format("Camera %s was null", mCameraId), mCameraUser);
    mHandlerThread = new HandlerThread(TAG);
    mHandlerThread.start();
    mHandler = new Handler(mHandlerThread.getLooper());
    createDefaultSurface();
    Log.v(TAG, String.format("Camera %s connected", mCameraId));
}
Also used : HandlerThread(android.os.HandlerThread) ICameraDeviceCallbacks(android.hardware.camera2.ICameraDeviceCallbacks) Handler(android.os.Handler)

Aggregations

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