Skip to content

Internal change #3317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,14 @@ public String getExternalStoragePath(String serial, int sdkVersion)
int currentUser = androidUserUtil.getCurrentUser(serial, sdkVersion);
logger.atInfo().log(
"Device %s current user: %s, sdk version: %s", serial, currentUser, sdkVersion);
if (currentUser == SYSTEM_USER
|| sdkVersion < AndroidVersion.ANDROID_11.getStartSdkVersion()) {
externalStoragePath = "/storage/emulated/" + currentUser;
} else {
// special cases for multi user devices, especially, auto OS.
if (currentUser != SYSTEM_USER
&& sdkVersion == AndroidVersion.ANDROID_11.getStartSdkVersion()) {
// Special case for multi user devices in Android R. Refer to b/152866706 for more
// details.
externalStoragePath =
MULTI_USER_EXTERNAL_STORAGE_PATH_PREFIX + currentUser + "/emulated/" + currentUser;
} else {
externalStoragePath = "/storage/emulated/" + currentUser;
}
}
} catch (MobileHarnessException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@ public void getExternalStoragePath_api30_multiuser() throws Exception {
.isEqualTo(AndroidErrorId.ANDROID_FILE_UTIL_GET_EXTERNAL_STORAGE_ERROR);
}

@Test
public void getExternalStoragePath_api32_multiuser() throws Exception {
when(androidUserUtil.getCurrentUser(SERIAL, /* sdkVersion= */ 32))
.thenReturn(10)
.thenThrow(
new MobileHarnessException(
AndroidErrorId.ANDROID_USER_UTIL_GET_FOREGROUND_USER_ERROR, "Error"));

assertThat(androidFileUtil.getExternalStoragePath(SERIAL, /* sdkVersion= */ 32))
.isEqualTo("/storage/emulated/10");
assertThat(
assertThrows(
MobileHarnessException.class,
() -> androidFileUtil.getExternalStoragePath(SERIAL, /* sdkVersion= */ 32))
.getErrorId())
.isEqualTo(AndroidErrorId.ANDROID_FILE_UTIL_GET_EXTERNAL_STORAGE_ERROR);
}

@Test
public void getFileInfo_file() throws Exception {
int sdkVersion = 28;
Expand Down