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

Commit fcafa1c9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Try closing PFDs sent in map after binder call" into main

parents 6f37bc6e b27d29b3
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);