Add finish() method to DataShare Read and Write Adapters

The finish() method is used to clear hard references after
the data copy has ended. This fixes a bug where the references are cleared before onError() is attempted to be called.

Test: CTS tests in followup CL
Bug: 157136368
Fixes: 157136368
Change-Id: If924fe388762831af90579e6b00bdf223230e203
This commit is contained in:
Yara Hassan
2020-05-20 17:38:20 +01:00
committed by Ahaan Ugale
parent 1298d2b760
commit dc699fb8ce
4 changed files with 14 additions and 8 deletions

View File

@@ -677,10 +677,6 @@ public abstract class ContentCaptureService extends Service {
throws RemoteException { throws RemoteException {
synchronized (mLock) { synchronized (mLock) {
executeAdapterMethodLocked(adapter -> adapter.onStart(fd), "onStart"); 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, private void executeAdapterMethodLocked(Consumer<DataShareReadAdapter> adapterFn,
String methodName) { String methodName) {
LocalDataShareAdapterResourceManager resourceManager = mResourceManagerReference.get(); LocalDataShareAdapterResourceManager resourceManager = mResourceManagerReference.get();

View File

@@ -22,4 +22,5 @@ import android.os.ICancellationSignal;
oneway interface IDataShareReadAdapter { oneway interface IDataShareReadAdapter {
void start(in ParcelFileDescriptor fd); void start(in ParcelFileDescriptor fd);
void error(int errorCode); void error(int errorCode);
void finish();
} }

View File

@@ -761,10 +761,6 @@ public final class ContentCaptureManager {
public void write(ParcelFileDescriptor destination) public void write(ParcelFileDescriptor destination)
throws RemoteException { throws RemoteException {
executeAdapterMethodLocked(adapter -> adapter.onWrite(destination), "onWrite"); 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 @Override
@@ -779,6 +775,11 @@ public final class ContentCaptureManager {
clearHardReferences(); clearHardReferences();
} }
@Override
public void finish() throws RemoteException {
clearHardReferences();
}
private void executeAdapterMethodLocked(Consumer<DataShareWriteAdapter> adapterFn, private void executeAdapterMethodLocked(Consumer<DataShareWriteAdapter> adapterFn,
String methodName) { String methodName) {
LocalDataShareAdapterResourceManager resourceManager = mResourceManagerReference.get(); LocalDataShareAdapterResourceManager resourceManager = mResourceManagerReference.get();

View File

@@ -25,4 +25,5 @@ oneway interface IDataShareWriteAdapter {
void write(in ParcelFileDescriptor destination); void write(in ParcelFileDescriptor destination);
void error(int errorCode); void error(int errorCode);
void rejected(); void rejected();
void finish();
} }