Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a533e52b authored by Dieter Hsu's avatar Dieter Hsu
Browse files

Dump accessibility event and node when tag is loggable

Let accessibility cache to dump events and nodes info only when
log.tag property has been set up in a debuggable build.

When analyzing we care about events before diving into details.
Using separate log level to decrease interfere and to lower the
performance impact.

- To debugging Cache and event set log.tag.AccessibilityCache property
  to DEBUG
- To dump node as well when get/add to Cache set
  log.tag.AccessibilityCache property to VERBOSE
- To dump additional debug info for NodeInfo/Event set corresponding
  log.tag.AccessibilityNodeInfo/log.tag.AccessibilityEvent property set
  to DEBUG.

Bug: 117150182
Test: `setprop log.tag.AccessibilityCache D` and
      enable talkback to use and check logcat manually
Test: `setprop log.tag.AccessibilityCache V` and
      enable talkback to use and check logcat manually

Change-Id: I433e21ffd21d4125caf938bc8271135bcefd66c3
parent 9b4cdaa8
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -35,7 +35,10 @@ public class AccessibilityCache {

    private static final String LOG_TAG = "AccessibilityCache";

    private static final boolean DEBUG = false;
    private static final boolean DEBUG = Log.isLoggable(LOG_TAG, Log.DEBUG) && Build.IS_DEBUGGABLE;

    private static final boolean VERBOSE =
            Log.isLoggable(LOG_TAG, Log.VERBOSE) && Build.IS_DEBUGGABLE;

    private static final boolean CHECK_INTEGRITY = Build.IS_ENG;

@@ -120,6 +123,9 @@ public class AccessibilityCache {
     */
    public void onAccessibilityEvent(AccessibilityEvent event) {
        synchronized (mLock) {
            if (DEBUG) {
                Log.i(LOG_TAG, "onAccessibilityEvent(" + event + ")");
            }
            final int eventType = event.getEventType();
            switch (eventType) {
                case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: {
@@ -223,8 +229,8 @@ public class AccessibilityCache {
                // will wipe the data of the cached info.
                info = new AccessibilityNodeInfo(info);
            }
            if (DEBUG) {
                Log.i(LOG_TAG, "get(" + accessibilityNodeId + ") = " + info);
            if (VERBOSE) {
                Log.i(LOG_TAG, "get(0x" + Long.toHexString(accessibilityNodeId) + ") = " + info);
            }
            return info;
        }
@@ -280,7 +286,7 @@ public class AccessibilityCache {
     */
    public void add(AccessibilityNodeInfo info) {
        synchronized(mLock) {
            if (DEBUG) {
            if (VERBOSE) {
                Log.i(LOG_TAG, "add(" + info + ")");
            }

+7 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pools.SynchronizedPool;

import com.android.internal.util.BitUtils;
@@ -390,7 +391,10 @@ import java.util.List;
 * @see AccessibilityNodeInfo
 */
public final class AccessibilityEvent extends AccessibilityRecord implements Parcelable {
    private static final boolean DEBUG = false;
    private static final String LOG_TAG = "AccessibilityEvent";

    private static final boolean DEBUG = Log.isLoggable(LOG_TAG, Log.DEBUG) && Build.IS_DEBUGGABLE;

    /** @hide */
    public static final boolean DEBUG_ORIGIN = false;

@@ -1346,8 +1350,8 @@ public final class AccessibilityEvent extends AccessibilityRecord implements Par
                builder.append("\n");
            }
            if (DEBUG) {
                builder.append("; SourceWindowId: ").append(mSourceWindowId);
                builder.append("; SourceNodeId: ").append(mSourceNodeId);
                builder.append("; SourceWindowId: 0x").append(Long.toHexString(mSourceWindowId));
                builder.append("; SourceNodeId: 0x").append(Long.toHexString(mSourceNodeId));
            }
            for (int i = 0; i < getRecordCount(); i++) {
                builder.append("  Record ").append(i).append(":");
+13 −10
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
import android.graphics.Rect;
import android.graphics.Region;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@@ -90,10 +91,10 @@ import java.util.concurrent.atomic.AtomicInteger;
 */
public class AccessibilityNodeInfo implements Parcelable {

    private static final boolean DEBUG = false;

    private static final String TAG = "AccessibilityNodeInfo";

    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG) && Build.IS_DEBUGGABLE;

    /** @hide */
    public static final int UNDEFINED_CONNECTION_ID = -1;

@@ -3943,13 +3944,15 @@ public class AccessibilityNodeInfo implements Parcelable {
        builder.append(super.toString());

        if (DEBUG) {
            builder.append("; sourceNodeId: " + mSourceNodeId);
            builder.append("; windowId: " + mWindowId);
            builder.append("; accessibilityViewId: ").append(getAccessibilityViewId(mSourceNodeId));
            builder.append("; virtualDescendantId: ").append(getVirtualDescendantId(mSourceNodeId));
            builder.append("; mParentNodeId: " + mParentNodeId);
            builder.append("; traversalBefore: ").append(mTraversalBefore);
            builder.append("; traversalAfter: ").append(mTraversalAfter);
            builder.append("; sourceNodeId: 0x").append(Long.toHexString(mSourceNodeId));
            builder.append("; windowId: 0x").append(Long.toHexString(mWindowId));
            builder.append("; accessibilityViewId: 0x")
                    .append(Long.toHexString(getAccessibilityViewId(mSourceNodeId)));
            builder.append("; virtualDescendantId: 0x")
                    .append(Long.toHexString(getVirtualDescendantId(mSourceNodeId)));
            builder.append("; mParentNodeId: 0x").append(Long.toHexString(mParentNodeId));
            builder.append("; traversalBefore: 0x").append(Long.toHexString(mTraversalBefore));
            builder.append("; traversalAfter: 0x").append(Long.toHexString(mTraversalAfter));

            int granularities = mMovementGranularities;
            builder.append("; MovementGranularities: [");
@@ -3967,7 +3970,7 @@ public class AccessibilityNodeInfo implements Parcelable {
            final LongArray childIds = mChildNodeIds;
            if (childIds != null) {
                for (int i = 0, count = childIds.size(); i < count; i++) {
                    builder.append(childIds.get(i));
                    builder.append("0x").append(Long.toHexString(childIds.get(i)));
                    if (i < count - 1) {
                        builder.append(", ");
                    }