From 66e09afd5452426a9f032c37b84a46ff60c1a1d7 Mon Sep 17 00:00:00 2001 From: Alexander Dorokhine Date: Tue, 15 Jun 2021 16:43:28 -0700 Subject: [PATCH] Switch to a non-hidden way to compute data path and switch to subdir. We need to store other things in the appsearch data dir other than what Icing stores, such as the storage info cache. Bug: 177685938 Bug: 181787682 Test: Presubmit Change-Id: I903c34a2c891d617217d44f5126d0d31c8c6bf39 --- .../server/appsearch/ImplInstanceManager.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java b/apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java index 289413aebbb51..2181dab90681e 100644 --- a/apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java +++ b/apex/appsearch/service/java/com/android/server/appsearch/ImplInstanceManager.java @@ -24,6 +24,7 @@ import android.content.Context; import android.os.Environment; import android.os.UserHandle; import android.util.ArrayMap; +import android.util.Log; import com.android.internal.annotations.GuardedBy; import com.android.server.appsearch.external.localstorage.AppSearchImpl; @@ -38,9 +39,10 @@ import java.util.Objects; * Manages the lifecycle of instances of {@link AppSearchImpl}. * *

These instances are managed per unique device-user. + * @hide */ public final class ImplInstanceManager { - private static final String APP_SEARCH_DIR = "appSearch"; + private static final String TAG = "AppSearchImplInstanceMa"; private static ImplInstanceManager sImplInstanceManager; @@ -71,8 +73,11 @@ public final class ImplInstanceManager { *

This folder should only be accessed after unlock. */ public static File getAppSearchDir(@NonNull UserHandle userHandle) { - return new File( - Environment.getDataSystemCeDirectory(userHandle.getIdentifier()), APP_SEARCH_DIR); + // Duplicates the implementation of Environment#getDataSystemCeDirectory + // TODO(b/191059409): Unhide Environment#getDataSystemCeDirectory and switch to it. + File systemCeDir = new File(Environment.getDataDirectory(), "system_ce"); + File systemCeUserDir = new File(systemCeDir, String.valueOf(userHandle.getIdentifier())); + return new File(systemCeUserDir, "appSearch"); } /** @@ -154,8 +159,10 @@ public final class ImplInstanceManager { @Nullable AppSearchLogger logger) throws AppSearchException { File appSearchDir = getAppSearchDir(userHandle); + File icingDir = new File(appSearchDir, "icing"); + Log.i(TAG, "Creating new AppSearch instance at: " + icingDir); return AppSearchImpl.create( - appSearchDir, + icingDir, userContext, /*logger=*/ null, new FrameworkOptimizeStrategy());