Loading apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +14 −14 Original line number Diff line number Diff line Loading @@ -119,8 +119,7 @@ public class AppSearchManagerService extends SystemService { } schemasPackageAccessible.put(entry.getKey(), packageIdentifiers); } AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(callingUserId); impl.setSchema( packageName, databaseName, Loading Loading @@ -153,7 +152,7 @@ public class AppSearchManagerService extends SystemService { verifyUserUnlocked(callingUserId); verifyCallingPackage(callingUid, packageName); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); List<AppSearchSchema> schemas = impl.getSchema(packageName, databaseName); List<Bundle> schemaBundles = new ArrayList<>(schemas.size()); for (int i = 0; i < schemas.size(); i++) { Loading Loading @@ -188,7 +187,7 @@ public class AppSearchManagerService extends SystemService { AppSearchBatchResult.Builder<String, Void> resultBuilder = new AppSearchBatchResult.Builder<>(); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); for (int i = 0; i < documentBundles.size(); i++) { GenericDocument document = new GenericDocument(documentBundles.get(i)); try { Loading Loading @@ -231,7 +230,7 @@ public class AppSearchManagerService extends SystemService { AppSearchBatchResult.Builder<String, Bundle> resultBuilder = new AppSearchBatchResult.Builder<>(); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); for (int i = 0; i < uris.size(); i++) { String uri = uris.get(i); try { Loading Loading @@ -276,7 +275,7 @@ public class AppSearchManagerService extends SystemService { verifyUserUnlocked(callingUserId); verifyCallingPackage(callingUid, packageName); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); SearchResultPage searchResultPage = impl.query( packageName, Loading Loading @@ -311,7 +310,7 @@ public class AppSearchManagerService extends SystemService { verifyUserUnlocked(callingUserId); verifyCallingPackage(callingUid, packageName); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); SearchResultPage searchResultPage = impl.globalQuery( queryExpression, Loading Loading @@ -342,7 +341,7 @@ public class AppSearchManagerService extends SystemService { try { verifyUserUnlocked(callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); SearchResultPage searchResultPage = impl.getNextPage(nextPageToken); invokeCallbackOnResult( callback, Loading @@ -362,7 +361,7 @@ public class AppSearchManagerService extends SystemService { try { verifyUserUnlocked(callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); impl.invalidateNextPageToken(nextPageToken); } catch (Throwable t) { Log.e(TAG, "Unable to invalidate the query page token", t); Loading Loading @@ -390,7 +389,7 @@ public class AppSearchManagerService extends SystemService { try { verifyUserUnlocked(callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); impl.reportUsage(packageName, databaseName, namespace, uri, usageTimeMillis); invokeCallbackOnResult( callback, AppSearchResult.newSuccessfulResult(/*result=*/ null)); Loading Loading @@ -422,7 +421,7 @@ public class AppSearchManagerService extends SystemService { AppSearchBatchResult.Builder<String, Void> resultBuilder = new AppSearchBatchResult.Builder<>(); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); for (int i = 0; i < uris.size(); i++) { String uri = uris.get(i); try { Loading Loading @@ -460,7 +459,7 @@ public class AppSearchManagerService extends SystemService { verifyUserUnlocked(callingUserId); verifyCallingPackage(callingUid, packageName); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); impl.removeByQuery( packageName, databaseName, Loading @@ -482,7 +481,7 @@ public class AppSearchManagerService extends SystemService { try { verifyUserUnlocked(callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); impl.persistToDisk(); } catch (Throwable t) { Log.e(TAG, "Unable to persist the data to disk", t); Loading @@ -499,7 +498,7 @@ public class AppSearchManagerService extends SystemService { final long callingIdentity = Binder.clearCallingIdentity(); try { verifyUserUnlocked(callingUserId); mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getOrCreateAppSearchImpl(getContext(), callingUserId); invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null)); } catch (Throwable t) { invokeCallbackOnError(callback, t); Loading Loading @@ -571,6 +570,7 @@ public class AppSearchManagerService extends SystemService { private void invokeCallbackOnError( IAppSearchBatchResultCallback callback, Throwable throwable) { try { //TODO(b/175067650) verify ParcelableException could propagate throwable correctly. callback.onSystemError(new ParcelableException(throwable)); } catch (RemoteException e) { Log.e(TAG, "Unable to send error to the callback", e); Loading apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java +29 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ public final class ImplInstanceManager { } /** * Gets an instance of AppSearchImpl for the given user. * Gets an instance of AppSearchImpl for the given user, or creates one if none exists. * * <p>If no AppSearchImpl instance exists for the unlocked user, Icing will be initialized and * one will be created. Loading @@ -84,7 +84,7 @@ public final class ImplInstanceManager { * @return An initialized {@link AppSearchImpl} for this user */ @NonNull public AppSearchImpl getAppSearchImpl( public AppSearchImpl getOrCreateAppSearchImpl( @NonNull Context context, @UserIdInt int userId) throws AppSearchException { synchronized (mInstancesLocked) { AppSearchImpl instance = mInstancesLocked.get(userId); Loading @@ -96,6 +96,32 @@ public final class ImplInstanceManager { } } /** * Gets an instance of AppSearchImpl for the given user. * * <p>This method should only be called by an initialized SearchSession, which has been already * created the AppSearchImpl instance for the given user. * * @param userId The multi-user userId of the device user calling AppSearch * @return An initialized {@link AppSearchImpl} for this user * @throws IllegalStateException if {@link AppSearchImpl} haven't created for the given user. */ @NonNull public AppSearchImpl getAppSearchImpl(@UserIdInt int userId) { synchronized (mInstancesLocked) { AppSearchImpl instance = mInstancesLocked.get(userId); if (instance == null) { // Impossible scenario, user cannot call an uninitialized SearchSession, // getInstance should always find the instance for the given user and never try to // create an instance for this user again. throw new IllegalStateException( "AppSearchImpl has never been created for this user: " + userId); } return instance; } } private AppSearchImpl createImpl(@NonNull Context context, @UserIdInt int userId) throws AppSearchException { File appSearchDir = getAppSearchDir(context, userId); Loading @@ -104,6 +130,7 @@ public final class ImplInstanceManager { private static File getAppSearchDir(@NonNull Context context, @UserIdInt int userId) { // See com.android.internal.app.ChooserActivity::getPinnedSharedPrefs //TODO(b/177685938):Switch from getDataUserCePackageDirectory to getDataSystemCeDirectory File userCeDir = Environment.getDataUserCePackageDirectory( StorageManager.UUID_PRIVATE_INTERNAL, userId, context.getPackageName()); Loading apex/appsearch/testing/Android.bp +4 −1 Original line number Diff line number Diff line Loading @@ -30,5 +30,8 @@ java_library { "guava", "truth-prebuilt", ], visibility: ["//cts/tests/appsearch"], visibility: [ "//cts/tests/appsearch", "//vendor:__subpackages__", ], } Loading
apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +14 −14 Original line number Diff line number Diff line Loading @@ -119,8 +119,7 @@ public class AppSearchManagerService extends SystemService { } schemasPackageAccessible.put(entry.getKey(), packageIdentifiers); } AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(callingUserId); impl.setSchema( packageName, databaseName, Loading Loading @@ -153,7 +152,7 @@ public class AppSearchManagerService extends SystemService { verifyUserUnlocked(callingUserId); verifyCallingPackage(callingUid, packageName); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); List<AppSearchSchema> schemas = impl.getSchema(packageName, databaseName); List<Bundle> schemaBundles = new ArrayList<>(schemas.size()); for (int i = 0; i < schemas.size(); i++) { Loading Loading @@ -188,7 +187,7 @@ public class AppSearchManagerService extends SystemService { AppSearchBatchResult.Builder<String, Void> resultBuilder = new AppSearchBatchResult.Builder<>(); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); for (int i = 0; i < documentBundles.size(); i++) { GenericDocument document = new GenericDocument(documentBundles.get(i)); try { Loading Loading @@ -231,7 +230,7 @@ public class AppSearchManagerService extends SystemService { AppSearchBatchResult.Builder<String, Bundle> resultBuilder = new AppSearchBatchResult.Builder<>(); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); for (int i = 0; i < uris.size(); i++) { String uri = uris.get(i); try { Loading Loading @@ -276,7 +275,7 @@ public class AppSearchManagerService extends SystemService { verifyUserUnlocked(callingUserId); verifyCallingPackage(callingUid, packageName); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); SearchResultPage searchResultPage = impl.query( packageName, Loading Loading @@ -311,7 +310,7 @@ public class AppSearchManagerService extends SystemService { verifyUserUnlocked(callingUserId); verifyCallingPackage(callingUid, packageName); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); SearchResultPage searchResultPage = impl.globalQuery( queryExpression, Loading Loading @@ -342,7 +341,7 @@ public class AppSearchManagerService extends SystemService { try { verifyUserUnlocked(callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); SearchResultPage searchResultPage = impl.getNextPage(nextPageToken); invokeCallbackOnResult( callback, Loading @@ -362,7 +361,7 @@ public class AppSearchManagerService extends SystemService { try { verifyUserUnlocked(callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); impl.invalidateNextPageToken(nextPageToken); } catch (Throwable t) { Log.e(TAG, "Unable to invalidate the query page token", t); Loading Loading @@ -390,7 +389,7 @@ public class AppSearchManagerService extends SystemService { try { verifyUserUnlocked(callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); impl.reportUsage(packageName, databaseName, namespace, uri, usageTimeMillis); invokeCallbackOnResult( callback, AppSearchResult.newSuccessfulResult(/*result=*/ null)); Loading Loading @@ -422,7 +421,7 @@ public class AppSearchManagerService extends SystemService { AppSearchBatchResult.Builder<String, Void> resultBuilder = new AppSearchBatchResult.Builder<>(); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); for (int i = 0; i < uris.size(); i++) { String uri = uris.get(i); try { Loading Loading @@ -460,7 +459,7 @@ public class AppSearchManagerService extends SystemService { verifyUserUnlocked(callingUserId); verifyCallingPackage(callingUid, packageName); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); impl.removeByQuery( packageName, databaseName, Loading @@ -482,7 +481,7 @@ public class AppSearchManagerService extends SystemService { try { verifyUserUnlocked(callingUserId); AppSearchImpl impl = mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getAppSearchImpl(callingUserId); impl.persistToDisk(); } catch (Throwable t) { Log.e(TAG, "Unable to persist the data to disk", t); Loading @@ -499,7 +498,7 @@ public class AppSearchManagerService extends SystemService { final long callingIdentity = Binder.clearCallingIdentity(); try { verifyUserUnlocked(callingUserId); mImplInstanceManager.getAppSearchImpl(getContext(), callingUserId); mImplInstanceManager.getOrCreateAppSearchImpl(getContext(), callingUserId); invokeCallbackOnResult(callback, AppSearchResult.newSuccessfulResult(null)); } catch (Throwable t) { invokeCallbackOnError(callback, t); Loading Loading @@ -571,6 +570,7 @@ public class AppSearchManagerService extends SystemService { private void invokeCallbackOnError( IAppSearchBatchResultCallback callback, Throwable throwable) { try { //TODO(b/175067650) verify ParcelableException could propagate throwable correctly. callback.onSystemError(new ParcelableException(throwable)); } catch (RemoteException e) { Log.e(TAG, "Unable to send error to the callback", e); Loading
apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java +29 −2 Original line number Diff line number Diff line Loading @@ -74,7 +74,7 @@ public final class ImplInstanceManager { } /** * Gets an instance of AppSearchImpl for the given user. * Gets an instance of AppSearchImpl for the given user, or creates one if none exists. * * <p>If no AppSearchImpl instance exists for the unlocked user, Icing will be initialized and * one will be created. Loading @@ -84,7 +84,7 @@ public final class ImplInstanceManager { * @return An initialized {@link AppSearchImpl} for this user */ @NonNull public AppSearchImpl getAppSearchImpl( public AppSearchImpl getOrCreateAppSearchImpl( @NonNull Context context, @UserIdInt int userId) throws AppSearchException { synchronized (mInstancesLocked) { AppSearchImpl instance = mInstancesLocked.get(userId); Loading @@ -96,6 +96,32 @@ public final class ImplInstanceManager { } } /** * Gets an instance of AppSearchImpl for the given user. * * <p>This method should only be called by an initialized SearchSession, which has been already * created the AppSearchImpl instance for the given user. * * @param userId The multi-user userId of the device user calling AppSearch * @return An initialized {@link AppSearchImpl} for this user * @throws IllegalStateException if {@link AppSearchImpl} haven't created for the given user. */ @NonNull public AppSearchImpl getAppSearchImpl(@UserIdInt int userId) { synchronized (mInstancesLocked) { AppSearchImpl instance = mInstancesLocked.get(userId); if (instance == null) { // Impossible scenario, user cannot call an uninitialized SearchSession, // getInstance should always find the instance for the given user and never try to // create an instance for this user again. throw new IllegalStateException( "AppSearchImpl has never been created for this user: " + userId); } return instance; } } private AppSearchImpl createImpl(@NonNull Context context, @UserIdInt int userId) throws AppSearchException { File appSearchDir = getAppSearchDir(context, userId); Loading @@ -104,6 +130,7 @@ public final class ImplInstanceManager { private static File getAppSearchDir(@NonNull Context context, @UserIdInt int userId) { // See com.android.internal.app.ChooserActivity::getPinnedSharedPrefs //TODO(b/177685938):Switch from getDataUserCePackageDirectory to getDataSystemCeDirectory File userCeDir = Environment.getDataUserCePackageDirectory( StorageManager.UUID_PRIVATE_INTERNAL, userId, context.getPackageName()); Loading
apex/appsearch/testing/Android.bp +4 −1 Original line number Diff line number Diff line Loading @@ -30,5 +30,8 @@ java_library { "guava", "truth-prebuilt", ], visibility: ["//cts/tests/appsearch"], visibility: [ "//cts/tests/appsearch", "//vendor:__subpackages__", ], }