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

Commit d2891727 authored by Ahaan Ugale's avatar Ahaan Ugale Committed by Automerger Merge Worker
Browse files

Merge changes from topic "Data Share Sender Crash" into rvc-dev am: 4d8efece am: 23811891

Change-Id: Ia1e59893c72046f3e039b979f04f2f37a11a0732
parents feece5da 23811891
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -930,7 +930,7 @@ public final class ContentCaptureManagerService extends
        }

        @Override
        public void accept(IDataShareReadAdapter serviceAdapter) throws RemoteException {
        public void accept(@NonNull IDataShareReadAdapter serviceAdapter) throws RemoteException {
            Slog.i(TAG, "Data share request accepted by Content Capture service");

            Pair<ParcelFileDescriptor, ParcelFileDescriptor> clientPipe = createPipe();
@@ -967,6 +967,7 @@ public final class ContentCaptureManagerService extends
            bestEffortCloseFileDescriptors(sourceIn, sinkOut);

            mParentService.mDataShareExecutor.execute(() -> {
                boolean receivedData = false;
                try (InputStream fis =
                             new ParcelFileDescriptor.AutoCloseInputStream(sinkIn);
                     OutputStream fos =
@@ -981,6 +982,8 @@ public final class ContentCaptureManagerService extends
                        }

                        fos.write(byteBuffer, 0 /* offset */, readBytes);

                        receivedData = true;
                    }
                } catch (IOException e) {
                    Slog.e(TAG, "Failed to pipe client and service streams", e);
@@ -992,6 +995,22 @@ public final class ContentCaptureManagerService extends
                        mParentService.mPackagesWithShareRequests
                                .remove(mDataShareRequest.getPackageName());
                    }
                    if (receivedData) {
                        try {
                            mClientAdapter.finish();
                        } catch (RemoteException e) {
                            Slog.e(TAG, "Failed to call finish() the client operation", e);
                        }
                        try {
                            serviceAdapter.finish();
                        } catch (RemoteException e) {
                            Slog.e(TAG, "Failed to call finish() the service operation", e);
                        }
                    } else {
                        // Client or service may have crashed before sending.
                        sendErrorSignal(mClientAdapter, serviceAdapter,
                                ContentCaptureManager.DATA_SHARE_ERROR_UNKNOWN);
                    }
                }
            });