/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.content; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.annotation.TestApi; import android.app.ActivityThread; import android.os.Parcel; import android.os.Parcelable; import android.util.ArraySet; import android.util.Log; import android.view.contentcapture.ContentCaptureManager; 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. * *
This object is created by the Content Capture System Service and passed back to the app when
* the application is created.
*
* @hide
*/
@TestApi
public final class ContentCaptureOptions implements Parcelable {
private static final String TAG = ContentCaptureOptions.class.getSimpleName();
/**
* Logging level for {@code logcat} statements.
*/
public final int loggingLevel;
/**
* Maximum number of events that are buffered before sent to the app.
*/
public final int maxBufferSize;
/**
* Frequency the buffer is flushed if idle.
*/
public final int idleFlushingFrequencyMs;
/**
* Frequency the buffer is flushed if last event is a text change.
*/
public final int textChangeFlushingFrequencyMs;
/**
* Size of events that are logging on {@code dump}.
*/
public final int logHistorySize;
/**
* Disable flush when receiving a VIEW_TREE_APPEARING event.
* @hide
*/
public final boolean disableFlushForViewTreeAppearing;
/**
* Is the content capture receiver enabled.
*
* @hide
*/
public final boolean enableReceiver;
/**
* Options for the content protection flow.
*
* @hide
*/
@NonNull public final ContentProtectionOptions contentProtectionOptions;
/**
* List of activities explicitly allowlisted for content capture (or {@code null} if allowlisted
* for all acitivites in the package).
*/
@Nullable
@SuppressLint("NullableCollection")
public final ArraySet Does not implement {@code Parcelable} since it is an inner class without a matching AIDL.
*
* @hide
*/
public static class ContentProtectionOptions {
/**
* Is the content protection receiver enabled.
*
* @hide
*/
public final boolean enableReceiver;
/**
* Size of the in-memory ring buffer for the content protection flow.
*
* @hide
*/
public final int bufferSize;
/**
* The list of required groups of strings to match.
*
* @hide
*/
@NonNull public final List> requiredGroups;
/**
* The list of optional groups of strings to match.
*
* @hide
*/
@NonNull public final List
> 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
> requiredGroups,
@NonNull List
> optionalGroups,
int optionalGroupsThreshold) {
this.enableReceiver = enableReceiver;
this.bufferSize = bufferSize;
this.requiredGroups = requiredGroups;
this.optionalGroups = optionalGroups;
this.optionalGroupsThreshold = optionalGroupsThreshold;
}
@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder("ContentProtectionOptions [");
stringBuilder
.append("enableReceiver=")
.append(enableReceiver)
.append(", bufferSize=")
.append(bufferSize)
.append(", requiredGroupsSize=")
.append(requiredGroups.size())
.append(", optionalGroupsSize=")
.append(optionalGroups.size())
.append(", optionalGroupsThreshold=")
.append(optionalGroupsThreshold);
return stringBuilder.append(']').toString();
}
private void dumpShort(@NonNull PrintWriter pw) {
pw.print("enableReceiver=");
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(@NonNull Parcel parcel) {
parcel.writeBoolean(enableReceiver);
parcel.writeInt(bufferSize);
writeGroupsToParcel(requiredGroups, parcel);
writeGroupsToParcel(optionalGroups, parcel);
parcel.writeInt(optionalGroupsThreshold);
}
@NonNull
private static ContentProtectionOptions createFromParcel(@NonNull Parcel parcel) {
boolean enableReceiver = parcel.readBoolean();
int bufferSize = parcel.readInt();
List
> requiredGroups = createGroupsFromParcel(parcel);
List
> optionalGroups = createGroupsFromParcel(parcel);
int optionalGroupsThreshold = parcel.readInt();
return new ContentProtectionOptions(
enableReceiver,
bufferSize,
requiredGroups,
optionalGroups,
optionalGroupsThreshold);
}
private static void writeGroupsToParcel(
@NonNull List
> groups, @NonNull Parcel parcel) {
parcel.writeInt(groups.size());
groups.forEach(parcel::writeStringList);
}
@NonNull
private static List
> createGroupsFromParcel(@NonNull Parcel parcel) {
int size = parcel.readInt();
return IntStream.range(0, size)
.mapToObj(i -> new ArrayList