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");
}
}
}
}
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;
}
}
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));
}
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)));
}
}
}
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);
}
}
Aggregations