FORUMS

SuperSU Beta Updates With Minor Fix For Galaxy S6

ChainFire’s root permissions app SuperSU has updated to v.2.49 to fix audits on … more

LG G4 Day Event Coverage: Specs, Features, Design & More!

LG has been teasing us with a countdown for a while now, and today it reached … more

Xposed Modules to Modify Email – XDA Xposed Tuesday

Even though we have Dropbox and other ways to share files, people still want … more

Google Teaches You to Use Wear Gestures

Now that the Watch Urbane is out with the latest firmware, we have new information regarding the … more
Post Reply Subscribe to Thread Email Thread

Post [Research, Android 4.2] Try to enable multi user support on phones

18th November 2012, 08:00 AM |#1  
ramdroid77's Avatar
OP Senior Member
Thanks Meter: 126
 
More
Like we all know Google has decided that multi user support is only needed on tablet devices. I don't agree with Google here so right after I've got Android 4.2 on my Galaxy Nexus I started to do some research to get multi user support enabled. My goal was to get a generic app published (probably it needs root access) that would allow to enable multi user support on any Android 4.2 phone.

After some research I figured out this is not possible. Multi user support is deeply integrated into the OS and the only way to get it enabled is by modding a custom ROM. In my investigation I started looking at the AOSP source code. There are two entries points that are relevant: the new UserManager API checks if multi users are supported on the device and KeyguardHostView allows to switch users on the lock screen.

UserManager

If you don't already have the whole AOSP available then you can only download this repository:

git clone https://android.googlesource.com/pla...rameworks/base

base/core/java/android/os --> UserManager.java --> function getMaxSupportedUser():

SystemProperties.getInt("fw.max_users",
Resources.getSystem().getInteger(R.integer.config_ multiuserMaximumUsers))


This can be achieved quite easily. Open a shell and type:

su
setprop fw.max_users 5
(actually any value > 1 works)

Now the user menu is visible in Android settings. Here you can choose "Create new user" just like you do on your Nexus 7. A new user account is created and your phone is running in the new user account. In the QuickSettings notification bar you go back to your lock screen. However the icons to switch users are missing. So let's look at the lock screen....

KeyGuard

Download the repository:

git clone https://android.googlesource.com/pla.../policies/base

base/policy/src/com/android/internal/policy/impl/keyguard --> KeyguardHostView.java

Actually what happens here is that KeyboardHostView is trying to add the KeyguardMultiUserSelectorView layout into the lock screen if the number of users is greater than one. Unfortunately we will see an exception in logcat because layout R.id.keyguard_user_selector is simply not included in phone layouts. Probably we could change build.prop to enable tablet mode and get it enabled, but that's not really what we want to do.

Now the idea is to develop a lock screen widget that would simulate the KeyboardHostView. The app probably needs to be installed as system app so it's available for all users. So let's go ahead and look what exactly is happening...

First the list of users is retrieved:

UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
um.getUserList()


This user list is added to KeyguardMultiUserSelectorView:

base/policy/src/com/android/internal/policy/impl/keyguard --> KeyguardMultiUserSelectorView.java

In order to finally switch users it just calls:

ActivityManagerNative.getDefault().switchUser(avat ar.getUserInfo().id);

Doesn't really look like rocket science! Let's try to reproduce this in our own app....

Implementation

The UserInfo class (which is returned in a List in getUserList) is not included in Android SDK. Copy into your project from AOSP sources:

base/core/java/android/content/pm/UserInfo.java

Some little hack for a hidden constructor:

public UserHandle getUserHandle() {
// Constructor UserHandle(int) is hidden, use public constructor instead
Parcel pId = Parcel.obtain();
pId.writeInt(id);
return new UserHandle(pId);
}


Oh well, the UserManager.getUserList() is hidden. Use reflection to retrieve the user list:

List<UserInfo> users = new ArrayList<UserInfo>();
final UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
Method getUsers = userManager.getClass().getMethod("getUsers", null);
users = (List<UserInfo>) getUsers.invoke(userManager, null);


ActivityManagerNative is nowhere available. Use reflection to get an instance:

Class activityManagerNative = classLoader.loadClass("android.app.ActivityManager Native");
Method getDefault = activityManagerNative.getMethod("getDefault", null);
Object instanceActivityManagerNative = getDefault.invoke(null, null);


Too lazy to figure out the proper call to getMethod, so just search for switchUser method:

Method switchUser = null;
Method methods[] = instanceActivityManagerNative.getClass().getDeclar edMethods();
for (Method m : methods) {
if (m.getName().equals("switchUser")) {
switchUser = m;
}
}


Call switch user with some ID that we retrieved from the user list:

switchUser.invoke(instanceActivityManagerNative, new Object[] { users.get(1).id } );

Executing this code will crash because we are missing some permissions....

Permissions

android.permission.MANAGE_USERS is needed for getUserList()

This permission has android:protectionLevel="signature|system"

--> Install app in system partition (we'd like to do this anyway) and the permission is granted

android.permission.INTERACT_ACROSS_USERS_FULL is needed for switchUser(). However this permission has android:protectionLevel="signature".

Here we can already stop because the app needs to be signed with platform key in order to get this permission. Sadly there's no way we can do this on devices with a retail firmware. Only way to get this permission is by building our own ROM from AOSP.

Besides, the alternative permission android.permission.INTERACT_ACROSS_USERS only has android:protectionLevel="signature|system" but it seems this is not good enough for switchUser()....

Implementation in Custom ROMs

As we can directly modify the framework files this shouldn't be too much effort:

--> set the fw.max_users system property to a value > 1
--> copy the KeyguardMultiUserSelectorView layout from a tablet device (R.id.keyguard_user_selector)

I don't really have the time and motivation to maintain any custom ROMs so I'm stopping here.
Last edited by ramdroid77; 23rd January 2013 at 04:30 AM.
The Following 3 Users Say Thank You to ramdroid77 For This Useful Post: [ View ]
 
 
19th November 2012, 12:26 AM |#2  
illinoissparks18's Avatar
Member
Thanks Meter: 16
 
More
Thanks!
Hey just wondering if you could explain more on the second part. I got the first part enabled perfectly. Thanks
19th November 2012, 05:49 AM |#3  
ramdroid77's Avatar
OP Senior Member
Thanks Meter: 126
 
More
Quote:
Originally Posted by illinoissparks18

Hey just wondering if you could explain more on the second part. I got the first part enabled perfectly. Thanks

what do you exactly mean with "second part"?
19th November 2012, 07:21 AM |#4  
McJesus15's Avatar
Senior Member
Thanks Meter: 285
 
More
If you don't mind root access then you can use Switchme. It's an app that allows user profiles to be created and used. It's fairly stable too.
19th November 2012, 09:28 AM |#5  
ramdroid77's Avatar
OP Senior Member
Thanks Meter: 126
 
More
Quote:
Originally Posted by McJesus15

If you don't mind root access then you can use Switchme. It's an app that allows user profiles to be created and used. It's fairly stable too.

I know about Switchme. However this thread is only about Android's native user management.
19th November 2012, 01:44 PM |#6  
illinoissparks18's Avatar
Member
Thanks Meter: 16
 
More
Lol sorry :P I got the user tab to show up. Now i need the lockscreen features :P haha sorry
19th November 2012, 02:24 PM |#7  
ramdroid77's Avatar
OP Senior Member
Thanks Meter: 126
 
More
Quote:
Originally Posted by illinoissparks18

Lol sorry :P I got the user tab to show up. Now i need the lockscreen features :P haha sorry

Probably you mean this part?

Quote:

copy the KeyguardMultiUserSelectorView layout from a tablet device (R.id.keyguard_user_selector)

You can only achieve this my compiling from source and migrate the user selection view into the phone layout. The most complicated part is probably to find some free space on the screen
The Following User Says Thank You to ramdroid77 For This Useful Post: [ View ]
19th November 2012, 06:24 PM |#8  
Junior Member
Thanks Meter: 2
 
More
Native multi user support works on Android 4.2 phone
I've got Android 4.2 on my Galaxy Nexus I started to do some research to get multi user support enabled. After some research I figured out this is very simple. It is only two steps from native multi user support on your phone.
1. First of all you need to enable "User" menu in Android settings:
Open build.prop file with any text editor and add line (actually any value > 1 works):
fw.max_users=5
2.Next, to make the icons to switch users visible - change display resolution.
Open build.prop file with any text editor find line with parameter ro.sf.lcd_density and change value from 320 to 192

Save changes what you made just. Reboot your phone and enjoin native multi user support on your phone.
The Following User Says Thank You to ArtuCer For This Useful Post: [ View ]
19th November 2012, 06:29 PM |#9  
ramdroid77's Avatar
OP Senior Member
Thanks Meter: 126
 
More
Quote:
Originally Posted by ArtuCer

I've got Android 4.2 on my Galaxy Nexus I started to do some research to get multi user support enabled. After some research I figured out this is very simple. It is only two steps from native multi user support on your phone.
1. First of all you need to enable "User" menu in Android settings:
Open build.prop file with any text editor and add line (actually any value > 1 works):
fw.max_users=5
2.Next, to make the icons to switch users visible - change display resolution.
Open build.prop file with any text editor find line with parameter ro.sf.lcd_density and change value from 320 to 192

Save changes what you made just. Reboot your phone and enjoin native multi user support on your phone.

The different density activates the tablet layout. But your apps and everything changes from phone UI to tablet UI as well, doesn't it?
19th November 2012, 06:44 PM |#10  
Junior Member
Thanks Meter: 2
 
More
Quote:
Originally Posted by ramdroid77

The different density activates the tablet layout. But your apps and everything changes from phone UI to tablet UI as well, doesn't it?

Well, it is one more way.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes