use of android.os.Messenger in project platform_frameworks_base by android.
the class WakeLoopService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// get wakeup interval from intent
long wakeupInterval = intent.getLongExtra(WAKEUP_INTERNAL, 0);
long maxLoop = intent.getLongExtra(MAX_LOOP, 0);
if (wakeupInterval == 0) {
// stop and error
Log.e(LOG_TAG, "No wakeup interval specified, not starting the service");
stopSelf();
return START_NOT_STICKY;
}
FileUtil.get().writeDateToFile(new File(Environment.getExternalStorageDirectory(), "wakeup-loop-start.txt"));
Log.d(LOG_TAG, String.format("WakeLoop: STARTED interval = %d, total loop = %d", wakeupInterval, maxLoop));
// calculate when device should be waken up
long atTime = SystemClock.elapsedRealtime() + wakeupInterval;
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent wakupIntent = new Intent(WakeUpCall.WAKEUP_CALL).putExtra(WAKEUP_INTERNAL, wakeupInterval).putExtra(MAX_LOOP, maxLoop).putExtra(THIS_LOOP, 0L).putExtra(STOP_CALLBACK, new Messenger(mHandler));
PendingIntent pi = PendingIntent.getBroadcast(this, 0, wakupIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// set alarm, which will be delivered in form of the wakeupIntent
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, atTime, pi);
return START_NOT_STICKY;
}
use of android.os.Messenger in project platform_frameworks_base by android.
the class WakeUpCall method stopService.
private void stopService(Intent i) {
Messenger msgr = i.getParcelableExtra(WakeLoopService.STOP_CALLBACK);
if (msgr == null) {
Log.e(LOG_TAG, "no stop service callback found, cannot stop");
} else {
Message msg = new Message();
msg.what = WakeLoopService.MSG_STOP_SERVICE;
try {
msgr.send(msg);
} catch (RemoteException e) {
Log.e(LOG_TAG, "ignored remoted exception while attempting to stop service", e);
}
}
}
use of android.os.Messenger in project platform_frameworks_base by android.
the class WifiManager method getChannel.
private synchronized AsyncChannel getChannel() {
if (mAsyncChannel == null) {
Messenger messenger = getWifiServiceMessenger();
if (messenger == null) {
throw new IllegalStateException("getWifiServiceMessenger() returned null! This is invalid.");
}
mAsyncChannel = new AsyncChannel();
mConnected = new CountDownLatch(1);
Handler handler = new ServiceHandler(mLooper);
mAsyncChannel.connect(mContext, handler, messenger);
try {
mConnected.await();
} catch (InterruptedException e) {
Log.e(TAG, "interrupted wait at init");
}
}
return mAsyncChannel;
}
use of android.os.Messenger in project XobotOS by xamarin.
the class DataConnectionTracker method broadcastMessenger.
protected void broadcastMessenger() {
Intent intent = new Intent(ACTION_DATA_CONNECTION_TRACKER_MESSENGER);
intent.putExtra(EXTRA_MESSENGER, new Messenger(this));
mPhone.getContext().sendBroadcast(intent);
}
use of android.os.Messenger in project XobotOS by xamarin.
the class AsyncChannel method connectSrcHandlerToPackageSync.
/**
* Connect handler to named package/class synchronously.
*
* @param srcContext is the context of the source
* @param srcHandler is the hander to receive CONNECTED & DISCONNECTED
* messages
* @param dstPackageName is the destination package name
* @param dstClassName is the fully qualified class name (i.e. contains
* package name)
*
* @return STATUS_SUCCESSFUL on success any other value is an error.
*/
public int connectSrcHandlerToPackageSync(Context srcContext, Handler srcHandler, String dstPackageName, String dstClassName) {
if (DBG)
log("connect srcHandler to dst Package & class E");
mConnection = new AsyncChannelConnection();
/* Initialize the source information */
mSrcContext = srcContext;
mSrcHandler = srcHandler;
mSrcMessenger = new Messenger(srcHandler);
/*
* Initialize destination information to null they will
* be initialized when the AsyncChannelConnection#onServiceConnected
* is called
*/
mDstMessenger = null;
/* Send intent to create the connection */
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(dstPackageName, dstClassName);
boolean result = srcContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
if (DBG)
log("connect srcHandler to dst Package & class X result=" + result);
return result ? STATUS_SUCCESSFUL : STATUS_BINDING_UNSUCCESSFUL;
}
Aggregations