Android Multi-User
2015-07-03 16:19
771 查看
How to check whether current user is owner
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.
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).
By reflection:
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)
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 remount adb shell "echo 'fw.max_users=3' >> /system/build.prop" adb shell "echo 'fw.show_multiuserui=1' >> /system/build.prop" adb reboot Adding and switching users from Settings > Users
相关文章推荐
- Mac配置Android adb环境
- Android自定义ProgressDialog样式
- Android实现背景音乐的播放
- Android自定义ProgressDialog样式 分类: Android 2015-07-03 16:17 12人阅读 评论(0) 收藏
- android 调试笔记
- Android5.0L下因sensorservice crash导致systemserver重启的另外一种场景分析
- Android 抓包使用
- AndroidManifest.xml——meta-data
- android: listview组件的应用-模拟微博
- Android gitHub 开源
- android View 详解
- Android中的加密技术
- Android开发(十一)——ImageView的尺寸设置scaleType
- Android开发(十)——像素单位dp、px、pt、sp的比较
- Android开发(九)——ViewFlipper实现图片轮播
- Android开发(八)——Android组件
- Android开发(六)——组件颜色Selector(Selector与Shape的基本用法 )
- Android repository 下载地址
- Viewpager实现图片轮播,广告轮播
- Android开发(五)——计时器