Search in sources :

Example 6 with Messenger

use of android.os.Messenger 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 7 with Messenger

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

the class WifiP2pManager method initialize.

/**
     * Registers the application with the Wi-Fi framework. This function
     * must be the first to be called before any p2p operations are performed.
     *
     * @param srcContext is the context of the source
     * @param srcLooper is the Looper on which the callbacks are receivied
     * @param listener for callback at loss of framework communication. Can be null.
     * @return Channel instance that is necessary for performing any further p2p operations
     */
public Channel initialize(Context srcContext, Looper srcLooper, ChannelListener listener) {
    Messenger messenger = getMessenger();
    if (messenger == null)
        return null;
    Channel c = new Channel(srcContext, srcLooper, listener);
    if (c.mAsyncChannel.connectSync(srcContext, c.mHandler, messenger) == AsyncChannel.STATUS_SUCCESSFUL) {
        return c;
    } else {
        return null;
    }
}
Also used : AsyncChannel(com.android.internal.util.AsyncChannel) Messenger(android.os.Messenger)

Example 8 with Messenger

use of android.os.Messenger in project robolectric by robolectric.

the class ShadowMessengerTest method testMessengerSend.

@Test
public void testMessengerSend() throws Exception {
    Handler handler = new Handler();
    Messenger messenger = new Messenger(handler);
    ShadowLooper.pauseMainLooper();
    Message msg = Message.obtain(null, 123);
    messenger.send(msg);
    assertTrue(handler.hasMessages(123));
    ShadowHandler.runMainLooperOneTask();
    assertFalse(handler.hasMessages(123));
}
Also used : Message(android.os.Message) Handler(android.os.Handler) Messenger(android.os.Messenger) Test(org.junit.Test)

Example 9 with Messenger

use of android.os.Messenger in project mechanoid by robotoworks.

the class OperationService method onOperationProgress.

public void onOperationProgress(Intent request, int progress, Bundle data) {
    if (mEnableLogging) {
        Log.d(mLogTag, String.format("[Operation Progress] request:%s, progress:%s, data:%s", request, progress, data));
    }
    Messenger messenger = request.getParcelableExtra(EXTRA_BRIDGE_MESSENGER);
    Message m = new Message();
    m.what = OperationServiceBridge.MSG_OPERATION_PROGRESS;
    m.arg1 = OperationServiceBridge.getOperationRequestId(request);
    m.arg2 = progress;
    m.setData(data);
    try {
        messenger.send(m);
    } catch (RemoteException e) {
        if (mEnableLogging) {
            Log.e(mLogTag, String.format("[Operation Exception] %s", Log.getStackTraceString(e)));
        }
    }
}
Also used : Message(android.os.Message) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

Example 10 with Messenger

use of android.os.Messenger in project nfcspy by sinpolib.

the class ServiceAgent method onStartCommand.

private void onStartCommand(Intent intent) {
    Messenger messenger = ServiceFactory.getReplyMessengerExtra(intent);
    if ((outbox = messenger) != null) {
        if (p2p.isConnected()) {
            sendStatus2Activity(MSG_P2P_CONNECT, STA_SUCCESS, STA_NOTCARE);
            return;
        }
        if (!p2p.isInited()) {
            p2p.init(service, this);
            if (!hasRegistered) {
                service.registerReceiver(this, P2PFILTER);
                hasRegistered = true;
            }
            sendStatus2Activity(MSG_P2P_INIT, STA_SUCCESS, STA_NOTCARE);
        }
        sendStatus2Activity(MSG_P2P_CONNECT, STA_P2P_WATING, STA_NOTCARE);
        delayAction(MSG_SERVER_KILL, 90000);
        new Wifip2pRequestConnectionInfo(this).execute(p2p);
    }
}
Also used : Messenger(android.os.Messenger)

Aggregations

Messenger (android.os.Messenger)108 RemoteException (android.os.RemoteException)44 Message (android.os.Message)42 Intent (android.content.Intent)38 Handler (android.os.Handler)27 ComponentName (android.content.ComponentName)23 IBinder (android.os.IBinder)23 ServiceConnection (android.content.ServiceConnection)19 DataUsageRequest (android.net.DataUsageRequest)9 Looper (android.os.Looper)9 ConditionVariable (android.os.ConditionVariable)8 AsyncChannel (com.android.internal.util.AsyncChannel)8 PendingIntent (android.app.PendingIntent)7 Bundle (android.os.Bundle)7 HandlerThread (android.os.HandlerThread)7 Binder (android.os.Binder)6 File (java.io.File)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 NetworkTemplate (android.net.NetworkTemplate)5 RecognizerIntent (android.speech.RecognizerIntent)5