The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 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 | |
| 17 | package com.android.server; |
| 18 | |
| 19 | import static android.os.FileObserver.*; |
| 20 | import static android.os.ParcelFileDescriptor.*; |
Christopher Tate | 111bd4a | 2009-06-24 17:29:38 -0700 | [diff] [blame] | 21 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 22 | import android.app.IWallpaperManager; |
| 23 | import android.app.IWallpaperManagerCallback; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 24 | import android.app.PendingIntent; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 25 | import android.app.WallpaperInfo; |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 26 | import android.app.backup.BackupManager; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 27 | import android.app.backup.WallpaperBackupHelper; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 31 | import android.content.ServiceConnection; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.pm.PackageManager; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 33 | import android.content.pm.ResolveInfo; |
| 34 | import android.content.pm.ServiceInfo; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 35 | import android.content.pm.PackageManager.NameNotFoundException; |
| 36 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.os.Binder; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 38 | import android.os.Bundle; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 39 | import android.os.FileUtils; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 40 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.os.RemoteException; |
| 42 | import android.os.FileObserver; |
| 43 | import android.os.ParcelFileDescriptor; |
| 44 | import android.os.RemoteCallbackList; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 45 | import android.os.ServiceManager; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 46 | import android.os.SystemClock; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 47 | import android.os.UserId; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 48 | import android.service.wallpaper.IWallpaperConnection; |
| 49 | import android.service.wallpaper.IWallpaperEngine; |
| 50 | import android.service.wallpaper.IWallpaperService; |
| 51 | import android.service.wallpaper.WallpaperService; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 52 | import android.util.Slog; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 53 | import android.util.SparseArray; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 54 | import android.util.Xml; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 55 | import android.view.Display; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 56 | import android.view.IWindowManager; |
| 57 | import android.view.WindowManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 59 | import java.io.FileDescriptor; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 60 | import java.io.IOException; |
| 61 | import java.io.InputStream; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import java.io.File; |
| 63 | import java.io.FileNotFoundException; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 64 | import java.io.FileInputStream; |
| 65 | import java.io.FileOutputStream; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 66 | import java.io.PrintWriter; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 67 | import java.util.List; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 68 | |
| 69 | import org.xmlpull.v1.XmlPullParser; |
| 70 | import org.xmlpull.v1.XmlPullParserException; |
| 71 | import org.xmlpull.v1.XmlSerializer; |
| 72 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 73 | import com.android.internal.content.PackageMonitor; |
Dianne Hackborn | 2269d157 | 2010-02-24 19:54:22 -0800 | [diff] [blame] | 74 | import com.android.internal.util.FastXmlSerializer; |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 75 | import com.android.internal.util.JournaledFile; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 76 | import com.android.server.am.ActivityManagerService; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 78 | class WallpaperManagerService extends IWallpaperManager.Stub { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 79 | static final String TAG = "WallpaperService"; |
Dianne Hackborn | cbf1504 | 2009-08-18 18:29:09 -0700 | [diff] [blame] | 80 | static final boolean DEBUG = false; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 81 | |
Romain Guy | 407ec78 | 2011-08-24 17:06:58 -0700 | [diff] [blame] | 82 | final Object mLock = new Object[0]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 84 | /** |
| 85 | * Minimum time between crashes of a wallpaper service for us to consider |
| 86 | * restarting it vs. just reverting to the static wallpaper. |
| 87 | */ |
| 88 | static final long MIN_WALLPAPER_CRASH_TIME = 10000; |
| 89 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 90 | static final File WALLPAPER_BASE_DIR = new File("/data/system/users"); |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 91 | static final String WALLPAPER = "wallpaper"; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 92 | static final String WALLPAPER_INFO = "wallpaper_info.xml"; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 93 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | /** |
| 95 | * Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks |
| 96 | * that the wallpaper has changed. The CREATE is triggered when there is no |
| 97 | * wallpaper set and is created for the first time. The CLOSE_WRITE is triggered |
| 98 | * everytime the wallpaper is changed. |
| 99 | */ |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 100 | private class WallpaperObserver extends FileObserver { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 101 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 102 | final WallpaperData mWallpaper; |
| 103 | final File mWallpaperDir; |
| 104 | final File mWallpaperFile; |
| 105 | |
| 106 | public WallpaperObserver(WallpaperData wallpaper) { |
| 107 | super(getWallpaperDir(wallpaper.userId).getAbsolutePath(), |
| 108 | CLOSE_WRITE | DELETE | DELETE_SELF); |
| 109 | mWallpaperDir = getWallpaperDir(wallpaper.userId); |
| 110 | mWallpaper = wallpaper; |
| 111 | mWallpaperFile = new File(mWallpaperDir, WALLPAPER); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void onEvent(int event, String path) { |
| 116 | if (path == null) { |
| 117 | return; |
| 118 | } |
| 119 | synchronized (mLock) { |
| 120 | // changing the wallpaper means we'll need to back up the new one |
| 121 | long origId = Binder.clearCallingIdentity(); |
| 122 | BackupManager bm = new BackupManager(mContext); |
| 123 | bm.dataChanged(); |
| 124 | Binder.restoreCallingIdentity(origId); |
| 125 | |
| 126 | File changedFile = new File(mWallpaperDir, path); |
| 127 | if (mWallpaperFile.equals(changedFile)) { |
| 128 | notifyCallbacksLocked(mWallpaper); |
| 129 | if (mWallpaper.wallpaperComponent == null || event != CLOSE_WRITE |
| 130 | || mWallpaper.imageWallpaperPending) { |
| 131 | if (event == CLOSE_WRITE) { |
| 132 | mWallpaper.imageWallpaperPending = false; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 133 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 134 | bindWallpaperComponentLocked(mWallpaper.imageWallpaperComponent, true, |
| 135 | false, mWallpaper); |
| 136 | saveSettingsLocked(mWallpaper); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | } |
| 138 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 143 | final Context mContext; |
| 144 | final IWindowManager mIWindowManager; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 145 | final MyPackageMonitor mMonitor; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 146 | WallpaperData mLastWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 148 | SparseArray<WallpaperData> mWallpaperMap = new SparseArray<WallpaperData>(); |
Dianne Hackborn | 07213e6 | 2011-08-24 20:05:39 -0700 | [diff] [blame] | 149 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 150 | int mCurrentUserId; |
Dianne Hackborn | 07213e6 | 2011-08-24 20:05:39 -0700 | [diff] [blame] | 151 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 152 | static class WallpaperData { |
| 153 | |
| 154 | int userId; |
| 155 | |
| 156 | File wallpaperFile; |
| 157 | |
| 158 | /** |
| 159 | * Client is currently writing a new image wallpaper. |
| 160 | */ |
| 161 | boolean imageWallpaperPending; |
| 162 | |
| 163 | /** |
| 164 | * Resource name if using a picture from the wallpaper gallery |
| 165 | */ |
| 166 | String name = ""; |
| 167 | |
| 168 | /** |
| 169 | * The component name of the currently set live wallpaper. |
| 170 | */ |
| 171 | ComponentName wallpaperComponent; |
| 172 | |
| 173 | /** |
| 174 | * The component name of the wallpaper that should be set next. |
| 175 | */ |
| 176 | ComponentName nextWallpaperComponent; |
| 177 | |
| 178 | /** |
| 179 | * Name of the component used to display bitmap wallpapers from either the gallery or |
| 180 | * built-in wallpapers. |
| 181 | */ |
| 182 | ComponentName imageWallpaperComponent = new ComponentName("com.android.systemui", |
| 183 | "com.android.systemui.ImageWallpaper"); |
| 184 | |
| 185 | WallpaperConnection connection; |
| 186 | long lastDiedTime; |
| 187 | boolean wallpaperUpdating; |
| 188 | WallpaperObserver wallpaperObserver; |
| 189 | |
| 190 | /** |
| 191 | * List of callbacks registered they should each be notified when the wallpaper is changed. |
| 192 | */ |
| 193 | private RemoteCallbackList<IWallpaperManagerCallback> callbacks |
| 194 | = new RemoteCallbackList<IWallpaperManagerCallback>(); |
| 195 | |
| 196 | int width = -1; |
| 197 | int height = -1; |
| 198 | |
| 199 | WallpaperData(int userId) { |
| 200 | this.userId = userId; |
| 201 | wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER); |
| 202 | } |
| 203 | } |
| 204 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 205 | class WallpaperConnection extends IWallpaperConnection.Stub |
| 206 | implements ServiceConnection { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 207 | final WallpaperInfo mInfo; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 208 | final Binder mToken = new Binder(); |
| 209 | IWallpaperService mService; |
| 210 | IWallpaperEngine mEngine; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 211 | WallpaperData mWallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 213 | public WallpaperConnection(WallpaperInfo info, WallpaperData wallpaper) { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 214 | mInfo = info; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 215 | mWallpaper = wallpaper; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 218 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 219 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 220 | if (mWallpaper.connection == this) { |
| 221 | mWallpaper.lastDiedTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 222 | mService = IWallpaperService.Stub.asInterface(service); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 223 | attachServiceLocked(this, mWallpaper); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 224 | // XXX should probably do saveSettingsLocked() later |
| 225 | // when we have an engine, but I'm not sure about |
| 226 | // locking there and anyway we always need to be able to |
| 227 | // recover if there is something wrong. |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 228 | saveSettingsLocked(mWallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | public void onServiceDisconnected(ComponentName name) { |
| 234 | synchronized (mLock) { |
| 235 | mService = null; |
| 236 | mEngine = null; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 237 | if (mWallpaper.connection == this) { |
| 238 | Slog.w(TAG, "Wallpaper service gone: " + mWallpaper.wallpaperComponent); |
| 239 | if (!mWallpaper.wallpaperUpdating |
| 240 | && (mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME) |
| 241 | > SystemClock.uptimeMillis() |
| 242 | && mWallpaper.userId == mCurrentUserId) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 243 | Slog.w(TAG, "Reverting to built-in wallpaper!"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 244 | clearWallpaperLocked(true, mWallpaper.userId); |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 249 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 250 | public void attachEngine(IWallpaperEngine engine) { |
| 251 | mEngine = engine; |
| 252 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 253 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 254 | public ParcelFileDescriptor setWallpaper(String name) { |
| 255 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 256 | if (mWallpaper.connection == this) { |
| 257 | return updateWallpaperBitmapLocked(name, mWallpaper); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 258 | } |
| 259 | return null; |
| 260 | } |
| 261 | } |
| 262 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 263 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 264 | class MyPackageMonitor extends PackageMonitor { |
| 265 | @Override |
| 266 | public void onPackageUpdateFinished(String packageName, int uid) { |
| 267 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 268 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 269 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
| 270 | if (wallpaper.wallpaperComponent != null |
| 271 | && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) { |
| 272 | wallpaper.wallpaperUpdating = false; |
| 273 | ComponentName comp = wallpaper.wallpaperComponent; |
| 274 | clearWallpaperComponentLocked(wallpaper); |
| 275 | // Do this only for the current user's wallpaper |
| 276 | if (wallpaper.userId == mCurrentUserId |
| 277 | && !bindWallpaperComponentLocked(comp, false, false, wallpaper)) { |
| 278 | Slog.w(TAG, "Wallpaper no longer available; reverting to default"); |
| 279 | clearWallpaperLocked(false, wallpaper.userId); |
| 280 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 281 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | @Override |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 287 | public void onPackageModified(String packageName) { |
| 288 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 289 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 290 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
| 291 | if (wallpaper.wallpaperComponent == null |
| 292 | || !wallpaper.wallpaperComponent.getPackageName().equals(packageName)) { |
| 293 | continue; |
| 294 | } |
| 295 | doPackagesChanged(true, wallpaper); |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 301 | public void onPackageUpdateStarted(String packageName, int uid) { |
| 302 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 303 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 304 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
| 305 | if (wallpaper.wallpaperComponent != null |
| 306 | && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) { |
| 307 | wallpaper.wallpaperUpdating = true; |
| 308 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 315 | boolean changed = false; |
| 316 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 317 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
| 318 | boolean res = doPackagesChanged(doit, wallpaper); |
| 319 | changed |= res; |
| 320 | } |
| 321 | return changed; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public void onSomePackagesChanged() { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 326 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 327 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
| 328 | doPackagesChanged(true, wallpaper); |
| 329 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 330 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 331 | |
| 332 | boolean doPackagesChanged(boolean doit, WallpaperData wallpaper) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 333 | boolean changed = false; |
| 334 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 335 | if (wallpaper.wallpaperComponent != null) { |
| 336 | int change = isPackageDisappearing(wallpaper.wallpaperComponent |
| 337 | .getPackageName()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 338 | if (change == PACKAGE_PERMANENT_CHANGE |
| 339 | || change == PACKAGE_TEMPORARY_CHANGE) { |
| 340 | changed = true; |
| 341 | if (doit) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 342 | Slog.w(TAG, "Wallpaper uninstalled, removing: " |
| 343 | + wallpaper.wallpaperComponent); |
| 344 | clearWallpaperLocked(false, wallpaper.userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 348 | if (wallpaper.nextWallpaperComponent != null) { |
| 349 | int change = isPackageDisappearing(wallpaper.nextWallpaperComponent |
| 350 | .getPackageName()); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 351 | if (change == PACKAGE_PERMANENT_CHANGE |
| 352 | || change == PACKAGE_TEMPORARY_CHANGE) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 353 | wallpaper.nextWallpaperComponent = null; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 354 | } |
| 355 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 356 | if (wallpaper.wallpaperComponent != null |
| 357 | && isPackageModified(wallpaper.wallpaperComponent.getPackageName())) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 358 | try { |
| 359 | mContext.getPackageManager().getServiceInfo( |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 360 | wallpaper.wallpaperComponent, 0); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 361 | } catch (NameNotFoundException e) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 362 | Slog.w(TAG, "Wallpaper component gone, removing: " |
| 363 | + wallpaper.wallpaperComponent); |
| 364 | clearWallpaperLocked(false, wallpaper.userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 365 | } |
| 366 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 367 | if (wallpaper.nextWallpaperComponent != null |
| 368 | && isPackageModified(wallpaper.nextWallpaperComponent.getPackageName())) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 369 | try { |
| 370 | mContext.getPackageManager().getServiceInfo( |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 371 | wallpaper.nextWallpaperComponent, 0); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 372 | } catch (NameNotFoundException e) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 373 | wallpaper.nextWallpaperComponent = null; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | } |
| 377 | return changed; |
| 378 | } |
| 379 | } |
| 380 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 381 | public WallpaperManagerService(Context context) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 382 | if (DEBUG) Slog.v(TAG, "WallpaperService startup"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | mContext = context; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 384 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 385 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 386 | mMonitor = new MyPackageMonitor(); |
| 387 | mMonitor.register(context, true); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 388 | WALLPAPER_BASE_DIR.mkdirs(); |
| 389 | loadSettingsLocked(0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 392 | private static File getWallpaperDir(int userId) { |
| 393 | return new File(WALLPAPER_BASE_DIR + "/" + userId); |
| 394 | } |
| 395 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 396 | @Override |
| 397 | protected void finalize() throws Throwable { |
| 398 | super.finalize(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 399 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 400 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
| 401 | wallpaper.wallpaperObserver.stopWatching(); |
| 402 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 403 | } |
| 404 | |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 405 | public void systemReady() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 406 | if (DEBUG) Slog.v(TAG, "systemReady"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 407 | WallpaperData wallpaper = mWallpaperMap.get(0); |
| 408 | switchWallpaper(wallpaper); |
| 409 | wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper); |
| 410 | wallpaper.wallpaperObserver.startWatching(); |
| 411 | ActivityManagerService ams = (ActivityManagerService) ServiceManager |
| 412 | .getService(Context.ACTIVITY_SERVICE); |
| 413 | ams.addUserListener(new ActivityManagerService.UserListener() { |
| 414 | |
| 415 | @Override |
| 416 | public void onUserChanged(int userId) { |
| 417 | switchUser(userId); |
| 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public void onUserAdded(int userId) { |
| 422 | } |
| 423 | |
| 424 | @Override |
| 425 | public void onUserRemoved(int userId) { |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public void onUserLoggedOut(int userId) { |
| 430 | } |
| 431 | |
| 432 | }); |
| 433 | } |
| 434 | |
| 435 | String getName() { |
| 436 | return mWallpaperMap.get(0).name; |
| 437 | } |
| 438 | |
| 439 | void switchUser(int userId) { |
| 440 | synchronized (mLock) { |
| 441 | mCurrentUserId = userId; |
| 442 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 443 | if (wallpaper == null) { |
| 444 | wallpaper = new WallpaperData(userId); |
| 445 | mWallpaperMap.put(userId, wallpaper); |
| 446 | loadSettingsLocked(userId); |
| 447 | wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper); |
| 448 | wallpaper.wallpaperObserver.startWatching(); |
| 449 | } |
| 450 | switchWallpaper(wallpaper); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | void switchWallpaper(WallpaperData wallpaper) { |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 455 | synchronized (mLock) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 456 | RuntimeException e = null; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 457 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 458 | ComponentName cname = wallpaper.wallpaperComponent != null ? |
| 459 | wallpaper.wallpaperComponent : wallpaper.nextWallpaperComponent; |
| 460 | if (bindWallpaperComponentLocked(cname, true, false, wallpaper)) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 461 | return; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 462 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 463 | } catch (RuntimeException e1) { |
| 464 | e = e1; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 465 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 466 | Slog.w(TAG, "Failure starting previous wallpaper", e); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 467 | clearWallpaperLocked(false, wallpaper.userId); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 471 | public void clearWallpaper() { |
| 472 | if (DEBUG) Slog.v(TAG, "clearWallpaper"); |
| 473 | synchronized (mLock) { |
| 474 | clearWallpaperLocked(false, UserId.getCallingUserId()); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | void clearWallpaperLocked(boolean defaultFailed, int userId) { |
| 479 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 480 | File f = new File(getWallpaperDir(userId), WALLPAPER); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 481 | if (f.exists()) { |
| 482 | f.delete(); |
| 483 | } |
| 484 | final long ident = Binder.clearCallingIdentity(); |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 485 | RuntimeException e = null; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 486 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 487 | wallpaper.imageWallpaperPending = false; |
| 488 | if (userId != mCurrentUserId) return; |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 489 | if (bindWallpaperComponentLocked(defaultFailed |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 490 | ? wallpaper.imageWallpaperComponent |
| 491 | : null, true, false, wallpaper)) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 492 | return; |
| 493 | } |
| 494 | } catch (IllegalArgumentException e1) { |
| 495 | e = e1; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 496 | } finally { |
| 497 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 499 | |
| 500 | // This can happen if the default wallpaper component doesn't |
| 501 | // exist. This should be a system configuration problem, but |
| 502 | // let's not let it crash the system and just live with no |
| 503 | // wallpaper. |
| 504 | Slog.e(TAG, "Default wallpaper component not found!", e); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 505 | clearWallpaperComponentLocked(wallpaper); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | public void setDimensionHints(int width, int height) throws RemoteException { |
| 509 | checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS); |
| 510 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 511 | int userId = UserId.getCallingUserId(); |
| 512 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 513 | if (wallpaper == null) { |
| 514 | throw new IllegalStateException("Wallpaper not yet initialized for user " + userId); |
| 515 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | if (width <= 0 || height <= 0) { |
| 517 | throw new IllegalArgumentException("width and height must be > 0"); |
| 518 | } |
| 519 | |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 520 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 521 | if (width != wallpaper.width || height != wallpaper.height) { |
| 522 | wallpaper.width = width; |
| 523 | wallpaper.height = height; |
| 524 | saveSettingsLocked(wallpaper); |
| 525 | if (mCurrentUserId != userId) return; // Don't change the properties now |
| 526 | if (wallpaper.connection != null) { |
| 527 | if (wallpaper.connection.mEngine != null) { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 528 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 529 | wallpaper.connection.mEngine.setDesiredSize( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 530 | width, height); |
| 531 | } catch (RemoteException e) { |
| 532 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 533 | notifyCallbacksLocked(wallpaper); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 534 | } |
| 535 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 536 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
| 540 | public int getWidthHint() throws RemoteException { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 541 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 542 | WallpaperData wallpaper = mWallpaperMap.get(UserId.getCallingUserId()); |
| 543 | return wallpaper.width; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 544 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | public int getHeightHint() throws RemoteException { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 548 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 549 | WallpaperData wallpaper = mWallpaperMap.get(UserId.getCallingUserId()); |
| 550 | return wallpaper.height; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 551 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 554 | public ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb, |
| 555 | Bundle outParams) { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 556 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 557 | // This returns the current user's wallpaper, if called by a system service. Else it |
| 558 | // returns the wallpaper for the calling user. |
| 559 | int callingUid = Binder.getCallingUid(); |
| 560 | int wallpaperUserId = 0; |
| 561 | if (callingUid == android.os.Process.SYSTEM_UID) { |
| 562 | wallpaperUserId = mCurrentUserId; |
| 563 | } else { |
| 564 | wallpaperUserId = UserId.getUserId(callingUid); |
| 565 | } |
| 566 | WallpaperData wallpaper = mWallpaperMap.get(wallpaperUserId); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 567 | try { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 568 | if (outParams != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 569 | outParams.putInt("width", wallpaper.width); |
| 570 | outParams.putInt("height", wallpaper.height); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 571 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 572 | wallpaper.callbacks.register(cb); |
| 573 | File f = new File(getWallpaperDir(wallpaperUserId), WALLPAPER); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 574 | if (!f.exists()) { |
| 575 | return null; |
| 576 | } |
| 577 | return ParcelFileDescriptor.open(f, MODE_READ_ONLY); |
| 578 | } catch (FileNotFoundException e) { |
| 579 | /* Shouldn't happen as we check to see if the file exists */ |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 580 | Slog.w(TAG, "Error getting wallpaper", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 582 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | } |
| 585 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 586 | public WallpaperInfo getWallpaperInfo() { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 587 | int userId = UserId.getCallingUserId(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 588 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 589 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 590 | if (wallpaper.connection != null) { |
| 591 | return wallpaper.connection.mInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 592 | } |
| 593 | return null; |
| 594 | } |
| 595 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 596 | |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 597 | public ParcelFileDescriptor setWallpaper(String name) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 598 | if (DEBUG) Slog.v(TAG, "setWallpaper"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 599 | int userId = UserId.getCallingUserId(); |
| 600 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 601 | if (wallpaper == null) { |
| 602 | throw new IllegalStateException("Wallpaper not yet initialized for user " + userId); |
| 603 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | checkPermission(android.Manifest.permission.SET_WALLPAPER); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 605 | synchronized (mLock) { |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 606 | final long ident = Binder.clearCallingIdentity(); |
| 607 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 608 | ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name, wallpaper); |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 609 | if (pfd != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 610 | wallpaper.imageWallpaperPending = true; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 611 | } |
| 612 | return pfd; |
| 613 | } finally { |
| 614 | Binder.restoreCallingIdentity(ident); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 615 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 619 | ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 620 | if (name == null) name = ""; |
| 621 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 622 | File dir = getWallpaperDir(wallpaper.userId); |
| 623 | if (!dir.exists()) { |
| 624 | dir.mkdir(); |
Dianne Hackborn | ebac48c | 2011-11-29 18:01:50 -0800 | [diff] [blame] | 625 | FileUtils.setPermissions( |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 626 | dir.getPath(), |
Dianne Hackborn | ebac48c | 2011-11-29 18:01:50 -0800 | [diff] [blame] | 627 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 628 | -1, -1); |
| 629 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 630 | ParcelFileDescriptor fd = ParcelFileDescriptor.open(new File(dir, WALLPAPER), |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 631 | MODE_CREATE|MODE_READ_WRITE); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 632 | wallpaper.name = name; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 633 | return fd; |
| 634 | } catch (FileNotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 635 | Slog.w(TAG, "Error setting wallpaper", e); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 636 | } |
| 637 | return null; |
| 638 | } |
| 639 | |
| 640 | public void setWallpaperComponent(ComponentName name) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 641 | if (DEBUG) Slog.v(TAG, "setWallpaperComponent name=" + name); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 642 | int userId = UserId.getCallingUserId(); |
| 643 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 644 | if (wallpaper == null) { |
| 645 | throw new IllegalStateException("Wallpaper not yet initialized for user " + userId); |
| 646 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 647 | checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT); |
| 648 | synchronized (mLock) { |
| 649 | final long ident = Binder.clearCallingIdentity(); |
| 650 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 651 | wallpaper.imageWallpaperPending = false; |
| 652 | bindWallpaperComponentLocked(name, false, true, wallpaper); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 653 | } finally { |
| 654 | Binder.restoreCallingIdentity(ident); |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 659 | boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force, |
| 660 | boolean fromUser, WallpaperData wallpaper) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 661 | if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 662 | // Has the component changed? |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 663 | if (!force) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 664 | if (wallpaper.connection != null) { |
| 665 | if (wallpaper.wallpaperComponent == null) { |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 666 | if (componentName == null) { |
| 667 | if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: still using default"); |
| 668 | // Still using default wallpaper. |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 669 | return true; |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 670 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 671 | } else if (wallpaper.wallpaperComponent.equals(componentName)) { |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 672 | // Changing to same wallpaper. |
| 673 | if (DEBUG) Slog.v(TAG, "same wallpaper"); |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 674 | return true; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 675 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
| 679 | try { |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 680 | if (componentName == null) { |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 681 | String defaultComponent = |
| 682 | mContext.getString(com.android.internal.R.string.default_wallpaper_component); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 683 | if (defaultComponent != null) { |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 684 | // See if there is a default wallpaper component specified |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 685 | componentName = ComponentName.unflattenFromString(defaultComponent); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 686 | if (DEBUG) Slog.v(TAG, "Use default component wallpaper:" + componentName); |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 687 | } |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 688 | if (componentName == null) { |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 689 | // Fall back to static image wallpaper |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 690 | componentName = wallpaper.imageWallpaperComponent; |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 691 | //clearWallpaperComponentLocked(); |
| 692 | //return; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 693 | if (DEBUG) Slog.v(TAG, "Using image wallpaper"); |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 694 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 695 | } |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 696 | ServiceInfo si = mContext.getPackageManager().getServiceInfo(componentName, |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 697 | PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS); |
| 698 | if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 699 | String msg = "Selected service does not require " |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 700 | + android.Manifest.permission.BIND_WALLPAPER |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 701 | + ": " + componentName; |
| 702 | if (fromUser) { |
| 703 | throw new SecurityException(msg); |
| 704 | } |
| 705 | Slog.w(TAG, msg); |
| 706 | return false; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 709 | WallpaperInfo wi = null; |
| 710 | |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 711 | Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 712 | if (componentName != null && !componentName.equals(wallpaper.imageWallpaperComponent)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 713 | // Make sure the selected service is actually a wallpaper service. |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 714 | List<ResolveInfo> ris = mContext.getPackageManager() |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 715 | .queryIntentServices(intent, PackageManager.GET_META_DATA); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 716 | for (int i=0; i<ris.size(); i++) { |
| 717 | ServiceInfo rsi = ris.get(i).serviceInfo; |
| 718 | if (rsi.name.equals(si.name) && |
| 719 | rsi.packageName.equals(si.packageName)) { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 720 | try { |
| 721 | wi = new WallpaperInfo(mContext, ris.get(i)); |
| 722 | } catch (XmlPullParserException e) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 723 | if (fromUser) { |
| 724 | throw new IllegalArgumentException(e); |
| 725 | } |
| 726 | Slog.w(TAG, e); |
| 727 | return false; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 728 | } catch (IOException e) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 729 | if (fromUser) { |
| 730 | throw new IllegalArgumentException(e); |
| 731 | } |
| 732 | Slog.w(TAG, e); |
| 733 | return false; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 734 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 735 | break; |
| 736 | } |
| 737 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 738 | if (wi == null) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 739 | String msg = "Selected service is not a wallpaper: " |
| 740 | + componentName; |
| 741 | if (fromUser) { |
| 742 | throw new SecurityException(msg); |
| 743 | } |
| 744 | Slog.w(TAG, msg); |
| 745 | return false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 746 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 747 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 748 | |
| 749 | // Bind the service! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 750 | if (DEBUG) Slog.v(TAG, "Binding to:" + componentName); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 751 | WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 752 | intent.setComponent(componentName); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 753 | int serviceUserId = wallpaper.userId; |
| 754 | // Because the image wallpaper is running in the system ui |
| 755 | if (componentName.equals(wallpaper.imageWallpaperComponent)) { |
| 756 | serviceUserId = 0; |
| 757 | } |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 758 | intent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 759 | com.android.internal.R.string.wallpaper_binding_label); |
| 760 | intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity( |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 761 | mContext, 0, |
| 762 | Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER), |
| 763 | mContext.getText(com.android.internal.R.string.chooser_wallpaper)), |
| 764 | 0)); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 765 | if (!mContext.bindService(intent, newConn, Context.BIND_AUTO_CREATE, serviceUserId)) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 766 | String msg = "Unable to bind service: " |
| 767 | + componentName; |
| 768 | if (fromUser) { |
| 769 | throw new IllegalArgumentException(msg); |
| 770 | } |
| 771 | Slog.w(TAG, msg); |
| 772 | return false; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 773 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 774 | if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) { |
| 775 | detachWallpaperLocked(mLastWallpaper); |
| 776 | } |
| 777 | wallpaper.wallpaperComponent = componentName; |
| 778 | wallpaper.connection = newConn; |
| 779 | wallpaper.lastDiedTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 780 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 781 | if (wallpaper.userId == mCurrentUserId) { |
| 782 | if (DEBUG) |
| 783 | Slog.v(TAG, "Adding window token: " + newConn.mToken); |
| 784 | mIWindowManager.addWindowToken(newConn.mToken, |
| 785 | WindowManager.LayoutParams.TYPE_WALLPAPER); |
| 786 | mLastWallpaper = wallpaper; |
| 787 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 788 | } catch (RemoteException e) { |
| 789 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 790 | } catch (PackageManager.NameNotFoundException e) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 791 | String msg = "Unknown component " + componentName; |
| 792 | if (fromUser) { |
| 793 | throw new IllegalArgumentException(msg); |
| 794 | } |
| 795 | Slog.w(TAG, msg); |
| 796 | return false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 797 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 798 | return true; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 799 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 800 | |
| 801 | void detachWallpaperLocked(WallpaperData wallpaper) { |
| 802 | if (wallpaper.connection != null) { |
| 803 | if (wallpaper.connection.mEngine != null) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 804 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 805 | wallpaper.connection.mEngine.destroy(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 806 | } catch (RemoteException e) { |
| 807 | } |
| 808 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 809 | mContext.unbindService(wallpaper.connection); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 810 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 811 | if (DEBUG) |
| 812 | Slog.v(TAG, "Removing window token: " + wallpaper.connection.mToken); |
| 813 | mIWindowManager.removeWindowToken(wallpaper.connection.mToken); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 814 | } catch (RemoteException e) { |
| 815 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 816 | wallpaper.connection.mService = null; |
| 817 | wallpaper.connection.mEngine = null; |
| 818 | wallpaper.connection = null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 819 | } |
| 820 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 821 | |
| 822 | void clearWallpaperComponentLocked(WallpaperData wallpaper) { |
| 823 | wallpaper.wallpaperComponent = null; |
| 824 | detachWallpaperLocked(wallpaper); |
| 825 | } |
| 826 | |
| 827 | void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 828 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 829 | conn.mService.attach(conn, conn.mToken, |
| 830 | WindowManager.LayoutParams.TYPE_WALLPAPER, false, |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 831 | wallpaper.width, wallpaper.height); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 832 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 833 | Slog.w(TAG, "Failed attaching wallpaper; clearing", e); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 834 | if (!wallpaper.wallpaperUpdating) { |
| 835 | bindWallpaperComponentLocked(null, false, false, wallpaper); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 836 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 837 | } |
| 838 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 839 | |
| 840 | private void notifyCallbacksLocked(WallpaperData wallpaper) { |
| 841 | final int n = wallpaper.callbacks.beginBroadcast(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | for (int i = 0; i < n; i++) { |
| 843 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 844 | wallpaper.callbacks.getBroadcastItem(i).onWallpaperChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 845 | } catch (RemoteException e) { |
| 846 | |
| 847 | // The RemoteCallbackList will take care of removing |
| 848 | // the dead object for us. |
| 849 | } |
| 850 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 851 | wallpaper.callbacks.finishBroadcast(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 852 | final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED); |
| 853 | mContext.sendBroadcast(intent); |
| 854 | } |
| 855 | |
| 856 | private void checkPermission(String permission) { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 857 | if (PackageManager.PERMISSION_GRANTED!= mContext.checkCallingOrSelfPermission(permission)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 858 | throw new SecurityException("Access denied to process: " + Binder.getCallingPid() |
| 859 | + ", must have permission " + permission); |
| 860 | } |
| 861 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 862 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 863 | private static JournaledFile makeJournaledFile(int userId) { |
| 864 | final String base = "/data/system/users/" + userId + "/" + WALLPAPER_INFO; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 865 | return new JournaledFile(new File(base), new File(base + ".tmp")); |
| 866 | } |
| 867 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 868 | private void saveSettingsLocked(WallpaperData wallpaper) { |
| 869 | JournaledFile journal = makeJournaledFile(wallpaper.userId); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 870 | FileOutputStream stream = null; |
| 871 | try { |
| 872 | stream = new FileOutputStream(journal.chooseForWrite(), false); |
| 873 | XmlSerializer out = new FastXmlSerializer(); |
| 874 | out.setOutput(stream, "utf-8"); |
| 875 | out.startDocument(null, true); |
| 876 | |
| 877 | out.startTag(null, "wp"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 878 | out.attribute(null, "width", Integer.toString(wallpaper.width)); |
| 879 | out.attribute(null, "height", Integer.toString(wallpaper.height)); |
| 880 | out.attribute(null, "name", wallpaper.name); |
| 881 | if (wallpaper.wallpaperComponent != null |
| 882 | && !wallpaper.wallpaperComponent.equals(wallpaper.imageWallpaperComponent)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 883 | out.attribute(null, "component", |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 884 | wallpaper.wallpaperComponent.flattenToShortString()); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 885 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 886 | out.endTag(null, "wp"); |
| 887 | |
| 888 | out.endDocument(); |
| 889 | stream.close(); |
| 890 | journal.commit(); |
| 891 | } catch (IOException e) { |
| 892 | try { |
| 893 | if (stream != null) { |
| 894 | stream.close(); |
| 895 | } |
| 896 | } catch (IOException ex) { |
| 897 | // Ignore |
| 898 | } |
| 899 | journal.rollback(); |
| 900 | } |
| 901 | } |
| 902 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 903 | private void migrateFromOld() { |
| 904 | File oldWallpaper = new File(WallpaperBackupHelper.WALLPAPER_IMAGE_KEY); |
| 905 | File oldInfo = new File(WallpaperBackupHelper.WALLPAPER_INFO_KEY); |
| 906 | if (oldWallpaper.exists()) { |
| 907 | File newWallpaper = new File(getWallpaperDir(0), WALLPAPER); |
| 908 | oldWallpaper.renameTo(newWallpaper); |
| 909 | } |
| 910 | if (oldInfo.exists()) { |
| 911 | File newInfo = new File(getWallpaperDir(0), WALLPAPER_INFO); |
| 912 | oldInfo.renameTo(newInfo); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | private void loadSettingsLocked(int userId) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 917 | if (DEBUG) Slog.v(TAG, "loadSettingsLocked"); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 918 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 919 | JournaledFile journal = makeJournaledFile(userId); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 920 | FileInputStream stream = null; |
| 921 | File file = journal.chooseForRead(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 922 | if (!file.exists()) { |
| 923 | // This should only happen one time, when upgrading from a legacy system |
| 924 | migrateFromOld(); |
| 925 | } |
| 926 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 927 | if (wallpaper == null) { |
| 928 | wallpaper = new WallpaperData(userId); |
| 929 | mWallpaperMap.put(userId, wallpaper); |
| 930 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 931 | boolean success = false; |
| 932 | try { |
| 933 | stream = new FileInputStream(file); |
| 934 | XmlPullParser parser = Xml.newPullParser(); |
| 935 | parser.setInput(stream, null); |
| 936 | |
| 937 | int type; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 938 | do { |
| 939 | type = parser.next(); |
| 940 | if (type == XmlPullParser.START_TAG) { |
| 941 | String tag = parser.getName(); |
| 942 | if ("wp".equals(tag)) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 943 | wallpaper.width = Integer.parseInt(parser.getAttributeValue(null, "width")); |
| 944 | wallpaper.height = Integer.parseInt(parser |
| 945 | .getAttributeValue(null, "height")); |
| 946 | wallpaper.name = parser.getAttributeValue(null, "name"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 947 | String comp = parser.getAttributeValue(null, "component"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 948 | wallpaper.nextWallpaperComponent = comp != null |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 949 | ? ComponentName.unflattenFromString(comp) |
| 950 | : null; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 951 | if (wallpaper.nextWallpaperComponent == null |
| 952 | || "android".equals(wallpaper.nextWallpaperComponent |
| 953 | .getPackageName())) { |
| 954 | wallpaper.nextWallpaperComponent = wallpaper.imageWallpaperComponent; |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 955 | } |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 956 | |
| 957 | if (DEBUG) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 958 | Slog.v(TAG, "mWidth:" + wallpaper.width); |
| 959 | Slog.v(TAG, "mHeight:" + wallpaper.height); |
| 960 | Slog.v(TAG, "mName:" + wallpaper.name); |
| 961 | Slog.v(TAG, "mNextWallpaperComponent:" |
| 962 | + wallpaper.nextWallpaperComponent); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 963 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | } while (type != XmlPullParser.END_DOCUMENT); |
| 967 | success = true; |
| 968 | } catch (NullPointerException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 969 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 970 | } catch (NumberFormatException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 971 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 972 | } catch (XmlPullParserException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 973 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 974 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 975 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 976 | } catch (IndexOutOfBoundsException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 977 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 978 | } |
| 979 | try { |
| 980 | if (stream != null) { |
| 981 | stream.close(); |
| 982 | } |
| 983 | } catch (IOException e) { |
| 984 | // Ignore |
| 985 | } |
| 986 | |
| 987 | if (!success) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 988 | wallpaper.width = -1; |
| 989 | wallpaper.height = -1; |
| 990 | wallpaper.name = ""; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 991 | } |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 992 | |
| 993 | // We always want to have some reasonable width hint. |
| 994 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 995 | Display d = wm.getDefaultDisplay(); |
| 996 | int baseSize = d.getMaximumSizeDimension(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 997 | if (wallpaper.width < baseSize) { |
| 998 | wallpaper.width = baseSize; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 999 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1000 | if (wallpaper.height < baseSize) { |
| 1001 | wallpaper.height = baseSize; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 1002 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Brad Fitzpatrick | 194b19a | 2010-09-14 11:30:29 -0700 | [diff] [blame] | 1005 | // Called by SystemBackupAgent after files are restored to disk. |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1006 | void settingsRestored() { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1007 | // TODO: If necessary, make it work for secondary users as well. This currently assumes |
| 1008 | // restores only to the primary user |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1009 | if (DEBUG) Slog.v(TAG, "settingsRestored"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1010 | WallpaperData wallpaper = null; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1011 | boolean success = false; |
| 1012 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1013 | loadSettingsLocked(0); |
| 1014 | wallpaper = mWallpaperMap.get(0); |
| 1015 | if (wallpaper.nextWallpaperComponent != null |
| 1016 | && !wallpaper.nextWallpaperComponent.equals(wallpaper.imageWallpaperComponent)) { |
| 1017 | if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false, |
| 1018 | wallpaper)) { |
Christopher Tate | e3ab4d0 | 2009-12-16 14:03:31 -0800 | [diff] [blame] | 1019 | // No such live wallpaper or other failure; fall back to the default |
| 1020 | // live wallpaper (since the profile being restored indicated that the |
| 1021 | // user had selected a live rather than static one). |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1022 | bindWallpaperComponentLocked(null, false, false, wallpaper); |
Christopher Tate | e3ab4d0 | 2009-12-16 14:03:31 -0800 | [diff] [blame] | 1023 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1024 | success = true; |
| 1025 | } else { |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1026 | // If there's a wallpaper name, we use that. If that can't be loaded, then we |
| 1027 | // use the default. |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1028 | if ("".equals(wallpaper.name)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1029 | if (DEBUG) Slog.v(TAG, "settingsRestored: name is empty"); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1030 | success = true; |
| 1031 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1032 | if (DEBUG) Slog.v(TAG, "settingsRestored: attempting to restore named resource"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1033 | success = restoreNamedResourceLocked(wallpaper); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1034 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1035 | if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1036 | if (success) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1037 | bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false, |
| 1038 | wallpaper); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1039 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | if (!success) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1044 | Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'"); |
| 1045 | wallpaper.name = ""; |
| 1046 | getWallpaperDir(0).delete(); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1047 | } |
Brad Fitzpatrick | 194b19a | 2010-09-14 11:30:29 -0700 | [diff] [blame] | 1048 | |
| 1049 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1050 | saveSettingsLocked(wallpaper); |
Brad Fitzpatrick | 194b19a | 2010-09-14 11:30:29 -0700 | [diff] [blame] | 1051 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1054 | boolean restoreNamedResourceLocked(WallpaperData wallpaper) { |
| 1055 | if (wallpaper.name.length() > 4 && "res:".equals(wallpaper.name.substring(0, 4))) { |
| 1056 | String resName = wallpaper.name.substring(4); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1057 | |
| 1058 | String pkg = null; |
| 1059 | int colon = resName.indexOf(':'); |
| 1060 | if (colon > 0) { |
| 1061 | pkg = resName.substring(0, colon); |
| 1062 | } |
| 1063 | |
| 1064 | String ident = null; |
| 1065 | int slash = resName.lastIndexOf('/'); |
| 1066 | if (slash > 0) { |
| 1067 | ident = resName.substring(slash+1); |
| 1068 | } |
| 1069 | |
| 1070 | String type = null; |
| 1071 | if (colon > 0 && slash > 0 && (slash-colon) > 1) { |
| 1072 | type = resName.substring(colon+1, slash); |
| 1073 | } |
| 1074 | |
| 1075 | if (pkg != null && ident != null && type != null) { |
| 1076 | int resId = -1; |
| 1077 | InputStream res = null; |
| 1078 | FileOutputStream fos = null; |
| 1079 | try { |
| 1080 | Context c = mContext.createPackageContext(pkg, Context.CONTEXT_RESTRICTED); |
| 1081 | Resources r = c.getResources(); |
| 1082 | resId = r.getIdentifier(resName, null, null); |
| 1083 | if (resId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1084 | Slog.e(TAG, "couldn't resolve identifier pkg=" + pkg + " type=" + type |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1085 | + " ident=" + ident); |
| 1086 | return false; |
| 1087 | } |
| 1088 | |
| 1089 | res = r.openRawResource(resId); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1090 | if (wallpaper.wallpaperFile.exists()) { |
| 1091 | wallpaper.wallpaperFile.delete(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 1092 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1093 | fos = new FileOutputStream(wallpaper.wallpaperFile); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1094 | |
| 1095 | byte[] buffer = new byte[32768]; |
| 1096 | int amt; |
| 1097 | while ((amt=res.read(buffer)) > 0) { |
| 1098 | fos.write(buffer, 0, amt); |
| 1099 | } |
| 1100 | // mWallpaperObserver will notice the close and send the change broadcast |
| 1101 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1102 | Slog.v(TAG, "Restored wallpaper: " + resName); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1103 | return true; |
| 1104 | } catch (NameNotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1105 | Slog.e(TAG, "Package name " + pkg + " not found"); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1106 | } catch (Resources.NotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1107 | Slog.e(TAG, "Resource not found: " + resId); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1108 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1109 | Slog.e(TAG, "IOException while restoring wallpaper ", e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1110 | } finally { |
| 1111 | if (res != null) { |
| 1112 | try { |
| 1113 | res.close(); |
| 1114 | } catch (IOException ex) {} |
| 1115 | } |
| 1116 | if (fos != null) { |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 1117 | FileUtils.sync(fos); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1118 | try { |
| 1119 | fos.close(); |
| 1120 | } catch (IOException ex) {} |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | return false; |
| 1126 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1127 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1128 | @Override |
| 1129 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1130 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 1131 | != PackageManager.PERMISSION_GRANTED) { |
| 1132 | |
| 1133 | pw.println("Permission Denial: can't dump wallpaper service from from pid=" |
| 1134 | + Binder.getCallingPid() |
| 1135 | + ", uid=" + Binder.getCallingUid()); |
| 1136 | return; |
| 1137 | } |
| 1138 | |
| 1139 | synchronized (mLock) { |
| 1140 | pw.println("Current Wallpaper Service state:"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1141 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 1142 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
| 1143 | pw.println(" User " + wallpaper.userId + ":"); |
| 1144 | pw.print(" mWidth="); |
| 1145 | pw.print(wallpaper.width); |
| 1146 | pw.print(" mHeight="); |
| 1147 | pw.println(wallpaper.height); |
| 1148 | pw.print(" mName="); |
| 1149 | pw.println(wallpaper.name); |
| 1150 | pw.print(" mWallpaperComponent="); |
| 1151 | pw.println(wallpaper.wallpaperComponent); |
| 1152 | if (wallpaper.connection != null) { |
| 1153 | WallpaperConnection conn = wallpaper.connection; |
| 1154 | pw.print(" Wallpaper connection "); |
| 1155 | pw.print(conn); |
| 1156 | pw.println(":"); |
| 1157 | if (conn.mInfo != null) { |
| 1158 | pw.print(" mInfo.component="); |
| 1159 | pw.println(conn.mInfo.getComponent()); |
| 1160 | } |
| 1161 | pw.print(" mToken="); |
| 1162 | pw.println(conn.mToken); |
| 1163 | pw.print(" mService="); |
| 1164 | pw.println(conn.mService); |
| 1165 | pw.print(" mEngine="); |
| 1166 | pw.println(conn.mEngine); |
| 1167 | pw.print(" mLastDiedTime="); |
| 1168 | pw.println(wallpaper.lastDiedTime - SystemClock.uptimeMillis()); |
| 1169 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | } |