Search in sources :

Example 51 with Messenger

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

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

Example 52 with Messenger

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

the class SettingInjectorService method sendStatus.

/**
     * Send the enabled values back to the caller via the messenger encoded in the
     * intent.
     */
private void sendStatus(Intent intent, boolean enabled) {
    Message message = Message.obtain();
    Bundle bundle = new Bundle();
    bundle.putBoolean(ENABLED_KEY, enabled);
    message.setData(bundle);
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, mName + ": received " + intent + ", enabled=" + enabled + ", sending message: " + message);
    }
    Messenger messenger = intent.getParcelableExtra(MESSENGER_KEY);
    try {
        messenger.send(message);
    } catch (RemoteException e) {
        Log.e(TAG, mName + ": sending dynamic status failed", e);
    }
}
Also used : Message(android.os.Message) Bundle(android.os.Bundle) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

Example 53 with Messenger

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

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Resources res = getResources();
    defaultColor = getColor(R.color.none_received);
    startJobColor = getColor(R.color.start_received);
    stopJobColor = getColor(R.color.stop_received);
    // Set up UI.
    mShowStartView = (TextView) findViewById(R.id.onstart_textview);
    mShowStopView = (TextView) findViewById(R.id.onstop_textview);
    mParamsTextView = (TextView) findViewById(R.id.task_params);
    mDelayEditText = (EditText) findViewById(R.id.delay_time);
    mDeadlineEditText = (EditText) findViewById(R.id.deadline_time);
    mWiFiConnectivityRadioButton = (RadioButton) findViewById(R.id.checkbox_unmetered);
    mAnyConnectivityRadioButton = (RadioButton) findViewById(R.id.checkbox_any);
    mRequiresChargingCheckBox = (CheckBox) findViewById(R.id.checkbox_charging);
    mRequiresIdleCheckbox = (CheckBox) findViewById(R.id.checkbox_idle);
    mIsPersistedCheckbox = (CheckBox) findViewById(R.id.checkbox_persisted);
    mServiceComponent = new ComponentName(this, TestJobService.class);
    // Start service and provide it a way to communicate with us.
    Intent startServiceIntent = new Intent(this, TestJobService.class);
    startServiceIntent.putExtra("messenger", new Messenger(mHandler));
    startService(startServiceIntent);
}
Also used : TestJobService(com.android.demo.jobSchedulerApp.service.TestJobService) ComponentName(android.content.ComponentName) Intent(android.content.Intent) Resources(android.content.res.Resources) Messenger(android.os.Messenger)

Example 54 with Messenger

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

the class TestJobService method onStartCommand.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Messenger callback = intent.getParcelableExtra("messenger");
    Message m = Message.obtain();
    m.what = MainActivity.MSG_SERVICE_OBJ;
    m.obj = this;
    try {
        callback.send(m);
    } catch (RemoteException e) {
        Log.e(TAG, "Error passing service object back to activity.");
    }
    return START_NOT_STICKY;
}
Also used : Message(android.os.Message) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

Example 55 with Messenger

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

the class ScreenshotTile method takeScreenshot.

private void takeScreenshot(final int screenshotType) {
    synchronized (mScreenshotLock) {
        if (mScreenshotConnection != null) {
            return;
        }
        ComponentName cn = new ComponentName("com.android.systemui", "com.android.systemui.screenshot.TakeScreenshotService");
        Intent intent = new Intent();
        intent.setComponent(cn);
        ServiceConnection conn = new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                synchronized (mScreenshotLock) {
                    if (mScreenshotConnection != this) {
                        return;
                    }
                    Messenger messenger = new Messenger(service);
                    Message msg = Message.obtain(null, screenshotType);
                    final ServiceConnection myConn = this;
                    Handler h = new Handler(mHandler.getLooper()) {

                        @Override
                        public void handleMessage(Message msg) {
                            synchronized (mScreenshotLock) {
                                if (mScreenshotConnection == myConn) {
                                    mContext.unbindService(mScreenshotConnection);
                                    mScreenshotConnection = null;
                                    mHandler.removeCallbacks(mScreenshotTimeout);
                                }
                            }
                        }
                    };
                    msg.replyTo = new Messenger(h);
                    msg.arg1 = msg.arg2 = 0;
                    // Take the screenshot
                    try {
                        messenger.send(msg);
                    } catch (RemoteException e) {
                    // Do nothing here
                    }
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
            }
        };
        if (mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
            mScreenshotConnection = conn;
            mHandler.postDelayed(mScreenshotTimeout, 10000);
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Message(android.os.Message) Handler(android.os.Handler) ComponentName(android.content.ComponentName) Intent(android.content.Intent) 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