Loading apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java +11 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,17 @@ public class AppSearchManager { return AppSearchResult.newSuccessfulResult(new SearchResults(searchResultProto)); } /** Deletes all documents owned by the calling app. */ public AppSearchResult<Void> deleteAll() { AndroidFuture<AppSearchResult> future = new AndroidFuture<>(); try { mService.deleteAll(future); } catch (RemoteException e) { future.completeExceptionally(e); } return getFutureOrThrow(future); } private static <T> T getFutureOrThrow(@NonNull AndroidFuture<T> future) { try { return future.get(); Loading apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl +8 −0 Original line number Diff line number Diff line Loading @@ -72,4 +72,12 @@ interface IAppSearchManager { void query( in byte[] searchSpecBytes, in byte[] resultSpecBytes, in byte[] scoringSpecBytes, in AndroidFuture<AppSearchResult> callback); /** * Deletes all documents belonging to the calling app. * * @param callback {@link AndroidFuture}<{@link AppSearchResult}<{@link Void}>>. * Will be completed with the result of the call. */ void deleteAll(in AndroidFuture<AppSearchResult> callback); } apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +17 −0 Original line number Diff line number Diff line Loading @@ -181,6 +181,23 @@ public class AppSearchManagerService extends SystemService { } } @Override public void deleteAll(@NonNull AndroidFuture<AppSearchResult> callback) { Preconditions.checkNotNull(callback); int callingUid = Binder.getCallingUidOrThrow(); int callingUserId = UserHandle.getUserId(callingUid); long callingIdentity = Binder.clearCallingIdentity(); try { AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); impl.deleteAll(callingUid); callback.complete(AppSearchResult.newSuccessfulResult(null)); } catch (Throwable t) { callback.complete(throwableToFailedResult(t)); } finally { Binder.restoreCallingIdentity(callingIdentity); } } private <ValueType> AppSearchResult<ValueType> throwableToFailedResult( @NonNull Throwable t) { if (t instanceof AppSearchException) { Loading apex/appsearch/service/java/com/android/server/appsearch/impl/AppSearchImpl.java +10 −0 Original line number Diff line number Diff line Loading @@ -208,6 +208,16 @@ public final class AppSearchImpl { return searchResultsBuilder.build(); } /** * Deletes all documents owned by the calling app. * * @param callingUid The uid of the app calling AppSearch. */ public void deleteAll(int callingUid) { String namespace = getTypePrefix(callingUid); mFakeIcing.deleteByNamespace(namespace); } /** * Rewrites all types mentioned anywhere in {@code documentBuilder} to prepend or remove * {@code typePrefix}. Loading apex/appsearch/service/java/com/android/server/appsearch/impl/FakeIcing.java +12 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,18 @@ public class FakeIcing { } } /** Deletes all documents belonging to the given namespace. */ public void deleteByNamespace(@NonNull String namespace) { for (int i = 0; i < mDocStore.size(); i++) { DocumentProto document = mDocStore.valueAt(i); if (namespace.equals(document.getNamespace())) { mDocStore.removeAt(i); mUriToDocIdMap.remove(document.getUri()); i--; } } } private void indexDocument(int docId, DocumentProto document) { for (PropertyProto property : document.getPropertiesList()) { for (String stringValue : property.getStringValuesList()) { Loading Loading
apex/appsearch/framework/java/android/app/appsearch/AppSearchManager.java +11 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,17 @@ public class AppSearchManager { return AppSearchResult.newSuccessfulResult(new SearchResults(searchResultProto)); } /** Deletes all documents owned by the calling app. */ public AppSearchResult<Void> deleteAll() { AndroidFuture<AppSearchResult> future = new AndroidFuture<>(); try { mService.deleteAll(future); } catch (RemoteException e) { future.completeExceptionally(e); } return getFutureOrThrow(future); } private static <T> T getFutureOrThrow(@NonNull AndroidFuture<T> future) { try { return future.get(); Loading
apex/appsearch/framework/java/android/app/appsearch/IAppSearchManager.aidl +8 −0 Original line number Diff line number Diff line Loading @@ -72,4 +72,12 @@ interface IAppSearchManager { void query( in byte[] searchSpecBytes, in byte[] resultSpecBytes, in byte[] scoringSpecBytes, in AndroidFuture<AppSearchResult> callback); /** * Deletes all documents belonging to the calling app. * * @param callback {@link AndroidFuture}<{@link AppSearchResult}<{@link Void}>>. * Will be completed with the result of the call. */ void deleteAll(in AndroidFuture<AppSearchResult> callback); }
apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +17 −0 Original line number Diff line number Diff line Loading @@ -181,6 +181,23 @@ public class AppSearchManagerService extends SystemService { } } @Override public void deleteAll(@NonNull AndroidFuture<AppSearchResult> callback) { Preconditions.checkNotNull(callback); int callingUid = Binder.getCallingUidOrThrow(); int callingUserId = UserHandle.getUserId(callingUid); long callingIdentity = Binder.clearCallingIdentity(); try { AppSearchImpl impl = ImplInstanceManager.getInstance(getContext(), callingUserId); impl.deleteAll(callingUid); callback.complete(AppSearchResult.newSuccessfulResult(null)); } catch (Throwable t) { callback.complete(throwableToFailedResult(t)); } finally { Binder.restoreCallingIdentity(callingIdentity); } } private <ValueType> AppSearchResult<ValueType> throwableToFailedResult( @NonNull Throwable t) { if (t instanceof AppSearchException) { Loading
apex/appsearch/service/java/com/android/server/appsearch/impl/AppSearchImpl.java +10 −0 Original line number Diff line number Diff line Loading @@ -208,6 +208,16 @@ public final class AppSearchImpl { return searchResultsBuilder.build(); } /** * Deletes all documents owned by the calling app. * * @param callingUid The uid of the app calling AppSearch. */ public void deleteAll(int callingUid) { String namespace = getTypePrefix(callingUid); mFakeIcing.deleteByNamespace(namespace); } /** * Rewrites all types mentioned anywhere in {@code documentBuilder} to prepend or remove * {@code typePrefix}. Loading
apex/appsearch/service/java/com/android/server/appsearch/impl/FakeIcing.java +12 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,18 @@ public class FakeIcing { } } /** Deletes all documents belonging to the given namespace. */ public void deleteByNamespace(@NonNull String namespace) { for (int i = 0; i < mDocStore.size(); i++) { DocumentProto document = mDocStore.valueAt(i); if (namespace.equals(document.getNamespace())) { mDocStore.removeAt(i); mUriToDocIdMap.remove(document.getUri()); i--; } } } private void indexDocument(int docId, DocumentProto document) { for (PropertyProto property : document.getPropertiesList()) { for (String stringValue : property.getStringValuesList()) { Loading