Skip to content

Conversation

@dellis1972
Copy link
Contributor

This commit adds support for running multi user tests on device.
It makes use of various adb commands to create test users and
remove them.

shell pm create-user --guest {name} will create a guest user of a
specific name.

shell pm remove-user --guest {userId} will remove a userId.

The userId can be retrieved via shell pm list users. This command
will return results as follows

Users:
    UserInfo{0:Owner:c13} running
    UserInfo{10:guest1:414}

We can then use a RegEx to pull out the required userId for a specific
user.

Finally shell am switch-user {userId} can be used to switch between
users on the device.

Emulators seem to create the main user with the name "Owner" so that should
be the default name we use for the main user. In the unit tests if we
cannot find a user named "Owner" when looking for "Owner" we will default
to a userId of 0. This always means the default user. This is to handle
the case where we are testing locally on devices where the main user is
not called "Owner".

@dellis1972 dellis1972 added the do-not-merge PR should not be merged. label Nov 18, 2020
@dellis1972 dellis1972 marked this pull request as ready for review December 3, 2020 21:35
@dellis1972 dellis1972 removed the do-not-merge PR should not be merged. label Dec 3, 2020
This commit adds support for running multi user tests on device.
It makes use of various adb commands to create test users and
remove them.

`shell pm create-user --guest {name}` will create a guest user of a
specific name.

`shell pm remove-user --guest {userId}` will remove a userId.

The userId can be retrieved via `shell pm list users`. This command
will return results as follows

    Users:
	    UserInfo{0:Owner:c13} running
	    UserInfo{10:guest1:414}

We can then use a RegEx to pull out the required `userId` for a specific
user.

Finally `shell am switch-user {userId}` can be used to switch between
users on the device.

Emulators seem to create the main user with the name "Owner" so that should
be the default name we use for the main user. In the unit tests if we
cannot find a user named "Owner" when looking for "Owner" we will default
to a `userId` of `0`. This always means the default user. This is to handle
the case where we are testing locally on devices where the main user is
not called "Owner".
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, if we are OK with the CI results.

@jonpryor jonpryor merged commit 7b51fd1 into dotnet:master Dec 9, 2020
@dellis1972 dellis1972 deleted the userIdSupport branch December 10, 2020 00:49
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants