10

There is an option to switch between users, but there isn't an option to logout from an active user session. The background apps and services for inactive users (once logged in and switched out) continue to run draining the battery.

The only way i think, is to reboot the device and not login the user.

So, is there any way that the owner can force subsequent inactive users to logout of their session? I have superuser access to the owner with android-5.0.2.

7

In a terminal app on Android, enter (requires root access) :

su
am stop-user USER_ID

E.g. For a Guest user, its USER_ID in my device is 11 so the command would be am stop-user 11.

am stop-user doesn't process multiple input so you've to execute the command for every secondary user which you want to pause.

This is bit different from restarting the device. If you check am's usage you would see,

am stop-user: stop execution of USER_ID, not allowing it to run any code until a later explicit start or switch to it.

As said, it simply pauses all the activities associated to that user account, so whenever an explicit start or switch is provided your session would resume rather than starting from scratch.

For confirmation that the user indeed has paused or is not running, see my answer for How to find out currently running user name/ID from ADB?

Briefly, pm list users or dumpsys activity would tell you whether the user is RUNNING or SHUTDOWN. The latter command is better. If the user-session is indeed put on halt by am stop-user, you would see mState=SHUTDOWN for that user. However, if the user hasn't been activated even once since the reboot, you wouldn't see any of its entry.

  • like I said am stopuser 10 was only showing pm list users command as user not running. I checked adb shell ps after am stop-user 10 and can find u10_axx processes running. To check if they are halted, I tried running a shell script in a terminal on 2nd user. The script loops an echo statement every second (displaying second). After starting this script, using the am stop-user 10 command, waiting for 5min and re-starting the 2nd user session, I can say that the script is not halted. It ran for the entire time. – Bharat G Oct 12 '15 at 5:47
  • The method I used for installing apps (terminal) in 2nd user of android 5.0.2 is by adb install -r app.apk . Don't know if that is the issue. – Bharat G Oct 12 '15 at 5:51
  • I'll update you if I get something relevant to your comments. – Firelord Oct 12 '15 at 6:05
  • 1
    I have checked the same command on friend's device with android-5.1.1 and it worked as stated. I haven't checked the script part, but on issuing am stop-user 10 , all the processes of 2nd user got killed and are not listed in Settings > Apps or with ps command. So, it is the way, but android-5.0.2 currently is either buggy with this command, or such functionality is not implemented as of that version I guess. But 5.1 has more intolerable bugs for me to switch yet. Thank you :) – Bharat G Oct 18 '15 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.