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

Commit 0951b28b authored by Alex Johnston's avatar Alex Johnston
Browse files

Make getCredentialManagerPolicy user handle aware

Bug: 294228721
Test: android.credentials.cts.CtsDevicePolicyTest
Change-Id: I167238e9cccb818643bc491ef56d40e042d80035
Merged-In: I167238e9cccb818643bc491ef56d40e042d80035
parent 1b2a424f
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -10335,11 +10335,14 @@ public class DevicePolicyManager {
     * @return the current credential manager policy if null then this policy has not been
     * configured.
     */
    @UserHandleAware(
            enabledSinceTargetSdkVersion = UPSIDE_DOWN_CAKE,
            requiresPermissionIfNotCaller = INTERACT_ACROSS_USERS)
    public @Nullable PackagePolicy getCredentialManagerPolicy() {
        throwIfParentInstance("getCredentialManagerPolicy");
        if (mService != null) {
            try {
                return mService.getCredentialManagerPolicy();
                return mService.getCredentialManagerPolicy(myUserId());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
+1 −1
Original line number Diff line number Diff line
@@ -344,7 +344,7 @@ interface IDevicePolicyManager {
    boolean hasManagedProfileCallerIdAccess(int userId, String packageName);

    void setCredentialManagerPolicy(in PackagePolicy policy);
    PackagePolicy getCredentialManagerPolicy();
    PackagePolicy getCredentialManagerPolicy(int userId);

    void setManagedProfileContactsAccessPolicy(in PackagePolicy policy);
    PackagePolicy getManagedProfileContactsAccessPolicy();
+6 −2
Original line number Diff line number Diff line
@@ -16646,16 +16646,20 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
    }
    @Override
    public PackagePolicy getCredentialManagerPolicy() {
    public PackagePolicy getCredentialManagerPolicy(int userId) {
        if (!mHasFeature) {
            return null;
        }
        final CallerIdentity caller = getCallerIdentity();
        Preconditions.checkCallAuthorization(
                canWriteCredentialManagerPolicy(caller) || canQueryAdminPolicy(caller));
        if (userId != caller.getUserId()) {
            Preconditions.checkCallAuthorization(
                    hasCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS));
        }
        synchronized (getLockObject()) {
            ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(caller.getUserId());
            ActiveAdmin admin = getProfileOwnerOrDeviceOwnerLocked(userId);
            return (admin != null) ? admin.mCredentialManagerPolicy : null;
        }
    }