use of android.os.Messenger in project mechanoid by robotoworks.
the class OperationService method onOperationComplete.
public void onOperationComplete(Intent request, Bundle data) {
if (mEnableLogging) {
Log.d(mLogTag, String.format("[Operation Complete] request:%s, data:%s", request, data));
}
Messenger messenger = request.getParcelableExtra(EXTRA_BRIDGE_MESSENGER);
Message m = new Message();
m.what = OperationServiceBridge.MSG_OPERATION_COMPLETE;
m.arg1 = OperationServiceBridge.getOperationRequestId(request);
m.setData(data);
try {
messenger.send(m);
} catch (Exception e) {
if (mEnableLogging) {
Log.w(mLogTag, String.format("[Operation Exception] %s", Log.getStackTraceString(e)));
}
}
sendStopMessage(request);
}
use of android.os.Messenger in project android_frameworks_base by ResurrectionRemix.
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;
}
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);
}
}
}
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);
}
}
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);
}
Aggregations