use of android.os.Messenger in project android_frameworks_base by DirtyUnicorns.
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 android_frameworks_base by DirtyUnicorns.
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 XobotOS by xamarin.
the class AsyncService method onCreate.
/**
* onCreate
*/
@Override
public void onCreate() {
super.onCreate();
mAsyncServiceInfo = createHandler();
mHandler = mAsyncServiceInfo.mHandler;
mMessenger = new Messenger(mHandler);
}
use of android.os.Messenger in project XobotOS by xamarin.
the class AsyncChannel method connected.
/**
* Connect handler to messenger. This method is typically called
* when a server receives a CMD_CHANNEL_FULL_CONNECTION request
* and initializes the internal instance variables to allow communication
* with the dstMessenger.
*
* @param srcContext
* @param srcHandler
* @param dstMessenger
*/
public void connected(Context srcContext, Handler srcHandler, Messenger dstMessenger) {
if (DBG)
log("connected srcHandler to the dstMessenger E");
// Initialize source fields
mSrcContext = srcContext;
mSrcHandler = srcHandler;
mSrcMessenger = new Messenger(mSrcHandler);
// Initialize destination fields
mDstMessenger = dstMessenger;
if (DBG)
log("connected srcHandler to the dstMessenger X");
}
use of android.os.Messenger in project android_frameworks_base by DirtyUnicorns.
the class NetworkStatsManager method registerUsageCallback.
/**
* Registers to receive notifications about data usage on specified networks.
*
* <p>The callbacks will continue to be called as long as the process is live or
* {@link #unregisterUsageCallback} is called.
*
* @param networkType Type of network to monitor. Either
{@link ConnectivityManager#TYPE_MOBILE} or {@link ConnectivityManager#TYPE_WIFI}.
* @param subscriberId If applicable, the subscriber id of the network interface.
* @param thresholdBytes Threshold in bytes to be notified on.
* @param callback The {@link UsageCallback} that the system will call when data usage
* has exceeded the specified threshold.
* @param handler to dispatch callback events through, otherwise if {@code null} it uses
* the calling thread.
*/
public void registerUsageCallback(int networkType, String subscriberId, long thresholdBytes, UsageCallback callback, @Nullable Handler handler) {
checkNotNull(callback, "UsageCallback cannot be null");
final Looper looper;
if (handler == null) {
looper = Looper.myLooper();
} else {
looper = handler.getLooper();
}
if (DBG) {
Log.d(TAG, "registerUsageCallback called with: {" + " networkType=" + networkType + " subscriberId=" + subscriberId + " thresholdBytes=" + thresholdBytes + " }");
}
NetworkTemplate template = createTemplate(networkType, subscriberId);
DataUsageRequest request = new DataUsageRequest(DataUsageRequest.REQUEST_ID_UNSET, template, thresholdBytes);
try {
CallbackHandler callbackHandler = new CallbackHandler(looper, networkType, subscriberId, callback);
callback.request = mService.registerUsageCallback(mContext.getOpPackageName(), request, new Messenger(callbackHandler), new Binder());
if (DBG)
Log.d(TAG, "registerUsageCallback returned " + callback.request);
if (callback.request == null) {
Log.e(TAG, "Request from callback is null; should not happen");
}
} catch (RemoteException e) {
if (DBG)
Log.d(TAG, "Remote exception when registering callback");
throw e.rethrowFromSystemServer();
}
}
Aggregations