diff options
| author | 2023-11-24 13:22:07 +0000 | |
|---|---|---|
| committer | 2023-11-24 13:22:07 +0000 | |
| commit | 2945b7b1010e971deefccd029e54f2287712448f (patch) | |
| tree | fb35af5b05db9e9aa3f1d8f638f41609e7dd3c63 | |
| parent | 5eb82e656af0d83f20e5a3fd676fd7b297ef84d8 (diff) | |
| parent | 64e1166d7b3cbf0755f7b95382f1b39511cbd6d9 (diff) | |
Merge "Logs number of times CCAPI running on wrong thread." into main
| -rw-r--r-- | core/java/android/view/contentcapture/MainContentCaptureSession.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java index 542c783c9dff..14ec14bf7cfc 100644 --- a/core/java/android/view/contentcapture/MainContentCaptureSession.java +++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java @@ -60,6 +60,7 @@ import android.view.inputmethod.BaseInputConnection; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.os.IResultReceiver; +import com.android.modules.expresslog.Counter; import java.io.PrintWriter; import java.lang.ref.WeakReference; @@ -68,6 +69,7 @@ import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; /** * Main session associated with a context. @@ -81,6 +83,9 @@ public final class MainContentCaptureSession extends ContentCaptureSession { private static final String TAG = MainContentCaptureSession.class.getSimpleName(); + private static final String CONTENT_CAPTURE_WRONG_THREAD_METRIC_ID = + "content_capture.value_content_capture_wrong_thread_count"; + // For readability purposes... private static final boolean FORCE_FLUSH = true; @@ -165,6 +170,8 @@ public final class MainContentCaptureSession extends ContentCaptureSession { @Nullable private final LocalLog mFlushHistory; + private final AtomicInteger mWrongThreadCount = new AtomicInteger(0); + /** * Binder object used to update the session state. */ @@ -701,6 +708,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession { + getDebugState()); } + reportWrongThreadMetric(); try { mSystemServerInterface.finishSession(mId); } catch (RemoteException e) { @@ -1040,20 +1048,27 @@ public final class MainContentCaptureSession extends ContentCaptureSession { } /** - * Checks that the current work is running on the assigned thread from {@code mHandler}. + * Checks that the current work is running on the assigned thread from {@code mHandler} and + * count the number of times running on the wrong thread. * * <p>It is not guaranteed that the callers always invoke function from a single thread. * Therefore, accessing internal properties in {@link MainContentCaptureSession} should * always delegate to the assigned thread from {@code mHandler} for synchronization.</p> */ private void checkOnContentCaptureThread() { - // TODO(b/309411951): Add metrics to track the issue instead. final boolean onContentCaptureThread = mHandler.getLooper().isCurrentThread(); if (!onContentCaptureThread) { + mWrongThreadCount.incrementAndGet(); Log.e(TAG, "MainContentCaptureSession running on " + Thread.currentThread()); } } + /** Reports number of times running on the wrong thread. */ + private void reportWrongThreadMetric() { + Counter.logIncrement( + CONTENT_CAPTURE_WRONG_THREAD_METRIC_ID, mWrongThreadCount.getAndSet(0)); + } + /** * Ensures that {@code r} will be running on the assigned thread. * |