diff options
author | Benjamin Franz <bfranz@google.com> | 2015-02-11 10:51:10 +0000 |
---|---|---|
committer | Benjamin Franz <bfranz@google.com> | 2015-03-09 10:39:21 +0000 |
commit | f3ece36535d4999cf2bfd2175a33da6c3cdf298e (patch) | |
tree | 3968fb249921a6e7cf86bead062f437991e44070 /core/java/android/app/WallpaperManager.java | |
parent | b3ec733bb830f2d4425825d93f9ed95f284e9145 (diff) | |
download | frameworks_base-f3ece36535d4999cf2bfd2175a33da6c3cdf298e.zip frameworks_base-f3ece36535d4999cf2bfd2175a33da6c3cdf298e.tar.gz frameworks_base-f3ece36535d4999cf2bfd2175a33da6c3cdf298e.tar.bz2 |
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
Diffstat (limited to 'core/java/android/app/WallpaperManager.java')
-rw-r--r-- | core/java/android/app/WallpaperManager.java | 54 |
1 files changed, 44 insertions, 10 deletions
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index badb606..22e79b6 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -64,7 +64,10 @@ import java.util.List; * Provides access to the system wallpaper. With WallpaperManager, you can * 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()}. + * {@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,7 +630,9 @@ public class WallpaperManager { * wallpaper will require reloading it again from disk. */ public void forgetLoadedWallpaper() { - sGlobals.forgetLoadedWallpaper(); + if (isWallpaperSupported()) { + sGlobals.forgetLoadedWallpaper(); + } } /** @@ -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 @@ -1096,7 +1113,24 @@ public class WallpaperManager { // Ignore. } } - + + /** + * 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 |