speech: Timely model download listening connection termination
Callbacks onSuccess, onSchedule and onError in ModelDownloadListener should be terminal ones, i.e., no callbacks should be called after one of these. Callback forwarding will be stopped inside the recognition service. Bug: 283102476 Test: test app, atest CtsVoiceRecognitionTestCases Change-Id: If1fdb09bd10ae36fe3eb02c562e6d2069745bb8e
This commit is contained in:
committed by
Aleksandar Kiridžić
parent
e75a45ec55
commit
37f847484e
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user