问题描述
我尝试使用 UserManager 而不是 DevicePolicyManager 创建托管用户。但日志正在显示
无法为用户 android 0 添加更多托管配置文件
下面的代码(AOSP 代码)总是返回 false (UserManagerService.java) (https://android.googlesource.com/platform/frameworks/base/+/a029ea1/services/java/com/android/server/pm/UserManagerService.java)
"hasSystemFeature false"
@Override
public boolean canAddMoreManagedProfiles(int userId,boolean allowedToRemoveOne) {
checkManageUsersPermission("check if more managed profiles can be added.");
Log.e(LOG_TAG,"isLowRamDeviceStatic check");
if (ActivityManager.isLowRamDeviceStatic()) {
return false;
}
Log.e(LOG_TAG,"isLowRamDeviceStatic false");
if (!mContext.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_MANAGED_USERS)) {
Log.e(LOG_TAG,"hasSystemFeature false");
return false;
}
Log.e(LOG_TAG,"hasSystemFeature true");
// Limit number of managed profiles that can be created
final int managedProfilesCount = getProfiles(userId,false).size() - 1;
final int profilesRemovedCount = managedProfilesCount > 0 && allowedToRemoveOne ? 1 : 0;
if (managedProfilesCount - profilesRemovedCount >= getMaxManagedProfiles()) {
return false;
}
Log.e(LOG_TAG,"managedProfilesCount "+ managedProfilesCount);
synchronized(mUsersLock) {
UserInfo userInfo = getUserInfoLU(userId);
if (userInfo == null || !userInfo.canHaveProfile()) {
return false;
}
Log.e(LOG_TAG,"getUserInfoLU not null or userInfo.canHaveProfile()");
int usersCountAfterRemoving = getAliveUsersExcludingGuestsCountLU()
- profilesRemovedCount;
// We allow creating a managed profile in the special case where there is only one user.
return usersCountAfterRemoving == 1
|| usersCountAfterRemoving < UserManager.getMaxSupportedUsers();
}
}
使用以下配置启用该功能。但不工作
https://android.googlesource.com/platform/frameworks/native/+/master/data/etc/android.software.managed_users.xml
<permissions>
<feature name="android.software.managed_users" />
</permissions>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)