Omit file existence check on notifyDexContainersLoaded. This is due to sepolicy restrictions on some platforms. Bug: 401662336 Bug: 391895923 Test: atest ArtServiceTests Test: app-debug.apk in b/391895923#comment3 Flag: EXEMPT bugfix (cherry picked from commit d62d66437f3b322f202c314672fbaf810fde7142) (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:9b3a1588981ca33693081a507744819871e5ca7f) Merged-In: Ib6d878a678ddafd02fb48d92ddfbabdfd6f4f14e Change-Id: Ib6d878a678ddafd02fb48d92ddfbabdfd6f4f14e
diff --git a/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java b/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java index 3d621bf..f79c1db 100644 --- a/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java +++ b/libartservice/service/java/com/android/server/art/DexUseManagerLocal.java
@@ -61,7 +61,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; -import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; @@ -493,23 +492,6 @@ @NonNull String loadingPackageName, boolean isolatedProcess, @NonNull String classLoaderContext, @NonNull String abiName, long lastUsedAtMs) { DexLoader loader = DexLoader.create(loadingPackageName, isolatedProcess); - // This is to avoid a loading package from using up the SecondaryDexUse entries for another - // package (up to the MAX_SECONDARY_DEX_FILES_PER_OWNER limit). - // Note that we are using system_server's permission to check the existence. This is fine - // with the assumption that the file must be world readable to be used by other apps. - // We could use artd's permission to check the existence, and then there wouldn't be any - // permission issue, but that requires bringing up the artd service, which may be too - // expensive. - // TODO(jiakaiz): Check if the assumption is true. - // This doesn't apply to secondary dex files that aren't used by other apps, but we - // don't care about the loading package messing up its own SecondaryDexUse - // entries. - // Also note that the check doesn't follow symlinks because GMSCore creates symlinks to - // its secondary dex files, while system_server doesn't have the permission to follow them. - if (isLoaderOtherApp(loader, owningPackageName) && !mInjector.pathExists(dexPath)) { - Log.w(TAG, "Not recording non-existent secondary dex file '" + dexPath + "'"); - return; - } synchronized (mLock) { PackageDexUse packageDexUse = mDexUse.mPackageDexUseByOwningPackageName.computeIfAbsent( owningPackageName, k -> new PackageDexUse()); @@ -1177,10 +1159,6 @@ return System.currentTimeMillis(); } - public boolean pathExists(String path) { - return Files.exists(Paths.get(path), LinkOption.NOFOLLOW_LINKS); - } - @NonNull public String getFilename() { return FILENAME;
diff --git a/libartservice/service/javatests/com/android/server/art/DexUseManagerTest.java b/libartservice/service/javatests/com/android/server/art/DexUseManagerTest.java index ddca9c4..e4a000c 100644 --- a/libartservice/service/javatests/com/android/server/art/DexUseManagerTest.java +++ b/libartservice/service/javatests/com/android/server/art/DexUseManagerTest.java
@@ -154,7 +154,6 @@ lenient().when(mInjector.getArtd()).thenReturn(mArtd); lenient().when(mInjector.getCurrentTimeMillis()).thenReturn(0l); - lenient().when(mInjector.pathExists(any())).thenReturn(true); lenient().when(mInjector.getFilename()).thenReturn(mTempFile.getPath()); lenient() .when(mInjector.createScheduledExecutor()) @@ -764,12 +763,11 @@ } @Test - public void testExistingExternalSecondaryDexPath() throws Exception { + public void testSecondaryDexPath() throws Exception { mMockClock.advanceTime(DexUseManagerLocal.INTERVAL_MS); // Save. long oldFileSize = mTempFile.length(); String existingDexPath = mCeDir + "/foo.apk"; - when(mInjector.pathExists(existingDexPath)).thenReturn(true); mDexUseManager.notifyDexContainersLoaded( mSnapshot, LOADING_PKG_NAME, Map.of(existingDexPath, "PCL[]")); @@ -778,35 +776,6 @@ } @Test - public void testNonexistingExternalSecondaryDexPath() throws Exception { - mMockClock.advanceTime(DexUseManagerLocal.INTERVAL_MS); // Save. - long oldFileSize = mTempFile.length(); - - String nonexistingDexPath = mCeDir + "/foo.apk"; - when(mInjector.pathExists(nonexistingDexPath)).thenReturn(false); - mDexUseManager.notifyDexContainersLoaded( - mSnapshot, LOADING_PKG_NAME, Map.of(nonexistingDexPath, "PCL[]")); - - mMockClock.advanceTime(DexUseManagerLocal.INTERVAL_MS); // Save. - assertThat(mTempFile.length()).isEqualTo(oldFileSize); - } - - @Test - public void testInternalSecondaryDexPath() throws Exception { - mMockClock.advanceTime(DexUseManagerLocal.INTERVAL_MS); // Save. - long oldFileSize = mTempFile.length(); - - String nonexistingDexPath = mCeDir + "/foo.apk"; - lenient().when(mInjector.pathExists(nonexistingDexPath)).thenReturn(false); - mDexUseManager.notifyDexContainersLoaded( - mSnapshot, OWNING_PKG_NAME, Map.of(nonexistingDexPath, "PCL[]")); - verify(mArtd, never()).getDexFileVisibility(nonexistingDexPath); - - mMockClock.advanceTime(DexUseManagerLocal.INTERVAL_MS); // Save. - assertThat(mTempFile.length()).isGreaterThan(oldFileSize); - } - - @Test public void testLimitSecondaryDexFiles() throws Exception { for (int n = 0; n < MAX_SECONDARY_DEX_FILES_PER_OWNER_FOR_TESTING - 1; ++n) { mDexUseManager.notifyDexContainersLoaded(mSnapshot, LOADING_PKG_NAME,