Skip to content

Commit 5fac883

Browse files
brettchabotcopybara-androidxtest
authored andcommitted
Omit TestStorageTest@writeInternalFile from running on multi user
PiperOrigin-RevId: 732969678
1 parent c71e99d commit 5fac883

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

services/storage/javatests/androidx/test/services/storage/TestStorageTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
import static com.google.common.truth.Truth.assertThat;
2020
import static junit.framework.TestCase.fail;
2121
import static org.junit.Assert.assertEquals;
22+
import static org.junit.Assume.assumeTrue;
2223

24+
import android.content.Context;
2325
import android.net.Uri;
26+
import android.os.Build;
27+
import android.os.UserManager;
2428
import androidx.test.services.storage.file.HostedFile;
2529
import androidx.test.services.storage.internal.TestStorageUtil;
2630
import java.io.BufferedReader;
@@ -110,11 +114,23 @@ public void addOutputProperties() throws Exception {
110114

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

124+
private static boolean isSystemUser() {
125+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
126+
return true;
127+
} else {
128+
UserManager um =
129+
((UserManager) getApplicationContext().getSystemService(Context.USER_SERVICE));
130+
return um.isSystemUser();
131+
}
132+
}
133+
118134
@Test
119135
public void readWriteOverwriteReadFile() throws IOException {
120136
try (OutputStream output = testStorage.openOutputFile("path/to/file")) {

0 commit comments

Comments
 (0)