Skip to content

Commit 3dbc74d

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Reduce TestStorage logspam.
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
1 parent c3e2559 commit 3dbc74d

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

services/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+
* Reduce HostedFile log spam
10+
911
**New Features**
1012

1113
**Breaking Changes**

services/storage/java/androidx/test/services/storage/file/HostedFile.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.util.Log;
2525
import androidx.test.services.storage.TestStorageConstants;
2626
import java.io.File;
27+
import java.util.concurrent.atomic.AtomicBoolean;
2728

2829
import androidx.annotation.RestrictTo;
2930
import androidx.annotation.RestrictTo.Scope;
@@ -38,6 +39,8 @@ public final class HostedFile {
3839

3940
private static final String TAG = "HostedFile";
4041

42+
private static final AtomicBoolean loggedOutputDir = new AtomicBoolean(false);
43+
4144
/** An enum of the columns returned by the hosted file service. */
4245
public enum HostedFileColumn {
4346
NAME("name", String.class, 3 /* Cursor.FIELD_TYPE_STRING since api 11 */, 0),
@@ -146,34 +149,25 @@ public static Uri buildUri(FileHost host, String fileName) {
146149

147150
public static File getInputRootDirectory(Context context) {
148151
// always use external storage dir for input
149-
Log.i(
150-
TAG,
151-
"Choosing external storage as root dir for input: "
152-
+ Environment.getExternalStorageDirectory().getAbsolutePath());
153152
return Environment.getExternalStorageDirectory();
154153
}
155154

156155
public static File getOutputRootDirectory(Context context) {
157156
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
158157
if (VERSION.SDK_INT < 23) {
159-
Log.i(
160-
TAG,
161-
"Running on API < 23; Choosing external storage as output root dir: "
162-
+ Environment.getExternalStorageDirectory().getAbsolutePath());
163158
return Environment.getExternalStorageDirectory();
164159
} else if (userManager.isSystemUser()) {
165-
Log.i(
166-
TAG,
167-
"System user detected. Choosing external storage as output root dir: "
168-
+ Environment.getExternalStorageDirectory().getAbsolutePath());
169160
return Environment.getExternalStorageDirectory();
170161
} else {
171162
// using legacy external storage for output in automotive devices where tests run as
172163
// a secondary user has been flaky. So use local storage instead.
173-
Log.i(
174-
TAG,
175-
"Secondary user detected. Choosing local storage as output root dir: "
176-
+ context.getCacheDir().getAbsolutePath());
164+
if (!loggedOutputDir.getAndSet(true)) {
165+
// limit log spam by only logging choice once
166+
Log.d(
167+
TAG,
168+
"Secondary user detected. Choosing local storage as output root dir: "
169+
+ context.getCacheDir().getAbsolutePath());
170+
}
177171
return context.getCacheDir();
178172
}
179173
}

0 commit comments

Comments
 (0)