Implement AppSearch.deleteByTypes()

Bug: 147636343
Test: atest CtsAppSearchTestCases FrameworksCoreTests:android.app.appsearch FrameworksServicesTests:com.android.server.appsearch.impl
Change-Id: I053b33744c1cec8f307ca975314c3b9415d48b68
diff --git a/service/java/com/android/server/appsearch/AppSearchManagerService.java b/service/java/com/android/server/appsearch/AppSearchManagerService.java
index 27c1419..16948b2 100644
--- a/service/java/com/android/server/appsearch/AppSearchManagerService.java
+++ b/service/java/com/android/server/appsearch/AppSearchManagerService.java
@@ -214,6 +214,41 @@
         }
 
         @Override
+        public void deleteByTypes(
+                List<String> schemaTypes, AndroidFuture<AppSearchBatchResult> callback) {
+            Preconditions.checkNotNull(schemaTypes);
+            Preconditions.checkNotNull(callback);
+            int callingUid = Binder.getCallingUidOrThrow();
+            int callingUserId = UserHandle.getUserId(callingUid);
+            long callingIdentity = Binder.clearCallingIdentity();
+            try {
+                AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId);
+                AppSearchBatchResult.Builder<String, Void> resultBuilder =
+                        new AppSearchBatchResult.Builder<>();
+                for (int i = 0; i < schemaTypes.size(); i++) {
+                    String schemaType = schemaTypes.get(i);
+                    try {
+                        if (!impl.deleteByType(callingUid, schemaType)) {
+                            resultBuilder.setFailure(
+                                    schemaType,
+                                    AppSearchResult.RESULT_NOT_FOUND,
+                                    /*errorMessage=*/ null);
+                        } else {
+                            resultBuilder.setSuccess(schemaType, /*value=*/ null);
+                        }
+                    } catch (Throwable t) {
+                        resultBuilder.setResult(schemaType, throwableToFailedResult(t));
+                    }
+                }
+                callback.complete(resultBuilder.build());
+            } catch (Throwable t) {
+                callback.completeExceptionally(t);
+            } finally {
+                Binder.restoreCallingIdentity(callingIdentity);
+            }
+        }
+
+        @Override
         public void deleteAll(@NonNull AndroidFuture<AppSearchResult> callback) {
             Preconditions.checkNotNull(callback);
             int callingUid = Binder.getCallingUidOrThrow();