Search in sources :

Example 71 with IBinder

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);
}
Also used : IAccessibilityManager(android.view.accessibility.IAccessibilityManager) IBinder(android.os.IBinder) AccessibilityManager(android.view.accessibility.AccessibilityManager) IAccessibilityManager(android.view.accessibility.IAccessibilityManager)

Example 72 with IBinder

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;
}
Also used : IBinder(android.os.IBinder)

Example 73 with IBinder

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;
}
Also used : DragEvent(android.view.DragEvent) IBinder(android.os.IBinder) Message(android.os.Message) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 74 with IBinder

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);
        }
    }
}
Also used : IBinder(android.os.IBinder)

Example 75 with IBinder

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);
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) IInterface(android.os.IInterface) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException)

Aggregations

IBinder (android.os.IBinder)991 RemoteException (android.os.RemoteException)494 Intent (android.content.Intent)141 ComponentName (android.content.ComponentName)128 ServiceConnection (android.content.ServiceConnection)94 Parcel (android.os.Parcel)91 Point (android.graphics.Point)67 PendingIntent (android.app.PendingIntent)60 IOException (java.io.IOException)53 UserHandle (android.os.UserHandle)50 Bundle (android.os.Bundle)40 Binder (android.os.Binder)37 Message (android.os.Message)37 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)34 AndroidRuntimeException (android.util.AndroidRuntimeException)33 Handler (android.os.Handler)31 ArrayList (java.util.ArrayList)27 IContentProvider (android.content.IContentProvider)25 TransactionTooLargeException (android.os.TransactionTooLargeException)25 OperationResult (android.security.keymaster.OperationResult)25