use of android.content.ServiceConnection in project android_frameworks_base by ResurrectionRemix.
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.omni.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);
}
}
}
use of android.content.ServiceConnection in project android_frameworks_base by ResurrectionRemix.
the class GlobalActions method takeScreenrecord.
private void takeScreenrecord() {
synchronized (mScreenrecordLock) {
if (mScreenrecordConnection != null) {
return;
}
ComponentName cn = new ComponentName("com.android.systemui", "com.android.systemui.omni.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);
}
}
}
use of android.content.ServiceConnection in project android_frameworks_base by ResurrectionRemix.
the class ScreenshotTile 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;
// 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);
}
}
}
use of android.content.ServiceConnection in project RSAndroidApp by RailwayStations.
the class MainActivity method bindToStatus.
private void bindToStatus() {
Intent intent = new Intent(this, NearbyNotificationService.class);
intent.setAction(NearbyNotificationService.STATUS_INTERFACE);
if (!this.getApplicationContext().bindService(intent, new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d(TAG, "Bound to status service of NearbyNotificationService");
statusBinder = (NearbyNotificationService.StatusBinder) service;
invalidateOptionsMenu();
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.d(TAG, "Unbound from status service of NearbyNotificationService");
statusBinder = null;
}
}, 0))
Log.e(TAG, "Bind request to statistics interface failed");
}
use of android.content.ServiceConnection in project android_frameworks_base by ResurrectionRemix.
the class PacManager method bind.
private void bind() {
if (mContext == null) {
Log.e(TAG, "No context for binding");
return;
}
Intent intent = new Intent();
intent.setClassName(PAC_PACKAGE, PAC_SERVICE);
if ((mProxyConnection != null) && (mConnection != null)) {
// Already bound no need to bind again, just download the new file.
mNetThreadHandler.post(mPacDownloader);
return;
}
mConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName component) {
synchronized (mProxyLock) {
mProxyService = null;
}
}
@Override
public void onServiceConnected(ComponentName component, IBinder binder) {
synchronized (mProxyLock) {
try {
Log.d(TAG, "Adding service " + PAC_SERVICE_NAME + " " + binder.getInterfaceDescriptor());
} catch (RemoteException e1) {
Log.e(TAG, "Remote Exception", e1);
}
ServiceManager.addService(PAC_SERVICE_NAME, binder);
mProxyService = IProxyService.Stub.asInterface(binder);
if (mProxyService == null) {
Log.e(TAG, "No proxy service");
} else {
try {
mProxyService.startPacSystem();
} catch (RemoteException e) {
Log.e(TAG, "Unable to reach ProxyService - PAC will not be started", e);
}
mNetThreadHandler.post(mPacDownloader);
}
}
}
};
mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_VISIBLE);
intent = new Intent();
intent.setClassName(PROXY_PACKAGE, PROXY_SERVICE);
mProxyConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName component) {
}
@Override
public void onServiceConnected(ComponentName component, IBinder binder) {
IProxyCallback callbackService = IProxyCallback.Stub.asInterface(binder);
if (callbackService != null) {
try {
callbackService.getProxyPort(new IProxyPortListener.Stub() {
@Override
public void setProxyPort(int port) throws RemoteException {
if (mLastPort != -1) {
// Always need to send if port changed
mHasSentBroadcast = false;
}
mLastPort = port;
if (port != -1) {
Log.d(TAG, "Local proxy is bound on " + port);
sendProxyIfNeeded();
} else {
Log.e(TAG, "Received invalid port from Local Proxy," + " PAC will not be operational");
}
}
});
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
};
mContext.bindService(intent, mProxyConnection, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND | Context.BIND_NOT_VISIBLE);
}
Aggregations