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

Commit 1d105c90 authored by Nino Jagar's avatar Nino Jagar Committed by Automerger Merge Worker
Browse files

Merge "Add new flush reason for content protection" into udc-qpr-dev am: ffaa29ba

parents b6a5c022 ffaa29ba
Loading
Loading
Loading
Loading
+21 −14
Original line number Diff line number Diff line
@@ -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,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,
@@ -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 {}
@@ -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;
        }
    }

+33 −0
Original line number Diff line number Diff line
@@ -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;