Skip to content

Commit

Permalink
Reduce TestStorage logspam.
Browse files Browse the repository at this point in the history
5acf36a added
logging whenever TestStorage calculates a file path, which can occur several times in a test run.
This is unnecessary and spams logcat.

This commit removes most logging, except for the special case where a new directory is chosen
when running as a non system user. And in that case a check is added to ensure the log
only happens once.

PiperOrigin-RevId: 630169476
  • Loading branch information
brettchabot authored and copybara-androidxtest committed May 2, 2024
1 parent c3e2559 commit 3dbc74d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
2 changes: 2 additions & 0 deletions services/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

**Bug Fixes**

* Reduce HostedFile log spam

**New Features**

**Breaking Changes**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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,6 +39,8 @@ 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 @@ -146,34 +149,25 @@ public static Uri buildUri(FileHost host, String fileName) {

public static File getInputRootDirectory(Context context) {
// always use external storage dir for input
Log.i(
TAG,
"Choosing external storage as root dir for input: "
+ Environment.getExternalStorageDirectory().getAbsolutePath());
return Environment.getExternalStorageDirectory();
}

public static File getOutputRootDirectory(Context context) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
if (VERSION.SDK_INT < 23) {
Log.i(
TAG,
"Running on API < 23; Choosing external storage as output root dir: "
+ Environment.getExternalStorageDirectory().getAbsolutePath());
return Environment.getExternalStorageDirectory();
} else if (userManager.isSystemUser()) {
Log.i(
TAG,
"System user detected. Choosing external storage as output root dir: "
+ Environment.getExternalStorageDirectory().getAbsolutePath());
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.
Log.i(
TAG,
"Secondary user detected. Choosing local storage as output root dir: "
+ context.getCacheDir().getAbsolutePath());
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();
}
}
Expand Down

0 comments on commit 3dbc74d

Please sign in to comment.