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. Android串口通信:抱歉,学会它真的可以为所
  3. Android gradle build 修改文件名称及目
  4. android教父高焕堂 成都之行
  5. 处理ArcGIS Android工程和ADT v17中的依
  6. 【Android】源码分析 - Handler消息机制
  7. 一个简单的Android进程管理器(初稿)
  8. 花了 6 个月整理了 100 篇 Android 干货
  9. Android教父高焕堂:开源只是手段,开放才是
  10. Android 程式开发:(一)详解Activity —— 1.