Add default lock wallpaper capability and API

If present, the system property "ro.config.lock_wallpaper" provides a
filesystem path to a decodeable image file to use as the system's
out-of-the-box lock wallpaper imagery.  In the absence of this
system property, or if the indicated file is absent or unreadable,
then the new framework resource
com.android.internal.R.drawable.default_lock_wallpaper is consulted to
locate a usable asset.  This mechanism parallels the existing one for
the default system wallpaper.

By default there is no specific lock wallpaper asset; the resource is
defined to be @null in the standard config.xml file.  A product that
wants to define such a factory-default lock-only wallpaper image
will provide the asset as part of its framework resource overlay.

Bug 27828056

Change-Id: Iebf3706222370d0a0a4baf88d71a59ead07a25c7
This commit is contained in:
Christopher Tate
2016-05-06 17:59:27 -07:00
committed by Chris Tate
parent b100777562
commit 5d99d47f39
6 changed files with 116 additions and 42 deletions

View File

@@ -5773,7 +5773,9 @@ package android.app {
method public void clearWallpaperOffsets(android.os.IBinder); method public void clearWallpaperOffsets(android.os.IBinder);
method public void forgetLoadedWallpaper(); method public void forgetLoadedWallpaper();
method public android.graphics.drawable.Drawable getBuiltInDrawable(); method public android.graphics.drawable.Drawable getBuiltInDrawable();
method public android.graphics.drawable.Drawable getBuiltInDrawable(int);
method public android.graphics.drawable.Drawable getBuiltInDrawable(int, int, boolean, float, float); method public android.graphics.drawable.Drawable getBuiltInDrawable(int, int, boolean, float, float);
method public android.graphics.drawable.Drawable getBuiltInDrawable(int, int, boolean, float, float, int);
method public android.content.Intent getCropAndSetWallpaperIntent(android.net.Uri); method public android.content.Intent getCropAndSetWallpaperIntent(android.net.Uri);
method public int getDesiredMinimumHeight(); method public int getDesiredMinimumHeight();
method public int getDesiredMinimumWidth(); method public int getDesiredMinimumWidth();

View File

@@ -5922,7 +5922,9 @@ package android.app {
method public void clearWallpaperOffsets(android.os.IBinder); method public void clearWallpaperOffsets(android.os.IBinder);
method public void forgetLoadedWallpaper(); method public void forgetLoadedWallpaper();
method public android.graphics.drawable.Drawable getBuiltInDrawable(); method public android.graphics.drawable.Drawable getBuiltInDrawable();
method public android.graphics.drawable.Drawable getBuiltInDrawable(int);
method public android.graphics.drawable.Drawable getBuiltInDrawable(int, int, boolean, float, float); method public android.graphics.drawable.Drawable getBuiltInDrawable(int, int, boolean, float, float);
method public android.graphics.drawable.Drawable getBuiltInDrawable(int, int, boolean, float, float, int);
method public android.content.Intent getCropAndSetWallpaperIntent(android.net.Uri); method public android.content.Intent getCropAndSetWallpaperIntent(android.net.Uri);
method public int getDesiredMinimumHeight(); method public int getDesiredMinimumHeight();
method public int getDesiredMinimumWidth(); method public int getDesiredMinimumWidth();

View File

@@ -5779,7 +5779,9 @@ package android.app {
method public void clearWallpaperOffsets(android.os.IBinder); method public void clearWallpaperOffsets(android.os.IBinder);
method public void forgetLoadedWallpaper(); method public void forgetLoadedWallpaper();
method public android.graphics.drawable.Drawable getBuiltInDrawable(); method public android.graphics.drawable.Drawable getBuiltInDrawable();
method public android.graphics.drawable.Drawable getBuiltInDrawable(int);
method public android.graphics.drawable.Drawable getBuiltInDrawable(int, int, boolean, float, float); method public android.graphics.drawable.Drawable getBuiltInDrawable(int, int, boolean, float, float);
method public android.graphics.drawable.Drawable getBuiltInDrawable(int, int, boolean, float, float, int);
method public android.content.Intent getCropAndSetWallpaperIntent(android.net.Uri); method public android.content.Intent getCropAndSetWallpaperIntent(android.net.Uri);
method public int getDesiredMinimumHeight(); method public int getDesiredMinimumHeight();
method public int getDesiredMinimumWidth(); method public int getDesiredMinimumWidth();

View File

@@ -26,6 +26,7 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder; import android.graphics.BitmapRegionDecoder;
@@ -86,6 +87,8 @@ public class WallpaperManager {
/** {@hide} */ /** {@hide} */
private static final String PROP_WALLPAPER = "ro.config.wallpaper"; private static final String PROP_WALLPAPER = "ro.config.wallpaper";
/** {@hide} */ /** {@hide} */
private static final String PROP_LOCK_WALLPAPER = "ro.config.lock_wallpaper";
/** {@hide} */
private static final String PROP_WALLPAPER_COMPONENT = "ro.config.wallpaper_component"; private static final String PROP_WALLPAPER_COMPONENT = "ro.config.wallpaper_component";
/** /**
@@ -157,7 +160,7 @@ public class WallpaperManager {
*/ */
public static final String EXTRA_NEW_WALLPAPER_ID = "android.service.wallpaper.extra.ID"; public static final String EXTRA_NEW_WALLPAPER_ID = "android.service.wallpaper.extra.ID";
// flags for which kind of wallpaper to set // flags for which kind of wallpaper to act on
/** @hide */ /** @hide */
@IntDef(flag = true, value = { @IntDef(flag = true, value = {
@@ -168,12 +171,12 @@ public class WallpaperManager {
public @interface SetWallpaperFlags {} public @interface SetWallpaperFlags {}
/** /**
* Flag: use the supplied imagery as the general system wallpaper. * Flag: set or retrieve the general system wallpaper.
*/ */
public static final int FLAG_SYSTEM = 1 << 0; public static final int FLAG_SYSTEM = 1 << 0;
/** /**
* Flag: use the supplied imagery as the lock-screen wallpaper. * Flag: set or retrieve the lock-screen-specific wallpaper.
*/ */
public static final int FLAG_LOCK = 1 << 1; public static final int FLAG_LOCK = 1 << 1;
@@ -281,11 +284,13 @@ public class WallpaperManager {
forgetLoadedWallpaper(); forgetLoadedWallpaper();
} }
public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault) { public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault,
return peekWallpaperBitmap(context, returnDefault, context.getUserId()); @SetWallpaperFlags int which) {
return peekWallpaperBitmap(context, returnDefault, which, context.getUserId());
} }
public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault, int userId) { public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault,
@SetWallpaperFlags int which, int userId) {
synchronized (this) { synchronized (this) {
if (mService != null) { if (mService != null) {
try { try {
@@ -312,7 +317,7 @@ public class WallpaperManager {
} }
if (returnDefault) { if (returnDefault) {
if (mDefaultWallpaper == null) { if (mDefaultWallpaper == null) {
mDefaultWallpaper = getDefaultWallpaperLocked(context); mDefaultWallpaper = getDefaultWallpaperLocked(context, which);
} }
return mDefaultWallpaper; return mDefaultWallpaper;
} }
@@ -355,8 +360,8 @@ public class WallpaperManager {
return null; return null;
} }
private Bitmap getDefaultWallpaperLocked(Context context) { private Bitmap getDefaultWallpaperLocked(Context context, @SetWallpaperFlags int which) {
InputStream is = openDefaultWallpaper(context); InputStream is = openDefaultWallpaper(context, which);
if (is != null) { if (is != null) {
try { try {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();
@@ -410,7 +415,7 @@ public class WallpaperManager {
* @return Returns a Drawable object that will draw the wallpaper. * @return Returns a Drawable object that will draw the wallpaper.
*/ */
public Drawable getDrawable() { public Drawable getDrawable() {
Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true); Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM);
if (bm != null) { if (bm != null) {
Drawable dr = new BitmapDrawable(mContext.getResources(), bm); Drawable dr = new BitmapDrawable(mContext.getResources(), bm);
dr.setDither(false); dr.setDither(false);
@@ -420,11 +425,22 @@ public class WallpaperManager {
} }
/** /**
* Returns a drawable for the system built-in static wallpaper . * Obtain a drawable for the built-in static system wallpaper.
*
*/ */
public Drawable getBuiltInDrawable() { public Drawable getBuiltInDrawable() {
return getBuiltInDrawable(0, 0, false, 0, 0); return getBuiltInDrawable(0, 0, false, 0, 0, FLAG_SYSTEM);
}
/**
* Obtain a drawable for the specified built-in static system wallpaper.
*
* @param which The {@code FLAG_*} identifier of a valid wallpaper type. Throws
* IllegalArgumentException if an invalid wallpaper is requested.
* @return A Drawable presenting the specified wallpaper image, or {@code null}
* if no built-in default image for that wallpaper type exists.
*/
public Drawable getBuiltInDrawable(@SetWallpaperFlags int which) {
return getBuiltInDrawable(0, 0, false, 0, 0, which);
} }
/** /**
@@ -438,30 +454,61 @@ public class WallpaperManager {
* 0 for left-aligned, 0.5 for horizontal center-aligned, and 1 for right-aligned * 0 for left-aligned, 0.5 for horizontal center-aligned, and 1 for right-aligned
* @param verticalAlignment A float value between 0 and 1 specifying where to crop the image; * @param verticalAlignment A float value between 0 and 1 specifying where to crop the image;
* 0 for top-aligned, 0.5 for vertical center-aligned, and 1 for bottom-aligned * 0 for top-aligned, 0.5 for vertical center-aligned, and 1 for bottom-aligned
* * @return A Drawable presenting the built-in default system wallpaper image,
* or {@code null} if no such default image is defined on this device.
*/ */
public Drawable getBuiltInDrawable(int outWidth, int outHeight, public Drawable getBuiltInDrawable(int outWidth, int outHeight,
boolean scaleToFit, float horizontalAlignment, float verticalAlignment) { boolean scaleToFit, float horizontalAlignment, float verticalAlignment) {
return getBuiltInDrawable(outWidth, outHeight, scaleToFit,
horizontalAlignment, verticalAlignment, FLAG_SYSTEM);
}
/**
* Returns a drawable for the built-in static wallpaper of the specified type. Based on the
* parameters, the drawable can be cropped and scaled.
*
* @param outWidth The width of the returned drawable
* @param outWidth The height of the returned drawable
* @param scaleToFit If true, scale the wallpaper down rather than just cropping it
* @param horizontalAlignment A float value between 0 and 1 specifying where to crop the image;
* 0 for left-aligned, 0.5 for horizontal center-aligned, and 1 for right-aligned
* @param verticalAlignment A float value between 0 and 1 specifying where to crop the image;
* 0 for top-aligned, 0.5 for vertical center-aligned, and 1 for bottom-aligned
* @param which The {@code FLAG_*} identifier of a valid wallpaper type. Throws
* IllegalArgumentException if an invalid wallpaper is requested.
* @return A Drawable presenting the built-in default wallpaper image of the given type,
* or {@code null} if no default image of that type is defined on this device.
*/
public Drawable getBuiltInDrawable(int outWidth, int outHeight, boolean scaleToFit,
float horizontalAlignment, float verticalAlignment, @SetWallpaperFlags int which) {
if (sGlobals.mService == null) { if (sGlobals.mService == null) {
Log.w(TAG, "WallpaperService not running"); Log.w(TAG, "WallpaperService not running");
return null; return null;
} }
if (which != FLAG_SYSTEM && which != FLAG_LOCK) {
throw new IllegalArgumentException("Must request exactly one kind of wallpaper");
}
Resources resources = mContext.getResources(); Resources resources = mContext.getResources();
horizontalAlignment = Math.max(0, Math.min(1, horizontalAlignment)); horizontalAlignment = Math.max(0, Math.min(1, horizontalAlignment));
verticalAlignment = Math.max(0, Math.min(1, verticalAlignment)); verticalAlignment = Math.max(0, Math.min(1, verticalAlignment));
InputStream is = new BufferedInputStream(openDefaultWallpaper(mContext)); InputStream wpStream = openDefaultWallpaper(mContext, which);
if (wpStream == null) {
if (is == null) { if (DEBUG) {
Log.e(TAG, "default wallpaper input stream is null"); Log.w(TAG, "default wallpaper stream " + which + " is null");
}
return null; return null;
} else { } else {
InputStream is = new BufferedInputStream(wpStream);
if (outWidth <= 0 || outHeight <= 0) { if (outWidth <= 0 || outHeight <= 0) {
Bitmap fullSize = BitmapFactory.decodeStream(is, null, null); Bitmap fullSize = BitmapFactory.decodeStream(is, null, null);
return new BitmapDrawable(resources, fullSize); return new BitmapDrawable(resources, fullSize);
} else { } else {
int inWidth; int inWidth;
int inHeight; int inHeight;
// Just measure this time through...
{ {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; options.inJustDecodeBounds = true;
@@ -475,7 +522,9 @@ public class WallpaperManager {
} }
} }
is = new BufferedInputStream(openDefaultWallpaper(mContext)); // Reopen the stream to do the full decode. We know at this point
// that openDefaultWallpaper() will return non-null.
is = new BufferedInputStream(openDefaultWallpaper(mContext, which));
RectF cropRectF; RectF cropRectF;
@@ -523,16 +572,15 @@ public class WallpaperManager {
} }
if (crop == null) { if (crop == null) {
// BitmapRegionDecoder has failed, try to crop in-memory // BitmapRegionDecoder has failed, try to crop in-memory. We know at
is = new BufferedInputStream(openDefaultWallpaper(mContext)); // this point that openDefaultWallpaper() will return non-null.
is = new BufferedInputStream(openDefaultWallpaper(mContext, which));
Bitmap fullSize = null; Bitmap fullSize = null;
if (is != null) { BitmapFactory.Options options = new BitmapFactory.Options();
BitmapFactory.Options options = new BitmapFactory.Options(); if (scaleDownSampleSize > 1) {
if (scaleDownSampleSize > 1) { options.inSampleSize = scaleDownSampleSize;
options.inSampleSize = scaleDownSampleSize;
}
fullSize = BitmapFactory.decodeStream(is, null, options);
} }
fullSize = BitmapFactory.decodeStream(is, null, options);
if (fullSize != null) { if (fullSize != null) {
crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left, crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left,
roundedTrueCrop.top, roundedTrueCrop.width(), roundedTrueCrop.top, roundedTrueCrop.width(),
@@ -598,7 +646,7 @@ public class WallpaperManager {
* null pointer if these is none. * null pointer if these is none.
*/ */
public Drawable peekDrawable() { public Drawable peekDrawable() {
Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false); Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, FLAG_SYSTEM);
if (bm != null) { if (bm != null) {
Drawable dr = new BitmapDrawable(mContext.getResources(), bm); Drawable dr = new BitmapDrawable(mContext.getResources(), bm);
dr.setDither(false); dr.setDither(false);
@@ -621,7 +669,7 @@ public class WallpaperManager {
* @return Returns a Drawable object that will draw the wallpaper. * @return Returns a Drawable object that will draw the wallpaper.
*/ */
public Drawable getFastDrawable() { public Drawable getFastDrawable() {
Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true); Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM);
if (bm != null) { if (bm != null) {
return new FastBitmapDrawable(bm); return new FastBitmapDrawable(bm);
} }
@@ -636,7 +684,7 @@ public class WallpaperManager {
* wallpaper or a null pointer if these is none. * wallpaper or a null pointer if these is none.
*/ */
public Drawable peekFastDrawable() { public Drawable peekFastDrawable() {
Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false); Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, FLAG_SYSTEM);
if (bm != null) { if (bm != null) {
return new FastBitmapDrawable(bm); return new FastBitmapDrawable(bm);
} }
@@ -658,7 +706,7 @@ public class WallpaperManager {
* @hide * @hide
*/ */
public Bitmap getBitmapAsUser(int userId) { public Bitmap getBitmapAsUser(int userId) {
return sGlobals.peekWallpaperBitmap(mContext, true, userId); return sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, userId);
} }
/** /**
@@ -676,7 +724,7 @@ public class WallpaperManager {
* @see #FLAG_LOCK * @see #FLAG_LOCK
* @see #FLAG_SYSTEM * @see #FLAG_SYSTEM
*/ */
public ParcelFileDescriptor getWallpaperFile(int which) { public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which) {
return getWallpaperFile(which, mContext.getUserId()); return getWallpaperFile(which, mContext.getUserId());
} }
@@ -695,7 +743,7 @@ public class WallpaperManager {
* *
* @hide * @hide
*/ */
public ParcelFileDescriptor getWallpaperFile(int which, int userId) { public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which, int userId) {
if (which != FLAG_SYSTEM && which != FLAG_LOCK) { if (which != FLAG_SYSTEM && which != FLAG_LOCK) {
throw new IllegalArgumentException("Must request exactly one kind of wallpaper"); throw new IllegalArgumentException("Must request exactly one kind of wallpaper");
} }
@@ -751,7 +799,7 @@ public class WallpaperManager {
* @return The positive numeric ID of the current wallpaper of the given kind, * @return The positive numeric ID of the current wallpaper of the given kind,
* or a negative value if no such wallpaper is configured. * or a negative value if no such wallpaper is configured.
*/ */
public int getWallpaperId(int which) { public int getWallpaperId(@SetWallpaperFlags int which) {
return getWallpaperIdForUser(which, mContext.getUserId()); return getWallpaperIdForUser(which, mContext.getUserId());
} }
@@ -760,7 +808,7 @@ public class WallpaperManager {
* is no such wallpaper configured, returns a negative number. * is no such wallpaper configured, returns a negative number.
* @hide * @hide
*/ */
public int getWallpaperIdForUser(int which, int userId) { public int getWallpaperIdForUser(@SetWallpaperFlags int which, int userId) {
try { try {
if (sGlobals.mService == null) { if (sGlobals.mService == null) {
Log.w(TAG, "WallpaperService not running"); Log.w(TAG, "WallpaperService not running");
@@ -1314,7 +1362,7 @@ public class WallpaperManager {
* @hide * @hide
*/ */
@SystemApi @SystemApi
public void clearWallpaper(int which, int userId) { public void clearWallpaper(@SetWallpaperFlags int which, int userId) {
if (sGlobals.mService == null) { if (sGlobals.mService == null) {
Log.w(TAG, "WallpaperService not running"); Log.w(TAG, "WallpaperService not running");
return; return;
@@ -1479,7 +1527,7 @@ public class WallpaperManager {
* wallpaper. * wallpaper.
*/ */
public void clear() throws IOException { public void clear() throws IOException {
setStream(openDefaultWallpaper(mContext)); setStream(openDefaultWallpaper(mContext, FLAG_SYSTEM), null, false);
} }
/** /**
@@ -1492,7 +1540,7 @@ public class WallpaperManager {
* {@link #FLAG_LOCK} * {@link #FLAG_LOCK}
* @throws IOException If an error occurs reverting to the built-in wallpaper. * @throws IOException If an error occurs reverting to the built-in wallpaper.
*/ */
public void clear(int which) throws IOException { public void clear(@SetWallpaperFlags int which) throws IOException {
if ((which & FLAG_SYSTEM) != 0) { if ((which & FLAG_SYSTEM) != 0) {
clear(); clear();
} }
@@ -1504,10 +1552,22 @@ public class WallpaperManager {
/** /**
* Open stream representing the default static image wallpaper. * Open stream representing the default static image wallpaper.
* *
* If the device defines no default wallpaper of the requested kind,
* {@code null} is returned.
*
* @hide * @hide
*/ */
public static InputStream openDefaultWallpaper(Context context) { public static InputStream openDefaultWallpaper(Context context, @SetWallpaperFlags int which) {
final String path = SystemProperties.get(PROP_WALLPAPER); final String whichProp;
final int defaultResId;
if (which == FLAG_LOCK) {
whichProp = PROP_LOCK_WALLPAPER;
defaultResId = com.android.internal.R.drawable.default_lock_wallpaper;
} else {
whichProp = PROP_WALLPAPER;
defaultResId = com.android.internal.R.drawable.default_wallpaper;
}
final String path = SystemProperties.get(whichProp);
if (!TextUtils.isEmpty(path)) { if (!TextUtils.isEmpty(path)) {
final File file = new File(path); final File file = new File(path);
if (file.exists()) { if (file.exists()) {
@@ -1518,8 +1578,12 @@ public class WallpaperManager {
} }
} }
} }
return context.getResources().openRawResource( try {
com.android.internal.R.drawable.default_wallpaper); return context.getResources().openRawResource(defaultResId);
} catch (NotFoundException e) {
// no default defined for this device; this is not a failure
}
return null;
} }
/** /**

View File

@@ -1127,6 +1127,9 @@
specified --> specified -->
<string name="default_wallpaper_component" translatable="false">@null</string> <string name="default_wallpaper_component" translatable="false">@null</string>
<!-- By default a product has no distinct default lock wallpaper -->
<item name="default_lock_wallpaper" type="drawable">@null</item>
<!-- Component name of the built in wallpaper used to display bitmap wallpapers. This must not be null. --> <!-- Component name of the built in wallpaper used to display bitmap wallpapers. This must not be null. -->
<string name="image_wallpaper_component" translatable="false">com.android.systemui/com.android.systemui.ImageWallpaper</string> <string name="image_wallpaper_component" translatable="false">com.android.systemui/com.android.systemui.ImageWallpaper</string>

View File

@@ -1140,6 +1140,7 @@
<java-symbol type="array" name="config_colorTransforms" /> <java-symbol type="array" name="config_colorTransforms" />
<java-symbol type="drawable" name="default_wallpaper" /> <java-symbol type="drawable" name="default_wallpaper" />
<java-symbol type="drawable" name="default_lock_wallpaper" />
<java-symbol type="drawable" name="indicator_input_error" /> <java-symbol type="drawable" name="indicator_input_error" />
<java-symbol type="drawable" name="popup_bottom_dark" /> <java-symbol type="drawable" name="popup_bottom_dark" />
<java-symbol type="drawable" name="popup_bottom_bright" /> <java-symbol type="drawable" name="popup_bottom_bright" />