Initial implementation of ContentCaptureService.setContentCaptureWhitelist()
For now it only whitelists packages, not activities.
Test: atest CtsContentCaptureServiceTestCases
Bug: 122595322
Change-Id: I5beb9b027eb704510e68f3af15e84e14bda07eb2
diff --git a/core/java/android/service/contentcapture/ContentCaptureService.java b/core/java/android/service/contentcapture/ContentCaptureService.java
index ae70775..b60fbc5 100644
--- a/core/java/android/service/contentcapture/ContentCaptureService.java
+++ b/core/java/android/service/contentcapture/ContentCaptureService.java
@@ -34,6 +34,7 @@
import android.os.RemoteException;
import android.service.autofill.AutofillService;
import android.util.ArrayMap;
+import android.util.ArraySet;
import android.util.Log;
import android.util.Slog;
import android.view.contentcapture.ContentCaptureContext;
@@ -171,16 +172,11 @@
@Deprecated
public final void setContentCaptureWhitelist(@Nullable List<String> packages,
@Nullable List<ComponentName> activities) {
- final IContentCaptureServiceCallback callback = mCallback;
- if (callback == null) {
- Log.w(TAG, "setContentCaptureWhitelist(): no server callback");
- return;
- }
- try {
- callback.setContentCaptureWhitelist(packages, activities);
- } catch (RemoteException e) {
- e.rethrowFromSystemServer();
- }
+ setContentCaptureWhitelist(toSet(packages), toSet(activities));
+ }
+
+ private <T> ArraySet<T> toSet(@Nullable List<T> set) {
+ return set == null ? null : new ArraySet<T>(set);
}
/**
@@ -197,7 +193,17 @@
*/
public final void setContentCaptureWhitelist(@Nullable Set<String> packages,
@Nullable Set<ComponentName> activities) {
- setContentCaptureWhitelist(toList(packages), toList(activities));
+ final IContentCaptureServiceCallback callback = mCallback;
+ if (callback == null) {
+ Log.w(TAG, "setContentCaptureWhitelist(): no server callback");
+ return;
+ }
+
+ try {
+ callback.setContentCaptureWhitelist(toList(packages), toList(activities));
+ } catch (RemoteException e) {
+ e.rethrowFromSystemServer();
+ }
}
private <T> ArrayList<T> toList(@Nullable Set<T> set) {