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

Commit cfc5d19e authored by Bookatz's avatar Bookatz
Browse files

Fix isSetWallpaperAllowed secondary user

isSetWallpaperAllowed calls hasUserRestriction
which has a permission check that was violated
because isSetWallpaperAllowed was calling from
the wrong user (the system rather than the
original caller).

Bug: 143958690
Test: Go to seconary user and try to change wallpaper
Change-Id: I42f8ed17fb76cb6f84d0c11266f163356656c0ac
parent bbf394bf
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ import android.os.SELinux;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManagerInternal;
import android.os.storage.StorageManager;
import android.service.wallpaper.IWallpaperConnection;
import android.service.wallpaper.IWallpaperEngine;
@@ -2747,12 +2748,19 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            return false;   // callingPackage was faked.
        }

        // TODO(b/144048540): DPM needs to take into account the userId, not just the package.
        final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class);
        if (dpm.isDeviceOwnerApp(callingPackage) || dpm.isProfileOwnerApp(callingPackage)) {
            return true;
        }
        final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        return !um.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER);
        final int callingUserId = UserHandle.getCallingUserId();
        final long ident = Binder.clearCallingIdentity();
        try {
            UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class);
            return !umi.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER, callingUserId);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    @Override