Fix pass null TranslationCapability to dispatchRequestTranslation()
We only provide text-text capability now and when the UiTranslation APIs are called, the model files should be ready. To simplify the call flow, we hardcode the TranslationCapability now. If more capabilities are supported, we will call the API to get the TranslationCapability. Bug: 183589662 Test: atest CtsTranslationTestCases Change-Id: Iea1baac7988402298b2577d03adf9d889f45ad53
This commit is contained in:
@@ -213,6 +213,11 @@ public class Translator {
|
||||
}
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public TranslationContext getTranslationContext() {
|
||||
return mTranslationContext;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public int getTranslatorId() {
|
||||
return mId;
|
||||
|
||||
@@ -451,13 +451,14 @@ public class UiTranslationController {
|
||||
int[] supportedFormats = getSupportedFormatsLocked();
|
||||
ArrayList<ViewRootImpl> roots =
|
||||
WindowManagerGlobal.getInstance().getRootViews(mActivity.getActivityToken());
|
||||
TranslationCapability capability =
|
||||
getTranslationCapability(translator.getTranslationContext());
|
||||
mActivity.runOnUiThread(() -> {
|
||||
// traverse the hierarchy to collect ViewTranslationRequests
|
||||
for (int rootNum = 0; rootNum < roots.size(); rootNum++) {
|
||||
View rootView = roots.get(rootNum).getView();
|
||||
// TODO(b/183589662): call getTranslationCapabilities() for capability
|
||||
rootView.dispatchRequestTranslation(viewIds, supportedFormats, /* capability */
|
||||
null, requests);
|
||||
rootView.dispatchRequestTranslation(viewIds, supportedFormats, capability,
|
||||
requests);
|
||||
}
|
||||
mWorkerHandler.sendMessage(PooledLambda.obtainMessage(
|
||||
UiTranslationController::sendTranslationRequest,
|
||||
@@ -487,6 +488,15 @@ public class UiTranslationController {
|
||||
return new int[] {TranslationSpec.DATA_FORMAT_TEXT};
|
||||
}
|
||||
|
||||
private TranslationCapability getTranslationCapability(TranslationContext translationContext) {
|
||||
// We only support text to text capability now, we will query real status from service when
|
||||
// we support more translation capabilities.
|
||||
return new TranslationCapability(TranslationCapability.STATE_ON_DEVICE,
|
||||
translationContext.getSourceSpec(),
|
||||
translationContext.getTargetSpec(), /* uiTranslationEnabled= */ true,
|
||||
/* supportedTranslationFlags= */ 0);
|
||||
}
|
||||
|
||||
private void findViewsTraversalByAutofillIds(IntArray sourceViewIds) {
|
||||
final ArrayList<ViewRootImpl> roots =
|
||||
WindowManagerGlobal.getInstance().getRootViews(mActivity.getActivityToken());
|
||||
|
||||
Reference in New Issue
Block a user