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

Commit 44c60f4d 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

Change-Id: Ie2c2f5b2ca1000cea5f33ca66f777c6d8eafa4e7
parents 4116ccbc 4d8efece
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -677,10 +677,6 @@ public abstract class ContentCaptureService extends Service {
                throws RemoteException {
            synchronized (mLock) {
                executeAdapterMethodLocked(adapter -> adapter.onStart(fd), "onStart");

                // Client app and Service successfully connected, so this object would be kept alive
                // until the session has finished.
                clearHardReferences();
            }
        }

@@ -693,6 +689,13 @@ public abstract class ContentCaptureService extends Service {
            }
        }

        @Override
        public void finish() throws RemoteException {
            synchronized (mLock) {
                clearHardReferences();
            }
        }

        private void executeAdapterMethodLocked(Consumer<DataShareReadAdapter> adapterFn,
                String methodName) {
            LocalDataShareAdapterResourceManager resourceManager = mResourceManagerReference.get();
+1 −0
Original line number Diff line number Diff line
@@ -22,4 +22,5 @@ import android.os.ICancellationSignal;
oneway interface IDataShareReadAdapter {
    void start(in ParcelFileDescriptor fd);
    void error(int errorCode);
    void finish();
}
+5 −4
Original line number Diff line number Diff line
@@ -761,10 +761,6 @@ public final class ContentCaptureManager {
        public void write(ParcelFileDescriptor destination)
                throws RemoteException {
            executeAdapterMethodLocked(adapter -> adapter.onWrite(destination), "onWrite");

            // Client app and Service successfully connected, so this object would be kept alive
            // until the session has finished.
            clearHardReferences();
        }

        @Override
@@ -779,6 +775,11 @@ public final class ContentCaptureManager {
            clearHardReferences();
        }

        @Override
        public void finish() throws RemoteException  {
            clearHardReferences();
        }

        private void executeAdapterMethodLocked(Consumer<DataShareWriteAdapter> adapterFn,
                String methodName) {
            LocalDataShareAdapterResourceManager resourceManager = mResourceManagerReference.get();
+1 −0
Original line number Diff line number Diff line
@@ -25,4 +25,5 @@ oneway interface IDataShareWriteAdapter {
    void write(in ParcelFileDescriptor destination);
    void error(int errorCode);
    void rejected();
    void finish();
}
+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);
                    }
                }
            });