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