Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a0ab128 authored by Jeff Brown's avatar Jeff Brown
Browse files

Use PARCELABLE_WIRTE_RETURN_VALUE flag in InputChannel.

Bug: 5161290

Replace mDisposeAfterWriteToParcel with code that takes advantage
of the standard Parcel API support for releasing resources after
writing a Binder reply.

This change makes it less likely that InputChannels will leak
accidentally when passed across a Binder.

Change-Id: Id37706e7b88d074e8e4ac687c88f0db8963200f2
parent c74a0287
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -48,8 +48,6 @@ public final class InputChannel implements Parcelable {
    @SuppressWarnings("unused")
    private int mPtr; // used by native code
    
    private boolean mDisposeAfterWriteToParcel;
    
    private static native InputChannel[] nativeOpenInputChannelPair(String name);
    
    private native void nativeDispose(boolean finalized);
@@ -117,13 +115,12 @@ public final class InputChannel implements Parcelable {
     * as an out parameter in a binder call.
     * @param other The other input channel instance.
     */
    public void transferToBinderOutParameter(InputChannel outParameter) {
    public void transferTo(InputChannel outParameter) {
        if (outParameter == null) {
            throw new IllegalArgumentException("outParameter must not be null");
        }
        
        nativeTransferTo(outParameter);
        outParameter.mDisposeAfterWriteToParcel = true;
    }

    public int describeContents() {
@@ -145,7 +142,7 @@ public final class InputChannel implements Parcelable {
        
        nativeWriteToParcel(out);
        
        if (mDisposeAfterWriteToParcel) {
        if ((flags & PARCELABLE_WRITE_RETURN_VALUE) != 0) {
            dispose();
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -2052,7 +2052,7 @@ public class WindowManagerService extends IWindowManager.Stub
                String name = win.makeInputChannelName();
                InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
                win.mInputChannel = inputChannels[0];
                inputChannels[1].transferToBinderOutParameter(outInputChannel);
                inputChannels[1].transferTo(outInputChannel);
                
                mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
            }