Cannot add more managed profiles for user 0

804 Views Asked by At

I tried to create managed user using UserManager instead of DevicePolicyManager.But the log is showing

Cannot add more managed profiles for user android 0

The below code (AOSP code) is returning always 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();
    }
}

The feature is enabled using below configuration. But not working

https://android.googlesource.com/platform/frameworks/native/+/master/data/etc/android.software.managed_users.xml

<permissions>
 <feature name="android.software.managed_users" />
</permissions>
0

There are 0 best solutions below