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

Commit f3ece365 authored by Benjamin Franz's avatar Benjamin Franz
Browse files

Block setting wallpapers from managed profiles.

Silently fail when a managed profile app tries to change the
wallpaper and return default values for getters in that case.
This is implemented through a new AppOp that is controlled by
a new user restriction that will be set during provisioning.

Bug: 18725052
Change-Id: I1601852617e738be86560f054daf3435dd9f5a9f
parent b3ec733b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5369,6 +5369,7 @@ package android.app {
    method public static android.app.WallpaperManager getInstance(android.content.Context);
    method public android.app.WallpaperInfo getWallpaperInfo();
    method public boolean hasResourceWallpaper(int);
    method public boolean isWallpaperSupported();
    method public android.graphics.drawable.Drawable peekDrawable();
    method public android.graphics.drawable.Drawable peekFastDrawable();
    method public void sendWallpaperCommand(android.os.IBinder, java.lang.String, int, int, int, android.os.Bundle);
+1 −0
Original line number Diff line number Diff line
@@ -5460,6 +5460,7 @@ package android.app {
    method public static android.app.WallpaperManager getInstance(android.content.Context);
    method public android.app.WallpaperInfo getWallpaperInfo();
    method public boolean hasResourceWallpaper(int);
    method public boolean isWallpaperSupported();
    method public android.graphics.drawable.Drawable peekDrawable();
    method public android.graphics.drawable.Drawable peekFastDrawable();
    method public void sendWallpaperCommand(android.os.IBinder, java.lang.String, int, int, int, android.os.Bundle);
+11 −1
Original line number Diff line number Diff line
@@ -206,8 +206,10 @@ public class AppOpsManager {
    public static final int OP_PROJECT_MEDIA = 46;
    /** @hide Activate a VPN connection without user intervention. */
    public static final int OP_ACTIVATE_VPN = 47;
    /** @hide Access the WallpaperManagerAPI to write wallpapers. */
    public static final int OP_WRITE_WALLPAPER = 48;
    /** @hide */
    public static final int _NUM_OP = 48;
    public static final int _NUM_OP = 49;

    /** Access to coarse location information. */
    public static final String OPSTR_COARSE_LOCATION =
@@ -285,6 +287,7 @@ public class AppOpsManager {
            OP_TOAST_WINDOW,
            OP_PROJECT_MEDIA,
            OP_ACTIVATE_VPN,
            OP_WRITE_WALLPAPER,
    };

    /**
@@ -340,6 +343,7 @@ public class AppOpsManager {
            null,
            null,
            OPSTR_ACTIVATE_VPN,
            null,
    };

    /**
@@ -395,6 +399,7 @@ public class AppOpsManager {
            "TOAST_WINDOW",
            "PROJECT_MEDIA",
            "ACTIVATE_VPN",
            "WRITE_WALLPAPER",
    };

    /**
@@ -450,6 +455,7 @@ public class AppOpsManager {
            null, // no permission for displaying toasts
            null, // no permission for projecting media
            null, // no permission for activating vpn
            null, // no permission for supporting wallpaper
    };

    /**
@@ -506,6 +512,7 @@ public class AppOpsManager {
            UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW
            null, //PROJECT_MEDIA
            UserManager.DISALLOW_CONFIG_VPN, // ACTIVATE_VPN
            UserManager.DISALLOW_WALLPAPER, // WRITE_WALLPAPER
    };

    /**
@@ -561,6 +568,7 @@ public class AppOpsManager {
            true, //TOAST_WINDOW
            false, //PROJECT_MEDIA
            false, //ACTIVATE_VPN
            false, //WALLPAPER
    };

    /**
@@ -615,6 +623,7 @@ public class AppOpsManager {
            AppOpsManager.MODE_ALLOWED,
            AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA
            AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
            AppOpsManager.MODE_ALLOWED,
    };

    /**
@@ -673,6 +682,7 @@ public class AppOpsManager {
            false,
            false,
            false,
            false,
    };

    private static HashMap<String, Integer> sOpStrToOp = new HashMap<String, Integer>();
+15 −5
Original line number Diff line number Diff line
@@ -29,7 +29,12 @@ interface IWallpaperManager {
    /**
     * Set the wallpaper.
     */
    ParcelFileDescriptor setWallpaper(String name);
    ParcelFileDescriptor setWallpaper(String name, in String callingPackage);
    
    /**
     * Set the live wallpaper.
     */
    void setWallpaperComponentChecked(in ComponentName name, in String callingPackage);

    /**
     * Set the live wallpaper.
@@ -50,7 +55,7 @@ interface IWallpaperManager {
    /**
     * Clear the wallpaper.
     */
    void clearWallpaper();
    void clearWallpaper(in String callingPackage);

    /**
     * Return whether there is a wallpaper set with the given name.
@@ -61,7 +66,7 @@ interface IWallpaperManager {
     * Sets the dimension hint for the wallpaper. These hints indicate the desired
     * minimum width and height for the wallpaper.
     */
    void setDimensionHints(in int width, in int height);
    void setDimensionHints(in int width, in int height, in String callingPackage);

    /**
     * Returns the desired minimum width for the wallpaper.
@@ -76,7 +81,7 @@ interface IWallpaperManager {
    /**
     * Sets extra padding that we would like the wallpaper to have outside of the display.
     */
    void setDisplayPadding(in Rect padding);
    void setDisplayPadding(in Rect padding, in String callingPackage);

    /**
     * Returns the name of the wallpaper. Private API.
@@ -87,4 +92,9 @@ interface IWallpaperManager {
     * Informs the service that wallpaper settings have been restored. Private API.
     */
    void settingsRestored();

    /**
     * Check whether wallpapers are supported for the calling user.
     */
    boolean isWallpaperSupported(in String callingPackage);
}
+44 −10
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ import java.util.List;
 * get the current wallpaper, get the desired dimensions for the wallpaper, set
 * the wallpaper, and more. Get an instance of WallpaperManager with
 * {@link #getInstance(android.content.Context) getInstance()}.
 *
 * <p> An app can check whether wallpapers are supported for the current user, by calling
 * {@link #isWallpaperSupported()}.
 */
public class WallpaperManager {
    private static String TAG = "WallpaperManager";
@@ -249,6 +252,15 @@ public class WallpaperManager {

        public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault) {
            synchronized (this) {
                if (mService != null) {
                    try {
                        if (!mService.isWallpaperSupported(context.getOpPackageName())) {
                            return null;
                        }
                    } catch (RemoteException e) {
                        // Ignore
                    }
                }
                if (mWallpaper != null) {
                    return mWallpaper;
                }
@@ -618,8 +630,10 @@ public class WallpaperManager {
     * wallpaper will require reloading it again from disk.
     */
    public void forgetLoadedWallpaper() {
        if (isWallpaperSupported()) {
            sGlobals.forgetLoadedWallpaper();
        }
    }

    /**
     * If the current wallpaper is a live wallpaper component, return the
@@ -717,7 +731,7 @@ public class WallpaperManager {
            Resources resources = mContext.getResources();
            /* Set the wallpaper to the default values */
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(
                    "res:" + resources.getResourceName(resid));
                    "res:" + resources.getResourceName(resid), mContext.getOpPackageName());
            if (fd != null) {
                FileOutputStream fos = null;
                try {
@@ -753,7 +767,8 @@ public class WallpaperManager {
            return;
        }
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null);
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
                    mContext.getOpPackageName());
            if (fd == null) {
                return;
            }
@@ -792,7 +807,8 @@ public class WallpaperManager {
            return;
        }
        try {
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null);
            ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null,
                    mContext.getOpPackageName());
            if (fd == null) {
                return;
            }
@@ -945,7 +961,8 @@ public class WallpaperManager {
            if (sGlobals.mService == null) {
                Log.w(TAG, "WallpaperService not running");
            } else {
                sGlobals.mService.setDimensionHints(minimumWidth, minimumHeight);
                sGlobals.mService.setDimensionHints(minimumWidth, minimumHeight,
                        mContext.getOpPackageName());
            }
        } catch (RemoteException e) {
            // Ignore
@@ -966,7 +983,7 @@ public class WallpaperManager {
            if (sGlobals.mService == null) {
                Log.w(TAG, "WallpaperService not running");
            } else {
                sGlobals.mService.setDisplayPadding(padding);
                sGlobals.mService.setDisplayPadding(padding, mContext.getOpPackageName());
            }
        } catch (RemoteException e) {
            // Ignore
@@ -1006,7 +1023,7 @@ public class WallpaperManager {
            return;
        }
        try {
            sGlobals.mService.clearWallpaper();
            sGlobals.mService.clearWallpaper(mContext.getOpPackageName());
        } catch (RemoteException e) {
            // Ignore
        }
@@ -1027,7 +1044,7 @@ public class WallpaperManager {
            return false;
        }
        try {
            sGlobals.mService.setWallpaperComponent(name);
            sGlobals.mService.setWallpaperComponentChecked(name, mContext.getOpPackageName());
            return true;
        } catch (RemoteException e) {
            // Ignore
@@ -1097,6 +1114,23 @@ public class WallpaperManager {
        }
    }

    /**
     * Returns whether wallpapers are supported for the calling user. If this function returns
     * false, any attempts to changing the wallpaper will have no effect.
     */
    public boolean isWallpaperSupported() {
        if (sGlobals.mService == null) {
            Log.w(TAG, "WallpaperService not running");
        } else {
            try {
                return sGlobals.mService.isWallpaperSupported(mContext.getOpPackageName());
            } catch (RemoteException e) {
                // Ignore
            }
        }
        return false;
    }

    /**
     * Clear the offsets previously associated with this window through
     * {@link #setWallpaperOffsets(IBinder, float, float)}.  This reverts
Loading