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

Commit 601d3e82 authored by Felipe Leme's avatar Felipe Leme
Browse files

Fixes some DPM APIs to use the context user.

This APIs are primarily used by CarService, which always runs as
system user, so they cannot rely on the calling user id.

Test: atest CtsDevicePolicyManagerTestCases com.android.cts.devicepolicy.DeviceOwnerTest#testCreateAndManageUser_newUserDisclaimer # on automotive and phone

Test: manual verification

Change-Id: I56bb8cd12be766ef9da6c71a524912f7f8680aad
parent badac481
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -3585,10 +3585,11 @@ public class DevicePolicyManager {
    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.INTERACT_ACROSS_USERS})
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    @UserHandleAware
    public void acknowledgeNewUserDisclaimer() {
        if (mService != null) {
            try {
                mService.acknowledgeNewUserDisclaimer();
                mService.acknowledgeNewUserDisclaimer(mContext.getUserId());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -3596,17 +3597,18 @@ public class DevicePolicyManager {
    }
    /**
     * Checks whether the new managed user disclaimer was viewed by the current user.
     * Checks whether the new managed user disclaimer was viewed by the user.
     *
     * @hide
     */
    @RequiresPermission(anyOf = {android.Manifest.permission.MANAGE_USERS,
            android.Manifest.permission.INTERACT_ACROSS_USERS})
    @TestApi
    @UserHandleAware
    public boolean isNewUserDisclaimerAcknowledged() {
        if (mService != null) {
            try {
                return mService.isNewUserDisclaimerAcknowledged();
                return mService.isNewUserDisclaimerAcknowledged(mContext.getUserId());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
+2 −2
Original line number Diff line number Diff line
@@ -271,8 +271,8 @@ interface IDevicePolicyManager {
    int logoutUserInternal(); // AIDL doesn't allow overloading name (logoutUser())
    int getLogoutUserId();
    List<UserHandle> getSecondaryUsers(in ComponentName who);
    void acknowledgeNewUserDisclaimer();
    boolean isNewUserDisclaimerAcknowledged();
    void acknowledgeNewUserDisclaimer(int userId);
    boolean isNewUserDisclaimerAcknowledged(int userId);

    void enableSystemApp(in ComponentName admin, in String callerPackage, in String packageName);
    int enableSystemAppWithIntent(in ComponentName admin, in String callerPackage, in Intent intent);
+3 −5
Original line number Diff line number Diff line
@@ -10982,13 +10982,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    @Override
    public void acknowledgeNewUserDisclaimer() {
    public void acknowledgeNewUserDisclaimer(@UserIdInt int userId) {
        CallerIdentity callerIdentity = getCallerIdentity();
        Preconditions.checkCallAuthorization(canManageUsers(callerIdentity)
                || hasCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS));
        setShowNewUserDisclaimer(callerIdentity.getUserId(),
                DevicePolicyData.NEW_USER_DISCLAIMER_ACKNOWLEDGED);
        setShowNewUserDisclaimer(userId, DevicePolicyData.NEW_USER_DISCLAIMER_ACKNOWLEDGED);
    }
    private void setShowNewUserDisclaimer(@UserIdInt int userId, String value) {
@@ -11021,11 +11020,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    }
    @Override
    public boolean isNewUserDisclaimerAcknowledged() {
    public boolean isNewUserDisclaimerAcknowledged(@UserIdInt int userId) {
        CallerIdentity callerIdentity = getCallerIdentity();
        Preconditions.checkCallAuthorization(canManageUsers(callerIdentity)
                || hasCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS));
        int userId = callerIdentity.getUserId();
        synchronized (getLockObject()) {
            DevicePolicyData policyData = getUserData(userId);
            return policyData.isNewUserDisclaimerAcknowledged();