Skip to content

Commit 4a23812

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Upstream TestStorage.isTestStoragePath to PlatformTestStorage
The TestStorage.isTestStoragePath will only work in environments where the TestStorage service is active. Upstream it so it can be handled in all possible storage situations. PiperOrigin-RevId: 603726706
1 parent 25900be commit 4a23812

File tree

10 files changed

+42
-3
lines changed

10 files changed

+42
-3
lines changed

core/javatests/androidx/test/core/graphics/BitmapStorageTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,9 @@ class BitmapStorageTest {
7979
override fun openInternalOutputFile(pathname: String?): OutputStream {
8080
TODO("Not yet implemented")
8181
}
82+
83+
override fun isTestStorageFilePath(pathname: String): Boolean {
84+
TODO("Not yet implemented")
85+
}
8286
}
8387
}

ext/junit/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
**Bug Fixes**
88

9+
* Use PlatformTestStorage instead of TestStorage in DeleteFilesRule
10+
911
**New Features**
1012

1113
**Breaking Changes**

ext/junit/java/androidx/test/ext/junit/rules/DeleteFilesRule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import android.os.Build;
2020
import android.os.Environment;
2121
import androidx.test.core.app.ApplicationProvider;
22-
import androidx.test.services.storage.TestStorage;
22+
import androidx.test.platform.io.PlatformTestStorageRegistry;
2323
import java.io.File;
2424
import java.util.ArrayList;
2525
import java.util.HashSet;
@@ -107,7 +107,7 @@ private static void deleteFilesRecursively(Set<File> existingFiles, File directo
107107
if (files != null) {
108108
for (File file : files) {
109109
if (file.isDirectory()) {
110-
if (TestStorage.isTestStorageFilePath(file.getPath())) {
110+
if (PlatformTestStorageRegistry.getInstance().isTestStorageFilePath(file.getPath())) {
111111
continue;
112112
}
113113
deleteFilesRecursively(existingFiles, file);

runner/android_junit_runner/javatests/androidx/test/internal/runner/RunnerArgsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,5 +755,10 @@ public InputStream openInternalInputFile(String pathname) throws IOException {
755755
public OutputStream openInternalOutputFile(String pathname) throws IOException {
756756
throw new UnsupportedOperationException();
757757
}
758+
759+
@Override
760+
public boolean isTestStorageFilePath(String pathname) {
761+
return false;
762+
}
758763
}
759764
}

runner/monitor/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
**API Changes**
1414
* Make DeviceController an public API from ExperimentalTestApi
15+
* Upstream TestStorage.isTestStoragePath to PlatformTestStorage
1516

1617
**Breaking API Changes**
1718

runner/monitor/java/androidx/test/platform/io/FileTestStorage.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import android.os.Bundle;
1919
import android.util.Log;
20+
import androidx.annotation.NonNull;
2021
import androidx.test.annotation.ExperimentalTestApi;
2122
import androidx.test.platform.app.InstrumentationRegistry;
2223
import java.io.File;
@@ -140,4 +141,10 @@ public InputStream openInternalInputFile(String pathname) throws IOException {
140141
public OutputStream openInternalOutputFile(String pathname) throws IOException {
141142
return openOutputFile(pathname);
142143
}
144+
145+
@Override
146+
public boolean isTestStorageFilePath(@NonNull String pathname) {
147+
String outputDir = outputDirCalculator.getOutputDir().getAbsolutePath();
148+
return pathname.startsWith(outputDir);
149+
}
143150
}

runner/monitor/java/androidx/test/platform/io/PlatformTestStorage.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package androidx.test.platform.io;
1717

18+
import androidx.annotation.NonNull;
1819
import androidx.test.annotation.ExperimentalTestApi;
1920
import java.io.IOException;
2021
import java.io.InputStream;
@@ -36,6 +37,7 @@
3637
*/
3738
@ExperimentalTestApi
3839
public interface PlatformTestStorage {
40+
3941
/**
4042
* Provides an InputStream to a test file dependency.
4143
*
@@ -103,4 +105,13 @@ public interface PlatformTestStorage {
103105
* @return an OutputStream to the given output file.
104106
*/
105107
OutputStream openInternalOutputFile(String pathname) throws IOException;
108+
109+
/**
110+
* Returns true if {@code pathname} corresponds to a file or directory that is in a directory
111+
* where the storage stores files.
112+
*
113+
* @param pathname path to a file or directory. Should not be null. This is an absolute path to a
114+
* file that may be a part of the storage service.
115+
*/
116+
boolean isTestStorageFilePath(@NonNull String pathname);
106117
}

runner/monitor/java/androidx/test/platform/io/PlatformTestStorageRegistry.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static androidx.test.internal.util.Checks.checkNotNull;
1919

20+
import androidx.annotation.NonNull;
2021
import androidx.test.annotation.ExperimentalTestApi;
2122
import androidx.test.internal.platform.ServiceLoaderWrapper;
2223
import java.io.IOException;
@@ -116,6 +117,11 @@ public OutputStream openInternalOutputFile(String pathname) throws IOException {
116117
return new NullOutputStream();
117118
}
118119

120+
@Override
121+
public boolean isTestStorageFilePath(@NonNull String pathname) {
122+
return false;
123+
}
124+
119125
static class NullInputStream extends InputStream {
120126
@Override
121127
public int read() {

services/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
**API Changes**
1414

15+
* Upstream TestStorage.isTestStoragePath to PlatformTestStorage
16+
1517
**Breaking API Changes**
1618

1719
**Known Issues**

services/storage/java/androidx/test/services/storage/TestStorage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public static Uri getOutputFileUri(@NonNull String pathname) {
120120
* @param pathname path to a file or directory. Should not be null. This is an absolute path to a
121121
* file that may be a part of the storage service.
122122
*/
123-
public static boolean isTestStorageFilePath(@NonNull String pathname) {
123+
@Override
124+
public boolean isTestStorageFilePath(@NonNull String pathname) {
124125
File onDevicePathRoot =
125126
new File(HostedFile.getRootDirectory(), TestStorageConstants.ON_DEVICE_PATH_ROOT);
126127
// Append a trailing slash because ON_DEVICE_PATH_ROOT has a trailing slash. If pathname already

0 commit comments

Comments
 (0)