Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0731f571 authored by Alexander Dorokhine's avatar Alexander Dorokhine Committed by Terry Wang
Browse files

Add AppSearch.java, containing the Document class, base Builder, and Email.

Document is the basic entity to be indexed and queried in AppSearch.
AppSearch.java contains all AppSearch Document types and their Builders.
They are grouped here to avoid potential collisions with other
generically-named classes like Email and Contact).

Bug: 143789408
Test: atest FrameworksCoreTests:android.app.appsearch
Change-Id: I7bb607ad4114451a3db11b9ade9c197da1e6556a
parent 9ebb72c7
Loading
Loading
Loading
Loading
+762 −0

File added.

Preview size limit exceeded, changes collapsed.

+32 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package android.app.appsearch;
import android.annotation.CallbackExecutor;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.SystemService;
import android.annotation.SystemService;
import android.app.appsearch.AppSearch.Document;
import android.content.Context;
import android.content.Context;
import android.os.RemoteException;
import android.os.RemoteException;


@@ -25,6 +26,7 @@ import com.android.internal.infra.AndroidFuture;


import com.google.android.icing.proto.SchemaProto;
import com.google.android.icing.proto.SchemaProto;


import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Consumer;


@@ -95,4 +97,34 @@ public class AppSearchManager {
        }
        }
        future.whenCompleteAsync((noop, err) -> callback.accept(err), executor);
        future.whenCompleteAsync((noop, err) -> callback.accept(err), executor);
    }
    }

    /**
     * Index {@link Document} to AppSearch
     *
     * <p>You should not call this method directly; instead, use the {@code AppSearch#put()} API
     * provided by JetPack.
     *
     * <p>The schema should be set via {@link #setSchema} method.
     *
     * @param documents {@link Document Documents} that need to be indexed.
     * @param executor Executor on which to invoke the callback.
     * @param callback Callback to receive errors resulting from setting the schema. If the
     *                 operation succeeds, the callback will be invoked with {@code null}.
     */
    public void put(@NonNull List<Document> documents,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull Consumer<? super Throwable> callback) {
        AndroidFuture<Void> future = new AndroidFuture<>();
        for (Document document : documents) {
            // TODO(b/146386470) batching Document protos
            try {
                mService.put(document.getProto().toByteArray(), future);
            } catch (RemoteException e) {
                future.completeExceptionally(e);
                break;
            }
        }
        // TODO(b/147614371) Fix error report for multiple documents.
        future.whenCompleteAsync((noop, err) -> callback.accept(err), executor);
    }
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -28,4 +28,5 @@ interface IAppSearchManager {
     *     if setSchema fails.
     *     if setSchema fails.
     */
     */
    void setSchema(in byte[] schemaProto, in AndroidFuture callback);
    void setSchema(in byte[] schemaProto, in AndroidFuture callback);
    void put(in byte[] documentBytes, in AndroidFuture callback);
}
}
+10 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,16 @@ public class AppSearchManagerService extends SystemService {
            try {
            try {
                SchemaProto schema = SchemaProto.parseFrom(schemaBytes);
                SchemaProto schema = SchemaProto.parseFrom(schemaBytes);
                throw new UnsupportedOperationException("setSchema not yet implemented: " + schema);
                throw new UnsupportedOperationException("setSchema not yet implemented: " + schema);

            } catch (Throwable t) {
                callback.completeExceptionally(t);
            }
        }

        @Override
        public void put(byte[] documentBytes, AndroidFuture callback) {
            try {
                throw new UnsupportedOperationException("Put document not yet implemented");
            } catch (Throwable t) {
            } catch (Throwable t) {
                callback.completeExceptionally(t);
                callback.completeExceptionally(t);
            }
            }
+8 −0
Original line number Original line Diff line number Diff line
@@ -10,6 +10,14 @@
          "include-filter": "com.android.server.appsearch"
          "include-filter": "com.android.server.appsearch"
        }
        }
      ]
      ]
    },
    {
      "name": "FrameworksCoreTests",
      "options": [
        {
           "include-filter": "android.app.appsearch"
        }
      ]
    }
    }
  ]
  ]
}
}
Loading