Merge "speech: Timely model download listening connection termination" into udc-qpr-dev

This commit is contained in:
Aleksandar Kiridžić
2023-08-17 21:24:53 +00:00
committed by Android (Google) Code Review

View File

@@ -38,6 +38,7 @@ import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.function.pooled.PooledLambda;
import java.lang.ref.WeakReference;
@@ -232,39 +233,68 @@ public abstract class RecognitionService extends Service {
intent,
attributionSource,
new ModelDownloadListener() {
private final Object mLock = new Object();
@GuardedBy("mLock")
private boolean mIsTerminated = false;
@Override
public void onProgress(int completedPercent) {
try {
listener.onProgress(completedPercent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
synchronized (mLock) {
if (mIsTerminated) {
return;
}
try {
listener.onProgress(completedPercent);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
@Override
public void onSuccess() {
try {
listener.onSuccess();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
synchronized (mLock) {
if (mIsTerminated) {
return;
}
mIsTerminated = true;
try {
listener.onSuccess();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
@Override
public void onScheduled() {
try {
listener.onScheduled();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
synchronized (mLock) {
if (mIsTerminated) {
return;
}
mIsTerminated = true;
try {
listener.onScheduled();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
@Override
public void onError(int error) {
try {
listener.onError(error);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
synchronized (mLock) {
if (mIsTerminated) {
return;
}
mIsTerminated = true;
try {
listener.onError(error);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
});