Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions services/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

{{date}}

<!-- disableFinding(LINE_OVER_80) -->
`androidx.test.services:test-services:{version}` `androidx.test.services:storage:{version}` are released.

**Bug Fixes**

* Ensure TestStorage library is multi-linux-user compatible.

**New Features**

**Breaking Changes**

* The location where TestStorage stores files has changed. This is non-breaking
if using the TestStorage API, but breaking if tests depended on the explicit
location of the files (e.g., by reading them without using TestStorage).

**API Changes**

* Update to minSdkVersion 23 and remove all related logic for SDKs < 23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ android_library(
name = "file",
srcs = glob(["*.java"]),
deps = [
"//opensource/androidx:annotation",
"//runner/monitor",
"//services/storage/java/androidx/test/services/storage:test_storage_constants",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import android.os.UserManager;
import android.provider.OpenableColumns;
import android.util.Log;
import androidx.test.services.storage.TestStorageConstants;
import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;

import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.Scope;
Expand All @@ -38,8 +35,6 @@ public final class HostedFile {

private static final String TAG = "HostedFile";

private static final AtomicBoolean loggedOutputDir = new AtomicBoolean(false);

/** An enum of the columns returned by the hosted file service. */
public enum HostedFileColumn {
NAME("name", String.class, 3 /* Cursor.FIELD_TYPE_STRING since api 11 */, 0),
Expand Down Expand Up @@ -152,21 +147,8 @@ public static File getInputRootDirectory(Context context) {
}

public static File getOutputRootDirectory(Context context) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
if (userManager.isSystemUser()) {
return Environment.getExternalStorageDirectory();
} else {
// using legacy external storage for output in automotive devices where tests run as
// a secondary user has been flaky. So use local storage instead.
if (!loggedOutputDir.getAndSet(true)) {
// limit log spam by only logging choice once
Log.d(
TAG,
"Secondary user detected. Choosing local storage as output root dir: "
+ context.getCacheDir().getAbsolutePath());
}
return context.getCacheDir();
}
// Use a reliably self-writable directory.
return context.getExternalFilesDir(null);
}

private static <T> T checkNotNull(T reference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public final class InternalUseOnlyFilesContentProvider extends AbstractFileConte

@Override
protected File getHostedDirectory(Context context) {
// use input root directory here, as TestArgsContentProvider also uses this directory
// Uses the output root directory since the provider is Read/Write and only the output directory
// is guaranteed to be writable.
return new File(
HostedFile.getInputRootDirectory(context),
HostedFile.getOutputRootDirectory(context),
TestStorageConstants.ON_DEVICE_PATH_INTERNAL_USE);
}

Expand Down
45 changes: 43 additions & 2 deletions services/storage/javatests/androidx/test/services/storage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Tests for the test storage.

load("//build_extensions:android_library_test.bzl", "axt_android_library_test")
load("//build_extensions:phone_devices.bzl", "devices")
load("//build_extensions:phone_devices.bzl", "apis", "devices")

package(
default_applicable_licenses = ["//services:license"],
Expand Down Expand Up @@ -30,10 +30,51 @@ axt_android_library_test(
],
deps = [
"//core/java/androidx/test/core",
"//runner/monitor/java/androidx/test:monitor",
"//services/storage/java/androidx/test/services/storage",
"//services/storage/java/androidx/test/services/storage/file",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
],
)

[
axt_android_library_test(
name = "TestStorageHsumTest_{user}".format(user = user),
size = "large",
srcs = [
"TestStorageTest.java",
],
args = [
"--install_test_services=true",
"--test_args=arg1=value1,arg2=value2,arg3=value3",
"--instrumentation_user={user}".format(user = user),
],
data = [
":testinput.txt",
],
device_list =
custom_devices(
apis(min_api = 36),
"hsum_phone",
"google_hsum",
"x86_64",
),
support_apps = [
"//services:test_services",
],
tags = ["requires-mem:20g"],
test_class = "androidx.test.services.storage.TestStorageTest",
deps = [
"//core/java/androidx/test/core",
"//runner/monitor/java/androidx/test:monitor",
"//services/storage/java/androidx/test/services/storage",
"//services/storage/java/androidx/test/services/storage/file",
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",
],
)
for user in [
"0",
"10",
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

import android.content.Context;
import android.net.Uri;
import android.os.UserManager;
import androidx.test.services.storage.file.HostedFile;
import androidx.test.services.storage.internal.TestStorageUtil;
import java.io.BufferedReader;
Expand Down Expand Up @@ -113,20 +110,11 @@ public void addOutputProperties() throws Exception {

@Test
public void writeInternalFile() throws IOException {
// known not to work in multi-user mode
assumeTrue(isSystemUser());
try (OutputStream output = testStorage.openInternalOutputFile("path/to/file")) {
output.write(new byte[] {'h', 'e', 'l', 'l', 'o'});
}
}

private static boolean isSystemUser() {

UserManager um =
((UserManager) getApplicationContext().getSystemService(Context.USER_SERVICE));
return um.isSystemUser();
}

@Test
public void readWriteOverwriteReadFile() throws IOException {
try (OutputStream output = testStorage.openOutputFile("path/to/file")) {
Expand Down
Loading