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

Commit 2e29aa5e authored by Fyodor Kupolov's avatar Fyodor Kupolov Committed by Android (Google) Code Review
Browse files

Merge "Added getUserCreationTime to query user/profile creation time"

parents c8f786b1 ff7233e2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23381,6 +23381,7 @@ package android.os {
    method public android.os.Bundle getApplicationRestrictions(java.lang.String);
    method public long getSerialNumberForUser(android.os.UserHandle);
    method public int getUserCount();
    method public long getUserCreationTime(int);
    method public android.os.UserHandle getUserForSerialNumber(long);
    method public java.lang.String getUserName();
    method public java.util.List<android.os.UserHandle> getUserProfiles();
+1 −0
Original line number Diff line number Diff line
@@ -25264,6 +25264,7 @@ package android.os {
    method public android.os.Bundle getApplicationRestrictions(java.lang.String);
    method public long getSerialNumberForUser(android.os.UserHandle);
    method public int getUserCount();
    method public long getUserCreationTime(int);
    method public android.os.UserHandle getUserForSerialNumber(long);
    method public java.lang.String getUserName();
    method public java.util.List<android.os.UserHandle> getUserProfiles();
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ interface IUserManager {
    List<UserInfo> getProfiles(int userHandle, boolean enabledOnly);
    UserInfo getProfileParent(int userHandle);
    UserInfo getUserInfo(int userHandle);
    long getUserCreationTime(int userHandle);
    boolean isRestricted();
    int getUserSerialNumber(int userHandle);
    int getUserHandle(int userSerialNumber);
+15 −0
Original line number Diff line number Diff line
@@ -1320,4 +1320,19 @@ public class UserManager {
        }
        return new Bundle();
    }

    /**
     * Returns creation time of the user or of a managed profile associated with the calling user.
     * @param userHandle user handle of the user or a managed profile associated with the
     *                   calling user.
     * @return creation time in milliseconds since Epoch time.
     */
    public long getUserCreationTime(int userHandle) {
        try {
            return mService.getUserCreationTime(userHandle);
        } catch (RemoteException re) {
            Log.w(TAG, "Could not get user creation time", re);
            return 0;
        }
    }
}
+35 −10
Original line number Diff line number Diff line
@@ -327,6 +327,11 @@ public class UserManagerService extends IUserManager.Stub {
    public UserInfo getProfileParent(int userHandle) {
        checkManageUsersPermission("get the profile parent");
        synchronized (mPackagesLock) {
            return getProfileParentLocked(userHandle);
        }
    }

    private UserInfo getProfileParentLocked(int userHandle) {
        UserInfo profile = getUserInfoLocked(userHandle);
        if (profile == null) {
            return null;
@@ -338,7 +343,6 @@ public class UserManagerService extends IUserManager.Stub {
            return getUserInfoLocked(parentUserId);
        }
    }
    }

    private boolean isProfileOf(UserInfo user, UserInfo profile) {
        return user.id == profile.id ||
@@ -1867,6 +1871,27 @@ public class UserManagerService extends IUserManager.Stub {
        }
    }

    @Override
    public long getUserCreationTime(int userHandle) {
        int callingUserId = UserHandle.getCallingUserId();
        UserInfo userInfo = null;
        synchronized (mPackagesLock) {
            if (callingUserId == userHandle) {
                userInfo = getUserInfoLocked(userHandle);
            } else {
                UserInfo parent = getProfileParentLocked(userHandle);
                if (parent != null && parent.id == callingUserId) {
                    userInfo = getUserInfoLocked(userHandle);
                }
            }
        }
        if (userInfo == null) {
            throw new SecurityException("userHandle can only be the calling user or a managed "
                    + "profile associated with this user");
        }
        return userInfo.creationTime;
    }

    /**
     * Caches the list of user ids in an array, adjusting the array size when necessary.
     */
Loading