Search in sources :

Example 26 with IBinder

use of android.os.IBinder in project android_frameworks_base by ParanoidAndroid.

the class DragState method notifyDropLw.

// Tell the drop target 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) {
    WindowState touchedWin = getTouchedWinAtPointLw(x, y);
    if (touchedWin == null) {
        // "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 (WindowManagerService.DEBUG_DRAG) {
        Slog.d(WindowManagerService.TAG, "sending DROP to " + touchedWin);
    }
    final int myPid = Process.myPid();
    final IBinder token = touchedWin.mClient.asBinder();
    DragEvent evt = obtainDragEvent(touchedWin, DragEvent.ACTION_DROP, x, y, null, null, mData, 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(WindowManagerService.TAG, "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 27 with IBinder

use of android.os.IBinder in project android_frameworks_base by ParanoidAndroid.

the class DragState method sendDragStartedLw.

/* helper - send a caller-provided event, presumed to be DRAG_STARTED, if the
     * designated window is potentially a drop recipient.  There are race situations
     * around DRAG_ENDED broadcast, so we make sure that once we've declared that
     * the drag has ended, we never send out another DRAG_STARTED for this drag action.
     *
     * This method clones the 'event' parameter if it's being delivered to the same
     * process, so it's safe for the caller to call recycle() on the event afterwards.
     */
private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, ClipDescription desc) {
    // to the originating window but 'newWin' is not that window.
    if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
        final IBinder winBinder = newWin.mClient.asBinder();
        if (winBinder != mLocalWin) {
            if (WindowManagerService.DEBUG_DRAG) {
                Slog.d(WindowManagerService.TAG, "Not dispatching local DRAG_STARTED to " + newWin);
            }
            return;
        }
    }
    if (mDragInProgress && newWin.isPotentialDragTarget()) {
        DragEvent event = obtainDragEvent(newWin, DragEvent.ACTION_DRAG_STARTED, touchX, touchY, null, desc, null, false);
        try {
            newWin.mClient.dispatchDragEvent(event);
            // track each window that we've notified that the drag is starting
            mNotifiedWindows.add(newWin);
        } catch (RemoteException e) {
            Slog.w(WindowManagerService.TAG, "Unable to drag-start window " + newWin);
        } finally {
            // if the callee was local, the dispatch has already recycled the event
            if (Process.myPid() != newWin.mSession.mPid) {
                event.recycle();
            }
        }
    }
}
Also used : DragEvent(android.view.DragEvent) IBinder(android.os.IBinder) RemoteException(android.os.RemoteException)

Example 28 with IBinder

use of android.os.IBinder in project android_frameworks_base by ParanoidAndroid.

the class WindowManagerService method removeAppTokensLocked.

private void removeAppTokensLocked(List<IBinder> tokens) {
    // XXX This should be done more efficiently!
    // (take advantage of the fact that both lists should be
    // ordered in the same way.)
    int N = tokens.size();
    for (int i = 0; i < N; i++) {
        IBinder token = tokens.get(i);
        final AppWindowToken wtoken = findAppWindowToken(token);
        if (DEBUG_REORDER || DEBUG_TOKEN_MOVEMENT)
            Slog.v(TAG, "Temporarily removing " + wtoken + " from " + mAppTokens.indexOf(wtoken));
        if (!mAppTokens.remove(wtoken)) {
            Slog.w(TAG, "Attempting to reorder token that doesn't exist: " + token + " (" + wtoken + ")");
            i--;
            N--;
        }
    }
}
Also used : IBinder(android.os.IBinder) Point(android.graphics.Point)

Example 29 with IBinder

use of android.os.IBinder in project android_frameworks_base by ParanoidAndroid.

the class WindowManagerService method prepareDragSurface.

// -------------------------------------------------------------
// Drag and drop
// -------------------------------------------------------------
IBinder prepareDragSurface(IWindow window, SurfaceSession session, int flags, int width, int height, Surface outSurface) {
    if (DEBUG_DRAG) {
        Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height + " flags=" + Integer.toHexString(flags) + " win=" + window + " asbinder=" + window.asBinder());
    }
    final int callerPid = Binder.getCallingPid();
    final long origId = Binder.clearCallingIdentity();
    IBinder token = null;
    try {
        synchronized (mWindowMap) {
            try {
                if (mDragState == null) {
                    // TODO(multi-display): support other displays
                    final DisplayContent displayContent = getDefaultDisplayContentLocked();
                    final Display display = displayContent.getDisplay();
                    SurfaceControl surface = new SurfaceControl(session, "drag surface", width, height, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
                    surface.setLayerStack(display.getLayerStack());
                    if (SHOW_TRANSACTIONS)
                        Slog.i(TAG, "  DRAG " + surface + ": CREATE");
                    outSurface.copyFrom(surface);
                    final IBinder winBinder = window.asBinder();
                    token = new Binder();
                    mDragState = new DragState(this, token, surface, /*flags*/
                    0, winBinder);
                    token = mDragState.mToken = new Binder();
                    // 5 second timeout for this window to actually begin the drag
                    mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
                    Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
                    mH.sendMessageDelayed(msg, 5000);
                } else {
                    Slog.w(TAG, "Drag already in progress");
                }
            } catch (SurfaceControl.OutOfResourcesException e) {
                Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
                if (mDragState != null) {
                    mDragState.reset();
                    mDragState = null;
                }
            }
        }
    } finally {
        Binder.restoreCallingIdentity(origId);
    }
    return token;
}
Also used : IBinder(android.os.IBinder) Binder(android.os.Binder) IBinder(android.os.IBinder) Message(android.os.Message) SurfaceControl(android.view.SurfaceControl) Point(android.graphics.Point) Display(android.view.Display)

Example 30 with IBinder

use of android.os.IBinder in project android_frameworks_base by ParanoidAndroid.

the class WindowManagerService method viewServerWindowCommand.

/**
     * Sends a command to a target window. The result of the command, if any, will be
     * written in the output stream of the specified socket.
     *
     * The parameters must follow this syntax:
     * windowHashcode extra
     *
     * Where XX is the length in characeters of the windowTitle.
     *
     * The first parameter is the target window. The window with the specified hashcode
     * will be the target. If no target can be found, nothing happens. The extra parameters
     * will be delivered to the target window and as parameters to the command itself.
     *
     * @param client The remote client to sent the result, if any, to.
     * @param command The command to execute.
     * @param parameters The command parameters.
     *
     * @return True if the command was successfully delivered, false otherwise. This does
     *         not indicate whether the command itself was successful.
     */
boolean viewServerWindowCommand(Socket client, String command, String parameters) {
    if (isSystemSecure()) {
        return false;
    }
    boolean success = true;
    Parcel data = null;
    Parcel reply = null;
    BufferedWriter out = null;
    // Any uncaught exception will crash the system process
    try {
        // Find the hashcode of the window
        int index = parameters.indexOf(' ');
        if (index == -1) {
            index = parameters.length();
        }
        final String code = parameters.substring(0, index);
        int hashCode = (int) Long.parseLong(code, 16);
        // Extract the command's parameter after the window description
        if (index < parameters.length()) {
            parameters = parameters.substring(index + 1);
        } else {
            parameters = "";
        }
        final WindowState window = findWindow(hashCode);
        if (window == null) {
            return false;
        }
        data = Parcel.obtain();
        data.writeInterfaceToken("android.view.IWindow");
        data.writeString(command);
        data.writeString(parameters);
        data.writeInt(1);
        ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
        reply = Parcel.obtain();
        final IBinder binder = window.mClient.asBinder();
        // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
        binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
        reply.readException();
        if (!client.isOutputShutdown()) {
            out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
            out.write("DONE\n");
            out.flush();
        }
    } catch (Exception e) {
        Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
        success = false;
    } finally {
        if (data != null) {
            data.recycle();
        }
        if (reply != null) {
            reply.recycle();
        }
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
            }
        }
    }
    return success;
}
Also used : IBinder(android.os.IBinder) Parcel(android.os.Parcel) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Point(android.graphics.Point) RemoteException(android.os.RemoteException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchElementException(java.util.NoSuchElementException) BufferedWriter(java.io.BufferedWriter)

Aggregations

IBinder (android.os.IBinder)1139 RemoteException (android.os.RemoteException)553 Intent (android.content.Intent)186 ComponentName (android.content.ComponentName)166 ServiceConnection (android.content.ServiceConnection)127 Parcel (android.os.Parcel)112 PendingIntent (android.app.PendingIntent)69 Point (android.graphics.Point)67 Bundle (android.os.Bundle)56 IOException (java.io.IOException)53 UserHandle (android.os.UserHandle)50 Binder (android.os.Binder)47 Message (android.os.Message)37 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)35 Handler (android.os.Handler)33 AndroidRuntimeException (android.util.AndroidRuntimeException)33 ArrayList (java.util.ArrayList)30 IUsbManager (android.hardware.usb.IUsbManager)29 Context (android.content.Context)28 Messenger (android.os.Messenger)26