Search in sources :

Example 21 with Messenger

use of android.os.Messenger in project XobotOS by xamarin.

the class WifiP2pManager method initialize.

/**
     * Registers the application with the Wi-Fi framework. This function
     * must be the first to be called before any p2p operations are performed.
     *
     * @param srcContext is the context of the source
     * @param srcLooper is the Looper on which the callbacks are receivied
     * @param listener for callback at loss of framework communication. Can be null.
     * @return Channel instance that is necessary for performing any further p2p operations
     */
public Channel initialize(Context srcContext, Looper srcLooper, ChannelListener listener) {
    Messenger messenger = getMessenger();
    if (messenger == null)
        return null;
    Channel c = new Channel(srcLooper, listener);
    if (c.mAsyncChannel.connectSync(srcContext, c.mHandler, messenger) == AsyncChannel.STATUS_SUCCESSFUL) {
        return c;
    } else {
        return null;
    }
}
Also used : AsyncChannel(com.android.internal.util.AsyncChannel) Messenger(android.os.Messenger)

Example 22 with Messenger

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

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;
}
Also used : Handler(android.os.Handler) AsyncChannel(com.android.internal.util.AsyncChannel) Messenger(android.os.Messenger) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 23 with Messenger

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

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

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

the class GlobalActions 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;
                    // Needs delay or else we'll be taking a screenshot of the dialog each time
                    try {
                        Thread.sleep(mScreenshotDelay);
                    } catch (InterruptedException ie) {
                    // Do nothing
                    }
                    // 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)

Example 25 with Messenger

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

the class GlobalActions method takeScreenrecord.

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;
            mHandler.postDelayed(mScreenrecordTimeout, 31 * 60 * 1000);
        }
    }
}
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