Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e46f4690 authored by Felipe Leme's avatar Felipe Leme
Browse files

DPMS: fixes calls to getMainUser()

It can return null, which was causing NPE on phone.

Test: build / boot / sys UI doesn't crash
Fixes: 265846998

Change-Id: I5659e9d9015aae8256dc34bc0492796c400cc4ca
parent 6c692638
Loading
Loading
Loading
Loading
+11 −2
Original line number Original line Diff line number Diff line
@@ -1092,13 +1092,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                // (ACTION_DATE_CHANGED), or when manual clock adjustment is made
                // (ACTION_DATE_CHANGED), or when manual clock adjustment is made
                // (ACTION_TIME_CHANGED)
                // (ACTION_TIME_CHANGED)
                updateSystemUpdateFreezePeriodsRecord(/* saveIfChanged */ true);
                updateSystemUpdateFreezePeriodsRecord(/* saveIfChanged */ true);
                final int userId = getManagedUserId(mUserManager.getMainUser().getIdentifier());
                final int userId = getManagedUserId(getMainUserId());
                if (userId >= 0) {
                if (userId >= 0) {
                    updatePersonalAppsSuspension(userId, mUserManager.isUserUnlocked(userId));
                    updatePersonalAppsSuspension(userId, mUserManager.isUserUnlocked(userId));
                }
                }
            } else if (ACTION_PROFILE_OFF_DEADLINE.equals(action)) {
            } else if (ACTION_PROFILE_OFF_DEADLINE.equals(action)) {
                Slogf.i(LOG_TAG, "Profile off deadline alarm was triggered");
                Slogf.i(LOG_TAG, "Profile off deadline alarm was triggered");
                final int userId = getManagedUserId(mUserManager.getMainUser().getIdentifier());
                final int userId = getManagedUserId(getMainUserId());
                if (userId >= 0) {
                if (userId >= 0) {
                    updatePersonalAppsSuspension(userId, mUserManager.isUserUnlocked(userId));
                    updatePersonalAppsSuspension(userId, mUserManager.isUserUnlocked(userId));
                } else {
                } else {
@@ -8880,6 +8880,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        }
        }
    }
    }
    private @UserIdInt int getMainUserId() {
        UserHandle mainUser = mUserManager.getMainUser();
        if (mainUser == null) {
            Slogf.d(LOG_TAG, "getMainUserId(): no main user, returning USER_SYSTEM");
            return UserHandle.USER_SYSTEM;
        }
        return mainUser.getIdentifier();
    }
    // TODO(b/240562946): Remove api as owner name is not used.
    // TODO(b/240562946): Remove api as owner name is not used.
    /**
    /**
     * Returns the "name" of the device owner.  It'll work for non-DO users too, but requires
     * Returns the "name" of the device owner.  It'll work for non-DO users too, but requires