Search in sources :

Example 66 with Messenger

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

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 67 with Messenger

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

the class ConnectivityManager method sendRequestForNetwork.

private NetworkRequest sendRequestForNetwork(NetworkCapabilities need, NetworkCallback callback, int timeoutMs, int action, int legacyType, CallbackHandler handler) {
    if (callback == null) {
        throw new IllegalArgumentException("null NetworkCallback");
    }
    if (need == null && action != REQUEST) {
        throw new IllegalArgumentException("null NetworkCapabilities");
    }
    // TODO: throw an exception if callback.networkRequest is not null.
    // http://b/20701525
    final NetworkRequest request;
    try {
        synchronized (sCallbacks) {
            Messenger messenger = new Messenger(handler);
            Binder binder = new Binder();
            if (action == LISTEN) {
                request = mService.listenForNetwork(need, messenger, binder);
            } else {
                request = mService.requestNetwork(need, messenger, timeoutMs, binder, legacyType);
            }
            if (request != null) {
                sCallbacks.put(request, callback);
            }
            callback.networkRequest = request;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
    return request;
}
Also used : IBinder(android.os.IBinder) Binder(android.os.Binder) Messenger(android.os.Messenger) RemoteException(android.os.RemoteException)

Example 68 with Messenger

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

the class NetworkFactory method register.

public void register() {
    if (DBG)
        log("Registering NetworkFactory");
    if (mMessenger == null) {
        mMessenger = new Messenger(this);
        ConnectivityManager.from(mContext).registerNetworkFactory(mMessenger, LOG_TAG);
    }
}
Also used : Messenger(android.os.Messenger)

Example 69 with Messenger

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

the class NetworkStatsObserversTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    MockitoAnnotations.initMocks(this);
    mObserverHandlerThread = new IdleableHandlerThread("HandlerThread");
    mObserverHandlerThread.start();
    final Looper observerLooper = mObserverHandlerThread.getLooper();
    mStatsObservers = new NetworkStatsObservers() {

        @Override
        protected Looper getHandlerLooperLocked() {
            return observerLooper;
        }
    };
    mCv = new ConditionVariable();
    mHandler = new LatchedHandler(Looper.getMainLooper(), mCv);
    mMessenger = new Messenger(mHandler);
    mActiveIfaces = new ArrayMap<>();
    mActiveUidIfaces = new ArrayMap<>();
}
Also used : ConditionVariable(android.os.ConditionVariable) Looper(android.os.Looper) LatchedHandler(com.android.server.net.NetworkStatsServiceTest.LatchedHandler) Messenger(android.os.Messenger) IdleableHandlerThread(com.android.server.net.NetworkStatsServiceTest.IdleableHandlerThread)

Example 70 with Messenger

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

the class PhoneWindowManager method takeScreenrecord.

// Assume this is called from the Handler thread.
private void takeScreenrecord() {
    synchronized (mScreenrecordLock) {
        if (mScreenrecordConnection != null) {
            return;
        }
        ComponentName cn = new ComponentName("com.android.systemui", "com.android.systemui.du.screenrecord.TakeScreenrecordService");
        Intent intent = new Intent();
        intent.setComponent(cn);
        ServiceConnection conn = new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                synchronized (mScreenrecordLock) {
                    Messenger messenger = new Messenger(service);
                    Message msg = Message.obtain(null, 1);
                    final ServiceConnection myConn = this;
                    Handler h = new Handler(mHandler.getLooper()) {

                        @Override
                        public void handleMessage(Message msg) {
                            synchronized (mScreenrecordLock) {
                                if (mScreenrecordConnection == myConn) {
                                    mContext.unbindService(mScreenrecordConnection);
                                    mScreenrecordConnection = null;
                                    mHandler.removeCallbacks(mScreenrecordTimeout);
                                }
                            }
                        }
                    };
                    msg.replyTo = new Messenger(h);
                    msg.arg1 = msg.arg2 = 0;
                    try {
                        messenger.send(msg);
                    } catch (RemoteException e) {
                    }
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
            }
        };
        if (mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
            mScreenrecordConnection = conn;
            // Screenrecord max duration is 30 minutes. Allow 31 minutes before killing
            // the service.
            mHandler.postDelayed(mScreenrecordTimeout, 31 * 60 * 1000);
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) Message(android.os.Message) ActionHandler(com.android.internal.utils.du.ActionHandler) Handler(android.os.Handler) DeviceKeyHandler(com.android.internal.os.DeviceKeyHandler) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) 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