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

Commit ee435ebc authored by Vania Desmonda's avatar Vania Desmonda Committed by Android (Google) Code Review
Browse files

Merge "Add ADB shell command to set dim amount using an arbitrary UID"

parents 22fba15a 3e7c1bd8
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -2591,8 +2591,20 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
     */
    @Override
    public void setWallpaperDimAmount(float dimAmount) throws RemoteException {
        setWallpaperDimAmountForUid(Binder.getCallingUid(), dimAmount);
    }

    /**
     * Sets wallpaper dim amount for a given UID. This only applies to FLAG_SYSTEM wallpaper as the
     * lock screen does not have a wallpaper component, so we use mWallpaperMap.
     *
     * @param uid Caller UID that wants to set the wallpaper dim amount
     * @param dimAmount Dim amount where 0f reverts any dimming applied by the caller (fully bright)
     *                  and 1f is fully black
     * @throws RemoteException
     */
    public void setWallpaperDimAmountForUid(int uid, float dimAmount) {
        checkPermission(android.Manifest.permission.SET_WALLPAPER_DIM_AMOUNT);
        int uid = Binder.getCallingUid();
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (mLock) {
+19 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ public class WallpaperManagerShellCommand extends ShellCommand {
        switch(cmd) {
            case "set-dim-amount":
                return setWallpaperDimAmount();
            case "dim-with-uid":
                return setDimmingWithUid();
            case "get-dim-amount":
                return getWallpaperDimAmount();
            case "-h":
@@ -64,6 +66,10 @@ public class WallpaperManagerShellCommand extends ShellCommand {
        pw.println("  set-dim-amount DIMMING");
        pw.println("    Sets the current dimming value to DIMMING (a number between 0 and 1).");
        pw.println();
        pw.println("  dim-with-uid UID DIMMING");
        pw.println("    Sets the wallpaper dim amount to DIMMING as if an app with uid, UID, "
                + "called it.");
        pw.println();
        pw.println("  get-dim-amount");
        pw.println("    Get the current wallpaper dim amount.");
    }
@@ -92,4 +98,17 @@ public class WallpaperManagerShellCommand extends ShellCommand {
        getOutPrintWriter().println("The current wallpaper dim amount is: " + dimAmount);
        return 0;
    }

    /**
     * Sets the wallpaper dim amount for an arbitrary UID to simulate multiple applications setting
     * a dim amount on the wallpaper.
     */
    private int setDimmingWithUid() {
        int mockUid = Integer.parseInt(getNextArgRequired());
        float mockDimAmount = Float.parseFloat(getNextArgRequired());
        mService.setWallpaperDimAmountForUid(mockUid, mockDimAmount);
        getOutPrintWriter().println("Dimming the wallpaper for UID: " + mockUid + " to: "
                + mockDimAmount);
        return 0;
    }
}