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;
}
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;
}
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);
}
}
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<>();
}
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);
}
}
}
Aggregations