blob: c129b9742f59083322d6a0e15bdc0a5ababa36b5 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server;
18
19import static android.os.FileObserver.*;
20import static android.os.ParcelFileDescriptor.*;
Christopher Tate111bd4a2009-06-24 17:29:38 -070021
Dianne Hackborn8cc6a502009-08-05 21:29:42 -070022import android.app.IWallpaperManager;
23import android.app.IWallpaperManagerCallback;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -070024import android.app.PendingIntent;
Dianne Hackborneb034652009-09-07 00:49:58 -070025import android.app.WallpaperInfo;
Christopher Tate45281862010-03-05 15:46:30 -080026import android.app.backup.BackupManager;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070027import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.content.Context;
29import android.content.Intent;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import android.content.ServiceConnection;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.content.pm.PackageManager;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070032import android.content.pm.ResolveInfo;
33import android.content.pm.ServiceInfo;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070034import android.content.pm.PackageManager.NameNotFoundException;
35import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.os.Binder;
Dianne Hackborn284ac932009-08-28 10:34:25 -070037import android.os.Bundle;
Dianne Hackborn8bdf5932010-10-15 12:54:40 -070038import android.os.FileUtils;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070039import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.os.RemoteException;
41import android.os.FileObserver;
42import android.os.ParcelFileDescriptor;
43import android.os.RemoteCallbackList;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070044import android.os.ServiceManager;
Dianne Hackborn0cd48872009-08-13 18:51:59 -070045import android.os.SystemClock;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070046import android.service.wallpaper.IWallpaperConnection;
47import android.service.wallpaper.IWallpaperEngine;
48import android.service.wallpaper.IWallpaperService;
49import android.service.wallpaper.WallpaperService;
Joe Onorato8a9b2202010-02-26 18:56:32 -080050import android.util.Slog;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070051import android.util.Xml;
Dianne Hackborn44bc17c2011-04-20 18:18:51 -070052import android.view.Display;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070053import android.view.IWindowManager;
54import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
Dianne Hackborneb034652009-09-07 00:49:58 -070056import java.io.FileDescriptor;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070057import java.io.IOException;
58import java.io.InputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import java.io.File;
60import java.io.FileNotFoundException;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070061import java.io.FileInputStream;
62import java.io.FileOutputStream;
Dianne Hackborneb034652009-09-07 00:49:58 -070063import java.io.PrintWriter;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070064import java.util.List;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070065
66import org.xmlpull.v1.XmlPullParser;
67import org.xmlpull.v1.XmlPullParserException;
68import org.xmlpull.v1.XmlSerializer;
69
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080070import com.android.internal.content.PackageMonitor;
Dianne Hackbornf21adf62009-08-13 10:20:21 -070071import com.android.internal.service.wallpaper.ImageWallpaper;
Dianne Hackborn2269d1572010-02-24 19:54:22 -080072import com.android.internal.util.FastXmlSerializer;
Dianne Hackborn1afd1c92010-03-18 22:47:17 -070073import com.android.internal.util.JournaledFile;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
Dianne Hackborn8cc6a502009-08-05 21:29:42 -070075class WallpaperManagerService extends IWallpaperManager.Stub {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070076 static final String TAG = "WallpaperService";
Dianne Hackborncbf15042009-08-18 18:29:09 -070077 static final boolean DEBUG = false;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070078
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070079 Object mLock = new Object();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080
Dianne Hackborn0cd48872009-08-13 18:51:59 -070081 /**
82 * Minimum time between crashes of a wallpaper service for us to consider
83 * restarting it vs. just reverting to the static wallpaper.
84 */
85 static final long MIN_WALLPAPER_CRASH_TIME = 10000;
86
87 static final File WALLPAPER_DIR = new File(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 "/data/data/com.android.settings/files");
Dianne Hackborn0cd48872009-08-13 18:51:59 -070089 static final String WALLPAPER = "wallpaper";
90 static final File WALLPAPER_FILE = new File(WALLPAPER_DIR, WALLPAPER);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 /**
93 * List of callbacks registered they should each be notified
94 * when the wallpaper is changed.
95 */
Dianne Hackborn8cc6a502009-08-05 21:29:42 -070096 private final RemoteCallbackList<IWallpaperManagerCallback> mCallbacks
97 = new RemoteCallbackList<IWallpaperManagerCallback>();
Joe Onorato9bb8fd72009-07-28 18:24:51 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 /**
100 * Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks
101 * that the wallpaper has changed. The CREATE is triggered when there is no
102 * wallpaper set and is created for the first time. The CLOSE_WRITE is triggered
103 * everytime the wallpaper is changed.
104 */
105 private final FileObserver mWallpaperObserver = new FileObserver(
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700106 WALLPAPER_DIR.getAbsolutePath(), CREATE | CLOSE_WRITE | DELETE | DELETE_SELF) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 @Override
108 public void onEvent(int event, String path) {
Joe Onoratoe712ee32009-07-29 16:23:58 -0700109 if (path == null) {
110 return;
111 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700112 synchronized (mLock) {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700113 // changing the wallpaper means we'll need to back up the new one
114 long origId = Binder.clearCallingIdentity();
115 BackupManager bm = new BackupManager(mContext);
116 bm.dataChanged();
117 Binder.restoreCallingIdentity(origId);
118
119 File changedFile = new File(WALLPAPER_DIR, path);
120 if (WALLPAPER_FILE.equals(changedFile)) {
121 notifyCallbacksLocked();
122 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 }
124 }
125 };
126
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700127 final Context mContext;
128 final IWindowManager mIWindowManager;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800129 final MyPackageMonitor mMonitor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700131 int mWidth = -1;
132 int mHeight = -1;
Mike Clerona428b2c2009-11-15 22:53:08 -0800133
134 /**
135 * Resource name if using a picture from the wallpaper gallery
136 */
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700137 String mName = "";
Mike Clerond6c0b842009-11-13 16:37:27 -0800138
139 /**
Mike Clerona428b2c2009-11-15 22:53:08 -0800140 * The component name of the currently set live wallpaper.
Mike Clerond6c0b842009-11-13 16:37:27 -0800141 */
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700142 ComponentName mWallpaperComponent;
Mike Clerona428b2c2009-11-15 22:53:08 -0800143
144 /**
145 * The component name of the wallpaper that should be set next.
146 */
147 ComponentName mNextWallpaperComponent;
148
149 /**
150 * Name of the component used to display bitmap wallpapers from either the gallery or
151 * built-in wallpapers.
152 */
153 ComponentName mImageWallpaperComponent = new ComponentName("android",
154 ImageWallpaper.class.getName());
155
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700156 WallpaperConnection mWallpaperConnection;
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700157 long mLastDiedTime;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800158 boolean mWallpaperUpdating;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700159
160 class WallpaperConnection extends IWallpaperConnection.Stub
161 implements ServiceConnection {
Dianne Hackborneb034652009-09-07 00:49:58 -0700162 final WallpaperInfo mInfo;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700163 final Binder mToken = new Binder();
164 IWallpaperService mService;
165 IWallpaperEngine mEngine;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166
Dianne Hackborneb034652009-09-07 00:49:58 -0700167 public WallpaperConnection(WallpaperInfo info) {
168 mInfo = info;
169 }
170
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700171 public void onServiceConnected(ComponentName name, IBinder service) {
172 synchronized (mLock) {
173 if (mWallpaperConnection == this) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800174 mLastDiedTime = SystemClock.uptimeMillis();
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700175 mService = IWallpaperService.Stub.asInterface(service);
176 attachServiceLocked(this);
Dianne Hackborneb034652009-09-07 00:49:58 -0700177 // XXX should probably do saveSettingsLocked() later
178 // when we have an engine, but I'm not sure about
179 // locking there and anyway we always need to be able to
180 // recover if there is something wrong.
181 saveSettingsLocked();
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700182 }
183 }
184 }
185
186 public void onServiceDisconnected(ComponentName name) {
187 synchronized (mLock) {
188 mService = null;
189 mEngine = null;
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700190 if (mWallpaperConnection == this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800191 Slog.w(TAG, "Wallpaper service gone: " + mWallpaperComponent);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800192 if (!mWallpaperUpdating && (mLastDiedTime+MIN_WALLPAPER_CRASH_TIME)
193 > SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800194 Slog.w(TAG, "Reverting to built-in wallpaper!");
Mike Clerona428b2c2009-11-15 22:53:08 -0800195 bindWallpaperComponentLocked(null);
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700196 }
197 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700198 }
199 }
200
201 public void attachEngine(IWallpaperEngine engine) {
202 mEngine = engine;
203 }
204
205 public ParcelFileDescriptor setWallpaper(String name) {
206 synchronized (mLock) {
207 if (mWallpaperConnection == this) {
Dianne Hackborneb034652009-09-07 00:49:58 -0700208 return updateWallpaperBitmapLocked(name);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700209 }
210 return null;
211 }
212 }
213 }
214
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800215 class MyPackageMonitor extends PackageMonitor {
216 @Override
217 public void onPackageUpdateFinished(String packageName, int uid) {
218 synchronized (mLock) {
219 if (mWallpaperComponent != null &&
220 mWallpaperComponent.getPackageName().equals(packageName)) {
221 mWallpaperUpdating = false;
222 ComponentName comp = mWallpaperComponent;
223 clearWallpaperComponentLocked();
224 bindWallpaperComponentLocked(comp);
225 }
226 }
227 }
228
229 @Override
230 public void onPackageUpdateStarted(String packageName, int uid) {
231 synchronized (mLock) {
232 if (mWallpaperComponent != null &&
233 mWallpaperComponent.getPackageName().equals(packageName)) {
234 mWallpaperUpdating = true;
235 }
236 }
237 }
238
239 @Override
240 public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
241 return doPackagesChanged(doit);
242 }
243
244 @Override
245 public void onSomePackagesChanged() {
246 doPackagesChanged(true);
247 }
248
249 boolean doPackagesChanged(boolean doit) {
250 boolean changed = false;
251 synchronized (mLock) {
252 if (mWallpaperComponent != null) {
253 int change = isPackageDisappearing(mWallpaperComponent.getPackageName());
254 if (change == PACKAGE_PERMANENT_CHANGE
255 || change == PACKAGE_TEMPORARY_CHANGE) {
256 changed = true;
257 if (doit) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800258 Slog.w(TAG, "Wallpaper uninstalled, removing: " + mWallpaperComponent);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800259 clearWallpaperLocked();
260 }
261 }
262 }
263 if (mNextWallpaperComponent != null) {
264 int change = isPackageDisappearing(mNextWallpaperComponent.getPackageName());
265 if (change == PACKAGE_PERMANENT_CHANGE
266 || change == PACKAGE_TEMPORARY_CHANGE) {
267 mNextWallpaperComponent = null;
268 }
269 }
270 if (mWallpaperComponent != null
271 && isPackageModified(mWallpaperComponent.getPackageName())) {
272 try {
273 mContext.getPackageManager().getServiceInfo(
274 mWallpaperComponent, 0);
275 } catch (NameNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800276 Slog.w(TAG, "Wallpaper component gone, removing: " + mWallpaperComponent);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800277 clearWallpaperLocked();
278 }
279 }
280 if (mNextWallpaperComponent != null
281 && isPackageModified(mNextWallpaperComponent.getPackageName())) {
282 try {
283 mContext.getPackageManager().getServiceInfo(
284 mNextWallpaperComponent, 0);
285 } catch (NameNotFoundException e) {
286 mNextWallpaperComponent = null;
287 }
288 }
289 }
290 return changed;
291 }
292 }
293
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700294 public WallpaperManagerService(Context context) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800295 if (DEBUG) Slog.v(TAG, "WallpaperService startup");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 mContext = context;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700297 mIWindowManager = IWindowManager.Stub.asInterface(
298 ServiceManager.getService(Context.WINDOW_SERVICE));
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800299 mMonitor = new MyPackageMonitor();
300 mMonitor.register(context, true);
Joe Onoratoe712ee32009-07-29 16:23:58 -0700301 WALLPAPER_DIR.mkdirs();
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700302 loadSettingsLocked();
Joe Onoratoe712ee32009-07-29 16:23:58 -0700303 mWallpaperObserver.startWatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 }
305
306 @Override
307 protected void finalize() throws Throwable {
308 super.finalize();
309 mWallpaperObserver.stopWatching();
310 }
311
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700312 public void systemReady() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800313 if (DEBUG) Slog.v(TAG, "systemReady");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700314 synchronized (mLock) {
315 try {
Mike Clerona428b2c2009-11-15 22:53:08 -0800316 bindWallpaperComponentLocked(mNextWallpaperComponent);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700317 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800318 Slog.w(TAG, "Failure starting previous wallpaper", e);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700319 try {
Mike Clerona428b2c2009-11-15 22:53:08 -0800320 bindWallpaperComponentLocked(null);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700321 } catch (RuntimeException e2) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800322 Slog.w(TAG, "Failure starting default wallpaper", e2);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700323 clearWallpaperComponentLocked();
324 }
325 }
326 }
327 }
328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800329 public void clearWallpaper() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800330 if (DEBUG) Slog.v(TAG, "clearWallpaper");
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700331 synchronized (mLock) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800332 clearWallpaperLocked();
333 }
334 }
335
336 public void clearWallpaperLocked() {
337 File f = WALLPAPER_FILE;
338 if (f.exists()) {
339 f.delete();
340 }
341 final long ident = Binder.clearCallingIdentity();
342 try {
343 bindWallpaperComponentLocked(null);
Dianne Hackbornc9421ba2010-03-11 22:23:46 -0800344 } catch (IllegalArgumentException e) {
345 // This can happen if the default wallpaper component doesn't
346 // exist. This should be a system configuration problem, but
347 // let's not let it crash the system and just live with no
348 // wallpaper.
349 Slog.e(TAG, "Default wallpaper component not found!", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800350 } finally {
351 Binder.restoreCallingIdentity(ident);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 }
353 }
354
355 public void setDimensionHints(int width, int height) throws RemoteException {
356 checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS);
357
358 if (width <= 0 || height <= 0) {
359 throw new IllegalArgumentException("width and height must be > 0");
360 }
361
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700362 synchronized (mLock) {
363 if (width != mWidth || height != mHeight) {
364 mWidth = width;
365 mHeight = height;
366 saveSettingsLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -0700367 if (mWallpaperConnection != null) {
368 if (mWallpaperConnection.mEngine != null) {
369 try {
370 mWallpaperConnection.mEngine.setDesiredSize(
371 width, height);
372 } catch (RemoteException e) {
373 }
374 notifyCallbacksLocked();
375 }
376 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700377 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 }
379 }
380
381 public int getWidthHint() throws RemoteException {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700382 synchronized (mLock) {
383 return mWidth;
384 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 }
386
387 public int getHeightHint() throws RemoteException {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700388 synchronized (mLock) {
389 return mHeight;
390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 }
392
Dianne Hackborn284ac932009-08-28 10:34:25 -0700393 public ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
394 Bundle outParams) {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700395 synchronized (mLock) {
396 try {
Dianne Hackborn284ac932009-08-28 10:34:25 -0700397 if (outParams != null) {
398 outParams.putInt("width", mWidth);
399 outParams.putInt("height", mHeight);
400 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700401 mCallbacks.register(cb);
402 File f = WALLPAPER_FILE;
403 if (!f.exists()) {
404 return null;
405 }
406 return ParcelFileDescriptor.open(f, MODE_READ_ONLY);
407 } catch (FileNotFoundException e) {
408 /* Shouldn't happen as we check to see if the file exists */
Joe Onorato8a9b2202010-02-26 18:56:32 -0800409 Slog.w(TAG, "Error getting wallpaper", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700411 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 }
414
Dianne Hackborneb034652009-09-07 00:49:58 -0700415 public WallpaperInfo getWallpaperInfo() {
416 synchronized (mLock) {
417 if (mWallpaperConnection != null) {
418 return mWallpaperConnection.mInfo;
419 }
420 return null;
421 }
422 }
423
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700424 public ParcelFileDescriptor setWallpaper(String name) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800425 if (DEBUG) Slog.v(TAG, "setWallpaper");
Mike Clerona428b2c2009-11-15 22:53:08 -0800426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 checkPermission(android.Manifest.permission.SET_WALLPAPER);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700428 synchronized (mLock) {
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700429 final long ident = Binder.clearCallingIdentity();
430 try {
431 ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name);
432 if (pfd != null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800433 // Bind the wallpaper to an ImageWallpaper
Mike Clerona428b2c2009-11-15 22:53:08 -0800434 bindWallpaperComponentLocked(mImageWallpaperComponent);
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700435 saveSettingsLocked();
436 }
437 return pfd;
438 } finally {
439 Binder.restoreCallingIdentity(ident);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 }
442 }
443
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700444 ParcelFileDescriptor updateWallpaperBitmapLocked(String name) {
445 if (name == null) name = "";
446 try {
447 ParcelFileDescriptor fd = ParcelFileDescriptor.open(WALLPAPER_FILE,
448 MODE_CREATE|MODE_READ_WRITE);
449 mName = name;
450 return fd;
451 } catch (FileNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800452 Slog.w(TAG, "Error setting wallpaper", e);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700453 }
454 return null;
455 }
456
457 public void setWallpaperComponent(ComponentName name) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800458 if (DEBUG) Slog.v(TAG, "setWallpaperComponent name=" + name);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700459 checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
460 synchronized (mLock) {
461 final long ident = Binder.clearCallingIdentity();
462 try {
Mike Clerona428b2c2009-11-15 22:53:08 -0800463 bindWallpaperComponentLocked(name);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700464 } finally {
465 Binder.restoreCallingIdentity(ident);
466 }
467 }
468 }
469
Mike Clerona428b2c2009-11-15 22:53:08 -0800470 void bindWallpaperComponentLocked(ComponentName componentName) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800471 if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
Mike Clerona428b2c2009-11-15 22:53:08 -0800472
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700473 // Has the component changed?
474 if (mWallpaperConnection != null) {
475 if (mWallpaperComponent == null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800476 if (componentName == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800477 if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: still using default");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700478 // Still using default wallpaper.
479 return;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700480 }
Mike Cleron322b6ee2009-11-12 07:45:47 -0800481 } else if (mWallpaperComponent.equals(componentName)) {
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700482 // Changing to same wallpaper.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800483 if (DEBUG) Slog.v(TAG, "same wallpaper");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700484 return;
485 }
486 }
487
488 try {
Mike Clerona428b2c2009-11-15 22:53:08 -0800489 if (componentName == null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800490 String defaultComponent =
491 mContext.getString(com.android.internal.R.string.default_wallpaper_component);
Mike Clerona428b2c2009-11-15 22:53:08 -0800492 if (defaultComponent != null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800493 // See if there is a default wallpaper component specified
Mike Clerona428b2c2009-11-15 22:53:08 -0800494 componentName = ComponentName.unflattenFromString(defaultComponent);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800495 if (DEBUG) Slog.v(TAG, "Use default component wallpaper:" + componentName);
Mike Cleron322b6ee2009-11-12 07:45:47 -0800496 }
Mike Clerona428b2c2009-11-15 22:53:08 -0800497 if (componentName == null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800498 // Fall back to static image wallpaper
Mike Clerona428b2c2009-11-15 22:53:08 -0800499 componentName = mImageWallpaperComponent;
Mike Cleron322b6ee2009-11-12 07:45:47 -0800500 //clearWallpaperComponentLocked();
501 //return;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800502 if (DEBUG) Slog.v(TAG, "Using image wallpaper");
Mike Cleron322b6ee2009-11-12 07:45:47 -0800503 }
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700504 }
Mike Clerona428b2c2009-11-15 22:53:08 -0800505 ServiceInfo si = mContext.getPackageManager().getServiceInfo(componentName,
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700506 PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS);
507 if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
508 throw new SecurityException("Selected service does not require "
509 + android.Manifest.permission.BIND_WALLPAPER
Mike Clerona428b2c2009-11-15 22:53:08 -0800510 + ": " + componentName);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700511 }
512
Dianne Hackborneb034652009-09-07 00:49:58 -0700513 WallpaperInfo wi = null;
514
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700515 Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
Mike Clerona428b2c2009-11-15 22:53:08 -0800516 if (componentName != null && !componentName.equals(mImageWallpaperComponent)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700517 // Make sure the selected service is actually a wallpaper service.
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700518 List<ResolveInfo> ris = mContext.getPackageManager()
Dianne Hackborneb034652009-09-07 00:49:58 -0700519 .queryIntentServices(intent, PackageManager.GET_META_DATA);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700520 for (int i=0; i<ris.size(); i++) {
521 ServiceInfo rsi = ris.get(i).serviceInfo;
522 if (rsi.name.equals(si.name) &&
523 rsi.packageName.equals(si.packageName)) {
Dianne Hackborneb034652009-09-07 00:49:58 -0700524 try {
525 wi = new WallpaperInfo(mContext, ris.get(i));
526 } catch (XmlPullParserException e) {
527 throw new IllegalArgumentException(e);
528 } catch (IOException e) {
529 throw new IllegalArgumentException(e);
530 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700531 break;
532 }
533 }
Dianne Hackborneb034652009-09-07 00:49:58 -0700534 if (wi == null) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700535 throw new SecurityException("Selected service is not a wallpaper: "
Mike Clerona428b2c2009-11-15 22:53:08 -0800536 + componentName);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700537 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700538 }
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700539
540 // Bind the service!
Joe Onorato8a9b2202010-02-26 18:56:32 -0800541 if (DEBUG) Slog.v(TAG, "Binding to:" + componentName);
Dianne Hackborneb034652009-09-07 00:49:58 -0700542 WallpaperConnection newConn = new WallpaperConnection(wi);
Mike Clerona428b2c2009-11-15 22:53:08 -0800543 intent.setComponent(componentName);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700544 intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
545 com.android.internal.R.string.wallpaper_binding_label);
546 intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
Dianne Hackborneb034652009-09-07 00:49:58 -0700547 mContext, 0,
548 Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
549 mContext.getText(com.android.internal.R.string.chooser_wallpaper)),
550 0));
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700551 if (!mContext.bindService(intent, newConn,
552 Context.BIND_AUTO_CREATE)) {
553 throw new IllegalArgumentException("Unable to bind service: "
Mike Cleron322b6ee2009-11-12 07:45:47 -0800554 + componentName);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700555 }
556
557 clearWallpaperComponentLocked();
Mike Cleron322b6ee2009-11-12 07:45:47 -0800558 mWallpaperComponent = componentName;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700559 mWallpaperConnection = newConn;
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700560 mLastDiedTime = SystemClock.uptimeMillis();
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700561 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800562 if (DEBUG) Slog.v(TAG, "Adding window token: " + newConn.mToken);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700563 mIWindowManager.addWindowToken(newConn.mToken,
564 WindowManager.LayoutParams.TYPE_WALLPAPER);
565 } catch (RemoteException e) {
566 }
567
568 } catch (PackageManager.NameNotFoundException e) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800569 throw new IllegalArgumentException("Unknown component " + componentName);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700570 }
571 }
572
573 void clearWallpaperComponentLocked() {
574 mWallpaperComponent = null;
575 if (mWallpaperConnection != null) {
576 if (mWallpaperConnection.mEngine != null) {
577 try {
578 mWallpaperConnection.mEngine.destroy();
579 } catch (RemoteException e) {
580 }
581 }
582 mContext.unbindService(mWallpaperConnection);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -0700583 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800584 if (DEBUG) Slog.v(TAG, "Removing window token: "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -0700585 + mWallpaperConnection.mToken);
586 mIWindowManager.removeWindowToken(mWallpaperConnection.mToken);
587 } catch (RemoteException e) {
588 }
Vairavan Srinivasanfdfc1b22010-12-23 14:05:44 -0800589 mWallpaperConnection.mService = null;
590 mWallpaperConnection.mEngine = null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700591 mWallpaperConnection = null;
592 }
593 }
594
595 void attachServiceLocked(WallpaperConnection conn) {
596 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700597 conn.mService.attach(conn, conn.mToken,
598 WindowManager.LayoutParams.TYPE_WALLPAPER, false,
599 mWidth, mHeight);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700600 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800601 Slog.w(TAG, "Failed attaching wallpaper; clearing", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800602 if (!mWallpaperUpdating) {
603 bindWallpaperComponentLocked(null);
604 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700605 }
606 }
607
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700608 private void notifyCallbacksLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800609 final int n = mCallbacks.beginBroadcast();
610 for (int i = 0; i < n; i++) {
611 try {
612 mCallbacks.getBroadcastItem(i).onWallpaperChanged();
613 } catch (RemoteException e) {
614
615 // The RemoteCallbackList will take care of removing
616 // the dead object for us.
617 }
618 }
619 mCallbacks.finishBroadcast();
620 final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED);
621 mContext.sendBroadcast(intent);
622 }
623
624 private void checkPermission(String permission) {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700625 if (PackageManager.PERMISSION_GRANTED!= mContext.checkCallingOrSelfPermission(permission)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 throw new SecurityException("Access denied to process: " + Binder.getCallingPid()
627 + ", must have permission " + permission);
628 }
629 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700630
631 private static JournaledFile makeJournaledFile() {
632 final String base = "/data/system/wallpaper_info.xml";
633 return new JournaledFile(new File(base), new File(base + ".tmp"));
634 }
635
636 private void saveSettingsLocked() {
637 JournaledFile journal = makeJournaledFile();
638 FileOutputStream stream = null;
639 try {
640 stream = new FileOutputStream(journal.chooseForWrite(), false);
641 XmlSerializer out = new FastXmlSerializer();
642 out.setOutput(stream, "utf-8");
643 out.startDocument(null, true);
644
645 out.startTag(null, "wp");
646 out.attribute(null, "width", Integer.toString(mWidth));
647 out.attribute(null, "height", Integer.toString(mHeight));
648 out.attribute(null, "name", mName);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700649 if (mWallpaperComponent != null) {
650 out.attribute(null, "component",
651 mWallpaperComponent.flattenToShortString());
652 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700653 out.endTag(null, "wp");
654
655 out.endDocument();
656 stream.close();
657 journal.commit();
658 } catch (IOException e) {
659 try {
660 if (stream != null) {
661 stream.close();
662 }
663 } catch (IOException ex) {
664 // Ignore
665 }
666 journal.rollback();
667 }
668 }
669
670 private void loadSettingsLocked() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800671 if (DEBUG) Slog.v(TAG, "loadSettingsLocked");
Mike Clerona428b2c2009-11-15 22:53:08 -0800672
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700673 JournaledFile journal = makeJournaledFile();
674 FileInputStream stream = null;
675 File file = journal.chooseForRead();
676 boolean success = false;
677 try {
678 stream = new FileInputStream(file);
679 XmlPullParser parser = Xml.newPullParser();
680 parser.setInput(stream, null);
681
682 int type;
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700683 do {
684 type = parser.next();
685 if (type == XmlPullParser.START_TAG) {
686 String tag = parser.getName();
687 if ("wp".equals(tag)) {
688 mWidth = Integer.parseInt(parser.getAttributeValue(null, "width"));
689 mHeight = Integer.parseInt(parser.getAttributeValue(null, "height"));
690 mName = parser.getAttributeValue(null, "name");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700691 String comp = parser.getAttributeValue(null, "component");
Mike Clerona428b2c2009-11-15 22:53:08 -0800692 mNextWallpaperComponent = comp != null
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700693 ? ComponentName.unflattenFromString(comp)
694 : null;
Mike Clerona428b2c2009-11-15 22:53:08 -0800695
696 if (DEBUG) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800697 Slog.v(TAG, "mWidth:" + mWidth);
698 Slog.v(TAG, "mHeight:" + mHeight);
699 Slog.v(TAG, "mName:" + mName);
700 Slog.v(TAG, "mNextWallpaperComponent:" + mNextWallpaperComponent);
Mike Clerona428b2c2009-11-15 22:53:08 -0800701 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700702 }
703 }
704 } while (type != XmlPullParser.END_DOCUMENT);
705 success = true;
706 } catch (NullPointerException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800707 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700708 } catch (NumberFormatException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800709 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700710 } catch (XmlPullParserException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800711 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700712 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800713 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700714 } catch (IndexOutOfBoundsException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800715 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700716 }
717 try {
718 if (stream != null) {
719 stream.close();
720 }
721 } catch (IOException e) {
722 // Ignore
723 }
724
725 if (!success) {
726 mWidth = -1;
727 mHeight = -1;
728 mName = "";
729 }
Dianne Hackborn44bc17c2011-04-20 18:18:51 -0700730
731 // We always want to have some reasonable width hint.
732 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
733 Display d = wm.getDefaultDisplay();
734 int baseSize = d.getMaximumSizeDimension();
735 if (mWidth < baseSize) {
736 mWidth = baseSize;
737 }
738 if (mHeight < baseSize) {
739 mHeight = baseSize;
740 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700741 }
742
Brad Fitzpatrick194b19a2010-09-14 11:30:29 -0700743 // Called by SystemBackupAgent after files are restored to disk.
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700744 void settingsRestored() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800745 if (DEBUG) Slog.v(TAG, "settingsRestored");
Brad Fitzpatrick194b19a2010-09-14 11:30:29 -0700746
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700747 boolean success = false;
748 synchronized (mLock) {
749 loadSettingsLocked();
Mike Clerona428b2c2009-11-15 22:53:08 -0800750 if (mNextWallpaperComponent != null &&
751 !mNextWallpaperComponent.equals(mImageWallpaperComponent)) {
Christopher Tatee3ab4d02009-12-16 14:03:31 -0800752 try {
753 bindWallpaperComponentLocked(mNextWallpaperComponent);
754 } catch (IllegalArgumentException e) {
755 // No such live wallpaper or other failure; fall back to the default
756 // live wallpaper (since the profile being restored indicated that the
757 // user had selected a live rather than static one).
758 bindWallpaperComponentLocked(null);
759 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700760 success = true;
761 } else {
Mike Clerona428b2c2009-11-15 22:53:08 -0800762 // If there's a wallpaper name, we use that. If that can't be loaded, then we
763 // use the default.
764 if ("".equals(mName)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800765 if (DEBUG) Slog.v(TAG, "settingsRestored: name is empty");
Mike Clerona428b2c2009-11-15 22:53:08 -0800766 success = true;
767 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800768 if (DEBUG) Slog.v(TAG, "settingsRestored: attempting to restore named resource");
Mike Clerona428b2c2009-11-15 22:53:08 -0800769 success = restoreNamedResourceLocked();
770 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800771 if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success);
Mike Clerona428b2c2009-11-15 22:53:08 -0800772 if (success) {
773 bindWallpaperComponentLocked(mImageWallpaperComponent);
774 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700775 }
776 }
777
778 if (!success) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800779 Slog.e(TAG, "Failed to restore wallpaper: '" + mName + "'");
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700780 mName = "";
781 WALLPAPER_FILE.delete();
782 }
Brad Fitzpatrick194b19a2010-09-14 11:30:29 -0700783
784 synchronized (mLock) {
785 saveSettingsLocked();
786 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700787 }
788
789 boolean restoreNamedResourceLocked() {
790 if (mName.length() > 4 && "res:".equals(mName.substring(0, 4))) {
791 String resName = mName.substring(4);
792
793 String pkg = null;
794 int colon = resName.indexOf(':');
795 if (colon > 0) {
796 pkg = resName.substring(0, colon);
797 }
798
799 String ident = null;
800 int slash = resName.lastIndexOf('/');
801 if (slash > 0) {
802 ident = resName.substring(slash+1);
803 }
804
805 String type = null;
806 if (colon > 0 && slash > 0 && (slash-colon) > 1) {
807 type = resName.substring(colon+1, slash);
808 }
809
810 if (pkg != null && ident != null && type != null) {
811 int resId = -1;
812 InputStream res = null;
813 FileOutputStream fos = null;
814 try {
815 Context c = mContext.createPackageContext(pkg, Context.CONTEXT_RESTRICTED);
816 Resources r = c.getResources();
817 resId = r.getIdentifier(resName, null, null);
818 if (resId == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800819 Slog.e(TAG, "couldn't resolve identifier pkg=" + pkg + " type=" + type
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700820 + " ident=" + ident);
821 return false;
822 }
823
824 res = r.openRawResource(resId);
Dianne Hackborn1afd1c92010-03-18 22:47:17 -0700825 if (WALLPAPER_FILE.exists()) {
826 WALLPAPER_FILE.delete();
827 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700828 fos = new FileOutputStream(WALLPAPER_FILE);
829
830 byte[] buffer = new byte[32768];
831 int amt;
832 while ((amt=res.read(buffer)) > 0) {
833 fos.write(buffer, 0, amt);
834 }
835 // mWallpaperObserver will notice the close and send the change broadcast
836
Joe Onorato8a9b2202010-02-26 18:56:32 -0800837 Slog.v(TAG, "Restored wallpaper: " + resName);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700838 return true;
839 } catch (NameNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800840 Slog.e(TAG, "Package name " + pkg + " not found");
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700841 } catch (Resources.NotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800842 Slog.e(TAG, "Resource not found: " + resId);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700843 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800844 Slog.e(TAG, "IOException while restoring wallpaper ", e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700845 } finally {
846 if (res != null) {
847 try {
848 res.close();
849 } catch (IOException ex) {}
850 }
851 if (fos != null) {
Dianne Hackborn8bdf5932010-10-15 12:54:40 -0700852 FileUtils.sync(fos);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700853 try {
854 fos.close();
855 } catch (IOException ex) {}
856 }
857 }
858 }
859 }
860 return false;
861 }
Dianne Hackborneb034652009-09-07 00:49:58 -0700862
863 @Override
864 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
865 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
866 != PackageManager.PERMISSION_GRANTED) {
867
868 pw.println("Permission Denial: can't dump wallpaper service from from pid="
869 + Binder.getCallingPid()
870 + ", uid=" + Binder.getCallingUid());
871 return;
872 }
873
874 synchronized (mLock) {
875 pw.println("Current Wallpaper Service state:");
876 pw.print(" mWidth="); pw.print(mWidth);
877 pw.print(" mHeight="); pw.println(mHeight);
878 pw.print(" mName="); pw.println(mName);
879 pw.print(" mWallpaperComponent="); pw.println(mWallpaperComponent);
880 if (mWallpaperConnection != null) {
881 WallpaperConnection conn = mWallpaperConnection;
882 pw.print(" Wallpaper connection ");
883 pw.print(conn); pw.println(":");
884 pw.print(" mInfo.component="); pw.println(conn.mInfo.getComponent());
885 pw.print(" mToken="); pw.println(conn.mToken);
886 pw.print(" mService="); pw.println(conn.mService);
887 pw.print(" mEngine="); pw.println(conn.mEngine);
888 pw.print(" mLastDiedTime=");
889 pw.println(mLastDiedTime - SystemClock.uptimeMillis());
890 }
891 }
892 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893}