0%

Android ADB and user management

⚠ This article requires Rooted Android phones, please follow the instructions with caution.

Background

Since Android 5, the Android system have added the capability of multi-user, the aim is most likely to make sharing devices easier between different users in the family. Later on, Google added again something called profile, this allows enterprise to manage devices their employers use. In this article, I am going to explore some other possibilities enabled by multiuser/profile functionality. More specifically I’m going to focus on the restricted user profile.

Problem to Solve

There are several problems I’m aiming to solve with the restricted profile:

  • I want to focus on things that actually matter rather than spending too much time on my phone, I would like my phone to be without any apps that can disturb or distract me when I want to focus. But I don’t want to uninstall certain apps, as they are necessary in order to keep in touch with my family and friends.
  • I want to install certain apps that can track me into a separate space, a space where it is impossible for them to track me using the microphone, camera, or location.

Solutions

Well, as an Android user that also owns an iOS device, I have to say Apple have done a good job in many of the things I mentioned above. For example, my first problem can be solved in the iOS setting natively. Android does have something similar called digital wellbeing, but since it is from Google, I’m not that comfortable installing it on to my phone.

Anyway, I feel like the restricted profile is still a good solution to my problem on Android.

How to?

So in Android shell, there’s something called pm. This command can be used to create a new user.
Here is part of the help doc that I’m interested in:

create-user [--profileOf USER_ID] [--managed] [--restricted] [--ephemeral] [--guest] USER_NAME Create a new user with the given USER_NAME, printing the new user identifier of the user.

That is, command pm create-user can be used to create user on your Android phone. Assuming you have access to Android adb, issuing
adb shell pm create-user --restricted test will create a user named test with restricted profile, the command will show the userid of the newly created user, will be referenced as $userId in the following.

Once the user has been created, you can manage the list of the users it will have access to in the settings, this is in Settings/Multi-user.

To me, I want impose more restrictions on the user, there is indeed a way to do so:

adb shell su -c 'pm set-user-restriction --user USER_ID no_install_apps 1' – this will disallow install apps for the newly created profile, in this case no_install_apps is the name of the restriction, while the ** 1** immidiately follow is a boolean representing whether the restriction is enabled. (This command assumes you use Magsik as su)

You can find a list of restrictions available from Google’s official document. Take note of the Constant Value in the document, that’s the restriction value you need to use.

If you want to see what restriction you’ve added, you can issue adb shell dumpsys user, this command will dump all the users on the current device and the restrictions if any.

To switch to a different user, you can use am switch-user USER_ID or do so from the UI.

The easiest way to delete an user is through the settings menu. Though you can also do so through the command: pm remove-user USER_ID

Caveat

There are several issues that need to be taken into consideration when using a restricted profile:

  1. You will not have access to any of the files in the primary account, this is a big issue if you have social media apps installed on this account and want to upload image from the primary account.
  2. You will not have Google account access or root access. Most people will be okay with this, but it is a bit troublesome at times.
  3. Remember to switch the profile back, when you no longer need to be in the restricted one. For example, if you leave your restricted profile on overnight, you will not have an alarm clock if you don’t set it up correctly.