1

我尝试使用 UserManager 而不是 DevicePolicyManager 创建托管用户。但日志显示

无法为用户 android 0 添加更多托管配置文件

下面的代码(AOSP 代码)总是返回错误(UserManagerService.java)(https://android.googlesource.com/platform/frameworks/base/+/a029ea1/services/java/com/android/server/pm/UserManagerService .java )

“hasSystemFeature 错误”

@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>
4

0 回答 0