summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Joanne Chung <joannechung@google.com> 2023-04-12 11:50:30 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-04-12 11:50:30 +0000
commite593fef839d6ed2335a71b51a2153d780b97d630 (patch)
treeb894d7d79d85fe8a4b8f41b22b6bca4bc5d7da98
parentd26c00f7832722db91acc8e1a213d629a478a8f6 (diff)
parent98221155d3c81612a5ea7c5b5252390082b77817 (diff)
Merge "Improve translation debugging logging not work" into udc-dev
-rw-r--r--core/java/android/view/translation/Translator.java3
-rw-r--r--core/java/android/view/translation/UiTranslationController.java26
2 files changed, 16 insertions, 13 deletions
diff --git a/core/java/android/view/translation/Translator.java b/core/java/android/view/translation/Translator.java
index 70db6e513c88..50249da08c3c 100644
--- a/core/java/android/view/translation/Translator.java
+++ b/core/java/android/view/translation/Translator.java
@@ -18,7 +18,6 @@ package android.view.translation;
import static android.view.translation.TranslationManager.STATUS_SYNC_CALL_FAIL;
import static android.view.translation.TranslationManager.SYNC_CALLS_TIMEOUT_MS;
-import static android.view.translation.UiTranslationController.DEBUG;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
@@ -402,7 +401,7 @@ public class Translator {
@Override
public void onTranslationResponse(TranslationResponse response) throws RemoteException {
- if (DEBUG) {
+ if (Log.isLoggable(UiTranslationManager.LOG_TAG, Log.DEBUG)) {
Log.i(TAG, "onTranslationResponse called.");
}
final Runnable runnable =
diff --git a/core/java/android/view/translation/UiTranslationController.java b/core/java/android/view/translation/UiTranslationController.java
index 514df59f1989..140e3f1b6fdc 100644
--- a/core/java/android/view/translation/UiTranslationController.java
+++ b/core/java/android/view/translation/UiTranslationController.java
@@ -122,8 +122,9 @@ public class UiTranslationController implements Dumpable {
Log.i(TAG, "Cannot update " + stateToString(state) + " for destroyed " + mActivity);
return;
}
+ boolean isLoggable = Log.isLoggable(UiTranslationManager.LOG_TAG, Log.DEBUG);
Log.i(TAG, "updateUiTranslationState state: " + stateToString(state)
- + (DEBUG ? (", views: " + views + ", spec: " + uiTranslationSpec) : ""));
+ + (isLoggable ? (", views: " + views + ", spec: " + uiTranslationSpec) : ""));
synchronized (mLock) {
mCurrentState = state;
if (views != null) {
@@ -237,7 +238,7 @@ public class UiTranslationController implements Dumpable {
}
pw.print(outerPrefix); pw.print("padded views: "); pw.println(mViewsToPadContent);
}
- if (DEBUG) {
+ if (Log.isLoggable(UiTranslationManager.LOG_TAG, Log.DEBUG)) {
dumpViewByTraversal(outerPrefix, pw);
}
}
@@ -345,6 +346,7 @@ public class UiTranslationController implements Dumpable {
*/
private void onVirtualViewTranslationCompleted(
SparseArray<LongSparseArray<ViewTranslationResponse>> translatedResult) {
+ boolean isLoggable = Log.isLoggable(UiTranslationManager.LOG_TAG, Log.DEBUG);
if (mActivity.isDestroyed()) {
Log.v(TAG, "onTranslationCompleted:" + mActivity + "is destroyed.");
return;
@@ -369,7 +371,7 @@ public class UiTranslationController implements Dumpable {
}
final LongSparseArray<ViewTranslationResponse> virtualChildResponse =
translatedResult.valueAt(i);
- if (DEBUG) {
+ if (isLoggable) {
Log.v(TAG, "onVirtualViewTranslationCompleted: received response for "
+ "AutofillId " + autofillId);
}
@@ -379,7 +381,7 @@ public class UiTranslationController implements Dumpable {
}
mActivity.runOnUiThread(() -> {
if (view.getViewTranslationCallback() == null) {
- if (DEBUG) {
+ if (isLoggable) {
Log.d(TAG, view + " doesn't support showing translation because of "
+ "null ViewTranslationCallback.");
}
@@ -397,12 +399,13 @@ public class UiTranslationController implements Dumpable {
* The method is used to handle the translation result for non-vertual views.
*/
private void onTranslationCompleted(SparseArray<ViewTranslationResponse> translatedResult) {
+ boolean isLoggable = Log.isLoggable(UiTranslationManager.LOG_TAG, Log.DEBUG);
if (mActivity.isDestroyed()) {
Log.v(TAG, "onTranslationCompleted:" + mActivity + "is destroyed.");
return;
}
final int resultCount = translatedResult.size();
- if (DEBUG) {
+ if (isLoggable) {
Log.v(TAG, "onTranslationCompleted: receive " + resultCount + " responses.");
}
synchronized (mLock) {
@@ -413,7 +416,7 @@ public class UiTranslationController implements Dumpable {
}
for (int i = 0; i < resultCount; i++) {
final ViewTranslationResponse response = translatedResult.valueAt(i);
- if (DEBUG) {
+ if (isLoggable) {
Log.v(TAG, "onTranslationCompleted: "
+ sanitizedViewTranslationResponse(response));
}
@@ -443,7 +446,7 @@ public class UiTranslationController implements Dumpable {
(TextViewTranslationCallback) callback;
if (textViewCallback.isShowingTranslation()
|| textViewCallback.isAnimationRunning()) {
- if (DEBUG) {
+ if (isLoggable) {
Log.d(TAG, "Duplicate ViewTranslationResponse for " + autofillId
+ ". Ignoring.");
}
@@ -458,7 +461,7 @@ public class UiTranslationController implements Dumpable {
callback = new TextViewTranslationCallback();
view.setViewTranslationCallback(callback);
} else {
- if (DEBUG) {
+ if (isLoggable) {
Log.d(TAG, view + " doesn't support showing translation because of "
+ "null ViewTranslationCallback.");
}
@@ -506,7 +509,7 @@ public class UiTranslationController implements Dumpable {
final TranslationRequest request = new TranslationRequest.Builder()
.setViewTranslationRequests(requests)
.build();
- if (DEBUG) {
+ if (Log.isLoggable(UiTranslationManager.LOG_TAG, Log.DEBUG)) {
StringBuilder msg = new StringBuilder("sendTranslationRequest:{requests=[");
for (ViewTranslationRequest viewRequest: requests) {
msg.append("{request=")
@@ -636,6 +639,7 @@ public class UiTranslationController implements Dumpable {
private void runForEachView(BiConsumer<View, ViewTranslationCallback> action) {
synchronized (mLock) {
+ boolean isLoggable = Log.isLoggable(UiTranslationManager.LOG_TAG, Log.DEBUG);
final ArrayMap<AutofillId, WeakReference<View>> views = new ArrayMap<>(mViews);
if (views.size() == 0) {
Log.w(TAG, "No views can be excuted for runForEachView.");
@@ -644,12 +648,12 @@ public class UiTranslationController implements Dumpable {
final int viewCounts = views.size();
for (int i = 0; i < viewCounts; i++) {
final View view = views.valueAt(i).get();
- if (DEBUG) {
+ if (isLoggable) {
Log.d(TAG, "runForEachView for autofillId = " + (view != null
? view.getAutofillId() : " null"));
}
if (view == null || view.getViewTranslationCallback() == null) {
- if (DEBUG) {
+ if (isLoggable) {
Log.d(TAG, "View was gone or ViewTranslationCallback for autofillId "
+ "= " + views.keyAt(i));
}