Search in sources :

Example 96 with Messenger

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

the class PhoneWindowManager method takeScreenshot.

// Assume this is called from the Handler thread.
private void takeScreenshot(final int screenshotType) {
    synchronized (mScreenshotLock) {
        if (mScreenshotConnection != null) {
            return;
        }
        final ComponentName serviceComponent = new ComponentName(SYSUI_PACKAGE, SYSUI_SCREENSHOT_SERVICE);
        final Intent serviceIntent = new Intent();
        serviceIntent.setComponent(serviceComponent);
        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
                    }
                    if (mStatusBar != null && mStatusBar.isVisibleLw())
                        msg.arg1 = 1;
                    if (mNavigationBar != null && mNavigationBar.isVisibleLw())
                        msg.arg2 = 1;
                    try {
                        messenger.send(msg);
                    } catch (RemoteException e) {
                    }
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                synchronized (mScreenshotLock) {
                    if (mScreenshotConnection != null) {
                        mContext.unbindService(mScreenshotConnection);
                        mScreenshotConnection = null;
                        mHandler.removeCallbacks(mScreenshotTimeout);
                        notifyScreenshotError();
                    }
                }
            }
        };
        if (mContext.bindServiceAsUser(serviceIntent, conn, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, UserHandle.CURRENT)) {
            mScreenshotConnection = conn;
            mHandler.postDelayed(mScreenshotTimeout, 10000);
        }
    }
}
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)

Example 97 with Messenger

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

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

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

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

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

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

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

the class NsdManager method init.

/**
     * Initialize AsyncChannel
     */
private void init() {
    final Messenger messenger = getMessenger();
    if (messenger == null)
        throw new RuntimeException("Failed to initialize");
    HandlerThread t = new HandlerThread("NsdManager");
    t.start();
    mHandler = new ServiceHandler(t.getLooper());
    mAsyncChannel.connect(mContext, mHandler, messenger);
    try {
        mConnected.await();
    } catch (InterruptedException e) {
        Log.e(TAG, "interrupted wait at init");
    }
}
Also used : HandlerThread(android.os.HandlerThread) Messenger(android.os.Messenger)

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