Loading core/java/android/content/ContentCaptureOptions.java +105 −12 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient; import com.android.internal.annotations.VisibleForTesting; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; /** * Content capture options for a given package. Loading Loading @@ -119,7 +124,10 @@ public final class ContentCaptureOptions implements Parcelable { /* enableReceiver= */ false, new ContentProtectionOptions( /* enableReceiver= */ false, /* bufferSize= */ 0), /* bufferSize= */ 0, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0), /* whitelistedComponents= */ null); } Loading @@ -141,9 +149,7 @@ public final class ContentCaptureOptions implements Parcelable { logHistorySize, ContentCaptureManager.DEFAULT_DISABLE_FLUSH_FOR_VIEW_TREE_APPEARING, ContentCaptureManager.DEFAULT_ENABLE_CONTENT_CAPTURE_RECEIVER, new ContentProtectionOptions( ContentCaptureManager.DEFAULT_ENABLE_CONTENT_PROTECTION_RECEIVER, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_BUFFER_SIZE), new ContentProtectionOptions(), whitelistedComponents); } Loading Loading @@ -183,9 +189,7 @@ public final class ContentCaptureOptions implements Parcelable { ContentCaptureManager.DEFAULT_LOG_HISTORY_SIZE, ContentCaptureManager.DEFAULT_DISABLE_FLUSH_FOR_VIEW_TREE_APPEARING, ContentCaptureManager.DEFAULT_ENABLE_CONTENT_CAPTURE_RECEIVER, new ContentProtectionOptions( ContentCaptureManager.DEFAULT_ENABLE_CONTENT_PROTECTION_RECEIVER, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_BUFFER_SIZE), new ContentProtectionOptions(), whitelistedComponents); } Loading Loading @@ -386,9 +390,58 @@ public final class ContentCaptureOptions implements Parcelable { */ public final int bufferSize; public ContentProtectionOptions(boolean enableReceiver, int bufferSize) { /** * The list of required groups of strings to match. * * @hide */ @NonNull public final List<List<String>> requiredGroups; /** * The list of optional groups of strings to match. * * @hide */ @NonNull public final List<List<String>> optionalGroups; /** * The minimal number of optional groups that have to be matched. This is the threshold * value and comparison is done with greater than or equals. * * @hide */ public final int optionalGroupsThreshold; /** * Empty constructor with default values. * * @hide */ public ContentProtectionOptions() { this( ContentCaptureManager.DEFAULT_ENABLE_CONTENT_PROTECTION_RECEIVER, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_BUFFER_SIZE, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_REQUIRED_GROUPS, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS_THRESHOLD); } /** * Full primary constructor. * * @hide */ public ContentProtectionOptions( boolean enableReceiver, int bufferSize, @NonNull List<List<String>> requiredGroups, @NonNull List<List<String>> optionalGroups, int optionalGroupsThreshold) { this.enableReceiver = enableReceiver; this.bufferSize = bufferSize; this.requiredGroups = requiredGroups; this.optionalGroups = optionalGroups; this.optionalGroupsThreshold = optionalGroupsThreshold; } @Override Loading @@ -398,7 +451,14 @@ public final class ContentCaptureOptions implements Parcelable { .append("enableReceiver=") .append(enableReceiver) .append(", bufferSize=") .append(bufferSize); .append(bufferSize) .append(", requiredGroupsSize=") .append(requiredGroups.size()) .append(", optionalGroupsSize=") .append(optionalGroups.size()) .append(", optionalGroupsThreshold=") .append(optionalGroupsThreshold); return stringBuilder.append(']').toString(); } Loading @@ -407,17 +467,50 @@ public final class ContentCaptureOptions implements Parcelable { pw.print(enableReceiver); pw.print(", bufferSize="); pw.print(bufferSize); pw.print(", requiredGroupsSize="); pw.print(requiredGroups.size()); pw.print(", optionalGroupsSize="); pw.print(optionalGroups.size()); pw.print(", optionalGroupsThreshold="); pw.print(optionalGroupsThreshold); } private void writeToParcel(Parcel parcel) { private void writeToParcel(@NonNull Parcel parcel) { parcel.writeBoolean(enableReceiver); parcel.writeInt(bufferSize); writeGroupsToParcel(requiredGroups, parcel); writeGroupsToParcel(optionalGroups, parcel); parcel.writeInt(optionalGroupsThreshold); } private static ContentProtectionOptions createFromParcel(Parcel parcel) { @NonNull private static ContentProtectionOptions createFromParcel(@NonNull Parcel parcel) { boolean enableReceiver = parcel.readBoolean(); int bufferSize = parcel.readInt(); return new ContentProtectionOptions(enableReceiver, bufferSize); List<List<String>> requiredGroups = createGroupsFromParcel(parcel); List<List<String>> optionalGroups = createGroupsFromParcel(parcel); int optionalGroupsThreshold = parcel.readInt(); return new ContentProtectionOptions( enableReceiver, bufferSize, requiredGroups, optionalGroups, optionalGroupsThreshold); } private static void writeGroupsToParcel( @NonNull List<List<String>> groups, @NonNull Parcel parcel) { parcel.writeInt(groups.size()); groups.forEach(parcel::writeStringList); } @NonNull private static List<List<String>> createGroupsFromParcel(@NonNull Parcel parcel) { int size = parcel.readInt(); return IntStream.range(0, size) .mapToObj(i -> new ArrayList<String>()) .peek(parcel::readStringList) .collect(Collectors.toUnmodifiableList()); } } } core/java/android/view/contentcapture/ContentCaptureManager.java +38 −0 Original line number Diff line number Diff line Loading @@ -60,7 +60,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; Loading Loading @@ -377,6 +379,30 @@ public final class ContentCaptureManager { public static final String DEVICE_CONFIG_PROPERTY_CONTENT_PROTECTION_BUFFER_SIZE = "content_protection_buffer_size"; /** * Sets the config for content protection required groups. * * @hide */ public static final String DEVICE_CONFIG_PROPERTY_CONTENT_PROTECTION_REQUIRED_GROUPS_CONFIG = "content_protection_required_groups_config"; /** * Sets the config for content protection optional groups. * * @hide */ public static final String DEVICE_CONFIG_PROPERTY_CONTENT_PROTECTION_OPTIONAL_GROUPS_CONFIG = "content_protection_optional_groups_config"; /** * Sets the threshold for content protection optional groups. * * @hide */ public static final String DEVICE_CONFIG_PROPERTY_CONTENT_PROTECTION_OPTIONAL_GROUPS_THRESHOLD = "content_protection_optional_groups_threshold"; /** @hide */ @TestApi public static final int LOGGING_LEVEL_OFF = 0; Loading Loading @@ -417,6 +443,18 @@ public final class ContentCaptureManager { public static final int DEFAULT_CONTENT_PROTECTION_APPS_BLOCKLIST_SIZE = 5000; /** @hide */ public static final int DEFAULT_CONTENT_PROTECTION_BUFFER_SIZE = 150; /** @hide */ public static final List<List<String>> DEFAULT_CONTENT_PROTECTION_REQUIRED_GROUPS = Collections.emptyList(); /** @hide */ public static final String DEFAULT_CONTENT_PROTECTION_REQUIRED_GROUPS_CONFIG = ""; /** @hide */ public static final List<List<String>> DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS = Collections.emptyList(); /** @hide */ public static final String DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS_CONFIG = ""; /** @hide */ public static final int DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS_THRESHOLD = 0; private final Object mLock = new Object(); Loading core/tests/coretests/src/android/content/ContentCaptureOptionsTest.java +31 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import java.util.List; /** * Unit test for {@link ContentCaptureOptions}. * Loading @@ -44,6 +46,9 @@ public class ContentCaptureOptionsTest { private static final ComponentName CONTEXT_COMPONENT = new ComponentName("marco", "polo"); private static final ComponentName COMPONENT1 = new ComponentName("comp", "one"); private static final ComponentName COMPONENT2 = new ComponentName("two", "comp"); private static final List<List<String>> CONTENT_PROTECTION_REQUIRED_GROUPS = List.of(List.of("first"), List.of("second", "third"), List.of()); private static final List<List<String>> CONTENT_PROTECTION_OPTIONAL_GROUPS = List.of(); private static final ContentCaptureOptions CONTENT_CAPTURE_OPTIONS = new ContentCaptureOptions( /* loggingLevel= */ 1000, Loading @@ -55,7 +60,10 @@ public class ContentCaptureOptionsTest { /* enableReceiver= */ false, new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ true, /* bufferSize= */ 2001), /* bufferSize= */ 2001, CONTENT_PROTECTION_REQUIRED_GROUPS, CONTENT_PROTECTION_OPTIONAL_GROUPS, /* optionalGroupsThreshold= */ 2002), /* whitelistedComponents= */ toSet(COMPONENT1, COMPONENT2)); @Mock private Context mContext; Loading Loading @@ -134,6 +142,19 @@ public class ContentCaptureOptionsTest { .append(CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.enableReceiver) .append(", bufferSize=") .append(CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.bufferSize) .append(", requiredGroupsSize=") .append( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.requiredGroups .size()) .append(", optionalGroupsSize=") .append( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.optionalGroups .size()) .append(", optionalGroupsThreshold=") .append( CONTENT_CAPTURE_OPTIONS .contentProtectionOptions .optionalGroupsThreshold) .append("], whitelisted=") .append(CONTENT_CAPTURE_OPTIONS.whitelistedComponents) .append(']') Loading Loading @@ -166,6 +187,15 @@ public class ContentCaptureOptionsTest { .isEqualTo(CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.enableReceiver); assertThat(actual.contentProtectionOptions.bufferSize) .isEqualTo(CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.bufferSize); assertThat(actual.contentProtectionOptions.requiredGroups) .containsExactlyElementsIn( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.requiredGroups); assertThat(actual.contentProtectionOptions.optionalGroups) .containsExactlyElementsIn( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.optionalGroups); assertThat(actual.contentProtectionOptions.optionalGroupsThreshold) .isEqualTo( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.optionalGroupsThreshold); assertThat(actual.whitelistedComponents) .containsExactlyElementsIn(CONTENT_CAPTURE_OPTIONS.whitelistedComponents); } Loading core/tests/coretests/src/android/view/contentcapture/ContentCaptureManagerTest.java +17 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import java.util.Collections; /** * Unit test for {@link ContentCaptureManager}. * Loading Loading @@ -69,7 +71,11 @@ public class ContentCaptureManagerTest { ContentCaptureOptions options = createOptions( new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ false, BUFFER_SIZE)); /* enableReceiver= */ false, BUFFER_SIZE, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); ContentCaptureManager manager = new ContentCaptureManager(mMockContext, mMockContentCaptureManager, options); Loading @@ -82,7 +88,11 @@ public class ContentCaptureManagerTest { ContentCaptureOptions options = createOptions( new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ true, /* bufferSize= */ 0)); /* enableReceiver= */ true, /* bufferSize= */ 0, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); ContentCaptureManager manager = new ContentCaptureManager(mMockContext, mMockContentCaptureManager, options); Loading @@ -95,7 +105,11 @@ public class ContentCaptureManagerTest { ContentCaptureOptions options = createOptions( new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ true, BUFFER_SIZE)); /* enableReceiver= */ true, BUFFER_SIZE, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); ContentCaptureManager manager = new ContentCaptureManager(mMockContext, mMockContentCaptureManager, options); Loading core/tests/coretests/src/android/view/contentcapture/MainContentCaptureSessionTest.java +11 −2 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import org.mockito.junit.MockitoRule; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; /** Loading Loading @@ -112,7 +113,11 @@ public class MainContentCaptureSessionTest { createOptions( /* enableContentCaptureReceiver= */ true, new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ true, -BUFFER_SIZE)); /* enableReceiver= */ true, -BUFFER_SIZE, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); MainContentCaptureSession session = createSession(options); session.mContentProtectionEventProcessor = mMockContentProtectionEventProcessor; Loading Loading @@ -313,7 +318,11 @@ public class MainContentCaptureSessionTest { return createOptions( enableContentCaptureReceiver, new ContentCaptureOptions.ContentProtectionOptions( enableContentProtectionReceiver, BUFFER_SIZE)); enableContentProtectionReceiver, BUFFER_SIZE, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); } private ContentCaptureManager createManager(ContentCaptureOptions options) { Loading Loading
core/java/android/content/ContentCaptureOptions.java +105 −12 Original line number Diff line number Diff line Loading @@ -30,6 +30,11 @@ import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient; import com.android.internal.annotations.VisibleForTesting; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; /** * Content capture options for a given package. Loading Loading @@ -119,7 +124,10 @@ public final class ContentCaptureOptions implements Parcelable { /* enableReceiver= */ false, new ContentProtectionOptions( /* enableReceiver= */ false, /* bufferSize= */ 0), /* bufferSize= */ 0, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0), /* whitelistedComponents= */ null); } Loading @@ -141,9 +149,7 @@ public final class ContentCaptureOptions implements Parcelable { logHistorySize, ContentCaptureManager.DEFAULT_DISABLE_FLUSH_FOR_VIEW_TREE_APPEARING, ContentCaptureManager.DEFAULT_ENABLE_CONTENT_CAPTURE_RECEIVER, new ContentProtectionOptions( ContentCaptureManager.DEFAULT_ENABLE_CONTENT_PROTECTION_RECEIVER, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_BUFFER_SIZE), new ContentProtectionOptions(), whitelistedComponents); } Loading Loading @@ -183,9 +189,7 @@ public final class ContentCaptureOptions implements Parcelable { ContentCaptureManager.DEFAULT_LOG_HISTORY_SIZE, ContentCaptureManager.DEFAULT_DISABLE_FLUSH_FOR_VIEW_TREE_APPEARING, ContentCaptureManager.DEFAULT_ENABLE_CONTENT_CAPTURE_RECEIVER, new ContentProtectionOptions( ContentCaptureManager.DEFAULT_ENABLE_CONTENT_PROTECTION_RECEIVER, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_BUFFER_SIZE), new ContentProtectionOptions(), whitelistedComponents); } Loading Loading @@ -386,9 +390,58 @@ public final class ContentCaptureOptions implements Parcelable { */ public final int bufferSize; public ContentProtectionOptions(boolean enableReceiver, int bufferSize) { /** * The list of required groups of strings to match. * * @hide */ @NonNull public final List<List<String>> requiredGroups; /** * The list of optional groups of strings to match. * * @hide */ @NonNull public final List<List<String>> optionalGroups; /** * The minimal number of optional groups that have to be matched. This is the threshold * value and comparison is done with greater than or equals. * * @hide */ public final int optionalGroupsThreshold; /** * Empty constructor with default values. * * @hide */ public ContentProtectionOptions() { this( ContentCaptureManager.DEFAULT_ENABLE_CONTENT_PROTECTION_RECEIVER, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_BUFFER_SIZE, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_REQUIRED_GROUPS, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS, ContentCaptureManager.DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS_THRESHOLD); } /** * Full primary constructor. * * @hide */ public ContentProtectionOptions( boolean enableReceiver, int bufferSize, @NonNull List<List<String>> requiredGroups, @NonNull List<List<String>> optionalGroups, int optionalGroupsThreshold) { this.enableReceiver = enableReceiver; this.bufferSize = bufferSize; this.requiredGroups = requiredGroups; this.optionalGroups = optionalGroups; this.optionalGroupsThreshold = optionalGroupsThreshold; } @Override Loading @@ -398,7 +451,14 @@ public final class ContentCaptureOptions implements Parcelable { .append("enableReceiver=") .append(enableReceiver) .append(", bufferSize=") .append(bufferSize); .append(bufferSize) .append(", requiredGroupsSize=") .append(requiredGroups.size()) .append(", optionalGroupsSize=") .append(optionalGroups.size()) .append(", optionalGroupsThreshold=") .append(optionalGroupsThreshold); return stringBuilder.append(']').toString(); } Loading @@ -407,17 +467,50 @@ public final class ContentCaptureOptions implements Parcelable { pw.print(enableReceiver); pw.print(", bufferSize="); pw.print(bufferSize); pw.print(", requiredGroupsSize="); pw.print(requiredGroups.size()); pw.print(", optionalGroupsSize="); pw.print(optionalGroups.size()); pw.print(", optionalGroupsThreshold="); pw.print(optionalGroupsThreshold); } private void writeToParcel(Parcel parcel) { private void writeToParcel(@NonNull Parcel parcel) { parcel.writeBoolean(enableReceiver); parcel.writeInt(bufferSize); writeGroupsToParcel(requiredGroups, parcel); writeGroupsToParcel(optionalGroups, parcel); parcel.writeInt(optionalGroupsThreshold); } private static ContentProtectionOptions createFromParcel(Parcel parcel) { @NonNull private static ContentProtectionOptions createFromParcel(@NonNull Parcel parcel) { boolean enableReceiver = parcel.readBoolean(); int bufferSize = parcel.readInt(); return new ContentProtectionOptions(enableReceiver, bufferSize); List<List<String>> requiredGroups = createGroupsFromParcel(parcel); List<List<String>> optionalGroups = createGroupsFromParcel(parcel); int optionalGroupsThreshold = parcel.readInt(); return new ContentProtectionOptions( enableReceiver, bufferSize, requiredGroups, optionalGroups, optionalGroupsThreshold); } private static void writeGroupsToParcel( @NonNull List<List<String>> groups, @NonNull Parcel parcel) { parcel.writeInt(groups.size()); groups.forEach(parcel::writeStringList); } @NonNull private static List<List<String>> createGroupsFromParcel(@NonNull Parcel parcel) { int size = parcel.readInt(); return IntStream.range(0, size) .mapToObj(i -> new ArrayList<String>()) .peek(parcel::readStringList) .collect(Collectors.toUnmodifiableList()); } } }
core/java/android/view/contentcapture/ContentCaptureManager.java +38 −0 Original line number Diff line number Diff line Loading @@ -60,7 +60,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; Loading Loading @@ -377,6 +379,30 @@ public final class ContentCaptureManager { public static final String DEVICE_CONFIG_PROPERTY_CONTENT_PROTECTION_BUFFER_SIZE = "content_protection_buffer_size"; /** * Sets the config for content protection required groups. * * @hide */ public static final String DEVICE_CONFIG_PROPERTY_CONTENT_PROTECTION_REQUIRED_GROUPS_CONFIG = "content_protection_required_groups_config"; /** * Sets the config for content protection optional groups. * * @hide */ public static final String DEVICE_CONFIG_PROPERTY_CONTENT_PROTECTION_OPTIONAL_GROUPS_CONFIG = "content_protection_optional_groups_config"; /** * Sets the threshold for content protection optional groups. * * @hide */ public static final String DEVICE_CONFIG_PROPERTY_CONTENT_PROTECTION_OPTIONAL_GROUPS_THRESHOLD = "content_protection_optional_groups_threshold"; /** @hide */ @TestApi public static final int LOGGING_LEVEL_OFF = 0; Loading Loading @@ -417,6 +443,18 @@ public final class ContentCaptureManager { public static final int DEFAULT_CONTENT_PROTECTION_APPS_BLOCKLIST_SIZE = 5000; /** @hide */ public static final int DEFAULT_CONTENT_PROTECTION_BUFFER_SIZE = 150; /** @hide */ public static final List<List<String>> DEFAULT_CONTENT_PROTECTION_REQUIRED_GROUPS = Collections.emptyList(); /** @hide */ public static final String DEFAULT_CONTENT_PROTECTION_REQUIRED_GROUPS_CONFIG = ""; /** @hide */ public static final List<List<String>> DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS = Collections.emptyList(); /** @hide */ public static final String DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS_CONFIG = ""; /** @hide */ public static final int DEFAULT_CONTENT_PROTECTION_OPTIONAL_GROUPS_THRESHOLD = 0; private final Object mLock = new Object(); Loading
core/tests/coretests/src/android/content/ContentCaptureOptionsTest.java +31 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import java.util.List; /** * Unit test for {@link ContentCaptureOptions}. * Loading @@ -44,6 +46,9 @@ public class ContentCaptureOptionsTest { private static final ComponentName CONTEXT_COMPONENT = new ComponentName("marco", "polo"); private static final ComponentName COMPONENT1 = new ComponentName("comp", "one"); private static final ComponentName COMPONENT2 = new ComponentName("two", "comp"); private static final List<List<String>> CONTENT_PROTECTION_REQUIRED_GROUPS = List.of(List.of("first"), List.of("second", "third"), List.of()); private static final List<List<String>> CONTENT_PROTECTION_OPTIONAL_GROUPS = List.of(); private static final ContentCaptureOptions CONTENT_CAPTURE_OPTIONS = new ContentCaptureOptions( /* loggingLevel= */ 1000, Loading @@ -55,7 +60,10 @@ public class ContentCaptureOptionsTest { /* enableReceiver= */ false, new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ true, /* bufferSize= */ 2001), /* bufferSize= */ 2001, CONTENT_PROTECTION_REQUIRED_GROUPS, CONTENT_PROTECTION_OPTIONAL_GROUPS, /* optionalGroupsThreshold= */ 2002), /* whitelistedComponents= */ toSet(COMPONENT1, COMPONENT2)); @Mock private Context mContext; Loading Loading @@ -134,6 +142,19 @@ public class ContentCaptureOptionsTest { .append(CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.enableReceiver) .append(", bufferSize=") .append(CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.bufferSize) .append(", requiredGroupsSize=") .append( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.requiredGroups .size()) .append(", optionalGroupsSize=") .append( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.optionalGroups .size()) .append(", optionalGroupsThreshold=") .append( CONTENT_CAPTURE_OPTIONS .contentProtectionOptions .optionalGroupsThreshold) .append("], whitelisted=") .append(CONTENT_CAPTURE_OPTIONS.whitelistedComponents) .append(']') Loading Loading @@ -166,6 +187,15 @@ public class ContentCaptureOptionsTest { .isEqualTo(CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.enableReceiver); assertThat(actual.contentProtectionOptions.bufferSize) .isEqualTo(CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.bufferSize); assertThat(actual.contentProtectionOptions.requiredGroups) .containsExactlyElementsIn( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.requiredGroups); assertThat(actual.contentProtectionOptions.optionalGroups) .containsExactlyElementsIn( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.optionalGroups); assertThat(actual.contentProtectionOptions.optionalGroupsThreshold) .isEqualTo( CONTENT_CAPTURE_OPTIONS.contentProtectionOptions.optionalGroupsThreshold); assertThat(actual.whitelistedComponents) .containsExactlyElementsIn(CONTENT_CAPTURE_OPTIONS.whitelistedComponents); } Loading
core/tests/coretests/src/android/view/contentcapture/ContentCaptureManagerTest.java +17 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import java.util.Collections; /** * Unit test for {@link ContentCaptureManager}. * Loading Loading @@ -69,7 +71,11 @@ public class ContentCaptureManagerTest { ContentCaptureOptions options = createOptions( new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ false, BUFFER_SIZE)); /* enableReceiver= */ false, BUFFER_SIZE, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); ContentCaptureManager manager = new ContentCaptureManager(mMockContext, mMockContentCaptureManager, options); Loading @@ -82,7 +88,11 @@ public class ContentCaptureManagerTest { ContentCaptureOptions options = createOptions( new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ true, /* bufferSize= */ 0)); /* enableReceiver= */ true, /* bufferSize= */ 0, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); ContentCaptureManager manager = new ContentCaptureManager(mMockContext, mMockContentCaptureManager, options); Loading @@ -95,7 +105,11 @@ public class ContentCaptureManagerTest { ContentCaptureOptions options = createOptions( new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ true, BUFFER_SIZE)); /* enableReceiver= */ true, BUFFER_SIZE, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); ContentCaptureManager manager = new ContentCaptureManager(mMockContext, mMockContentCaptureManager, options); Loading
core/tests/coretests/src/android/view/contentcapture/MainContentCaptureSessionTest.java +11 −2 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ import org.mockito.junit.MockitoRule; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; /** Loading Loading @@ -112,7 +113,11 @@ public class MainContentCaptureSessionTest { createOptions( /* enableContentCaptureReceiver= */ true, new ContentCaptureOptions.ContentProtectionOptions( /* enableReceiver= */ true, -BUFFER_SIZE)); /* enableReceiver= */ true, -BUFFER_SIZE, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); MainContentCaptureSession session = createSession(options); session.mContentProtectionEventProcessor = mMockContentProtectionEventProcessor; Loading Loading @@ -313,7 +318,11 @@ public class MainContentCaptureSessionTest { return createOptions( enableContentCaptureReceiver, new ContentCaptureOptions.ContentProtectionOptions( enableContentProtectionReceiver, BUFFER_SIZE)); enableContentProtectionReceiver, BUFFER_SIZE, /* requiredGroups= */ Collections.emptyList(), /* optionalGroups= */ Collections.emptyList(), /* optionalGroupsThreshold= */ 0)); } private ContentCaptureManager createManager(ContentCaptureOptions options) { Loading