Loading core/java/android/view/contentcapture/ContentCaptureSession.java +21 −14 Original line number Diff line number Diff line Loading @@ -181,6 +181,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { public static final int FLUSH_REASON_VIEW_TREE_APPEARING = 9; /** @hide */ public static final int FLUSH_REASON_VIEW_TREE_APPEARED = 10; /** @hide */ public static final int FLUSH_REASON_LOGIN_DETECTED = 11; /** * After {@link UPSIDE_DOWN_CAKE}, {@link #notifyViewsDisappeared(AutofillId, long[])} wraps Loading @@ -191,7 +193,9 @@ public abstract class ContentCaptureSession implements AutoCloseable { static final long NOTIFY_NODES_DISAPPEAR_NOW_SENDS_TREE_EVENTS = 258825825L; /** @hide */ @IntDef(prefix = { "FLUSH_REASON_" }, value = { @IntDef( prefix = {"FLUSH_REASON_"}, value = { FLUSH_REASON_FULL, FLUSH_REASON_VIEW_ROOT_ENTERED, FLUSH_REASON_SESSION_STARTED, Loading @@ -201,7 +205,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { FLUSH_REASON_SESSION_CONNECTED, FLUSH_REASON_FORCE_FLUSH, FLUSH_REASON_VIEW_TREE_APPEARING, FLUSH_REASON_VIEW_TREE_APPEARED FLUSH_REASON_VIEW_TREE_APPEARED, FLUSH_REASON_LOGIN_DETECTED }) @Retention(RetentionPolicy.SOURCE) public @interface FlushReason {} Loading Loading @@ -685,8 +690,10 @@ public abstract class ContentCaptureSession implements AutoCloseable { return "VIEW_TREE_APPEARING"; case FLUSH_REASON_VIEW_TREE_APPEARED: return "VIEW_TREE_APPEARED"; case FLUSH_REASON_LOGIN_DETECTED: return "LOGIN_DETECTED"; default: return "UNKOWN-" + reason; return "UNKNOWN-" + reason; } } Loading core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import android.view.ViewStructure; import android.view.autofill.AutofillId; import android.view.contentcapture.ViewNode.ViewStructureImpl; import com.google.common.collect.ImmutableMap; import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges; import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; Loading @@ -37,6 +39,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import java.util.Map; /** * Unit tests for {@link ContentCaptureSession}. * Loading Loading @@ -145,6 +149,35 @@ public class ContentCaptureSessionTest { assertThat(session.mInternalNotifyViewTreeEventFinishedCount).isEqualTo(1); } @Test public void testGetFlushReasonAsString() { int invalidFlushReason = ContentCaptureSession.FLUSH_REASON_LOGIN_DETECTED + 1; Map<Integer, String> expectedMap = new ImmutableMap.Builder<Integer, String>() .put(ContentCaptureSession.FLUSH_REASON_FULL, "FULL") .put(ContentCaptureSession.FLUSH_REASON_VIEW_ROOT_ENTERED, "VIEW_ROOT") .put(ContentCaptureSession.FLUSH_REASON_SESSION_STARTED, "STARTED") .put(ContentCaptureSession.FLUSH_REASON_SESSION_FINISHED, "FINISHED") .put(ContentCaptureSession.FLUSH_REASON_IDLE_TIMEOUT, "IDLE") .put(ContentCaptureSession.FLUSH_REASON_TEXT_CHANGE_TIMEOUT, "TEXT_CHANGE") .put(ContentCaptureSession.FLUSH_REASON_SESSION_CONNECTED, "CONNECTED") .put(ContentCaptureSession.FLUSH_REASON_FORCE_FLUSH, "FORCE_FLUSH") .put( ContentCaptureSession.FLUSH_REASON_VIEW_TREE_APPEARING, "VIEW_TREE_APPEARING") .put( ContentCaptureSession.FLUSH_REASON_VIEW_TREE_APPEARED, "VIEW_TREE_APPEARED") .put(ContentCaptureSession.FLUSH_REASON_LOGIN_DETECTED, "LOGIN_DETECTED") .put(invalidFlushReason, "UNKOWN-" + invalidFlushReason) .build(); expectedMap.forEach( (reason, expected) -> assertThat(ContentCaptureSession.getFlushReasonAsString(reason)) .isEqualTo(expected)); } // Cannot use @Spy because we need to pass the session id on constructor private class MyContentCaptureSession extends ContentCaptureSession { int mInternalNotifyViewTreeEventStartedCount = 0; Loading Loading
core/java/android/view/contentcapture/ContentCaptureSession.java +21 −14 Original line number Diff line number Diff line Loading @@ -181,6 +181,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { public static final int FLUSH_REASON_VIEW_TREE_APPEARING = 9; /** @hide */ public static final int FLUSH_REASON_VIEW_TREE_APPEARED = 10; /** @hide */ public static final int FLUSH_REASON_LOGIN_DETECTED = 11; /** * After {@link UPSIDE_DOWN_CAKE}, {@link #notifyViewsDisappeared(AutofillId, long[])} wraps Loading @@ -191,7 +193,9 @@ public abstract class ContentCaptureSession implements AutoCloseable { static final long NOTIFY_NODES_DISAPPEAR_NOW_SENDS_TREE_EVENTS = 258825825L; /** @hide */ @IntDef(prefix = { "FLUSH_REASON_" }, value = { @IntDef( prefix = {"FLUSH_REASON_"}, value = { FLUSH_REASON_FULL, FLUSH_REASON_VIEW_ROOT_ENTERED, FLUSH_REASON_SESSION_STARTED, Loading @@ -201,7 +205,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { FLUSH_REASON_SESSION_CONNECTED, FLUSH_REASON_FORCE_FLUSH, FLUSH_REASON_VIEW_TREE_APPEARING, FLUSH_REASON_VIEW_TREE_APPEARED FLUSH_REASON_VIEW_TREE_APPEARED, FLUSH_REASON_LOGIN_DETECTED }) @Retention(RetentionPolicy.SOURCE) public @interface FlushReason {} Loading Loading @@ -685,8 +690,10 @@ public abstract class ContentCaptureSession implements AutoCloseable { return "VIEW_TREE_APPEARING"; case FLUSH_REASON_VIEW_TREE_APPEARED: return "VIEW_TREE_APPEARED"; case FLUSH_REASON_LOGIN_DETECTED: return "LOGIN_DETECTED"; default: return "UNKOWN-" + reason; return "UNKNOWN-" + reason; } } Loading
core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import android.view.ViewStructure; import android.view.autofill.AutofillId; import android.view.contentcapture.ViewNode.ViewStructureImpl; import com.google.common.collect.ImmutableMap; import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges; import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges; Loading @@ -37,6 +39,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import java.util.Map; /** * Unit tests for {@link ContentCaptureSession}. * Loading Loading @@ -145,6 +149,35 @@ public class ContentCaptureSessionTest { assertThat(session.mInternalNotifyViewTreeEventFinishedCount).isEqualTo(1); } @Test public void testGetFlushReasonAsString() { int invalidFlushReason = ContentCaptureSession.FLUSH_REASON_LOGIN_DETECTED + 1; Map<Integer, String> expectedMap = new ImmutableMap.Builder<Integer, String>() .put(ContentCaptureSession.FLUSH_REASON_FULL, "FULL") .put(ContentCaptureSession.FLUSH_REASON_VIEW_ROOT_ENTERED, "VIEW_ROOT") .put(ContentCaptureSession.FLUSH_REASON_SESSION_STARTED, "STARTED") .put(ContentCaptureSession.FLUSH_REASON_SESSION_FINISHED, "FINISHED") .put(ContentCaptureSession.FLUSH_REASON_IDLE_TIMEOUT, "IDLE") .put(ContentCaptureSession.FLUSH_REASON_TEXT_CHANGE_TIMEOUT, "TEXT_CHANGE") .put(ContentCaptureSession.FLUSH_REASON_SESSION_CONNECTED, "CONNECTED") .put(ContentCaptureSession.FLUSH_REASON_FORCE_FLUSH, "FORCE_FLUSH") .put( ContentCaptureSession.FLUSH_REASON_VIEW_TREE_APPEARING, "VIEW_TREE_APPEARING") .put( ContentCaptureSession.FLUSH_REASON_VIEW_TREE_APPEARED, "VIEW_TREE_APPEARED") .put(ContentCaptureSession.FLUSH_REASON_LOGIN_DETECTED, "LOGIN_DETECTED") .put(invalidFlushReason, "UNKOWN-" + invalidFlushReason) .build(); expectedMap.forEach( (reason, expected) -> assertThat(ContentCaptureSession.getFlushReasonAsString(reason)) .isEqualTo(expected)); } // Cannot use @Spy because we need to pass the session id on constructor private class MyContentCaptureSession extends ContentCaptureSession { int mInternalNotifyViewTreeEventStartedCount = 0; Loading