How to check whether current user is owner

boolean isOwner = false;UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);if (um != null) {    UserHandle userHandle = android.os.Process.myUserHandle();    isOwner = um.getSerialNumberForUser(userHandle) == 0;}

How to check whether the process runs on current user

It will need to use permission INTERACT_ACROSS_USERS and MANAGE_USERS (both are signature|system) for getCurrentUser.

boolean isCurrentUser = false;try {    Method getUhId = UserHandle.class.getDeclaredMethod("getIdentifier");    Method getCuId = ActivityManager.class.getDeclaredMethod("getCurrentUser");    Integer myUhId = (Integer) getUhId.invoke(android.os.Process.myUserHandle());    Integer cuId = (Integer) getCuId.invoke(null);    isCurrentUser = myUhId != null && myUhId.equals(cuId);} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException         | InvocationTargetException e) {    // ...}

How to check whether the process runs on managed profile (Android for Work) or guest user

It will need to use permission MANAGE_USERS (signature|system).

UserManager um = UserManager.get(context);boolean isManagedProfile = um.isManagedProfile();boolean isGuestUser = um.isGuestUser();

By reflection:

try {    Method getUM = UserManager.class.getDeclaredMethod("get", Context.class);    Method isMP = UserManager.class.getDeclaredMethod("isManagedProfile");    Method isGU = UserManager.class.getDeclaredMethod("isGuestUser");    UserManager um = (UserManager) getUM.invoke(null, context);    Boolean isManagedProfile = (Boolean) isMP.invoke(um);    Boolean isGuestUser = (Boolean) isGU.invoke(um);} catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {}

Effective criteria of singleUser attribute for component This flag can only be used with services, receivers, and providers; it can not be used with activities.
Need permission android.permission.INTERACT_ACROSS_USERS (system|signature).
Need to satisfy one of the below conditions appId >= 10000 (appId means base uid that stripping out the user id, see slide page 19) appId is PHONE_UID (1001)
Declared android:persistent=”true”

Single user component constraint
exported will be false, only put in priv-app can set to true.
It will need to declare android.permission.INTERACT_ACROSS_USERS_FULL (platform key signature) to allow other application access it. reference

Broadcast send from system uid will ignore singleUser attribute, which means the receiver will have different processes on each running users.

Background user launches activity

According to 93529a4, 4f1df4fa.
The last focused stack will be remembered when the user changes. It will restore that stack when the user changes back.

So if user 0 is on home activity (home stack), then switch to user 10. A component in user 0 starts an activity X (in app stack). Switch back to user 0 will see home. The activity X will be created when its task becomes top task.
If user 0 switch to user 10 when user 0’s top is an application (app stack), then A component in user 0 starts an activity X, switch back to user 0 will see the activity X.

Steps of enable multi-user on SHEP/HEP (for local test)

adb remountadb shell "echo 'fw.max_users=3' >> /system/build.prop"adb shell "echo 'fw.show_multiuserui=1' >> /system/build.prop"adb rebootAdding and switching users from Settings > Users 

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android进阶知识:Handler相关
  2. FastBoot 刷机方法
  3. 在Ubuntu上下载、编译、运行Android系统
  4. Android期末基础复习
  5. Android之路-------浅淡Android历史、系
  6. Android(安卓)内存泄漏调试
  7. Android(安卓)Service生命周期及用法!
  8. Android(安卓)判断用户2G/3G/4G移动数据
  9. Android(安卓)USB HID设备通信controlTra
  10. Android(安卓)4.0的12大新特性