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:
@@ -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();
|
||||
|
||||
@@ -22,4 +22,5 @@ import android.os.ICancellationSignal;
|
||||
oneway interface IDataShareReadAdapter {
|
||||
void start(in ParcelFileDescriptor fd);
|
||||
void error(int errorCode);
|
||||
void finish();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -25,4 +25,5 @@ oneway interface IDataShareWriteAdapter {
|
||||
void write(in ParcelFileDescriptor destination);
|
||||
void error(int errorCode);
|
||||
void rejected();
|
||||
void finish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user