use of android.os.IBinder in project platform_frameworks_base by android.
the class DevicePolicyManagerService method getAccessibilityManagerForUser.
private AccessibilityManager getAccessibilityManagerForUser(int userId) {
// Not using AccessibilityManager.getInstance because that guesses
// at the user you require based on callingUid and caches for a given
// process.
IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
IAccessibilityManager service = iBinder == null ? null : IAccessibilityManager.Stub.asInterface(iBinder);
return new AccessibilityManager(mContext, service, userId);
}
use of android.os.IBinder in project platform_frameworks_base by android.
the class ServiceTestCase method bindService.
/**
* <p>
* Starts the service under test, in the same way as if it were started by
* {@link android.content.Context#bindService(Intent, ServiceConnection, int)
* Context.bindService(Intent, ServiceConnection, flags)} with an
* {@link android.content.Intent} that identifies a service.
* </p>
* <p>
* Notice that the parameters are different. You do not provide a
* {@link android.content.ServiceConnection} object or the flags parameter. Instead,
* you only provide the Intent. The method returns an object whose type is a
* subclass of {@link android.os.IBinder}, or null if the method fails. An IBinder
* object refers to a communication channel between the application and
* the service. The flag is assumed to be {@link android.content.Context#BIND_AUTO_CREATE}.
* </p>
* <p>
* See <a href="{@docRoot}guide/components/aidl.html">Designing a Remote Interface
* Using AIDL</a> for more information about the communication channel object returned
* by this method.
* </p>
* Note: To be able to use bindService in a test, the service must implement getService()
* method. An example of this is in the ApiDemos sample application, in the
* LocalService demo.
*
* @param intent An Intent object of the form expected by
* {@link android.content.Context#bindService}.
*
* @return An object whose type is a subclass of IBinder, for making further calls into
* the service.
*/
protected IBinder bindService(Intent intent) {
if (!mServiceAttached) {
setupService();
}
assertNotNull(mService);
if (!mServiceCreated) {
mService.onCreate();
mServiceCreated = true;
}
// no extras are expected by unbind
mServiceIntent = intent.cloneFilter();
IBinder result = mService.onBind(intent);
mServiceBound = true;
return result;
}
use of android.os.IBinder in project platform_frameworks_base by android.
the class DragState method notifyDropLw.
// Find the drop target and tell it about the data. Returns 'true' if we can immediately
// dispatch the global drag-ended message, 'false' if we need to wait for a
// result from the recipient.
boolean notifyDropLw(float x, float y) {
if (mAnimation != null) {
return false;
}
mCurrentX = x;
mCurrentY = y;
WindowState touchedWin = mDisplayContent.getTouchableWinAtPointLocked(x, y);
if (!isWindowNotified(touchedWin)) {
// "drop" outside a valid window -- no recipient to apply a
// timeout to, and we can send the drag-ended message immediately.
mDragResult = false;
return true;
}
if (DEBUG_DRAG) {
Slog.d(TAG_WM, "sending DROP to " + touchedWin);
}
final int targetUserId = UserHandle.getUserId(touchedWin.getOwningUid());
DragAndDropPermissionsHandler dragAndDropPermissions = null;
if ((mFlags & View.DRAG_FLAG_GLOBAL) != 0 && (mFlags & DRAG_FLAGS_URI_ACCESS) != 0) {
dragAndDropPermissions = new DragAndDropPermissionsHandler(mData, mUid, touchedWin.getOwningPackage(), mFlags & DRAG_FLAGS_URI_PERMISSIONS, mSourceUserId, targetUserId);
}
if (mSourceUserId != targetUserId) {
mData.fixUris(mSourceUserId);
}
final int myPid = Process.myPid();
final IBinder token = touchedWin.mClient.asBinder();
DragEvent evt = obtainDragEvent(touchedWin, DragEvent.ACTION_DROP, x, y, null, null, mData, dragAndDropPermissions, false);
try {
touchedWin.mClient.dispatchDragEvent(evt);
// 5 second timeout for this window to respond to the drop
mService.mH.removeMessages(H.DRAG_END_TIMEOUT, token);
Message msg = mService.mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
mService.mH.sendMessageDelayed(msg, 5000);
} catch (RemoteException e) {
Slog.w(TAG_WM, "can't send drop notification to win " + touchedWin);
return true;
} finally {
if (myPid != touchedWin.mSession.mPid) {
evt.recycle();
}
}
mToken = token;
return false;
}
use of android.os.IBinder in project platform_frameworks_base by android.
the class Session method reportDropResult.
public void reportDropResult(IWindow window, boolean consumed) {
IBinder token = window.asBinder();
if (DEBUG_DRAG) {
Slog.d(TAG_WM, "Drop result=" + consumed + " reported by " + token);
}
synchronized (mService.mWindowMap) {
long ident = Binder.clearCallingIdentity();
try {
if (mService.mDragState == null) {
// Most likely the drop recipient ANRed and we ended the drag
// out from under it. Log the issue and move on.
Slog.w(TAG_WM, "Drop result given but no drag in progress");
return;
}
if (mService.mDragState.mToken != token) {
// We're in a drag, but the wrong window has responded.
Slog.w(TAG_WM, "Invalid drop-result claim by " + window);
throw new IllegalStateException("reportDropResult() by non-recipient");
}
// The right window has responded, even if it's no longer around,
// so be sure to halt the timeout even if the later WindowState
// lookup fails.
mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
WindowState callingWin = mService.windowForClientLocked(null, window, false);
if (callingWin == null) {
Slog.w(TAG_WM, "Bad result-reporting window " + window);
// !!! TODO: throw here?
return;
}
mService.mDragState.mDragResult = consumed;
mService.mDragState.endDragLw();
} finally {
Binder.restoreCallingIdentity(ident);
}
}
}
use of android.os.IBinder in project platform_frameworks_base by android.
the class ManagedApplicationService method connect.
/**
* Asynchronously bind to the application service if not bound.
*/
public void connect() {
synchronized (mLock) {
if (mConnection != null || mPendingConnection != null) {
// We're already connected or are trying to connect
return;
}
final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mSettingsAction), 0);
final Intent intent = new Intent().setComponent(mComponent).putExtra(Intent.EXTRA_CLIENT_LABEL, mClientLabel).putExtra(Intent.EXTRA_CLIENT_INTENT, pendingIntent);
final ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
IInterface iface = null;
PendingEvent pendingEvent = null;
synchronized (mLock) {
if (mPendingConnection == this) {
// No longer pending, remove from pending connection
mPendingConnection = null;
mConnection = this;
} else {
// Service connection wasn't pending, must have been disconnected
mContext.unbindService(this);
return;
}
try {
iBinder.linkToDeath(mDeathRecipient, 0);
mBoundInterface = mChecker.asInterface(iBinder);
if (!mChecker.checkType(mBoundInterface)) {
// Received an invalid binder, disconnect
mContext.unbindService(this);
mBoundInterface = null;
}
iface = mBoundInterface;
pendingEvent = mPendingEvent;
mPendingEvent = null;
} catch (RemoteException e) {
// DOA
Slog.w(TAG, "Unable to bind service: " + intent, e);
mBoundInterface = null;
}
}
if (iface != null && pendingEvent != null) {
try {
pendingEvent.runEvent(iface);
} catch (RuntimeException | RemoteException ex) {
Slog.e(TAG, "Received exception from user service: ", ex);
}
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
Slog.w(TAG, "Service disconnected: " + intent);
mConnection = null;
mBoundInterface = null;
}
};
mPendingConnection = serviceConnection;
try {
if (!mContext.bindServiceAsUser(intent, serviceConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUserId))) {
Slog.w(TAG, "Unable to bind service: " + intent);
}
} catch (SecurityException e) {
Slog.w(TAG, "Unable to bind service: " + intent, e);
}
}
}
Aggregations