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

Commit b27d29b3 authored by sandeepbandaru's avatar sandeepbandaru Committed by Sandeep Bandaru
Browse files

Try closing PFDs sent in map after binder call

- Iterate through all PFDs sent by caller after the binder call to send
  to system-server is complete. This prevents any potential leakages if
  the client does not close the FDs themselves.

Bug: 347173075
Test: cts
Change-Id: I06652b561d3548f7d5ec976b7a787e9c6c3d0b74
parent 5cc2247e
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import com.android.internal.infra.AndroidFuture;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -224,6 +225,7 @@ public abstract class OnDeviceIntelligenceService extends Service {
                                        Bundle bundle = new Bundle();
                                        parcelFileDescriptorMap.forEach(bundle::putParcelable);
                                        remoteCallback.sendResult(bundle);
                                        tryClosePfds(parcelFileDescriptorMap.values());
                                    }));
                }

@@ -444,6 +446,16 @@ public abstract class OnDeviceIntelligenceService extends Service {
        };
    }

    private static void tryClosePfds(Collection<ParcelFileDescriptor> pfds) {
        pfds.forEach(pfd -> {
            try {
                pfd.close();
            } catch (Exception e) {
                Log.w(TAG, "Error closing FD", e);
            }
        });
    }

    private void onGetReadOnlyFileDescriptor(@NonNull String fileName,
            @NonNull AndroidFuture<ParcelFileDescriptor> future) {
        Slog.v(TAG, "onGetReadOnlyFileDescriptor " + fileName);