Add new flush reason for content protection

Bug: 275732576
Test: Added new tests
No-Typo-Check: This typeo has been merged since Jan 2019
Change-Id: I0f507a8f57bfab50df9a9b3234a3679a06b75423
This commit is contained in:
Nino Jagar
2023-05-18 17:32:31 +00:00
parent ca8950256d
commit 705bb6525c
2 changed files with 54 additions and 14 deletions

View File

@@ -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
@@ -191,20 +193,23 @@ public abstract class ContentCaptureSession implements AutoCloseable {
static final long NOTIFY_NODES_DISAPPEAR_NOW_SENDS_TREE_EVENTS = 258825825L;
/** @hide */
@IntDef(prefix = { "FLUSH_REASON_" }, value = {
FLUSH_REASON_FULL,
FLUSH_REASON_VIEW_ROOT_ENTERED,
FLUSH_REASON_SESSION_STARTED,
FLUSH_REASON_SESSION_FINISHED,
FLUSH_REASON_IDLE_TIMEOUT,
FLUSH_REASON_TEXT_CHANGE_TIMEOUT,
FLUSH_REASON_SESSION_CONNECTED,
FLUSH_REASON_FORCE_FLUSH,
FLUSH_REASON_VIEW_TREE_APPEARING,
FLUSH_REASON_VIEW_TREE_APPEARED
})
@IntDef(
prefix = {"FLUSH_REASON_"},
value = {
FLUSH_REASON_FULL,
FLUSH_REASON_VIEW_ROOT_ENTERED,
FLUSH_REASON_SESSION_STARTED,
FLUSH_REASON_SESSION_FINISHED,
FLUSH_REASON_IDLE_TIMEOUT,
FLUSH_REASON_TEXT_CHANGE_TIMEOUT,
FLUSH_REASON_SESSION_CONNECTED,
FLUSH_REASON_FORCE_FLUSH,
FLUSH_REASON_VIEW_TREE_APPEARING,
FLUSH_REASON_VIEW_TREE_APPEARED,
FLUSH_REASON_LOGIN_DETECTED
})
@Retention(RetentionPolicy.SOURCE)
public @interface FlushReason{}
public @interface FlushReason {}
private final Object mLock = new Object();
@@ -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;
}
}

View File

@@ -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;
@@ -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}.
*
@@ -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;