Loading core/java/android/app/appfunctions/AppFunctionStaticMetadataHelper.java +2 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,8 @@ public class AppFunctionStaticMetadataHelper { public static final String STATIC_PROPERTY_ENABLED_BY_DEFAULT = "enabledByDefault"; public static final String APP_FUNCTION_STATIC_NAMESPACE = "app_functions"; public static final String PROPERTY_FUNCTION_ID = "functionId"; public static final String PROPERTY_PACKAGE_NAME = "packageName"; // These are constants that has to be kept the same with {@code // com.android.server.appsearch.appsindexer.appsearchtypes.AppSearchHelper}. Loading services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java +36 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.appfunctions; import android.annotation.NonNull; import android.annotation.WorkerThread; import android.app.appsearch.PropertyPath; import android.app.appsearch.SearchResult; import android.app.appsearch.SearchSpec; import android.util.ArrayMap; Loading Loading @@ -110,26 +111,29 @@ public class MetadataSyncAdapter { } /** * This method returns a map of package names to a set of function ids. * This method returns a map of package names to a set of function ids from the AppFunction * metadata. * * @param queryExpression The query expression to use when searching for AppFunction metadata. * @param metadataSearchSpec The search spec to use when searching for AppFunction metadata. * @return A map of package names to a set of function ids. * @throws ExecutionException If the future search results fail to execute. * @throws InterruptedException If the future search results are interrupted. * @param schemaType The name space of the AppFunction metadata. * @return A map of package names to a set of function ids from the AppFunction metadata. */ @NonNull @VisibleForTesting @WorkerThread ArrayMap<String, ArraySet<String>> getPackageToFunctionIdMap( @NonNull String queryExpression, @NonNull SearchSpec metadataSearchSpec, @NonNull String schemaType, @NonNull String propertyFunctionId, @NonNull String propertyPackageName) throws ExecutionException, InterruptedException { ArrayMap<String, ArraySet<String>> packageToFunctionIds = new ArrayMap<>(); FutureSearchResults futureSearchResults = mFutureAppSearchSession.search(queryExpression, metadataSearchSpec).get(); mFutureAppSearchSession .search( "", buildMetadataSearchSpec( schemaType, propertyFunctionId, propertyPackageName)) .get(); List<SearchResult> searchResultsList = futureSearchResults.getNextPage().get(); // TODO(b/357551503): This could be expensive if we have more functions while (!searchResultsList.isEmpty()) { Loading @@ -146,4 +150,27 @@ public class MetadataSyncAdapter { } return packageToFunctionIds; } /** * This method returns a {@link SearchSpec} for searching the AppFunction metadata. * * @param schemaType The schema type of the AppFunction metadata. * @param propertyFunctionId The property name of the function id in the AppFunction metadata. * @param propertyPackageName The property name of the package name in the AppFunction metadata. * @return A {@link SearchSpec} for searching the AppFunction metadata. */ @NonNull private static SearchSpec buildMetadataSearchSpec( @NonNull String schemaType, @NonNull String propertyFunctionId, @NonNull String propertyPackageName) { return new SearchSpec.Builder() .addFilterSchemas(schemaType) .addProjectionPaths( schemaType, List.of( new PropertyPath(propertyFunctionId), new PropertyPath(propertyPackageName))) .build(); } } services/tests/appfunctions/src/com/android/server/appfunctions/MetadataSyncAdapterTest.kt +6 −28 Original line number Diff line number Diff line Loading @@ -16,12 +16,9 @@ package com.android.server.appfunctions import android.app.appfunctions.AppFunctionRuntimeMetadata import android.app.appfunctions.AppFunctionRuntimeMetadata.PROPERTY_FUNCTION_ID import android.app.appfunctions.AppFunctionRuntimeMetadata.PROPERTY_PACKAGE_NAME import android.app.appsearch.AppSearchManager import android.app.appsearch.AppSearchManager.SearchContext import android.app.appsearch.PutDocumentsRequest import android.app.appsearch.SearchSpec import android.app.appsearch.SetSchemaRequest import android.util.ArrayMap import android.util.ArraySet Loading Loading @@ -76,20 +73,11 @@ class MetadataSyncAdapterTest { testExecutor, FutureAppSearchSession(appSearchManager, testExecutor, searchContext), ) val searchSpec: SearchSpec = SearchSpec.Builder() .addFilterSchemas( AppFunctionRuntimeMetadata.RUNTIME_SCHEMA_TYPE, AppFunctionRuntimeMetadata.createAppFunctionRuntimeSchema(TEST_TARGET_PKG_NAME) .schemaType, ) .build() val packageToFunctionIdMap = metadataSyncAdapter.getPackageToFunctionIdMap( "", searchSpec, PROPERTY_FUNCTION_ID, PROPERTY_PACKAGE_NAME, AppFunctionRuntimeMetadata.RUNTIME_SCHEMA_TYPE, AppFunctionRuntimeMetadata.PROPERTY_FUNCTION_ID, AppFunctionRuntimeMetadata.PROPERTY_PACKAGE_NAME, ) assertThat(packageToFunctionIdMap).isNotNull() Loading Loading @@ -135,21 +123,11 @@ class MetadataSyncAdapterTest { testExecutor, FutureAppSearchSession(appSearchManager, testExecutor, searchContext), ) val searchSpec: SearchSpec = SearchSpec.Builder() .setResultCountPerPage(1) .addFilterSchemas( AppFunctionRuntimeMetadata.RUNTIME_SCHEMA_TYPE, AppFunctionRuntimeMetadata.createAppFunctionRuntimeSchema(TEST_TARGET_PKG_NAME) .schemaType, ) .build() val packageToFunctionIdMap = metadataSyncAdapter.getPackageToFunctionIdMap( "", searchSpec, PROPERTY_FUNCTION_ID, PROPERTY_PACKAGE_NAME, AppFunctionRuntimeMetadata.RUNTIME_SCHEMA_TYPE, AppFunctionRuntimeMetadata.PROPERTY_FUNCTION_ID, AppFunctionRuntimeMetadata.PROPERTY_PACKAGE_NAME, ) assertThat(packageToFunctionIdMap).isNotNull() Loading Loading
core/java/android/app/appfunctions/AppFunctionStaticMetadataHelper.java +2 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,8 @@ public class AppFunctionStaticMetadataHelper { public static final String STATIC_PROPERTY_ENABLED_BY_DEFAULT = "enabledByDefault"; public static final String APP_FUNCTION_STATIC_NAMESPACE = "app_functions"; public static final String PROPERTY_FUNCTION_ID = "functionId"; public static final String PROPERTY_PACKAGE_NAME = "packageName"; // These are constants that has to be kept the same with {@code // com.android.server.appsearch.appsindexer.appsearchtypes.AppSearchHelper}. Loading
services/appfunctions/java/com/android/server/appfunctions/MetadataSyncAdapter.java +36 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.appfunctions; import android.annotation.NonNull; import android.annotation.WorkerThread; import android.app.appsearch.PropertyPath; import android.app.appsearch.SearchResult; import android.app.appsearch.SearchSpec; import android.util.ArrayMap; Loading Loading @@ -110,26 +111,29 @@ public class MetadataSyncAdapter { } /** * This method returns a map of package names to a set of function ids. * This method returns a map of package names to a set of function ids from the AppFunction * metadata. * * @param queryExpression The query expression to use when searching for AppFunction metadata. * @param metadataSearchSpec The search spec to use when searching for AppFunction metadata. * @return A map of package names to a set of function ids. * @throws ExecutionException If the future search results fail to execute. * @throws InterruptedException If the future search results are interrupted. * @param schemaType The name space of the AppFunction metadata. * @return A map of package names to a set of function ids from the AppFunction metadata. */ @NonNull @VisibleForTesting @WorkerThread ArrayMap<String, ArraySet<String>> getPackageToFunctionIdMap( @NonNull String queryExpression, @NonNull SearchSpec metadataSearchSpec, @NonNull String schemaType, @NonNull String propertyFunctionId, @NonNull String propertyPackageName) throws ExecutionException, InterruptedException { ArrayMap<String, ArraySet<String>> packageToFunctionIds = new ArrayMap<>(); FutureSearchResults futureSearchResults = mFutureAppSearchSession.search(queryExpression, metadataSearchSpec).get(); mFutureAppSearchSession .search( "", buildMetadataSearchSpec( schemaType, propertyFunctionId, propertyPackageName)) .get(); List<SearchResult> searchResultsList = futureSearchResults.getNextPage().get(); // TODO(b/357551503): This could be expensive if we have more functions while (!searchResultsList.isEmpty()) { Loading @@ -146,4 +150,27 @@ public class MetadataSyncAdapter { } return packageToFunctionIds; } /** * This method returns a {@link SearchSpec} for searching the AppFunction metadata. * * @param schemaType The schema type of the AppFunction metadata. * @param propertyFunctionId The property name of the function id in the AppFunction metadata. * @param propertyPackageName The property name of the package name in the AppFunction metadata. * @return A {@link SearchSpec} for searching the AppFunction metadata. */ @NonNull private static SearchSpec buildMetadataSearchSpec( @NonNull String schemaType, @NonNull String propertyFunctionId, @NonNull String propertyPackageName) { return new SearchSpec.Builder() .addFilterSchemas(schemaType) .addProjectionPaths( schemaType, List.of( new PropertyPath(propertyFunctionId), new PropertyPath(propertyPackageName))) .build(); } }
services/tests/appfunctions/src/com/android/server/appfunctions/MetadataSyncAdapterTest.kt +6 −28 Original line number Diff line number Diff line Loading @@ -16,12 +16,9 @@ package com.android.server.appfunctions import android.app.appfunctions.AppFunctionRuntimeMetadata import android.app.appfunctions.AppFunctionRuntimeMetadata.PROPERTY_FUNCTION_ID import android.app.appfunctions.AppFunctionRuntimeMetadata.PROPERTY_PACKAGE_NAME import android.app.appsearch.AppSearchManager import android.app.appsearch.AppSearchManager.SearchContext import android.app.appsearch.PutDocumentsRequest import android.app.appsearch.SearchSpec import android.app.appsearch.SetSchemaRequest import android.util.ArrayMap import android.util.ArraySet Loading Loading @@ -76,20 +73,11 @@ class MetadataSyncAdapterTest { testExecutor, FutureAppSearchSession(appSearchManager, testExecutor, searchContext), ) val searchSpec: SearchSpec = SearchSpec.Builder() .addFilterSchemas( AppFunctionRuntimeMetadata.RUNTIME_SCHEMA_TYPE, AppFunctionRuntimeMetadata.createAppFunctionRuntimeSchema(TEST_TARGET_PKG_NAME) .schemaType, ) .build() val packageToFunctionIdMap = metadataSyncAdapter.getPackageToFunctionIdMap( "", searchSpec, PROPERTY_FUNCTION_ID, PROPERTY_PACKAGE_NAME, AppFunctionRuntimeMetadata.RUNTIME_SCHEMA_TYPE, AppFunctionRuntimeMetadata.PROPERTY_FUNCTION_ID, AppFunctionRuntimeMetadata.PROPERTY_PACKAGE_NAME, ) assertThat(packageToFunctionIdMap).isNotNull() Loading Loading @@ -135,21 +123,11 @@ class MetadataSyncAdapterTest { testExecutor, FutureAppSearchSession(appSearchManager, testExecutor, searchContext), ) val searchSpec: SearchSpec = SearchSpec.Builder() .setResultCountPerPage(1) .addFilterSchemas( AppFunctionRuntimeMetadata.RUNTIME_SCHEMA_TYPE, AppFunctionRuntimeMetadata.createAppFunctionRuntimeSchema(TEST_TARGET_PKG_NAME) .schemaType, ) .build() val packageToFunctionIdMap = metadataSyncAdapter.getPackageToFunctionIdMap( "", searchSpec, PROPERTY_FUNCTION_ID, PROPERTY_PACKAGE_NAME, AppFunctionRuntimeMetadata.RUNTIME_SCHEMA_TYPE, AppFunctionRuntimeMetadata.PROPERTY_FUNCTION_ID, AppFunctionRuntimeMetadata.PROPERTY_PACKAGE_NAME, ) assertThat(packageToFunctionIdMap).isNotNull() Loading