Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1 | /* |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2 | * Copyright (C) 2009 The Android Open Source Project |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 17 | package android.app; |
| 18 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 22 | import android.annotation.RawRes; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Jeff Sharkey | 0f3f60b | 2017-04-24 18:06:20 -0600 | [diff] [blame] | 24 | import android.annotation.SdkConstant; |
Christopher Tate | dbf4a9c | 2017-06-27 12:37:23 -0700 | [diff] [blame] | 25 | import android.annotation.SdkConstant.SdkConstantType; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 26 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 27 | import android.annotation.SystemService; |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Adam Lesinski | bba72d1 | 2013-10-11 18:10:56 -0700 | [diff] [blame] | 29 | import android.content.ContentResolver; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 32 | import android.content.pm.PackageManager; |
| 33 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 34 | import android.content.res.Resources; |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 35 | import android.content.res.Resources.NotFoundException; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 36 | import android.graphics.Bitmap; |
| 37 | import android.graphics.BitmapFactory; |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 38 | import android.graphics.BitmapRegionDecoder; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 39 | import android.graphics.Canvas; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 40 | import android.graphics.ColorFilter; |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 41 | import android.graphics.Matrix; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 42 | import android.graphics.Paint; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 43 | import android.graphics.PixelFormat; |
Jeff Brown | 2457237 | 2011-06-09 19:05:15 -0700 | [diff] [blame] | 44 | import android.graphics.PorterDuff; |
| 45 | import android.graphics.PorterDuffXfermode; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 46 | import android.graphics.Rect; |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 47 | import android.graphics.RectF; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 48 | import android.graphics.drawable.BitmapDrawable; |
| 49 | import android.graphics.drawable.Drawable; |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 50 | import android.net.Uri; |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 51 | import android.os.Build; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 52 | import android.os.Bundle; |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 53 | import android.os.DeadSystemException; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 54 | import android.os.Handler; |
| 55 | import android.os.IBinder; |
Dianne Hackborn | 840c3a2 | 2009-09-02 17:35:17 -0700 | [diff] [blame] | 56 | import android.os.Looper; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 57 | import android.os.ParcelFileDescriptor; |
| 58 | import android.os.RemoteException; |
| 59 | import android.os.ServiceManager; |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 60 | import android.os.SystemProperties; |
Jorim Jaggi | e31f6b8 | 2016-07-01 16:15:09 -0700 | [diff] [blame] | 61 | import android.os.UserHandle; |
Lucas Dupin | eeb36be | 2017-08-04 10:45:12 -0700 | [diff] [blame] | 62 | import android.service.wallpaper.WallpaperService; |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 63 | import android.text.TextUtils; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 64 | import android.util.Log; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 65 | import android.util.Pair; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 66 | import android.view.WindowManagerGlobal; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 67 | |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 68 | import libcore.io.IoUtils; |
| 69 | |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 70 | import java.io.BufferedInputStream; |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 71 | import java.io.File; |
| 72 | import java.io.FileInputStream; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 73 | import java.io.FileOutputStream; |
| 74 | import java.io.IOException; |
| 75 | import java.io.InputStream; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 76 | import java.lang.annotation.Retention; |
| 77 | import java.lang.annotation.RetentionPolicy; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 78 | import java.util.ArrayList; |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 79 | import java.util.List; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 80 | import java.util.concurrent.CountDownLatch; |
| 81 | import java.util.concurrent.TimeUnit; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 82 | |
Scott Main | 8b2e000 | 2009-09-29 18:17:31 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Provides access to the system wallpaper. With WallpaperManager, you can |
| 85 | * get the current wallpaper, get the desired dimensions for the wallpaper, set |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 86 | * the wallpaper, and more. |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 87 | * |
| 88 | * <p> An app can check whether wallpapers are supported for the current user, by calling |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 89 | * {@link #isWallpaperSupported()}, and whether setting of wallpapers is allowed, by calling |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 90 | * {@link #isSetWallpaperAllowed()}. |
Scott Main | 8b2e000 | 2009-09-29 18:17:31 -0700 | [diff] [blame] | 91 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 92 | @SystemService(Context.WALLPAPER_SERVICE) |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 93 | public class WallpaperManager { |
| 94 | private static String TAG = "WallpaperManager"; |
| 95 | private static boolean DEBUG = false; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 96 | private float mWallpaperXStep = -1; |
| 97 | private float mWallpaperYStep = -1; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 98 | |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 99 | /** {@hide} */ |
| 100 | private static final String PROP_WALLPAPER = "ro.config.wallpaper"; |
| 101 | /** {@hide} */ |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 102 | private static final String PROP_LOCK_WALLPAPER = "ro.config.lock_wallpaper"; |
| 103 | /** {@hide} */ |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 104 | private static final String PROP_WALLPAPER_COMPONENT = "ro.config.wallpaper_component"; |
| 105 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 106 | /** |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 107 | * Activity Action: Show settings for choosing wallpaper. Do not use directly to construct |
| 108 | * an intent; instead, use {@link #getCropAndSetWallpaperIntent}. |
| 109 | * <p>Input: {@link Intent#getData} is the URI of the image to crop and set as wallpaper. |
| 110 | * <p>Output: RESULT_OK if user decided to crop/set the wallpaper, RESULT_CANCEL otherwise |
Adam Lesinski | bba72d1 | 2013-10-11 18:10:56 -0700 | [diff] [blame] | 111 | * Activities that support this intent should specify a MIME filter of "image/*" |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 112 | */ |
Jeff Sharkey | 0f3f60b | 2017-04-24 18:06:20 -0600 | [diff] [blame] | 113 | @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 114 | public static final String ACTION_CROP_AND_SET_WALLPAPER = |
| 115 | "android.service.wallpaper.CROP_AND_SET_WALLPAPER"; |
| 116 | |
| 117 | /** |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 118 | * Launch an activity for the user to pick the current global live |
| 119 | * wallpaper. |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 120 | */ |
| 121 | public static final String ACTION_LIVE_WALLPAPER_CHOOSER |
| 122 | = "android.service.wallpaper.LIVE_WALLPAPER_CHOOSER"; |
Adam Cohen | 5a242ec | 2010-12-07 21:07:07 -0800 | [diff] [blame] | 123 | |
| 124 | /** |
Dianne Hackborn | 7df7d20 | 2012-04-19 18:00:04 -0700 | [diff] [blame] | 125 | * Directly launch live wallpaper preview, allowing the user to immediately |
| 126 | * confirm to switch to a specific live wallpaper. You must specify |
| 127 | * {@link #EXTRA_LIVE_WALLPAPER_COMPONENT} with the ComponentName of |
| 128 | * a live wallpaper component that is to be shown. |
| 129 | */ |
| 130 | public static final String ACTION_CHANGE_LIVE_WALLPAPER |
| 131 | = "android.service.wallpaper.CHANGE_LIVE_WALLPAPER"; |
| 132 | |
| 133 | /** |
| 134 | * Extra in {@link #ACTION_CHANGE_LIVE_WALLPAPER} that specifies the |
| 135 | * ComponentName of a live wallpaper that should be shown as a preview, |
| 136 | * for the user to confirm. |
| 137 | */ |
| 138 | public static final String EXTRA_LIVE_WALLPAPER_COMPONENT |
| 139 | = "android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT"; |
| 140 | |
| 141 | /** |
Adam Cohen | 5a242ec | 2010-12-07 21:07:07 -0800 | [diff] [blame] | 142 | * Manifest entry for activities that respond to {@link Intent#ACTION_SET_WALLPAPER} |
| 143 | * which allows them to provide a custom large icon associated with this action. |
| 144 | */ |
| 145 | public static final String WALLPAPER_PREVIEW_META_DATA = "android.wallpaper.preview"; |
| 146 | |
Dianne Hackborn | 23ef7b4 | 2009-11-18 18:20:39 -0800 | [diff] [blame] | 147 | /** |
| 148 | * Command for {@link #sendWallpaperCommand}: reported by the wallpaper |
| 149 | * host when the user taps on an empty area (not performing an action |
| 150 | * in the host). The x and y arguments are the location of the tap in |
| 151 | * screen coordinates. |
| 152 | */ |
| 153 | public static final String COMMAND_TAP = "android.wallpaper.tap"; |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 154 | |
Dianne Hackborn | 23ef7b4 | 2009-11-18 18:20:39 -0800 | [diff] [blame] | 155 | /** |
| 156 | * Command for {@link #sendWallpaperCommand}: reported by the wallpaper |
Jeff Brown | 9f3bdfe | 2010-10-13 06:01:27 -0700 | [diff] [blame] | 157 | * host when the user releases a secondary pointer on an empty area |
| 158 | * (not performing an action in the host). The x and y arguments are |
| 159 | * the location of the secondary tap in screen coordinates. |
| 160 | */ |
| 161 | public static final String COMMAND_SECONDARY_TAP = "android.wallpaper.secondaryTap"; |
| 162 | |
| 163 | /** |
| 164 | * Command for {@link #sendWallpaperCommand}: reported by the wallpaper |
Dianne Hackborn | 23ef7b4 | 2009-11-18 18:20:39 -0800 | [diff] [blame] | 165 | * host when the user drops an object into an area of the host. The x |
| 166 | * and y arguments are the location of the drop. |
| 167 | */ |
| 168 | public static final String COMMAND_DROP = "android.home.drop"; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * Extra passed back from setWallpaper() giving the new wallpaper's assigned ID. |
| 172 | * @hide |
| 173 | */ |
| 174 | public static final String EXTRA_NEW_WALLPAPER_ID = "android.service.wallpaper.extra.ID"; |
| 175 | |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 176 | // flags for which kind of wallpaper to act on |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 177 | |
| 178 | /** @hide */ |
| 179 | @IntDef(flag = true, value = { |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 180 | FLAG_SYSTEM, |
| 181 | FLAG_LOCK |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 182 | }) |
| 183 | @Retention(RetentionPolicy.SOURCE) |
| 184 | public @interface SetWallpaperFlags {} |
| 185 | |
| 186 | /** |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 187 | * Flag: set or retrieve the general system wallpaper. |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 188 | */ |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 189 | public static final int FLAG_SYSTEM = 1 << 0; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 190 | |
| 191 | /** |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 192 | * Flag: set or retrieve the lock-screen-specific wallpaper. |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 193 | */ |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 194 | public static final int FLAG_LOCK = 1 << 1; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 195 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 196 | private final Context mContext; |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 197 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 198 | /** |
| 199 | * Special drawable that draws a wallpaper as fast as possible. Assumes |
| 200 | * no scaling or placement off (0,0) of the wallpaper (this should be done |
| 201 | * at the time the bitmap is loaded). |
| 202 | */ |
| 203 | static class FastBitmapDrawable extends Drawable { |
| 204 | private final Bitmap mBitmap; |
| 205 | private final int mWidth; |
| 206 | private final int mHeight; |
| 207 | private int mDrawLeft; |
| 208 | private int mDrawTop; |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 209 | private final Paint mPaint; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 210 | |
| 211 | private FastBitmapDrawable(Bitmap bitmap) { |
| 212 | mBitmap = bitmap; |
| 213 | mWidth = bitmap.getWidth(); |
| 214 | mHeight = bitmap.getHeight(); |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 215 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 216 | setBounds(0, 0, mWidth, mHeight); |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 217 | |
| 218 | mPaint = new Paint(); |
| 219 | mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | @Override |
| 223 | public void draw(Canvas canvas) { |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 224 | canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, mPaint); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public int getOpacity() { |
| 229 | return PixelFormat.OPAQUE; |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public void setBounds(int left, int top, int right, int bottom) { |
| 234 | mDrawLeft = left + (right-left - mWidth) / 2; |
| 235 | mDrawTop = top + (bottom-top - mHeight) / 2; |
| 236 | } |
| 237 | |
| 238 | @Override |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 239 | public void setAlpha(int alpha) { |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 240 | throw new UnsupportedOperationException("Not supported with this drawable"); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Override |
Chris Craik | bd3bfc5 | 2015-03-02 10:43:29 -0800 | [diff] [blame] | 244 | public void setColorFilter(ColorFilter colorFilter) { |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 245 | throw new UnsupportedOperationException("Not supported with this drawable"); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void setDither(boolean dither) { |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 250 | throw new UnsupportedOperationException("Not supported with this drawable"); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void setFilterBitmap(boolean filter) { |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 255 | throw new UnsupportedOperationException("Not supported with this drawable"); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public int getIntrinsicWidth() { |
| 260 | return mWidth; |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public int getIntrinsicHeight() { |
| 265 | return mHeight; |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public int getMinimumWidth() { |
| 270 | return mWidth; |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public int getMinimumHeight() { |
| 275 | return mHeight; |
| 276 | } |
| 277 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 278 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 279 | private static class Globals extends IWallpaperManagerCallback.Stub { |
Fyodor Kupolov | b6378cf | 2016-07-12 10:32:08 -0700 | [diff] [blame] | 280 | private final IWallpaperManager mService; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 281 | private boolean mColorCallbackRegistered; |
| 282 | private final ArrayList<Pair<OnColorsChangedListener, Handler>> mColorListeners = |
| 283 | new ArrayList<>(); |
Vadim Tryshev | 93a914a | 2016-03-07 12:48:51 -0800 | [diff] [blame] | 284 | private Bitmap mCachedWallpaper; |
| 285 | private int mCachedWallpaperUserId; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 286 | private Bitmap mDefaultWallpaper; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 287 | private Handler mMainLooperHandler; |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 288 | |
Dianne Hackborn | 5e802fb | 2009-09-02 21:50:50 -0700 | [diff] [blame] | 289 | Globals(Looper looper) { |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 290 | IBinder b = ServiceManager.getService(Context.WALLPAPER_SERVICE); |
| 291 | mService = IWallpaperManager.Stub.asInterface(b); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 292 | mMainLooperHandler = new Handler(looper); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 293 | forgetLoadedWallpaper(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 294 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 295 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 296 | public void onWallpaperChanged() { |
| 297 | /* The wallpaper has changed but we shouldn't eagerly load the |
| 298 | * wallpaper as that would be inefficient. Reset the cached wallpaper |
| 299 | * to null so if the user requests the wallpaper again then we'll |
| 300 | * fetch it. |
| 301 | */ |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 302 | forgetLoadedWallpaper(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 303 | } |
Adam Cohen | 041a0ba | 2011-11-09 20:10:27 -0800 | [diff] [blame] | 304 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 305 | /** |
| 306 | * Start listening to wallpaper color events. |
| 307 | * Will be called whenever someone changes their wallpaper or if a live wallpaper |
| 308 | * changes its colors. |
| 309 | * @param callback Listener |
| 310 | * @param handler Thread to call it from. Main thread if null. |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 311 | * @param userId Owner of the wallpaper or UserHandle.USER_ALL |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 312 | */ |
| 313 | public void addOnColorsChangedListener(@NonNull OnColorsChangedListener callback, |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 314 | @Nullable Handler handler, int userId) { |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 315 | synchronized (this) { |
| 316 | if (!mColorCallbackRegistered) { |
| 317 | try { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 318 | mService.registerWallpaperColorsCallback(this, userId); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 319 | mColorCallbackRegistered = true; |
| 320 | } catch (RemoteException e) { |
| 321 | // Failed, service is gone |
| 322 | Log.w(TAG, "Can't register for color updates", e); |
| 323 | } |
| 324 | } |
| 325 | mColorListeners.add(new Pair<>(callback, handler)); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Stop listening to wallpaper color events. |
| 331 | * |
| 332 | * @param callback listener |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 333 | * @param userId Owner of the wallpaper or UserHandle.USER_ALL |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 334 | */ |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 335 | public void removeOnColorsChangedListener(@NonNull OnColorsChangedListener callback, |
| 336 | int userId) { |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 337 | synchronized (this) { |
| 338 | mColorListeners.removeIf(pair -> pair.first == callback); |
| 339 | |
| 340 | if (mColorListeners.size() == 0 && mColorCallbackRegistered) { |
| 341 | mColorCallbackRegistered = false; |
| 342 | try { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 343 | mService.unregisterWallpaperColorsCallback(this, userId); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 344 | } catch (RemoteException e) { |
| 345 | // Failed, service is gone |
| 346 | Log.w(TAG, "Can't unregister color updates", e); |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | @Override |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 353 | public void onWallpaperColorsChanged(WallpaperColors colors, int which, int userId) { |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 354 | synchronized (this) { |
| 355 | for (Pair<OnColorsChangedListener, Handler> listener : mColorListeners) { |
| 356 | Handler handler = listener.second; |
| 357 | if (listener.second == null) { |
| 358 | handler = mMainLooperHandler; |
| 359 | } |
| 360 | handler.post(() -> { |
| 361 | // Dealing with race conditions between posting a callback and |
| 362 | // removeOnColorsChangedListener being called. |
| 363 | boolean stillExists; |
| 364 | synchronized (sGlobals) { |
| 365 | stillExists = mColorListeners.contains(listener); |
| 366 | } |
| 367 | if (stillExists) { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 368 | listener.first.onColorsChanged(colors, which, userId); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 369 | } |
| 370 | }); |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 375 | WallpaperColors getWallpaperColors(int which, int userId) { |
Christopher Tate | dbf4a9c | 2017-06-27 12:37:23 -0700 | [diff] [blame] | 376 | if (which != FLAG_LOCK && which != FLAG_SYSTEM) { |
| 377 | throw new IllegalArgumentException( |
| 378 | "Must request colors for exactly one kind of wallpaper"); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 379 | } |
Christopher Tate | dbf4a9c | 2017-06-27 12:37:23 -0700 | [diff] [blame] | 380 | |
| 381 | try { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 382 | return mService.getWallpaperColors(which, userId); |
Christopher Tate | dbf4a9c | 2017-06-27 12:37:23 -0700 | [diff] [blame] | 383 | } catch (RemoteException e) { |
| 384 | // Can't get colors, connection lost. |
| 385 | } |
| 386 | return null; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 389 | public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault, |
| 390 | @SetWallpaperFlags int which) { |
| 391 | return peekWallpaperBitmap(context, returnDefault, which, context.getUserId()); |
Yorke Lee | dcd93cc | 2016-01-08 14:12:55 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 394 | public Bitmap peekWallpaperBitmap(Context context, boolean returnDefault, |
| 395 | @SetWallpaperFlags int which, int userId) { |
Fyodor Kupolov | b6378cf | 2016-07-12 10:32:08 -0700 | [diff] [blame] | 396 | if (mService != null) { |
| 397 | try { |
| 398 | if (!mService.isWallpaperSupported(context.getOpPackageName())) { |
| 399 | return null; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 400 | } |
Fyodor Kupolov | b6378cf | 2016-07-12 10:32:08 -0700 | [diff] [blame] | 401 | } catch (RemoteException e) { |
| 402 | throw e.rethrowFromSystemServer(); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 403 | } |
Fyodor Kupolov | b6378cf | 2016-07-12 10:32:08 -0700 | [diff] [blame] | 404 | } |
| 405 | synchronized (this) { |
Vadim Tryshev | 93a914a | 2016-03-07 12:48:51 -0800 | [diff] [blame] | 406 | if (mCachedWallpaper != null && mCachedWallpaperUserId == userId) { |
| 407 | return mCachedWallpaper; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 408 | } |
Vadim Tryshev | 93a914a | 2016-03-07 12:48:51 -0800 | [diff] [blame] | 409 | mCachedWallpaper = null; |
| 410 | mCachedWallpaperUserId = 0; |
Dianne Hackborn | c9dbbe2 | 2009-11-11 22:50:37 -0800 | [diff] [blame] | 411 | try { |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 412 | mCachedWallpaper = getCurrentWallpaperLocked(context, userId); |
Vadim Tryshev | 93a914a | 2016-03-07 12:48:51 -0800 | [diff] [blame] | 413 | mCachedWallpaperUserId = userId; |
Dianne Hackborn | c9dbbe2 | 2009-11-11 22:50:37 -0800 | [diff] [blame] | 414 | } catch (OutOfMemoryError e) { |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 415 | Log.w(TAG, "Out of memory loading the current wallpaper: " + e); |
| 416 | } catch (SecurityException e) { |
| 417 | if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.O) { |
| 418 | Log.w(TAG, "No permission to access wallpaper, suppressing" |
| 419 | + " exception to avoid crashing legacy app."); |
| 420 | } else { |
| 421 | // Post-O apps really most sincerely need the permission. |
| 422 | throw e; |
| 423 | } |
Dianne Hackborn | c9dbbe2 | 2009-11-11 22:50:37 -0800 | [diff] [blame] | 424 | } |
Vadim Tryshev | 93a914a | 2016-03-07 12:48:51 -0800 | [diff] [blame] | 425 | if (mCachedWallpaper != null) { |
| 426 | return mCachedWallpaper; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 427 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 428 | } |
Fyodor Kupolov | b6378cf | 2016-07-12 10:32:08 -0700 | [diff] [blame] | 429 | if (returnDefault) { |
| 430 | Bitmap defaultWallpaper = mDefaultWallpaper; |
| 431 | if (defaultWallpaper == null) { |
| 432 | defaultWallpaper = getDefaultWallpaper(context, which); |
| 433 | synchronized (this) { |
| 434 | mDefaultWallpaper = defaultWallpaper; |
| 435 | } |
| 436 | } |
| 437 | return defaultWallpaper; |
| 438 | } |
| 439 | return null; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 440 | } |
Dianne Hackborn | ba39839 | 2011-08-01 16:11:57 -0700 | [diff] [blame] | 441 | |
Fyodor Kupolov | b6378cf | 2016-07-12 10:32:08 -0700 | [diff] [blame] | 442 | void forgetLoadedWallpaper() { |
Dianne Hackborn | ba39839 | 2011-08-01 16:11:57 -0700 | [diff] [blame] | 443 | synchronized (this) { |
Vadim Tryshev | 93a914a | 2016-03-07 12:48:51 -0800 | [diff] [blame] | 444 | mCachedWallpaper = null; |
| 445 | mCachedWallpaperUserId = 0; |
Dianne Hackborn | ba39839 | 2011-08-01 16:11:57 -0700 | [diff] [blame] | 446 | mDefaultWallpaper = null; |
| 447 | } |
| 448 | } |
| 449 | |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 450 | private Bitmap getCurrentWallpaperLocked(Context context, int userId) { |
Adam Lesinski | 2c8d67c | 2014-04-23 13:46:21 -0700 | [diff] [blame] | 451 | if (mService == null) { |
| 452 | Log.w(TAG, "WallpaperService not running"); |
| 453 | return null; |
| 454 | } |
| 455 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 456 | try { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 457 | Bundle params = new Bundle(); |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 458 | ParcelFileDescriptor fd = mService.getWallpaper(context.getOpPackageName(), |
| 459 | this, FLAG_SYSTEM, params, userId); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 460 | if (fd != null) { |
Jeff Brown | 2457237 | 2011-06-09 19:05:15 -0700 | [diff] [blame] | 461 | try { |
| 462 | BitmapFactory.Options options = new BitmapFactory.Options(); |
Michael Jurka | 824a4b5 | 2013-12-18 17:10:16 +0100 | [diff] [blame] | 463 | return BitmapFactory.decodeFileDescriptor( |
Jeff Brown | 2457237 | 2011-06-09 19:05:15 -0700 | [diff] [blame] | 464 | fd.getFileDescriptor(), null, options); |
Jeff Brown | 2457237 | 2011-06-09 19:05:15 -0700 | [diff] [blame] | 465 | } catch (OutOfMemoryError e) { |
| 466 | Log.w(TAG, "Can't decode file", e); |
| 467 | } finally { |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 468 | IoUtils.closeQuietly(fd); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 469 | } |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 470 | } |
| 471 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 472 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 473 | } |
| 474 | return null; |
| 475 | } |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 476 | |
Fyodor Kupolov | b6378cf | 2016-07-12 10:32:08 -0700 | [diff] [blame] | 477 | private Bitmap getDefaultWallpaper(Context context, @SetWallpaperFlags int which) { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 478 | InputStream is = openDefaultWallpaper(context, which); |
Adam Lesinski | 2c8d67c | 2014-04-23 13:46:21 -0700 | [diff] [blame] | 479 | if (is != null) { |
| 480 | try { |
| 481 | BitmapFactory.Options options = new BitmapFactory.Options(); |
| 482 | return BitmapFactory.decodeStream(is, null, options); |
| 483 | } catch (OutOfMemoryError e) { |
| 484 | Log.w(TAG, "Can't decode stream", e); |
| 485 | } finally { |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 486 | IoUtils.closeQuietly(is); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 487 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 488 | } |
| 489 | return null; |
| 490 | } |
| 491 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 492 | |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 493 | private static final Object sSync = new Object[0]; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 494 | private static Globals sGlobals; |
| 495 | |
Dianne Hackborn | 840c3a2 | 2009-09-02 17:35:17 -0700 | [diff] [blame] | 496 | static void initGlobals(Looper looper) { |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 497 | synchronized (sSync) { |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 498 | if (sGlobals == null) { |
Dianne Hackborn | 5e802fb | 2009-09-02 21:50:50 -0700 | [diff] [blame] | 499 | sGlobals = new Globals(looper); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 500 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 501 | } |
| 502 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 503 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 504 | /*package*/ WallpaperManager(Context context, Handler handler) { |
| 505 | mContext = context; |
Dianne Hackborn | 840c3a2 | 2009-09-02 17:35:17 -0700 | [diff] [blame] | 506 | initGlobals(context.getMainLooper()); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /** |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 510 | * Retrieve a WallpaperManager associated with the given Context. |
| 511 | */ |
| 512 | public static WallpaperManager getInstance(Context context) { |
| 513 | return (WallpaperManager)context.getSystemService( |
| 514 | Context.WALLPAPER_SERVICE); |
| 515 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 516 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 517 | /** @hide */ |
| 518 | public IWallpaperManager getIWallpaperManager() { |
Dianne Hackborn | 840c3a2 | 2009-09-02 17:35:17 -0700 | [diff] [blame] | 519 | return sGlobals.mService; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 520 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 521 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 522 | /** |
Scott Main | 8b2e000 | 2009-09-29 18:17:31 -0700 | [diff] [blame] | 523 | * Retrieve the current system wallpaper; if |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 524 | * no wallpaper is set, the system built-in static wallpaper is returned. |
Scott Main | 8b2e000 | 2009-09-29 18:17:31 -0700 | [diff] [blame] | 525 | * This is returned as an |
| 526 | * abstract Drawable that you can install in a View to display whatever |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 527 | * wallpaper the user has currently set. |
Christopher Tate | 41dc83bd | 2016-07-15 15:59:23 -0700 | [diff] [blame] | 528 | * <p> |
| 529 | * This method can return null if there is no system wallpaper available, if |
| 530 | * wallpapers are not supported in the current user, or if the calling app is not |
| 531 | * permitted to access the system wallpaper. |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 532 | * |
Christopher Tate | 41dc83bd | 2016-07-15 15:59:23 -0700 | [diff] [blame] | 533 | * @return Returns a Drawable object that will draw the system wallpaper, |
| 534 | * or {@code null} if no system wallpaper exists or if the calling application |
| 535 | * is not able to access the wallpaper. |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 536 | */ |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 537 | public Drawable getDrawable() { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 538 | Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 539 | if (bm != null) { |
| 540 | Drawable dr = new BitmapDrawable(mContext.getResources(), bm); |
| 541 | dr.setDither(false); |
| 542 | return dr; |
| 543 | } |
| 544 | return null; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /** |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 548 | * Obtain a drawable for the built-in static system wallpaper. |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 549 | */ |
| 550 | public Drawable getBuiltInDrawable() { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 551 | return getBuiltInDrawable(0, 0, false, 0, 0, FLAG_SYSTEM); |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * Obtain a drawable for the specified built-in static system wallpaper. |
| 556 | * |
| 557 | * @param which The {@code FLAG_*} identifier of a valid wallpaper type. Throws |
| 558 | * IllegalArgumentException if an invalid wallpaper is requested. |
| 559 | * @return A Drawable presenting the specified wallpaper image, or {@code null} |
| 560 | * if no built-in default image for that wallpaper type exists. |
| 561 | */ |
| 562 | public Drawable getBuiltInDrawable(@SetWallpaperFlags int which) { |
| 563 | return getBuiltInDrawable(0, 0, false, 0, 0, which); |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /** |
| 567 | * Returns a drawable for the system built-in static wallpaper. Based on the parameters, the |
| 568 | * drawable can be cropped and scaled |
| 569 | * |
| 570 | * @param outWidth The width of the returned drawable |
| 571 | * @param outWidth The height of the returned drawable |
| 572 | * @param scaleToFit If true, scale the wallpaper down rather than just cropping it |
| 573 | * @param horizontalAlignment A float value between 0 and 1 specifying where to crop the image; |
| 574 | * 0 for left-aligned, 0.5 for horizontal center-aligned, and 1 for right-aligned |
| 575 | * @param verticalAlignment A float value between 0 and 1 specifying where to crop the image; |
| 576 | * 0 for top-aligned, 0.5 for vertical center-aligned, and 1 for bottom-aligned |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 577 | * @return A Drawable presenting the built-in default system wallpaper image, |
| 578 | * or {@code null} if no such default image is defined on this device. |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 579 | */ |
| 580 | public Drawable getBuiltInDrawable(int outWidth, int outHeight, |
| 581 | boolean scaleToFit, float horizontalAlignment, float verticalAlignment) { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 582 | return getBuiltInDrawable(outWidth, outHeight, scaleToFit, |
| 583 | horizontalAlignment, verticalAlignment, FLAG_SYSTEM); |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * Returns a drawable for the built-in static wallpaper of the specified type. Based on the |
| 588 | * parameters, the drawable can be cropped and scaled. |
| 589 | * |
| 590 | * @param outWidth The width of the returned drawable |
| 591 | * @param outWidth The height of the returned drawable |
| 592 | * @param scaleToFit If true, scale the wallpaper down rather than just cropping it |
| 593 | * @param horizontalAlignment A float value between 0 and 1 specifying where to crop the image; |
| 594 | * 0 for left-aligned, 0.5 for horizontal center-aligned, and 1 for right-aligned |
| 595 | * @param verticalAlignment A float value between 0 and 1 specifying where to crop the image; |
| 596 | * 0 for top-aligned, 0.5 for vertical center-aligned, and 1 for bottom-aligned |
| 597 | * @param which The {@code FLAG_*} identifier of a valid wallpaper type. Throws |
| 598 | * IllegalArgumentException if an invalid wallpaper is requested. |
| 599 | * @return A Drawable presenting the built-in default wallpaper image of the given type, |
| 600 | * or {@code null} if no default image of that type is defined on this device. |
| 601 | */ |
| 602 | public Drawable getBuiltInDrawable(int outWidth, int outHeight, boolean scaleToFit, |
| 603 | float horizontalAlignment, float verticalAlignment, @SetWallpaperFlags int which) { |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 604 | if (sGlobals.mService == null) { |
| 605 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 606 | throw new RuntimeException(new DeadSystemException()); |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 607 | } |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 608 | |
| 609 | if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
| 610 | throw new IllegalArgumentException("Must request exactly one kind of wallpaper"); |
| 611 | } |
| 612 | |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 613 | Resources resources = mContext.getResources(); |
| 614 | horizontalAlignment = Math.max(0, Math.min(1, horizontalAlignment)); |
| 615 | verticalAlignment = Math.max(0, Math.min(1, verticalAlignment)); |
| 616 | |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 617 | InputStream wpStream = openDefaultWallpaper(mContext, which); |
| 618 | if (wpStream == null) { |
| 619 | if (DEBUG) { |
| 620 | Log.w(TAG, "default wallpaper stream " + which + " is null"); |
| 621 | } |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 622 | return null; |
| 623 | } else { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 624 | InputStream is = new BufferedInputStream(wpStream); |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 625 | if (outWidth <= 0 || outHeight <= 0) { |
| 626 | Bitmap fullSize = BitmapFactory.decodeStream(is, null, null); |
| 627 | return new BitmapDrawable(resources, fullSize); |
| 628 | } else { |
| 629 | int inWidth; |
| 630 | int inHeight; |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 631 | // Just measure this time through... |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 632 | { |
| 633 | BitmapFactory.Options options = new BitmapFactory.Options(); |
| 634 | options.inJustDecodeBounds = true; |
| 635 | BitmapFactory.decodeStream(is, null, options); |
| 636 | if (options.outWidth != 0 && options.outHeight != 0) { |
| 637 | inWidth = options.outWidth; |
| 638 | inHeight = options.outHeight; |
| 639 | } else { |
| 640 | Log.e(TAG, "default wallpaper dimensions are 0"); |
| 641 | return null; |
| 642 | } |
| 643 | } |
| 644 | |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 645 | // Reopen the stream to do the full decode. We know at this point |
| 646 | // that openDefaultWallpaper() will return non-null. |
| 647 | is = new BufferedInputStream(openDefaultWallpaper(mContext, which)); |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 648 | |
| 649 | RectF cropRectF; |
| 650 | |
| 651 | outWidth = Math.min(inWidth, outWidth); |
| 652 | outHeight = Math.min(inHeight, outHeight); |
| 653 | if (scaleToFit) { |
| 654 | cropRectF = getMaxCropRect(inWidth, inHeight, outWidth, outHeight, |
| 655 | horizontalAlignment, verticalAlignment); |
| 656 | } else { |
| 657 | float left = (inWidth - outWidth) * horizontalAlignment; |
| 658 | float right = left + outWidth; |
| 659 | float top = (inHeight - outHeight) * verticalAlignment; |
| 660 | float bottom = top + outHeight; |
Michael Jurka | 0539153 | 2013-10-14 20:44:42 -0700 | [diff] [blame] | 661 | cropRectF = new RectF(left, top, right, bottom); |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 662 | } |
| 663 | Rect roundedTrueCrop = new Rect(); |
| 664 | cropRectF.roundOut(roundedTrueCrop); |
| 665 | |
| 666 | if (roundedTrueCrop.width() <= 0 || roundedTrueCrop.height() <= 0) { |
| 667 | Log.w(TAG, "crop has bad values for full size image"); |
| 668 | return null; |
| 669 | } |
| 670 | |
| 671 | // See how much we're reducing the size of the image |
| 672 | int scaleDownSampleSize = Math.min(roundedTrueCrop.width() / outWidth, |
| 673 | roundedTrueCrop.height() / outHeight); |
| 674 | |
| 675 | // Attempt to open a region decoder |
| 676 | BitmapRegionDecoder decoder = null; |
| 677 | try { |
| 678 | decoder = BitmapRegionDecoder.newInstance(is, true); |
| 679 | } catch (IOException e) { |
| 680 | Log.w(TAG, "cannot open region decoder for default wallpaper"); |
| 681 | } |
| 682 | |
| 683 | Bitmap crop = null; |
| 684 | if (decoder != null) { |
| 685 | // Do region decoding to get crop bitmap |
| 686 | BitmapFactory.Options options = new BitmapFactory.Options(); |
| 687 | if (scaleDownSampleSize > 1) { |
| 688 | options.inSampleSize = scaleDownSampleSize; |
| 689 | } |
| 690 | crop = decoder.decodeRegion(roundedTrueCrop, options); |
| 691 | decoder.recycle(); |
| 692 | } |
| 693 | |
| 694 | if (crop == null) { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 695 | // BitmapRegionDecoder has failed, try to crop in-memory. We know at |
| 696 | // this point that openDefaultWallpaper() will return non-null. |
| 697 | is = new BufferedInputStream(openDefaultWallpaper(mContext, which)); |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 698 | Bitmap fullSize = null; |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 699 | BitmapFactory.Options options = new BitmapFactory.Options(); |
| 700 | if (scaleDownSampleSize > 1) { |
| 701 | options.inSampleSize = scaleDownSampleSize; |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 702 | } |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 703 | fullSize = BitmapFactory.decodeStream(is, null, options); |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 704 | if (fullSize != null) { |
| 705 | crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left, |
| 706 | roundedTrueCrop.top, roundedTrueCrop.width(), |
| 707 | roundedTrueCrop.height()); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | if (crop == null) { |
| 712 | Log.w(TAG, "cannot decode default wallpaper"); |
| 713 | return null; |
| 714 | } |
| 715 | |
| 716 | // Scale down if necessary |
| 717 | if (outWidth > 0 && outHeight > 0 && |
| 718 | (crop.getWidth() != outWidth || crop.getHeight() != outHeight)) { |
| 719 | Matrix m = new Matrix(); |
| 720 | RectF cropRect = new RectF(0, 0, crop.getWidth(), crop.getHeight()); |
| 721 | RectF returnRect = new RectF(0, 0, outWidth, outHeight); |
| 722 | m.setRectToRect(cropRect, returnRect, Matrix.ScaleToFit.FILL); |
| 723 | Bitmap tmp = Bitmap.createBitmap((int) returnRect.width(), |
| 724 | (int) returnRect.height(), Bitmap.Config.ARGB_8888); |
| 725 | if (tmp != null) { |
| 726 | Canvas c = new Canvas(tmp); |
| 727 | Paint p = new Paint(); |
| 728 | p.setFilterBitmap(true); |
| 729 | c.drawBitmap(crop, m, p); |
| 730 | crop = tmp; |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | return new BitmapDrawable(resources, crop); |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | private static RectF getMaxCropRect(int inWidth, int inHeight, int outWidth, int outHeight, |
| 740 | float horizontalAlignment, float verticalAlignment) { |
| 741 | RectF cropRect = new RectF(); |
| 742 | // Get a crop rect that will fit this |
| 743 | if (inWidth / (float) inHeight > outWidth / (float) outHeight) { |
| 744 | cropRect.top = 0; |
| 745 | cropRect.bottom = inHeight; |
| 746 | float cropWidth = outWidth * (inHeight / (float) outHeight); |
| 747 | cropRect.left = (inWidth - cropWidth) * horizontalAlignment; |
| 748 | cropRect.right = cropRect.left + cropWidth; |
| 749 | } else { |
| 750 | cropRect.left = 0; |
| 751 | cropRect.right = inWidth; |
| 752 | float cropHeight = outHeight * (inWidth / (float) outWidth); |
| 753 | cropRect.top = (inHeight - cropHeight) * verticalAlignment; |
| 754 | cropRect.bottom = cropRect.top + cropHeight; |
| 755 | } |
| 756 | return cropRect; |
| 757 | } |
| 758 | |
| 759 | /** |
Scott Main | 8b2e000 | 2009-09-29 18:17:31 -0700 | [diff] [blame] | 760 | * Retrieve the current system wallpaper; if there is no wallpaper set, |
| 761 | * a null pointer is returned. This is returned as an |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 762 | * abstract Drawable that you can install in a View to display whatever |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 763 | * wallpaper the user has currently set. |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 764 | * |
| 765 | * @return Returns a Drawable object that will draw the wallpaper or a |
| 766 | * null pointer if these is none. |
| 767 | */ |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 768 | public Drawable peekDrawable() { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 769 | Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, FLAG_SYSTEM); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 770 | if (bm != null) { |
| 771 | Drawable dr = new BitmapDrawable(mContext.getResources(), bm); |
| 772 | dr.setDither(false); |
| 773 | return dr; |
| 774 | } |
| 775 | return null; |
| 776 | } |
| 777 | |
| 778 | /** |
Scott Main | 8b2e000 | 2009-09-29 18:17:31 -0700 | [diff] [blame] | 779 | * Like {@link #getDrawable()}, but the returned Drawable has a number |
| 780 | * of limitations to reduce its overhead as much as possible. It will |
| 781 | * never scale the wallpaper (only centering it if the requested bounds |
| 782 | * do match the bitmap bounds, which should not be typical), doesn't |
| 783 | * allow setting an alpha, color filter, or other attributes, etc. The |
| 784 | * bounds of the returned drawable will be initialized to the same bounds |
| 785 | * as the wallpaper, so normally you will not need to touch it. The |
| 786 | * drawable also assumes that it will be used in a context running in |
| 787 | * the same density as the screen (not in density compatibility mode). |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 788 | * |
| 789 | * @return Returns a Drawable object that will draw the wallpaper. |
| 790 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 791 | @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 792 | public Drawable getFastDrawable() { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 793 | Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 794 | if (bm != null) { |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 795 | return new FastBitmapDrawable(bm); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 796 | } |
| 797 | return null; |
| 798 | } |
| 799 | |
| 800 | /** |
Scott Main | 8b2e000 | 2009-09-29 18:17:31 -0700 | [diff] [blame] | 801 | * Like {@link #getFastDrawable()}, but if there is no wallpaper set, |
| 802 | * a null pointer is returned. |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 803 | * |
| 804 | * @return Returns an optimized Drawable object that will draw the |
| 805 | * wallpaper or a null pointer if these is none. |
| 806 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 807 | @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 808 | public Drawable peekFastDrawable() { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 809 | Bitmap bm = sGlobals.peekWallpaperBitmap(mContext, false, FLAG_SYSTEM); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 810 | if (bm != null) { |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 811 | return new FastBitmapDrawable(bm); |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 812 | } |
| 813 | return null; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /** |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 817 | * Like {@link #getDrawable()} but returns a Bitmap. |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 818 | * |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 819 | * @hide |
| 820 | */ |
| 821 | public Bitmap getBitmap() { |
Yorke Lee | dcd93cc | 2016-01-08 14:12:55 -0800 | [diff] [blame] | 822 | return getBitmapAsUser(mContext.getUserId()); |
| 823 | } |
| 824 | |
| 825 | /** |
| 826 | * Like {@link #getDrawable()} but returns a Bitmap for the provided user. |
| 827 | * |
| 828 | * @hide |
| 829 | */ |
| 830 | public Bitmap getBitmapAsUser(int userId) { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 831 | return sGlobals.peekWallpaperBitmap(mContext, true, FLAG_SYSTEM, userId); |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | /** |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 835 | * Get an open, readable file descriptor to the given wallpaper image file. |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 836 | * The caller is responsible for closing the file descriptor when done ingesting the file. |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 837 | * |
| 838 | * <p>If no lock-specific wallpaper has been configured for the given user, then |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 839 | * this method will return {@code null} when requesting {@link #FLAG_LOCK} rather than |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 840 | * returning the system wallpaper's image file. |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 841 | * |
| 842 | * @param which The wallpaper whose image file is to be retrieved. Must be a single |
| 843 | * defined kind of wallpaper, either {@link #FLAG_SYSTEM} or |
| 844 | * {@link #FLAG_LOCK}. |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 845 | * @return An open, readable file desriptor to the requested wallpaper image file; |
| 846 | * or {@code null} if no such wallpaper is configured or if the calling app does |
| 847 | * not have permission to read the current wallpaper. |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 848 | * |
| 849 | * @see #FLAG_LOCK |
| 850 | * @see #FLAG_SYSTEM |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 851 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 852 | @RequiresPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 853 | public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 854 | return getWallpaperFile(which, mContext.getUserId()); |
| 855 | } |
| 856 | |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 857 | /** |
| 858 | * Registers a listener to get notified when the wallpaper colors change. |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 859 | * @param listener A listener to register |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 860 | * @param handler Where to call it from. Will be called from the main thread |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 861 | * if null. |
| 862 | */ |
| 863 | public void addOnColorsChangedListener(@NonNull OnColorsChangedListener listener, |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 864 | @NonNull Handler handler) { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 865 | addOnColorsChangedListener(listener, handler, mContext.getUserId()); |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * Registers a listener to get notified when the wallpaper colors change |
| 870 | * @param listener A listener to register |
| 871 | * @param handler Where to call it from. Will be called from the main thread |
| 872 | * if null. |
| 873 | * @param userId Owner of the wallpaper or UserHandle.USER_ALL. |
| 874 | * @hide |
| 875 | */ |
| 876 | public void addOnColorsChangedListener(@NonNull OnColorsChangedListener listener, |
| 877 | @NonNull Handler handler, int userId) { |
| 878 | sGlobals.addOnColorsChangedListener(listener, handler, userId); |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | /** |
| 882 | * Stop listening to color updates. |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 883 | * @param callback A callback to unsubscribe. |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 884 | */ |
| 885 | public void removeOnColorsChangedListener(@NonNull OnColorsChangedListener callback) { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 886 | removeOnColorsChangedListener(callback, mContext.getUserId()); |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * Stop listening to color updates. |
| 891 | * @param callback A callback to unsubscribe. |
| 892 | * @param userId Owner of the wallpaper or UserHandle.USER_ALL. |
| 893 | * @hide |
| 894 | */ |
| 895 | public void removeOnColorsChangedListener(@NonNull OnColorsChangedListener callback, |
| 896 | int userId) { |
| 897 | sGlobals.removeOnColorsChangedListener(callback, userId); |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | /** |
Lucas Dupin | eeb36be | 2017-08-04 10:45:12 -0700 | [diff] [blame] | 901 | * Get the primary colors of a wallpaper. |
| 902 | * |
| 903 | * <p>You can expect null if: |
| 904 | * • Colors are still being processed by the system. |
| 905 | * • A live wallpaper doesn't implement {@link WallpaperService.Engine#onComputeColors()}. |
| 906 | * |
| 907 | * @param which Wallpaper type. Must be either {@link #FLAG_SYSTEM} or |
| 908 | * {@link #FLAG_LOCK}. |
| 909 | * @return Current {@link WallpaperColors} or null if colors are unknown. |
| 910 | * @see #addOnColorsChangedListener(OnColorsChangedListener, Handler) |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 911 | */ |
| 912 | public @Nullable WallpaperColors getWallpaperColors(int which) { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 913 | return getWallpaperColors(which, mContext.getUserId()); |
| 914 | } |
| 915 | |
| 916 | /** |
| 917 | * Get the primary colors of a wallpaper |
| 918 | * @param which wallpaper type. Must be either {@link #FLAG_SYSTEM} or |
| 919 | * {@link #FLAG_LOCK} |
| 920 | * @param userId Owner of the wallpaper. |
| 921 | * @return {@link WallpaperColors} or null if colors are unknown. |
| 922 | * @hide |
| 923 | */ |
| 924 | public @Nullable WallpaperColors getWallpaperColors(int which, int userId) { |
| 925 | return sGlobals.getWallpaperColors(which, userId); |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 928 | /** |
| 929 | * Version of {@link #getWallpaperFile(int)} that can access the wallpaper data |
| 930 | * for a given user. The caller must hold the INTERACT_ACROSS_USERS_FULL |
| 931 | * permission to access another user's wallpaper data. |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 932 | * |
| 933 | * @param which The wallpaper whose image file is to be retrieved. Must be a single |
| 934 | * defined kind of wallpaper, either {@link #FLAG_SYSTEM} or |
| 935 | * {@link #FLAG_LOCK}. |
| 936 | * @param userId The user or profile whose imagery is to be retrieved |
| 937 | * |
| 938 | * @see #FLAG_LOCK |
| 939 | * @see #FLAG_SYSTEM |
| 940 | * |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 941 | * @hide |
| 942 | */ |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 943 | public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which, int userId) { |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 944 | if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 945 | throw new IllegalArgumentException("Must request exactly one kind of wallpaper"); |
| 946 | } |
| 947 | |
| 948 | if (sGlobals.mService == null) { |
| 949 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 950 | throw new RuntimeException(new DeadSystemException()); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 951 | } else { |
| 952 | try { |
| 953 | Bundle outParams = new Bundle(); |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 954 | return sGlobals.mService.getWallpaper(mContext.getOpPackageName(), null, which, |
| 955 | outParams, userId); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 956 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 957 | throw e.rethrowFromSystemServer(); |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 958 | } catch (SecurityException e) { |
| 959 | if (mContext.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.O) { |
| 960 | Log.w(TAG, "No permission to access wallpaper, suppressing" |
| 961 | + " exception to avoid crashing legacy app."); |
| 962 | return null; |
| 963 | } else { |
| 964 | throw e; |
| 965 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | } |
| 969 | |
| 970 | /** |
Dianne Hackborn | ba39839 | 2011-08-01 16:11:57 -0700 | [diff] [blame] | 971 | * Remove all internal references to the last loaded wallpaper. Useful |
| 972 | * for apps that want to reduce memory usage when they only temporarily |
| 973 | * need to have the wallpaper. After calling, the next request for the |
| 974 | * wallpaper will require reloading it again from disk. |
| 975 | */ |
| 976 | public void forgetLoadedWallpaper() { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 977 | sGlobals.forgetLoadedWallpaper(); |
Dianne Hackborn | ba39839 | 2011-08-01 16:11:57 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | /** |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 981 | * If the current wallpaper is a live wallpaper component, return the |
| 982 | * information about that wallpaper. Otherwise, if it is a static image, |
| 983 | * simply return null. |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 984 | */ |
| 985 | public WallpaperInfo getWallpaperInfo() { |
| 986 | try { |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 987 | if (sGlobals.mService == null) { |
| 988 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 989 | throw new RuntimeException(new DeadSystemException()); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 990 | } else { |
Jorim Jaggi | e31f6b8 | 2016-07-01 16:15:09 -0700 | [diff] [blame] | 991 | return sGlobals.mService.getWallpaperInfo(UserHandle.myUserId()); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 992 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 993 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 994 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 995 | } |
| 996 | } |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 997 | |
| 998 | /** |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 999 | * Get the ID of the current wallpaper of the given kind. If there is no |
| 1000 | * such wallpaper configured, returns a negative number. |
| 1001 | * |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1002 | * <p>Every time the wallpaper image is set, a new ID is assigned to it. |
| 1003 | * This method allows the caller to determine whether the wallpaper imagery |
| 1004 | * has changed, regardless of how that change happened. |
| 1005 | * |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1006 | * @param which The wallpaper whose ID is to be returned. Must be a single |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1007 | * defined kind of wallpaper, either {@link #FLAG_SYSTEM} or |
| 1008 | * {@link #FLAG_LOCK}. |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1009 | * @return The positive numeric ID of the current wallpaper of the given kind, |
| 1010 | * or a negative value if no such wallpaper is configured. |
| 1011 | */ |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1012 | public int getWallpaperId(@SetWallpaperFlags int which) { |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1013 | return getWallpaperIdForUser(which, mContext.getUserId()); |
| 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * Get the ID of the given user's current wallpaper of the given kind. If there |
| 1018 | * is no such wallpaper configured, returns a negative number. |
| 1019 | * @hide |
| 1020 | */ |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1021 | public int getWallpaperIdForUser(@SetWallpaperFlags int which, int userId) { |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1022 | try { |
| 1023 | if (sGlobals.mService == null) { |
| 1024 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1025 | throw new RuntimeException(new DeadSystemException()); |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1026 | } else { |
| 1027 | return sGlobals.mService.getWallpaperIdForUser(which, userId); |
| 1028 | } |
| 1029 | } catch (RemoteException e) { |
| 1030 | throw e.rethrowFromSystemServer(); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | /** |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 1035 | * Gets an Intent that will launch an activity that crops the given |
| 1036 | * image and sets the device's wallpaper. If there is a default HOME activity |
| 1037 | * that supports cropping wallpapers, it will be preferred as the default. |
Ying Wang | 930d4e5 | 2013-09-14 11:57:17 -0700 | [diff] [blame] | 1038 | * Use this method instead of directly creating a {@link #ACTION_CROP_AND_SET_WALLPAPER} |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 1039 | * intent. |
Adam Lesinski | bba72d1 | 2013-10-11 18:10:56 -0700 | [diff] [blame] | 1040 | * |
| 1041 | * @param imageUri The image URI that will be set in the intent. The must be a content |
| 1042 | * URI and its provider must resolve its type to "image/*" |
| 1043 | * |
| 1044 | * @throws IllegalArgumentException if the URI is not a content URI or its MIME type is |
| 1045 | * not "image/*" |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 1046 | */ |
| 1047 | public Intent getCropAndSetWallpaperIntent(Uri imageUri) { |
Allen Shen | 1c0f21e | 2014-04-29 16:16:29 +0800 | [diff] [blame] | 1048 | if (imageUri == null) { |
| 1049 | throw new IllegalArgumentException("Image URI must not be null"); |
| 1050 | } |
| 1051 | |
Adam Lesinski | bba72d1 | 2013-10-11 18:10:56 -0700 | [diff] [blame] | 1052 | if (!ContentResolver.SCHEME_CONTENT.equals(imageUri.getScheme())) { |
| 1053 | throw new IllegalArgumentException("Image URI must be of the " |
| 1054 | + ContentResolver.SCHEME_CONTENT + " scheme type"); |
| 1055 | } |
| 1056 | |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 1057 | final PackageManager packageManager = mContext.getPackageManager(); |
| 1058 | Intent cropAndSetWallpaperIntent = |
| 1059 | new Intent(ACTION_CROP_AND_SET_WALLPAPER, imageUri); |
| 1060 | cropAndSetWallpaperIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| 1061 | |
| 1062 | // Find out if the default HOME activity supports CROP_AND_SET_WALLPAPER |
| 1063 | Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME); |
| 1064 | ResolveInfo resolvedHome = packageManager.resolveActivity(homeIntent, |
| 1065 | PackageManager.MATCH_DEFAULT_ONLY); |
| 1066 | if (resolvedHome != null) { |
| 1067 | cropAndSetWallpaperIntent.setPackage(resolvedHome.activityInfo.packageName); |
| 1068 | |
| 1069 | List<ResolveInfo> cropAppList = packageManager.queryIntentActivities( |
| 1070 | cropAndSetWallpaperIntent, 0); |
| 1071 | if (cropAppList.size() > 0) { |
| 1072 | return cropAndSetWallpaperIntent; |
| 1073 | } |
| 1074 | } |
| 1075 | |
| 1076 | // fallback crop activity |
Oren Blasberg | 60598ea0a | 2016-02-26 11:01:23 -0800 | [diff] [blame] | 1077 | final String cropperPackage = mContext.getString( |
| 1078 | com.android.internal.R.string.config_wallpaperCropperPackage); |
| 1079 | cropAndSetWallpaperIntent.setPackage(cropperPackage); |
Adam Lesinski | bba72d1 | 2013-10-11 18:10:56 -0700 | [diff] [blame] | 1080 | List<ResolveInfo> cropAppList = packageManager.queryIntentActivities( |
| 1081 | cropAndSetWallpaperIntent, 0); |
| 1082 | if (cropAppList.size() > 0) { |
| 1083 | return cropAndSetWallpaperIntent; |
| 1084 | } |
| 1085 | // If the URI is not of the right type, or for some reason the system wallpaper |
| 1086 | // cropper doesn't exist, return null |
| 1087 | throw new IllegalArgumentException("Cannot use passed URI to set wallpaper; " + |
| 1088 | "check that the type returned by ContentProvider matches image/*"); |
Michael Jurka | e8d1bf7 | 2013-09-09 15:58:54 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1091 | /** |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1092 | * Change the current system wallpaper to the bitmap in the given resource. |
| 1093 | * The resource is opened as a raw data stream and copied into the |
| 1094 | * wallpaper; it must be a valid PNG or JPEG image. On success, the intent |
| 1095 | * {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast. |
| 1096 | * |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 1097 | * <p>This method requires the caller to hold the permission |
| 1098 | * {@link android.Manifest.permission#SET_WALLPAPER}. |
| 1099 | * |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1100 | * @param resid The resource ID of the bitmap to be used as the wallpaper image |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1101 | * |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 1102 | * @throws IOException If an error occurs reverting to the built-in |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1103 | * wallpaper. |
| 1104 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1105 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 1106 | public void setResource(@RawRes int resid) throws IOException { |
Edward Savage-Jones | 6009d9d | 2016-08-30 18:44:19 +0200 | [diff] [blame] | 1107 | setResource(resid, FLAG_SYSTEM | FLAG_LOCK); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | /** |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1111 | * Version of {@link #setResource(int)} that allows the caller to specify which |
| 1112 | * of the supported wallpaper categories to set. |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1113 | * |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1114 | * @param resid The resource ID of the bitmap to be used as the wallpaper image |
| 1115 | * @param which Flags indicating which wallpaper(s) to configure with the new imagery |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1116 | * |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1117 | * @see #FLAG_LOCK |
| 1118 | * @see #FLAG_SYSTEM |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1119 | * |
| 1120 | * @return An integer ID assigned to the newly active wallpaper; or zero on failure. |
| 1121 | * |
| 1122 | * @throws IOException |
| 1123 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1124 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1125 | public int setResource(@RawRes int resid, @SetWallpaperFlags int which) |
| 1126 | throws IOException { |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1127 | if (sGlobals.mService == null) { |
| 1128 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1129 | throw new RuntimeException(new DeadSystemException()); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1130 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1131 | final Bundle result = new Bundle(); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1132 | final WallpaperSetCompletion completion = new WallpaperSetCompletion(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1133 | try { |
| 1134 | Resources resources = mContext.getResources(); |
| 1135 | /* Set the wallpaper to the default values */ |
Dianne Hackborn | 840c3a2 | 2009-09-02 17:35:17 -0700 | [diff] [blame] | 1136 | ParcelFileDescriptor fd = sGlobals.mService.setWallpaper( |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1137 | "res:" + resources.getResourceName(resid), |
Jorim Jaggi | 6c902d0 | 2016-08-18 10:44:54 -0700 | [diff] [blame] | 1138 | mContext.getOpPackageName(), null, false, result, which, completion, |
| 1139 | UserHandle.myUserId()); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1140 | if (fd != null) { |
| 1141 | FileOutputStream fos = null; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1142 | boolean ok = false; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1143 | try { |
| 1144 | fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1145 | copyStreamToWallpaperFile(resources.openRawResource(resid), fos); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1146 | // The 'close()' is the trigger for any server-side image manipulation, |
| 1147 | // so we must do that before waiting for completion. |
| 1148 | fos.close(); |
| 1149 | completion.waitForCompletion(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1150 | } finally { |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1151 | // Might be redundant but completion shouldn't wait unless the write |
| 1152 | // succeeded; this is a fallback if it threw past the close+wait. |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1153 | IoUtils.closeQuietly(fos); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1157 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1158 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1159 | return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1160 | } |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1161 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1162 | /** |
| 1163 | * Change the current system wallpaper to a bitmap. The given bitmap is |
| 1164 | * converted to a PNG and stored as the wallpaper. On success, the intent |
| 1165 | * {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast. |
| 1166 | * |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1167 | * <p>This method is equivalent to calling |
| 1168 | * {@link #setBitmap(Bitmap, Rect, boolean)} and passing {@code null} for the |
| 1169 | * {@code visibleCrop} rectangle and {@code true} for the {@code allowBackup} |
| 1170 | * parameter. |
| 1171 | * |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 1172 | * <p>This method requires the caller to hold the permission |
| 1173 | * {@link android.Manifest.permission#SET_WALLPAPER}. |
| 1174 | * |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1175 | * @param bitmap The bitmap to be used as the new system wallpaper. |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1176 | * |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1177 | * @throws IOException If an error occurs when attempting to set the wallpaper |
| 1178 | * to the provided image. |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1179 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1180 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1181 | public void setBitmap(Bitmap bitmap) throws IOException { |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1182 | setBitmap(bitmap, null, true); |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Change the current system wallpaper to a bitmap, specifying a hint about |
| 1187 | * which subrectangle of the full image is to be visible. The OS will then |
| 1188 | * try to best present the given portion of the full image as the static system |
| 1189 | * wallpaper image. On success, the intent |
| 1190 | * {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast. |
| 1191 | * |
| 1192 | * <p>Passing {@code null} as the {@code visibleHint} parameter is equivalent to |
| 1193 | * passing (0, 0, {@code fullImage.getWidth()}, {@code fullImage.getHeight()}). |
| 1194 | * |
| 1195 | * <p>This method requires the caller to hold the permission |
| 1196 | * {@link android.Manifest.permission#SET_WALLPAPER}. |
| 1197 | * |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1198 | * @param fullImage A bitmap that will supply the wallpaper imagery. |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1199 | * @param visibleCropHint The rectangular subregion of {@code fullImage} that should be |
| 1200 | * displayed as wallpaper. Passing {@code null} for this parameter means that |
| 1201 | * the full image should be displayed if possible given the image's and device's |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1202 | * aspect ratios, etc. |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1203 | * @param allowBackup {@code true} if the OS is permitted to back up this wallpaper |
| 1204 | * image for restore to a future device; {@code false} otherwise. |
| 1205 | * |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1206 | * @return An integer ID assigned to the newly active wallpaper; or zero on failure. |
| 1207 | * |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1208 | * @throws IOException If an error occurs when attempting to set the wallpaper |
| 1209 | * to the provided image. |
| 1210 | * @throws IllegalArgumentException If the {@code visibleCropHint} rectangle is |
| 1211 | * empty or invalid. |
| 1212 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1213 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1214 | public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup) |
| 1215 | throws IOException { |
Edward Savage-Jones | 6009d9d | 2016-08-30 18:44:19 +0200 | [diff] [blame] | 1216 | return setBitmap(fullImage, visibleCropHint, allowBackup, FLAG_SYSTEM | FLAG_LOCK); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | /** |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1220 | * Version of {@link #setBitmap(Bitmap, Rect, boolean)} that allows the caller |
| 1221 | * to specify which of the supported wallpaper categories to set. |
| 1222 | * |
| 1223 | * @param fullImage A bitmap that will supply the wallpaper imagery. |
| 1224 | * @param visibleCropHint The rectangular subregion of {@code fullImage} that should be |
| 1225 | * displayed as wallpaper. Passing {@code null} for this parameter means that |
| 1226 | * the full image should be displayed if possible given the image's and device's |
| 1227 | * aspect ratios, etc. |
| 1228 | * @param allowBackup {@code true} if the OS is permitted to back up this wallpaper |
| 1229 | * image for restore to a future device; {@code false} otherwise. |
| 1230 | * @param which Flags indicating which wallpaper(s) to configure with the new imagery. |
| 1231 | * |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1232 | * @see #FLAG_LOCK |
| 1233 | * @see #FLAG_SYSTEM |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1234 | * |
| 1235 | * @return An integer ID assigned to the newly active wallpaper; or zero on failure. |
| 1236 | * |
| 1237 | * @throws IOException |
| 1238 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1239 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1240 | public int setBitmap(Bitmap fullImage, Rect visibleCropHint, |
| 1241 | boolean allowBackup, @SetWallpaperFlags int which) |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1242 | throws IOException { |
Jorim Jaggi | 6c902d0 | 2016-08-18 10:44:54 -0700 | [diff] [blame] | 1243 | return setBitmap(fullImage, visibleCropHint, allowBackup, which, |
| 1244 | UserHandle.myUserId()); |
| 1245 | } |
| 1246 | |
| 1247 | /** |
| 1248 | * Like {@link #setBitmap(Bitmap, Rect, boolean, int)}, but allows to pass in an explicit user |
| 1249 | * id. If the user id doesn't match the user id the process is running under, calling this |
| 1250 | * requires permission {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}. |
| 1251 | * @hide |
| 1252 | */ |
| 1253 | public int setBitmap(Bitmap fullImage, Rect visibleCropHint, |
| 1254 | boolean allowBackup, @SetWallpaperFlags int which, int userId) |
| 1255 | throws IOException { |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1256 | validateRect(visibleCropHint); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1257 | if (sGlobals.mService == null) { |
| 1258 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1259 | throw new RuntimeException(new DeadSystemException()); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1260 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1261 | final Bundle result = new Bundle(); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1262 | final WallpaperSetCompletion completion = new WallpaperSetCompletion(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1263 | try { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1264 | ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null, |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1265 | mContext.getOpPackageName(), visibleCropHint, allowBackup, |
Jorim Jaggi | 6c902d0 | 2016-08-18 10:44:54 -0700 | [diff] [blame] | 1266 | result, which, completion, userId); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1267 | if (fd != null) { |
| 1268 | FileOutputStream fos = null; |
| 1269 | try { |
| 1270 | fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd); |
| 1271 | fullImage.compress(Bitmap.CompressFormat.PNG, 90, fos); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1272 | fos.close(); |
| 1273 | completion.waitForCompletion(); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1274 | } finally { |
| 1275 | IoUtils.closeQuietly(fos); |
| 1276 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1277 | } |
| 1278 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1279 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1280 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1281 | return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1284 | private final void validateRect(Rect rect) { |
| 1285 | if (rect != null && rect.isEmpty()) { |
| 1286 | throw new IllegalArgumentException("visibleCrop rectangle must be valid and non-empty"); |
| 1287 | } |
| 1288 | } |
| 1289 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1290 | /** |
| 1291 | * Change the current system wallpaper to a specific byte stream. The |
| 1292 | * give InputStream is copied into persistent storage and will now be |
| 1293 | * used as the wallpaper. Currently it must be either a JPEG or PNG |
| 1294 | * image. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED} |
| 1295 | * is broadcast. |
| 1296 | * |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1297 | * <p>This method is equivalent to calling |
| 1298 | * {@link #setStream(InputStream, Rect, boolean)} and passing {@code null} for the |
| 1299 | * {@code visibleCrop} rectangle and {@code true} for the {@code allowBackup} |
| 1300 | * parameter. |
| 1301 | * |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 1302 | * <p>This method requires the caller to hold the permission |
| 1303 | * {@link android.Manifest.permission#SET_WALLPAPER}. |
| 1304 | * |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1305 | * @param bitmapData A stream containing the raw data to install as a wallpaper. This |
| 1306 | * data can be in any format handled by {@link BitmapRegionDecoder}. |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1307 | * |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1308 | * @throws IOException If an error occurs when attempting to set the wallpaper |
| 1309 | * based on the provided image data. |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1310 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1311 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1312 | public void setStream(InputStream bitmapData) throws IOException { |
| 1313 | setStream(bitmapData, null, true); |
| 1314 | } |
| 1315 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1316 | private void copyStreamToWallpaperFile(InputStream data, FileOutputStream fos) |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1317 | throws IOException { |
| 1318 | byte[] buffer = new byte[32768]; |
| 1319 | int amt; |
| 1320 | while ((amt=data.read(buffer)) > 0) { |
| 1321 | fos.write(buffer, 0, amt); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * Change the current system wallpaper to a specific byte stream, specifying a |
| 1327 | * hint about which subrectangle of the full image is to be visible. The OS will |
| 1328 | * then try to best present the given portion of the full image as the static system |
| 1329 | * wallpaper image. The data from the given InputStream is copied into persistent |
| 1330 | * storage and will then be used as the system wallpaper. Currently the data must |
| 1331 | * be either a JPEG or PNG image. On success, the intent |
| 1332 | * {@link Intent#ACTION_WALLPAPER_CHANGED} is broadcast. |
| 1333 | * |
| 1334 | * <p>This method requires the caller to hold the permission |
| 1335 | * {@link android.Manifest.permission#SET_WALLPAPER}. |
| 1336 | * |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1337 | * @param bitmapData A stream containing the raw data to install as a wallpaper. This |
| 1338 | * data can be in any format handled by {@link BitmapRegionDecoder}. |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1339 | * @param visibleCropHint The rectangular subregion of the streamed image that should be |
| 1340 | * displayed as wallpaper. Passing {@code null} for this parameter means that |
| 1341 | * the full image should be displayed if possible given the image's and device's |
| 1342 | * aspect ratios, etc. |
| 1343 | * @param allowBackup {@code true} if the OS is permitted to back up this wallpaper |
| 1344 | * image for restore to a future device; {@code false} otherwise. |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1345 | * @return An integer ID assigned to the newly active wallpaper; or zero on failure. |
| 1346 | * |
| 1347 | * @see #getWallpaperId(int) |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1348 | * |
| 1349 | * @throws IOException If an error occurs when attempting to set the wallpaper |
| 1350 | * based on the provided image data. |
| 1351 | * @throws IllegalArgumentException If the {@code visibleCropHint} rectangle is |
| 1352 | * empty or invalid. |
| 1353 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1354 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1355 | public int setStream(InputStream bitmapData, Rect visibleCropHint, boolean allowBackup) |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1356 | throws IOException { |
Edward Savage-Jones | 6009d9d | 2016-08-30 18:44:19 +0200 | [diff] [blame] | 1357 | return setStream(bitmapData, visibleCropHint, allowBackup, FLAG_SYSTEM | FLAG_LOCK); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | /** |
| 1361 | * Version of {@link #setStream(InputStream, Rect, boolean)} that allows the caller |
| 1362 | * to specify which of the supported wallpaper categories to set. |
| 1363 | * |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1364 | * @param bitmapData A stream containing the raw data to install as a wallpaper. This |
| 1365 | * data can be in any format handled by {@link BitmapRegionDecoder}. |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1366 | * @param visibleCropHint The rectangular subregion of the streamed image that should be |
| 1367 | * displayed as wallpaper. Passing {@code null} for this parameter means that |
| 1368 | * the full image should be displayed if possible given the image's and device's |
| 1369 | * aspect ratios, etc. |
| 1370 | * @param allowBackup {@code true} if the OS is permitted to back up this wallpaper |
| 1371 | * image for restore to a future device; {@code false} otherwise. |
| 1372 | * @param which Flags indicating which wallpaper(s) to configure with the new imagery. |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1373 | * @return An integer ID assigned to the newly active wallpaper; or zero on failure. |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1374 | * |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1375 | * @see #getWallpaperId(int) |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1376 | * @see #FLAG_LOCK |
| 1377 | * @see #FLAG_SYSTEM |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1378 | * |
| 1379 | * @throws IOException |
| 1380 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1381 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1382 | public int setStream(InputStream bitmapData, Rect visibleCropHint, |
| 1383 | boolean allowBackup, @SetWallpaperFlags int which) |
| 1384 | throws IOException { |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1385 | validateRect(visibleCropHint); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1386 | if (sGlobals.mService == null) { |
| 1387 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1388 | throw new RuntimeException(new DeadSystemException()); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1389 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1390 | final Bundle result = new Bundle(); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1391 | final WallpaperSetCompletion completion = new WallpaperSetCompletion(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1392 | try { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1393 | ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null, |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1394 | mContext.getOpPackageName(), visibleCropHint, allowBackup, |
Jorim Jaggi | 6c902d0 | 2016-08-18 10:44:54 -0700 | [diff] [blame] | 1395 | result, which, completion, UserHandle.myUserId()); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1396 | if (fd != null) { |
| 1397 | FileOutputStream fos = null; |
| 1398 | try { |
| 1399 | fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd); |
| 1400 | copyStreamToWallpaperFile(bitmapData, fos); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1401 | fos.close(); |
| 1402 | completion.waitForCompletion(); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1403 | } finally { |
| 1404 | IoUtils.closeQuietly(fos); |
| 1405 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1406 | } |
| 1407 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1408 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1409 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1410 | |
| 1411 | return result.getInt(EXTRA_NEW_WALLPAPER_ID, 0); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1414 | /** |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1415 | * Return whether any users are currently set to use the wallpaper |
| 1416 | * with the given resource ID. That is, their wallpaper has been |
| 1417 | * set through {@link #setResource(int)} with the same resource id. |
| 1418 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 1419 | public boolean hasResourceWallpaper(@RawRes int resid) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1420 | if (sGlobals.mService == null) { |
| 1421 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1422 | throw new RuntimeException(new DeadSystemException()); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1423 | } |
| 1424 | try { |
| 1425 | Resources resources = mContext.getResources(); |
| 1426 | String name = "res:" + resources.getResourceName(resid); |
| 1427 | return sGlobals.mService.hasNamedWallpaper(name); |
| 1428 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1429 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | /** |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1434 | * Returns the desired minimum width for the wallpaper. Callers of |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1435 | * {@link #setBitmap(android.graphics.Bitmap)} or |
| 1436 | * {@link #setStream(java.io.InputStream)} should check this value |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1437 | * beforehand to make sure the supplied wallpaper respects the desired |
| 1438 | * minimum width. |
| 1439 | * |
| 1440 | * If the returned value is <= 0, the caller should use the width of |
| 1441 | * the default display instead. |
| 1442 | * |
| 1443 | * @return The desired minimum width for the wallpaper. This value should |
| 1444 | * be honored by applications that set the wallpaper but it is not |
| 1445 | * mandatory. |
| 1446 | */ |
| 1447 | public int getDesiredMinimumWidth() { |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1448 | if (sGlobals.mService == null) { |
| 1449 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1450 | throw new RuntimeException(new DeadSystemException()); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1451 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1452 | try { |
Dianne Hackborn | 840c3a2 | 2009-09-02 17:35:17 -0700 | [diff] [blame] | 1453 | return sGlobals.mService.getWidthHint(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1454 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1455 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | /** |
| 1460 | * Returns the desired minimum height for the wallpaper. Callers of |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1461 | * {@link #setBitmap(android.graphics.Bitmap)} or |
| 1462 | * {@link #setStream(java.io.InputStream)} should check this value |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1463 | * beforehand to make sure the supplied wallpaper respects the desired |
| 1464 | * minimum height. |
| 1465 | * |
| 1466 | * If the returned value is <= 0, the caller should use the height of |
| 1467 | * the default display instead. |
| 1468 | * |
| 1469 | * @return The desired minimum height for the wallpaper. This value should |
| 1470 | * be honored by applications that set the wallpaper but it is not |
| 1471 | * mandatory. |
| 1472 | */ |
| 1473 | public int getDesiredMinimumHeight() { |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1474 | if (sGlobals.mService == null) { |
| 1475 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1476 | throw new RuntimeException(new DeadSystemException()); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1477 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1478 | try { |
Dianne Hackborn | 840c3a2 | 2009-09-02 17:35:17 -0700 | [diff] [blame] | 1479 | return sGlobals.mService.getHeightHint(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1480 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1481 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | /** |
| 1486 | * For use only by the current home application, to specify the size of |
| 1487 | * wallpaper it would like to use. This allows such applications to have |
| 1488 | * a virtual wallpaper that is larger than the physical screen, matching |
| 1489 | * the size of their workspace. |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1490 | * |
| 1491 | * <p>Note developers, who don't seem to be reading this. This is |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1492 | * for <em>home apps</em> to tell what size wallpaper they would like. |
| 1493 | * Nobody else should be calling this! Certainly not other non-home |
Dianne Hackborn | c5bf758 | 2012-04-25 19:12:07 -0700 | [diff] [blame] | 1494 | * apps that change the wallpaper. Those apps are supposed to |
| 1495 | * <b>retrieve</b> the suggested size so they can construct a wallpaper |
| 1496 | * that matches it. |
| 1497 | * |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 1498 | * <p>This method requires the caller to hold the permission |
| 1499 | * {@link android.Manifest.permission#SET_WALLPAPER_HINTS}. |
| 1500 | * |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1501 | * @param minimumWidth Desired minimum width |
| 1502 | * @param minimumHeight Desired minimum height |
| 1503 | */ |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1504 | public void suggestDesiredDimensions(int minimumWidth, int minimumHeight) { |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1505 | try { |
Donghan Ryu | 289c273 | 2011-11-14 18:56:11 -0800 | [diff] [blame] | 1506 | /** |
| 1507 | * The framework makes no attempt to limit the window size |
| 1508 | * to the maximum texture size. Any window larger than this |
| 1509 | * cannot be composited. |
| 1510 | * |
| 1511 | * Read maximum texture size from system property and scale down |
| 1512 | * minimumWidth and minimumHeight accordingly. |
| 1513 | */ |
| 1514 | int maximumTextureSize; |
| 1515 | try { |
| 1516 | maximumTextureSize = SystemProperties.getInt("sys.max_texture_size", 0); |
| 1517 | } catch (Exception e) { |
| 1518 | maximumTextureSize = 0; |
| 1519 | } |
| 1520 | |
| 1521 | if (maximumTextureSize > 0) { |
| 1522 | if ((minimumWidth > maximumTextureSize) || |
| 1523 | (minimumHeight > maximumTextureSize)) { |
| 1524 | float aspect = (float)minimumHeight / (float)minimumWidth; |
| 1525 | if (minimumWidth > minimumHeight) { |
| 1526 | minimumWidth = maximumTextureSize; |
| 1527 | minimumHeight = (int)((minimumWidth * aspect) + 0.5); |
| 1528 | } else { |
| 1529 | minimumHeight = maximumTextureSize; |
| 1530 | minimumWidth = (int)((minimumHeight / aspect) + 0.5); |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1535 | if (sGlobals.mService == null) { |
| 1536 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1537 | throw new RuntimeException(new DeadSystemException()); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1538 | } else { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1539 | sGlobals.mService.setDimensionHints(minimumWidth, minimumHeight, |
| 1540 | mContext.getOpPackageName()); |
Mike Lockwood | c067c9c | 2011-10-31 12:50:12 -0400 | [diff] [blame] | 1541 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1542 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1543 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1544 | } |
| 1545 | } |
Adam Cohen | 041a0ba | 2011-11-09 20:10:27 -0800 | [diff] [blame] | 1546 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1547 | /** |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1548 | * Specify extra padding that the wallpaper should have outside of the display. |
| 1549 | * That is, the given padding supplies additional pixels the wallpaper should extend |
| 1550 | * outside of the display itself. |
| 1551 | * @param padding The number of pixels the wallpaper should extend beyond the display, |
| 1552 | * on its left, top, right, and bottom sides. |
| 1553 | * @hide |
| 1554 | */ |
| 1555 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1556 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_HINTS) |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1557 | public void setDisplayPadding(Rect padding) { |
| 1558 | try { |
| 1559 | if (sGlobals.mService == null) { |
| 1560 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1561 | throw new RuntimeException(new DeadSystemException()); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1562 | } else { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1563 | sGlobals.mService.setDisplayPadding(padding, mContext.getOpPackageName()); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1564 | } |
| 1565 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1566 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | /** |
| 1571 | * Apply a raw offset to the wallpaper window. Should only be used in |
| 1572 | * combination with {@link #setDisplayPadding(android.graphics.Rect)} when you |
| 1573 | * have ensured that the wallpaper will extend outside of the display area so that |
| 1574 | * it can be moved without leaving part of the display uncovered. |
| 1575 | * @param x The offset, in pixels, to apply to the left edge. |
| 1576 | * @param y The offset, in pixels, to apply to the top edge. |
| 1577 | * @hide |
| 1578 | */ |
| 1579 | @SystemApi |
| 1580 | public void setDisplayOffset(IBinder windowToken, int x, int y) { |
| 1581 | try { |
| 1582 | //Log.v(TAG, "Sending new wallpaper display offsets from app..."); |
| 1583 | WindowManagerGlobal.getWindowSession().setWallpaperDisplayOffset( |
| 1584 | windowToken, x, y); |
| 1585 | //Log.v(TAG, "...app returning after sending display offset!"); |
| 1586 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1587 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | /** |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1592 | * Clear the wallpaper. |
| 1593 | * |
| 1594 | * @hide |
| 1595 | */ |
| 1596 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1597 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1598 | public void clearWallpaper() { |
Christopher Tate | a2bd512 | 2016-09-22 13:18:05 -0700 | [diff] [blame] | 1599 | clearWallpaper(FLAG_LOCK, mContext.getUserId()); |
| 1600 | clearWallpaper(FLAG_SYSTEM, mContext.getUserId()); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | /** |
| 1604 | * Clear the wallpaper for a specific user. The caller must hold the |
| 1605 | * INTERACT_ACROSS_USERS_FULL permission to clear another user's |
Christopher Tate | 11620ed | 2017-08-28 14:16:22 -0700 | [diff] [blame] | 1606 | * wallpaper, and must hold the SET_WALLPAPER permission in all |
| 1607 | * circumstances. |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1608 | * @hide |
| 1609 | */ |
| 1610 | @SystemApi |
Christopher Tate | 11620ed | 2017-08-28 14:16:22 -0700 | [diff] [blame] | 1611 | @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1612 | public void clearWallpaper(@SetWallpaperFlags int which, int userId) { |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1613 | if (sGlobals.mService == null) { |
| 1614 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1615 | throw new RuntimeException(new DeadSystemException()); |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1616 | } |
| 1617 | try { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1618 | sGlobals.mService.clearWallpaper(mContext.getOpPackageName(), which, userId); |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1619 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1620 | throw e.rethrowFromSystemServer(); |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | /** |
| 1625 | * Set the live wallpaper. |
| 1626 | * |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1627 | * @hide |
| 1628 | */ |
| 1629 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1630 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT) |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1631 | public boolean setWallpaperComponent(ComponentName name) { |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 1632 | return setWallpaperComponent(name, UserHandle.myUserId()); |
| 1633 | } |
| 1634 | |
| 1635 | /** |
| 1636 | * Set the live wallpaper. |
| 1637 | * |
| 1638 | * This can only be called by packages with android.permission.SET_WALLPAPER_COMPONENT |
| 1639 | * permission. The caller must hold the INTERACT_ACROSS_USERS_FULL permission to change |
| 1640 | * another user's wallpaper. |
| 1641 | * |
| 1642 | * @hide |
| 1643 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1644 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT) |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 1645 | public boolean setWallpaperComponent(ComponentName name, int userId) { |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1646 | if (sGlobals.mService == null) { |
| 1647 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1648 | throw new RuntimeException(new DeadSystemException()); |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1649 | } |
| 1650 | try { |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 1651 | sGlobals.mService.setWallpaperComponentChecked(name, mContext.getOpPackageName(), |
| 1652 | userId); |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1653 | return true; |
| 1654 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1655 | throw e.rethrowFromSystemServer(); |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1656 | } |
Filip Gruszczynski | 9fedc72 | 2015-01-28 15:59:46 -0800 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /** |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1660 | * Set the display position of the current wallpaper within any larger space, when |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1661 | * that wallpaper is visible behind the given window. The X and Y offsets |
| 1662 | * are floating point numbers ranging from 0 to 1, representing where the |
| 1663 | * wallpaper should be positioned within the screen space. These only |
Christopher Tate | ffa6a88 | 2015-12-11 15:08:46 -0800 | [diff] [blame] | 1664 | * make sense when the wallpaper is larger than the display. |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1665 | * |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1666 | * @param windowToken The window who these offsets should be associated |
Scott Main | 8b2e000 | 2009-09-29 18:17:31 -0700 | [diff] [blame] | 1667 | * with, as returned by {@link android.view.View#getWindowToken() |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1668 | * View.getWindowToken()}. |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1669 | * @param xOffset The offset along the X dimension, from 0 to 1. |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1670 | * @param yOffset The offset along the Y dimension, from 0 to 1. |
| 1671 | */ |
| 1672 | public void setWallpaperOffsets(IBinder windowToken, float xOffset, float yOffset) { |
Adam Cohen | 791a633 | 2012-01-12 14:38:38 -0800 | [diff] [blame] | 1673 | try { |
| 1674 | //Log.v(TAG, "Sending new wallpaper offsets from app..."); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 1675 | WindowManagerGlobal.getWindowSession().setWallpaperPosition( |
Adam Cohen | 791a633 | 2012-01-12 14:38:38 -0800 | [diff] [blame] | 1676 | windowToken, xOffset, yOffset, mWallpaperXStep, mWallpaperYStep); |
| 1677 | //Log.v(TAG, "...app returning after sending offsets!"); |
| 1678 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1679 | throw e.rethrowFromSystemServer(); |
Adam Cohen | 791a633 | 2012-01-12 14:38:38 -0800 | [diff] [blame] | 1680 | } |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1681 | } |
Adam Cohen | 041a0ba | 2011-11-09 20:10:27 -0800 | [diff] [blame] | 1682 | |
Dianne Hackborn | c8a0a75 | 2009-08-10 23:05:49 -0700 | [diff] [blame] | 1683 | /** |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1684 | * For applications that use multiple virtual screens showing a wallpaper, |
| 1685 | * specify the step size between virtual screens. For example, if the |
Dianne Hackborn | 23ef7b4 | 2009-11-18 18:20:39 -0800 | [diff] [blame] | 1686 | * launcher has 3 virtual screens, it would specify an xStep of 0.5, |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1687 | * since the X offset for those screens are 0.0, 0.5 and 1.0 |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1688 | * @param xStep The X offset delta from one screen to the next one |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1689 | * @param yStep The Y offset delta from one screen to the next one |
| 1690 | */ |
| 1691 | public void setWallpaperOffsetSteps(float xStep, float yStep) { |
| 1692 | mWallpaperXStep = xStep; |
| 1693 | mWallpaperYStep = yStep; |
| 1694 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1695 | |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1696 | /** |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1697 | * Send an arbitrary command to the current active wallpaper. |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1698 | * |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1699 | * @param windowToken The window who these offsets should be associated |
| 1700 | * with, as returned by {@link android.view.View#getWindowToken() |
| 1701 | * View.getWindowToken()}. |
| 1702 | * @param action Name of the command to perform. This must be a scoped |
| 1703 | * name to avoid collisions, such as "com.mycompany.wallpaper.DOIT". |
| 1704 | * @param x Arbitrary integer argument based on command. |
| 1705 | * @param y Arbitrary integer argument based on command. |
| 1706 | * @param z Arbitrary integer argument based on command. |
| 1707 | * @param extras Optional additional information for the command, or null. |
| 1708 | */ |
| 1709 | public void sendWallpaperCommand(IBinder windowToken, String action, |
| 1710 | int x, int y, int z, Bundle extras) { |
| 1711 | try { |
| 1712 | //Log.v(TAG, "Sending new wallpaper offsets from app..."); |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 1713 | WindowManagerGlobal.getWindowSession().sendWallpaperCommand( |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1714 | windowToken, action, x, y, z, extras, false); |
| 1715 | //Log.v(TAG, "...app returning after sending offsets!"); |
| 1716 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1717 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1718 | } |
| 1719 | } |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1720 | |
| 1721 | /** |
| 1722 | * Returns whether wallpapers are supported for the calling user. If this function returns |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1723 | * {@code false}, any attempts to changing the wallpaper will have no effect, |
| 1724 | * and any attempt to obtain of the wallpaper will return {@code null}. |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1725 | */ |
| 1726 | public boolean isWallpaperSupported() { |
| 1727 | if (sGlobals.mService == null) { |
| 1728 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1729 | throw new RuntimeException(new DeadSystemException()); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1730 | } else { |
| 1731 | try { |
| 1732 | return sGlobals.mService.isWallpaperSupported(mContext.getOpPackageName()); |
| 1733 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1734 | throw e.rethrowFromSystemServer(); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1735 | } |
| 1736 | } |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1739 | /** |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1740 | * Returns whether the calling package is allowed to set the wallpaper for the calling user. |
| 1741 | * If this function returns {@code false}, any attempts to change the wallpaper will have |
| 1742 | * no effect. Always returns {@code true} for device owner and profile owner. |
| 1743 | * |
| 1744 | * @see android.os.UserManager#DISALLOW_SET_WALLPAPER |
| 1745 | */ |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1746 | public boolean isSetWallpaperAllowed() { |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1747 | if (sGlobals.mService == null) { |
| 1748 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1749 | throw new RuntimeException(new DeadSystemException()); |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1750 | } else { |
| 1751 | try { |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1752 | return sGlobals.mService.isSetWallpaperAllowed(mContext.getOpPackageName()); |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1753 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1754 | throw e.rethrowFromSystemServer(); |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1755 | } |
| 1756 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | /** |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1760 | * Clear the offsets previously associated with this window through |
| 1761 | * {@link #setWallpaperOffsets(IBinder, float, float)}. This reverts |
| 1762 | * the window to its default state, where it does not cause the wallpaper |
| 1763 | * to scroll from whatever its last offsets were. |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1764 | * |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1765 | * @param windowToken The window who these offsets should be associated |
Scott Main | 8b2e000 | 2009-09-29 18:17:31 -0700 | [diff] [blame] | 1766 | * with, as returned by {@link android.view.View#getWindowToken() |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1767 | * View.getWindowToken()}. |
| 1768 | */ |
| 1769 | public void clearWallpaperOffsets(IBinder windowToken) { |
| 1770 | try { |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 1771 | WindowManagerGlobal.getWindowSession().setWallpaperPosition( |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1772 | windowToken, -1, -1, -1, -1); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1773 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1774 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1775 | } |
| 1776 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1777 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1778 | /** |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1779 | * Remove any currently set system wallpaper, reverting to the system's built-in |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1780 | * wallpaper. On success, the intent {@link Intent#ACTION_WALLPAPER_CHANGED} |
| 1781 | * is broadcast. |
| 1782 | * |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 1783 | * <p>This method requires the caller to hold the permission |
| 1784 | * {@link android.Manifest.permission#SET_WALLPAPER}. |
| 1785 | * |
Michael Jurka | b668d0b | 2013-10-04 15:11:05 -0700 | [diff] [blame] | 1786 | * @throws IOException If an error occurs reverting to the built-in |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1787 | * wallpaper. |
| 1788 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1789 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1790 | public void clear() throws IOException { |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1791 | setStream(openDefaultWallpaper(mContext, FLAG_SYSTEM), null, false); |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | /** |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1795 | * Remove one or more currently set wallpapers, reverting to the system default |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1796 | * display for each one. If {@link #FLAG_SYSTEM} is set in the {@code which} |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1797 | * parameter, the intent {@link Intent#ACTION_WALLPAPER_CHANGED} will be broadcast |
| 1798 | * upon success. |
| 1799 | * |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1800 | * @param which A bitwise combination of {@link #FLAG_SYSTEM} or |
| 1801 | * {@link #FLAG_LOCK} |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1802 | * @throws IOException If an error occurs reverting to the built-in wallpaper. |
| 1803 | */ |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 1804 | @RequiresPermission(android.Manifest.permission.SET_WALLPAPER) |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1805 | public void clear(@SetWallpaperFlags int which) throws IOException { |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1806 | if ((which & FLAG_SYSTEM) != 0) { |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1807 | clear(); |
| 1808 | } |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1809 | if ((which & FLAG_LOCK) != 0) { |
| 1810 | clearWallpaper(FLAG_LOCK, mContext.getUserId()); |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | /** |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 1815 | * Open stream representing the default static image wallpaper. |
| 1816 | * |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1817 | * If the device defines no default wallpaper of the requested kind, |
| 1818 | * {@code null} is returned. |
| 1819 | * |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 1820 | * @hide |
| 1821 | */ |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1822 | public static InputStream openDefaultWallpaper(Context context, @SetWallpaperFlags int which) { |
| 1823 | final String whichProp; |
| 1824 | final int defaultResId; |
| 1825 | if (which == FLAG_LOCK) { |
Christopher Tate | 36cb2a7a | 2016-06-09 13:44:48 -0700 | [diff] [blame] | 1826 | /* Factory-default lock wallpapers are not yet supported |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1827 | whichProp = PROP_LOCK_WALLPAPER; |
| 1828 | defaultResId = com.android.internal.R.drawable.default_lock_wallpaper; |
Christopher Tate | 36cb2a7a | 2016-06-09 13:44:48 -0700 | [diff] [blame] | 1829 | */ |
| 1830 | return null; |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1831 | } else { |
| 1832 | whichProp = PROP_WALLPAPER; |
| 1833 | defaultResId = com.android.internal.R.drawable.default_wallpaper; |
| 1834 | } |
| 1835 | final String path = SystemProperties.get(whichProp); |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 1836 | if (!TextUtils.isEmpty(path)) { |
| 1837 | final File file = new File(path); |
| 1838 | if (file.exists()) { |
| 1839 | try { |
| 1840 | return new FileInputStream(file); |
| 1841 | } catch (IOException e) { |
| 1842 | // Ignored, fall back to platform default below |
| 1843 | } |
| 1844 | } |
| 1845 | } |
Christopher Tate | 5d99d47 | 2016-05-06 17:59:27 -0700 | [diff] [blame] | 1846 | try { |
| 1847 | return context.getResources().openRawResource(defaultResId); |
| 1848 | } catch (NotFoundException e) { |
| 1849 | // no default defined for this device; this is not a failure |
| 1850 | } |
| 1851 | return null; |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | /** |
| 1855 | * Return {@link ComponentName} of the default live wallpaper, or |
| 1856 | * {@code null} if none is defined. |
| 1857 | * |
| 1858 | * @hide |
| 1859 | */ |
| 1860 | public static ComponentName getDefaultWallpaperComponent(Context context) { |
| 1861 | String flat = SystemProperties.get(PROP_WALLPAPER_COMPONENT); |
| 1862 | if (!TextUtils.isEmpty(flat)) { |
| 1863 | final ComponentName cn = ComponentName.unflattenFromString(flat); |
| 1864 | if (cn != null) { |
| 1865 | return cn; |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | flat = context.getString(com.android.internal.R.string.default_wallpaper_component); |
| 1870 | if (!TextUtils.isEmpty(flat)) { |
| 1871 | final ComponentName cn = ComponentName.unflattenFromString(flat); |
| 1872 | if (cn != null) { |
| 1873 | return cn; |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | return null; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1878 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1879 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1880 | /** |
| 1881 | * Register a callback for lock wallpaper observation. Only the OS may use this. |
| 1882 | * |
| 1883 | * @return true on success; false on error. |
| 1884 | * @hide |
| 1885 | */ |
| 1886 | public boolean setLockWallpaperCallback(IWallpaperManagerCallback callback) { |
| 1887 | if (sGlobals.mService == null) { |
| 1888 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1889 | throw new RuntimeException(new DeadSystemException()); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | try { |
| 1893 | return sGlobals.mService.setLockWallpaperCallback(callback); |
| 1894 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1895 | throw e.rethrowFromSystemServer(); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1896 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1897 | } |
| 1898 | |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1899 | /** |
| 1900 | * Is the current system wallpaper eligible for backup? |
| 1901 | * |
| 1902 | * Only the OS itself may use this method. |
| 1903 | * @hide |
| 1904 | */ |
Christopher Tate | 6172266 | 2016-08-10 16:13:14 -0700 | [diff] [blame] | 1905 | public boolean isWallpaperBackupEligible(int which) { |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1906 | if (sGlobals.mService == null) { |
| 1907 | Log.w(TAG, "WallpaperService not running"); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1908 | throw new RuntimeException(new DeadSystemException()); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1909 | } |
| 1910 | try { |
Christopher Tate | 6172266 | 2016-08-10 16:13:14 -0700 | [diff] [blame] | 1911 | return sGlobals.mService.isWallpaperBackupEligible(which, mContext.getUserId()); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1912 | } catch (RemoteException e) { |
| 1913 | Log.e(TAG, "Exception querying wallpaper backup eligibility: " + e.getMessage()); |
| 1914 | } |
| 1915 | return false; |
| 1916 | } |
| 1917 | |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1918 | // Private completion callback for setWallpaper() synchronization |
| 1919 | private class WallpaperSetCompletion extends IWallpaperManagerCallback.Stub { |
| 1920 | final CountDownLatch mLatch; |
| 1921 | |
| 1922 | public WallpaperSetCompletion() { |
| 1923 | mLatch = new CountDownLatch(1); |
| 1924 | } |
| 1925 | |
| 1926 | public void waitForCompletion() { |
| 1927 | try { |
| 1928 | mLatch.await(30, TimeUnit.SECONDS); |
| 1929 | } catch (InterruptedException e) { |
| 1930 | // This might be legit: the crop may take a very long time. Don't sweat |
| 1931 | // it in that case; we are okay with display lagging behind in order to |
| 1932 | // keep the caller from locking up indeterminately. |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | @Override |
| 1937 | public void onWallpaperChanged() throws RemoteException { |
| 1938 | mLatch.countDown(); |
| 1939 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 1940 | |
| 1941 | @Override |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 1942 | public void onWallpaperColorsChanged(WallpaperColors colors, int which, int userId) |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 1943 | throws RemoteException { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 1944 | sGlobals.onWallpaperColorsChanged(colors, which, userId); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 1945 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1946 | } |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 1947 | |
| 1948 | /** |
| 1949 | * Interface definition for a callback to be invoked when colors change on a wallpaper. |
| 1950 | */ |
| 1951 | public interface OnColorsChangedListener { |
| 1952 | /** |
| 1953 | * Called when colors change. |
| 1954 | * A {@link android.app.WallpaperColors} object containing a simplified |
| 1955 | * color histogram will be given. |
| 1956 | * |
| 1957 | * @param colors Wallpaper color info |
| 1958 | * @param which A combination of {@link #FLAG_LOCK} and {@link #FLAG_SYSTEM} |
| 1959 | */ |
| 1960 | void onColorsChanged(WallpaperColors colors, int which); |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 1961 | |
| 1962 | /** |
| 1963 | * Called when colors change. |
| 1964 | * A {@link android.app.WallpaperColors} object containing a simplified |
| 1965 | * color histogram will be given. |
| 1966 | * |
| 1967 | * @param colors Wallpaper color info |
| 1968 | * @param which A combination of {@link #FLAG_LOCK} and {@link #FLAG_SYSTEM} |
| 1969 | * @param userId Owner of the wallpaper |
| 1970 | * @hide |
| 1971 | */ |
| 1972 | default void onColorsChanged(WallpaperColors colors, int which, int userId) { |
| 1973 | onColorsChanged(colors, which); |
| 1974 | } |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 1975 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1976 | } |