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