Search in sources :

Example 76 with Messenger

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);
        }
    }
}
Also used : Message(android.os.Message) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

Example 77 with Messenger

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;
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Messenger(android.os.Messenger) PendingIntent(android.app.PendingIntent) File(java.io.File)

Example 78 with Messenger

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);
}
Also used : Messenger(android.os.Messenger)

Example 79 with Messenger

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");
}
Also used : Messenger(android.os.Messenger)

Example 80 with Messenger

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();
    }
}
Also used : Looper(android.os.Looper) DataUsageRequest(android.net.DataUsageRequest) Binder(android.os.Binder) NetworkTemplate(android.net.NetworkTemplate) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

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