blob: 859c85cd4f27437336c057a16315f8a3c4810ce4 [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 Hackborn4c62fc02009-08-08 20:40:27 -070052import android.view.IWindowManager;
53import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054
Dianne Hackborneb034652009-09-07 00:49:58 -070055import java.io.FileDescriptor;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070056import java.io.IOException;
57import java.io.InputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import java.io.File;
59import java.io.FileNotFoundException;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070060import java.io.FileInputStream;
61import java.io.FileOutputStream;
Dianne Hackborneb034652009-09-07 00:49:58 -070062import java.io.PrintWriter;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070063import java.util.List;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070064
65import org.xmlpull.v1.XmlPullParser;
66import org.xmlpull.v1.XmlPullParserException;
67import org.xmlpull.v1.XmlSerializer;
68
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080069import com.android.internal.content.PackageMonitor;
Dianne Hackbornf21adf62009-08-13 10:20:21 -070070import com.android.internal.service.wallpaper.ImageWallpaper;
Dianne Hackborn2269d1572010-02-24 19:54:22 -080071import com.android.internal.util.FastXmlSerializer;
Dianne Hackborn1afd1c92010-03-18 22:47:17 -070072import com.android.internal.util.JournaledFile;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080073import com.android.server.DevicePolicyManagerService.ActiveAdmin;
74import com.android.server.DevicePolicyManagerService.MyPackageMonitor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075
Dianne Hackborn8cc6a502009-08-05 21:29:42 -070076class WallpaperManagerService extends IWallpaperManager.Stub {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070077 static final String TAG = "WallpaperService";
Dianne Hackborncbf15042009-08-18 18:29:09 -070078 static final boolean DEBUG = false;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070079
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070080 Object mLock = new Object();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
Dianne Hackborn0cd48872009-08-13 18:51:59 -070082 /**
83 * Minimum time between crashes of a wallpaper service for us to consider
84 * restarting it vs. just reverting to the static wallpaper.
85 */
86 static final long MIN_WALLPAPER_CRASH_TIME = 10000;
87
88 static final File WALLPAPER_DIR = new File(
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 "/data/data/com.android.settings/files");
Dianne Hackborn0cd48872009-08-13 18:51:59 -070090 static final String WALLPAPER = "wallpaper";
91 static final File WALLPAPER_FILE = new File(WALLPAPER_DIR, WALLPAPER);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 /**
94 * List of callbacks registered they should each be notified
95 * when the wallpaper is changed.
96 */
Dianne Hackborn8cc6a502009-08-05 21:29:42 -070097 private final RemoteCallbackList<IWallpaperManagerCallback> mCallbacks
98 = new RemoteCallbackList<IWallpaperManagerCallback>();
Joe Onorato9bb8fd72009-07-28 18:24:51 -070099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 /**
101 * Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks
102 * that the wallpaper has changed. The CREATE is triggered when there is no
103 * wallpaper set and is created for the first time. The CLOSE_WRITE is triggered
104 * everytime the wallpaper is changed.
105 */
106 private final FileObserver mWallpaperObserver = new FileObserver(
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700107 WALLPAPER_DIR.getAbsolutePath(), CREATE | CLOSE_WRITE | DELETE | DELETE_SELF) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 @Override
109 public void onEvent(int event, String path) {
Joe Onoratoe712ee32009-07-29 16:23:58 -0700110 if (path == null) {
111 return;
112 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700113 synchronized (mLock) {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700114 // changing the wallpaper means we'll need to back up the new one
115 long origId = Binder.clearCallingIdentity();
116 BackupManager bm = new BackupManager(mContext);
117 bm.dataChanged();
118 Binder.restoreCallingIdentity(origId);
119
120 File changedFile = new File(WALLPAPER_DIR, path);
121 if (WALLPAPER_FILE.equals(changedFile)) {
122 notifyCallbacksLocked();
123 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 }
125 }
126 };
127
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700128 final Context mContext;
129 final IWindowManager mIWindowManager;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800130 final MyPackageMonitor mMonitor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700132 int mWidth = -1;
133 int mHeight = -1;
Mike Clerona428b2c2009-11-15 22:53:08 -0800134
135 /**
136 * Resource name if using a picture from the wallpaper gallery
137 */
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700138 String mName = "";
Mike Clerond6c0b842009-11-13 16:37:27 -0800139
140 /**
Mike Clerona428b2c2009-11-15 22:53:08 -0800141 * The component name of the currently set live wallpaper.
Mike Clerond6c0b842009-11-13 16:37:27 -0800142 */
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700143 ComponentName mWallpaperComponent;
Mike Clerona428b2c2009-11-15 22:53:08 -0800144
145 /**
146 * The component name of the wallpaper that should be set next.
147 */
148 ComponentName mNextWallpaperComponent;
149
150 /**
151 * Name of the component used to display bitmap wallpapers from either the gallery or
152 * built-in wallpapers.
153 */
154 ComponentName mImageWallpaperComponent = new ComponentName("android",
155 ImageWallpaper.class.getName());
156
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700157 WallpaperConnection mWallpaperConnection;
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700158 long mLastDiedTime;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800159 boolean mWallpaperUpdating;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700160
161 class WallpaperConnection extends IWallpaperConnection.Stub
162 implements ServiceConnection {
Dianne Hackborneb034652009-09-07 00:49:58 -0700163 final WallpaperInfo mInfo;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700164 final Binder mToken = new Binder();
165 IWallpaperService mService;
166 IWallpaperEngine mEngine;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167
Dianne Hackborneb034652009-09-07 00:49:58 -0700168 public WallpaperConnection(WallpaperInfo info) {
169 mInfo = info;
170 }
171
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700172 public void onServiceConnected(ComponentName name, IBinder service) {
173 synchronized (mLock) {
174 if (mWallpaperConnection == this) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800175 mLastDiedTime = SystemClock.uptimeMillis();
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700176 mService = IWallpaperService.Stub.asInterface(service);
177 attachServiceLocked(this);
Dianne Hackborneb034652009-09-07 00:49:58 -0700178 // XXX should probably do saveSettingsLocked() later
179 // when we have an engine, but I'm not sure about
180 // locking there and anyway we always need to be able to
181 // recover if there is something wrong.
182 saveSettingsLocked();
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700183 }
184 }
185 }
186
187 public void onServiceDisconnected(ComponentName name) {
188 synchronized (mLock) {
189 mService = null;
190 mEngine = null;
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700191 if (mWallpaperConnection == this) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800192 Slog.w(TAG, "Wallpaper service gone: " + mWallpaperComponent);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800193 if (!mWallpaperUpdating && (mLastDiedTime+MIN_WALLPAPER_CRASH_TIME)
194 > SystemClock.uptimeMillis()) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800195 Slog.w(TAG, "Reverting to built-in wallpaper!");
Mike Clerona428b2c2009-11-15 22:53:08 -0800196 bindWallpaperComponentLocked(null);
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700197 }
198 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700199 }
200 }
201
202 public void attachEngine(IWallpaperEngine engine) {
203 mEngine = engine;
204 }
205
206 public ParcelFileDescriptor setWallpaper(String name) {
207 synchronized (mLock) {
208 if (mWallpaperConnection == this) {
Dianne Hackborneb034652009-09-07 00:49:58 -0700209 return updateWallpaperBitmapLocked(name);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700210 }
211 return null;
212 }
213 }
214 }
215
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800216 class MyPackageMonitor extends PackageMonitor {
217 @Override
218 public void onPackageUpdateFinished(String packageName, int uid) {
219 synchronized (mLock) {
220 if (mWallpaperComponent != null &&
221 mWallpaperComponent.getPackageName().equals(packageName)) {
222 mWallpaperUpdating = false;
223 ComponentName comp = mWallpaperComponent;
224 clearWallpaperComponentLocked();
225 bindWallpaperComponentLocked(comp);
226 }
227 }
228 }
229
230 @Override
231 public void onPackageUpdateStarted(String packageName, int uid) {
232 synchronized (mLock) {
233 if (mWallpaperComponent != null &&
234 mWallpaperComponent.getPackageName().equals(packageName)) {
235 mWallpaperUpdating = true;
236 }
237 }
238 }
239
240 @Override
241 public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
242 return doPackagesChanged(doit);
243 }
244
245 @Override
246 public void onSomePackagesChanged() {
247 doPackagesChanged(true);
248 }
249
250 boolean doPackagesChanged(boolean doit) {
251 boolean changed = false;
252 synchronized (mLock) {
253 if (mWallpaperComponent != null) {
254 int change = isPackageDisappearing(mWallpaperComponent.getPackageName());
255 if (change == PACKAGE_PERMANENT_CHANGE
256 || change == PACKAGE_TEMPORARY_CHANGE) {
257 changed = true;
258 if (doit) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800259 Slog.w(TAG, "Wallpaper uninstalled, removing: " + mWallpaperComponent);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800260 clearWallpaperLocked();
261 }
262 }
263 }
264 if (mNextWallpaperComponent != null) {
265 int change = isPackageDisappearing(mNextWallpaperComponent.getPackageName());
266 if (change == PACKAGE_PERMANENT_CHANGE
267 || change == PACKAGE_TEMPORARY_CHANGE) {
268 mNextWallpaperComponent = null;
269 }
270 }
271 if (mWallpaperComponent != null
272 && isPackageModified(mWallpaperComponent.getPackageName())) {
273 try {
274 mContext.getPackageManager().getServiceInfo(
275 mWallpaperComponent, 0);
276 } catch (NameNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800277 Slog.w(TAG, "Wallpaper component gone, removing: " + mWallpaperComponent);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800278 clearWallpaperLocked();
279 }
280 }
281 if (mNextWallpaperComponent != null
282 && isPackageModified(mNextWallpaperComponent.getPackageName())) {
283 try {
284 mContext.getPackageManager().getServiceInfo(
285 mNextWallpaperComponent, 0);
286 } catch (NameNotFoundException e) {
287 mNextWallpaperComponent = null;
288 }
289 }
290 }
291 return changed;
292 }
293 }
294
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700295 public WallpaperManagerService(Context context) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800296 if (DEBUG) Slog.v(TAG, "WallpaperService startup");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297 mContext = context;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700298 mIWindowManager = IWindowManager.Stub.asInterface(
299 ServiceManager.getService(Context.WINDOW_SERVICE));
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800300 mMonitor = new MyPackageMonitor();
301 mMonitor.register(context, true);
Joe Onoratoe712ee32009-07-29 16:23:58 -0700302 WALLPAPER_DIR.mkdirs();
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700303 loadSettingsLocked();
Joe Onoratoe712ee32009-07-29 16:23:58 -0700304 mWallpaperObserver.startWatching();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800305 }
306
307 @Override
308 protected void finalize() throws Throwable {
309 super.finalize();
310 mWallpaperObserver.stopWatching();
311 }
312
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700313 public void systemReady() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800314 if (DEBUG) Slog.v(TAG, "systemReady");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700315 synchronized (mLock) {
316 try {
Mike Clerona428b2c2009-11-15 22:53:08 -0800317 bindWallpaperComponentLocked(mNextWallpaperComponent);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700318 } catch (RuntimeException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800319 Slog.w(TAG, "Failure starting previous wallpaper", e);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700320 try {
Mike Clerona428b2c2009-11-15 22:53:08 -0800321 bindWallpaperComponentLocked(null);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700322 } catch (RuntimeException e2) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800323 Slog.w(TAG, "Failure starting default wallpaper", e2);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700324 clearWallpaperComponentLocked();
325 }
326 }
327 }
328 }
329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330 public void clearWallpaper() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800331 if (DEBUG) Slog.v(TAG, "clearWallpaper");
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700332 synchronized (mLock) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800333 clearWallpaperLocked();
334 }
335 }
336
337 public void clearWallpaperLocked() {
338 File f = WALLPAPER_FILE;
339 if (f.exists()) {
340 f.delete();
341 }
342 final long ident = Binder.clearCallingIdentity();
343 try {
344 bindWallpaperComponentLocked(null);
Dianne Hackbornc9421ba2010-03-11 22:23:46 -0800345 } catch (IllegalArgumentException e) {
346 // This can happen if the default wallpaper component doesn't
347 // exist. This should be a system configuration problem, but
348 // let's not let it crash the system and just live with no
349 // wallpaper.
350 Slog.e(TAG, "Default wallpaper component not found!", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800351 } finally {
352 Binder.restoreCallingIdentity(ident);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 }
354 }
355
356 public void setDimensionHints(int width, int height) throws RemoteException {
357 checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS);
358
359 if (width <= 0 || height <= 0) {
360 throw new IllegalArgumentException("width and height must be > 0");
361 }
362
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700363 synchronized (mLock) {
364 if (width != mWidth || height != mHeight) {
365 mWidth = width;
366 mHeight = height;
367 saveSettingsLocked();
Dianne Hackborn284ac932009-08-28 10:34:25 -0700368 if (mWallpaperConnection != null) {
369 if (mWallpaperConnection.mEngine != null) {
370 try {
371 mWallpaperConnection.mEngine.setDesiredSize(
372 width, height);
373 } catch (RemoteException e) {
374 }
375 notifyCallbacksLocked();
376 }
377 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700378 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 }
380 }
381
382 public int getWidthHint() throws RemoteException {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700383 synchronized (mLock) {
384 return mWidth;
385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 }
387
388 public int getHeightHint() throws RemoteException {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700389 synchronized (mLock) {
390 return mHeight;
391 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 }
393
Dianne Hackborn284ac932009-08-28 10:34:25 -0700394 public ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
395 Bundle outParams) {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700396 synchronized (mLock) {
397 try {
Dianne Hackborn284ac932009-08-28 10:34:25 -0700398 if (outParams != null) {
399 outParams.putInt("width", mWidth);
400 outParams.putInt("height", mHeight);
401 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700402 mCallbacks.register(cb);
403 File f = WALLPAPER_FILE;
404 if (!f.exists()) {
405 return null;
406 }
407 return ParcelFileDescriptor.open(f, MODE_READ_ONLY);
408 } catch (FileNotFoundException e) {
409 /* Shouldn't happen as we check to see if the file exists */
Joe Onorato8a9b2202010-02-26 18:56:32 -0800410 Slog.w(TAG, "Error getting wallpaper", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700412 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414 }
415
Dianne Hackborneb034652009-09-07 00:49:58 -0700416 public WallpaperInfo getWallpaperInfo() {
417 synchronized (mLock) {
418 if (mWallpaperConnection != null) {
419 return mWallpaperConnection.mInfo;
420 }
421 return null;
422 }
423 }
424
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700425 public ParcelFileDescriptor setWallpaper(String name) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800426 if (DEBUG) Slog.v(TAG, "setWallpaper");
Mike Clerona428b2c2009-11-15 22:53:08 -0800427
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 checkPermission(android.Manifest.permission.SET_WALLPAPER);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700429 synchronized (mLock) {
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700430 final long ident = Binder.clearCallingIdentity();
431 try {
432 ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name);
433 if (pfd != null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800434 // Bind the wallpaper to an ImageWallpaper
Mike Clerona428b2c2009-11-15 22:53:08 -0800435 bindWallpaperComponentLocked(mImageWallpaperComponent);
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700436 saveSettingsLocked();
437 }
438 return pfd;
439 } finally {
440 Binder.restoreCallingIdentity(ident);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700441 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 }
443 }
444
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700445 ParcelFileDescriptor updateWallpaperBitmapLocked(String name) {
446 if (name == null) name = "";
447 try {
448 ParcelFileDescriptor fd = ParcelFileDescriptor.open(WALLPAPER_FILE,
449 MODE_CREATE|MODE_READ_WRITE);
450 mName = name;
451 return fd;
452 } catch (FileNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800453 Slog.w(TAG, "Error setting wallpaper", e);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700454 }
455 return null;
456 }
457
458 public void setWallpaperComponent(ComponentName name) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800459 if (DEBUG) Slog.v(TAG, "setWallpaperComponent name=" + name);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700460 checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
461 synchronized (mLock) {
462 final long ident = Binder.clearCallingIdentity();
463 try {
Mike Clerona428b2c2009-11-15 22:53:08 -0800464 bindWallpaperComponentLocked(name);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700465 } finally {
466 Binder.restoreCallingIdentity(ident);
467 }
468 }
469 }
470
Mike Clerona428b2c2009-11-15 22:53:08 -0800471 void bindWallpaperComponentLocked(ComponentName componentName) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800472 if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
Mike Clerona428b2c2009-11-15 22:53:08 -0800473
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700474 // Has the component changed?
475 if (mWallpaperConnection != null) {
476 if (mWallpaperComponent == null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800477 if (componentName == null) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800478 if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: still using default");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700479 // Still using default wallpaper.
480 return;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700481 }
Mike Cleron322b6ee2009-11-12 07:45:47 -0800482 } else if (mWallpaperComponent.equals(componentName)) {
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700483 // Changing to same wallpaper.
Joe Onorato8a9b2202010-02-26 18:56:32 -0800484 if (DEBUG) Slog.v(TAG, "same wallpaper");
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700485 return;
486 }
487 }
488
489 try {
Mike Clerona428b2c2009-11-15 22:53:08 -0800490 if (componentName == null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800491 String defaultComponent =
492 mContext.getString(com.android.internal.R.string.default_wallpaper_component);
Mike Clerona428b2c2009-11-15 22:53:08 -0800493 if (defaultComponent != null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800494 // See if there is a default wallpaper component specified
Mike Clerona428b2c2009-11-15 22:53:08 -0800495 componentName = ComponentName.unflattenFromString(defaultComponent);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800496 if (DEBUG) Slog.v(TAG, "Use default component wallpaper:" + componentName);
Mike Cleron322b6ee2009-11-12 07:45:47 -0800497 }
Mike Clerona428b2c2009-11-15 22:53:08 -0800498 if (componentName == null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800499 // Fall back to static image wallpaper
Mike Clerona428b2c2009-11-15 22:53:08 -0800500 componentName = mImageWallpaperComponent;
Mike Cleron322b6ee2009-11-12 07:45:47 -0800501 //clearWallpaperComponentLocked();
502 //return;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800503 if (DEBUG) Slog.v(TAG, "Using image wallpaper");
Mike Cleron322b6ee2009-11-12 07:45:47 -0800504 }
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700505 }
Mike Clerona428b2c2009-11-15 22:53:08 -0800506 ServiceInfo si = mContext.getPackageManager().getServiceInfo(componentName,
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700507 PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS);
508 if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
509 throw new SecurityException("Selected service does not require "
510 + android.Manifest.permission.BIND_WALLPAPER
Mike Clerona428b2c2009-11-15 22:53:08 -0800511 + ": " + componentName);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700512 }
513
Dianne Hackborneb034652009-09-07 00:49:58 -0700514 WallpaperInfo wi = null;
515
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700516 Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
Mike Clerona428b2c2009-11-15 22:53:08 -0800517 if (componentName != null && !componentName.equals(mImageWallpaperComponent)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700518 // Make sure the selected service is actually a wallpaper service.
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700519 List<ResolveInfo> ris = mContext.getPackageManager()
Dianne Hackborneb034652009-09-07 00:49:58 -0700520 .queryIntentServices(intent, PackageManager.GET_META_DATA);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700521 for (int i=0; i<ris.size(); i++) {
522 ServiceInfo rsi = ris.get(i).serviceInfo;
523 if (rsi.name.equals(si.name) &&
524 rsi.packageName.equals(si.packageName)) {
Dianne Hackborneb034652009-09-07 00:49:58 -0700525 try {
526 wi = new WallpaperInfo(mContext, ris.get(i));
527 } catch (XmlPullParserException e) {
528 throw new IllegalArgumentException(e);
529 } catch (IOException e) {
530 throw new IllegalArgumentException(e);
531 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700532 break;
533 }
534 }
Dianne Hackborneb034652009-09-07 00:49:58 -0700535 if (wi == null) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700536 throw new SecurityException("Selected service is not a wallpaper: "
Mike Clerona428b2c2009-11-15 22:53:08 -0800537 + componentName);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700538 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700539 }
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700540
541 // Bind the service!
Joe Onorato8a9b2202010-02-26 18:56:32 -0800542 if (DEBUG) Slog.v(TAG, "Binding to:" + componentName);
Dianne Hackborneb034652009-09-07 00:49:58 -0700543 WallpaperConnection newConn = new WallpaperConnection(wi);
Mike Clerona428b2c2009-11-15 22:53:08 -0800544 intent.setComponent(componentName);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700545 intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
546 com.android.internal.R.string.wallpaper_binding_label);
547 intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
Dianne Hackborneb034652009-09-07 00:49:58 -0700548 mContext, 0,
549 Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
550 mContext.getText(com.android.internal.R.string.chooser_wallpaper)),
551 0));
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700552 if (!mContext.bindService(intent, newConn,
553 Context.BIND_AUTO_CREATE)) {
554 throw new IllegalArgumentException("Unable to bind service: "
Mike Cleron322b6ee2009-11-12 07:45:47 -0800555 + componentName);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700556 }
557
558 clearWallpaperComponentLocked();
Mike Cleron322b6ee2009-11-12 07:45:47 -0800559 mWallpaperComponent = componentName;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700560 mWallpaperConnection = newConn;
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700561 mLastDiedTime = SystemClock.uptimeMillis();
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700562 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800563 if (DEBUG) Slog.v(TAG, "Adding window token: " + newConn.mToken);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700564 mIWindowManager.addWindowToken(newConn.mToken,
565 WindowManager.LayoutParams.TYPE_WALLPAPER);
566 } catch (RemoteException e) {
567 }
568
569 } catch (PackageManager.NameNotFoundException e) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800570 throw new IllegalArgumentException("Unknown component " + componentName);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700571 }
572 }
573
574 void clearWallpaperComponentLocked() {
575 mWallpaperComponent = null;
576 if (mWallpaperConnection != null) {
577 if (mWallpaperConnection.mEngine != null) {
578 try {
579 mWallpaperConnection.mEngine.destroy();
580 } catch (RemoteException e) {
581 }
582 }
583 mContext.unbindService(mWallpaperConnection);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -0700584 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800585 if (DEBUG) Slog.v(TAG, "Removing window token: "
Dianne Hackborne9e9bca2009-08-18 15:08:22 -0700586 + mWallpaperConnection.mToken);
587 mIWindowManager.removeWindowToken(mWallpaperConnection.mToken);
588 } catch (RemoteException e) {
589 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700590 mWallpaperConnection = null;
591 }
592 }
593
594 void attachServiceLocked(WallpaperConnection conn) {
595 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700596 conn.mService.attach(conn, conn.mToken,
597 WindowManager.LayoutParams.TYPE_WALLPAPER, false,
598 mWidth, mHeight);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700599 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800600 Slog.w(TAG, "Failed attaching wallpaper; clearing", e);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800601 if (!mWallpaperUpdating) {
602 bindWallpaperComponentLocked(null);
603 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700604 }
605 }
606
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700607 private void notifyCallbacksLocked() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 final int n = mCallbacks.beginBroadcast();
609 for (int i = 0; i < n; i++) {
610 try {
611 mCallbacks.getBroadcastItem(i).onWallpaperChanged();
612 } catch (RemoteException e) {
613
614 // The RemoteCallbackList will take care of removing
615 // the dead object for us.
616 }
617 }
618 mCallbacks.finishBroadcast();
619 final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED);
620 mContext.sendBroadcast(intent);
621 }
622
623 private void checkPermission(String permission) {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700624 if (PackageManager.PERMISSION_GRANTED!= mContext.checkCallingOrSelfPermission(permission)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 throw new SecurityException("Access denied to process: " + Binder.getCallingPid()
626 + ", must have permission " + permission);
627 }
628 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700629
630 private static JournaledFile makeJournaledFile() {
631 final String base = "/data/system/wallpaper_info.xml";
632 return new JournaledFile(new File(base), new File(base + ".tmp"));
633 }
634
635 private void saveSettingsLocked() {
636 JournaledFile journal = makeJournaledFile();
637 FileOutputStream stream = null;
638 try {
639 stream = new FileOutputStream(journal.chooseForWrite(), false);
640 XmlSerializer out = new FastXmlSerializer();
641 out.setOutput(stream, "utf-8");
642 out.startDocument(null, true);
643
644 out.startTag(null, "wp");
645 out.attribute(null, "width", Integer.toString(mWidth));
646 out.attribute(null, "height", Integer.toString(mHeight));
647 out.attribute(null, "name", mName);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700648 if (mWallpaperComponent != null) {
649 out.attribute(null, "component",
650 mWallpaperComponent.flattenToShortString());
651 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700652 out.endTag(null, "wp");
653
654 out.endDocument();
655 stream.close();
656 journal.commit();
657 } catch (IOException e) {
658 try {
659 if (stream != null) {
660 stream.close();
661 }
662 } catch (IOException ex) {
663 // Ignore
664 }
665 journal.rollback();
666 }
667 }
668
669 private void loadSettingsLocked() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800670 if (DEBUG) Slog.v(TAG, "loadSettingsLocked");
Mike Clerona428b2c2009-11-15 22:53:08 -0800671
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700672 JournaledFile journal = makeJournaledFile();
673 FileInputStream stream = null;
674 File file = journal.chooseForRead();
675 boolean success = false;
676 try {
677 stream = new FileInputStream(file);
678 XmlPullParser parser = Xml.newPullParser();
679 parser.setInput(stream, null);
680
681 int type;
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700682 do {
683 type = parser.next();
684 if (type == XmlPullParser.START_TAG) {
685 String tag = parser.getName();
686 if ("wp".equals(tag)) {
687 mWidth = Integer.parseInt(parser.getAttributeValue(null, "width"));
688 mHeight = Integer.parseInt(parser.getAttributeValue(null, "height"));
689 mName = parser.getAttributeValue(null, "name");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700690 String comp = parser.getAttributeValue(null, "component");
Mike Clerona428b2c2009-11-15 22:53:08 -0800691 mNextWallpaperComponent = comp != null
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700692 ? ComponentName.unflattenFromString(comp)
693 : null;
Mike Clerona428b2c2009-11-15 22:53:08 -0800694
695 if (DEBUG) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800696 Slog.v(TAG, "mWidth:" + mWidth);
697 Slog.v(TAG, "mHeight:" + mHeight);
698 Slog.v(TAG, "mName:" + mName);
699 Slog.v(TAG, "mNextWallpaperComponent:" + mNextWallpaperComponent);
Mike Clerona428b2c2009-11-15 22:53:08 -0800700 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700701 }
702 }
703 } while (type != XmlPullParser.END_DOCUMENT);
704 success = true;
705 } catch (NullPointerException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800706 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700707 } catch (NumberFormatException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800708 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700709 } catch (XmlPullParserException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800710 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700711 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800712 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700713 } catch (IndexOutOfBoundsException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800714 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700715 }
716 try {
717 if (stream != null) {
718 stream.close();
719 }
720 } catch (IOException e) {
721 // Ignore
722 }
723
724 if (!success) {
725 mWidth = -1;
726 mHeight = -1;
727 mName = "";
728 }
729 }
730
Brad Fitzpatrick194b19a2010-09-14 11:30:29 -0700731 // Called by SystemBackupAgent after files are restored to disk.
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700732 void settingsRestored() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800733 if (DEBUG) Slog.v(TAG, "settingsRestored");
Brad Fitzpatrick194b19a2010-09-14 11:30:29 -0700734
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700735 boolean success = false;
736 synchronized (mLock) {
737 loadSettingsLocked();
Mike Clerona428b2c2009-11-15 22:53:08 -0800738 if (mNextWallpaperComponent != null &&
739 !mNextWallpaperComponent.equals(mImageWallpaperComponent)) {
Christopher Tatee3ab4d02009-12-16 14:03:31 -0800740 try {
741 bindWallpaperComponentLocked(mNextWallpaperComponent);
742 } catch (IllegalArgumentException e) {
743 // No such live wallpaper or other failure; fall back to the default
744 // live wallpaper (since the profile being restored indicated that the
745 // user had selected a live rather than static one).
746 bindWallpaperComponentLocked(null);
747 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700748 success = true;
749 } else {
Mike Clerona428b2c2009-11-15 22:53:08 -0800750 // If there's a wallpaper name, we use that. If that can't be loaded, then we
751 // use the default.
752 if ("".equals(mName)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800753 if (DEBUG) Slog.v(TAG, "settingsRestored: name is empty");
Mike Clerona428b2c2009-11-15 22:53:08 -0800754 success = true;
755 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800756 if (DEBUG) Slog.v(TAG, "settingsRestored: attempting to restore named resource");
Mike Clerona428b2c2009-11-15 22:53:08 -0800757 success = restoreNamedResourceLocked();
758 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800759 if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success);
Mike Clerona428b2c2009-11-15 22:53:08 -0800760 if (success) {
761 bindWallpaperComponentLocked(mImageWallpaperComponent);
762 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700763 }
764 }
765
766 if (!success) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800767 Slog.e(TAG, "Failed to restore wallpaper: '" + mName + "'");
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700768 mName = "";
769 WALLPAPER_FILE.delete();
770 }
Brad Fitzpatrick194b19a2010-09-14 11:30:29 -0700771
772 synchronized (mLock) {
773 saveSettingsLocked();
774 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700775 }
776
777 boolean restoreNamedResourceLocked() {
778 if (mName.length() > 4 && "res:".equals(mName.substring(0, 4))) {
779 String resName = mName.substring(4);
780
781 String pkg = null;
782 int colon = resName.indexOf(':');
783 if (colon > 0) {
784 pkg = resName.substring(0, colon);
785 }
786
787 String ident = null;
788 int slash = resName.lastIndexOf('/');
789 if (slash > 0) {
790 ident = resName.substring(slash+1);
791 }
792
793 String type = null;
794 if (colon > 0 && slash > 0 && (slash-colon) > 1) {
795 type = resName.substring(colon+1, slash);
796 }
797
798 if (pkg != null && ident != null && type != null) {
799 int resId = -1;
800 InputStream res = null;
801 FileOutputStream fos = null;
802 try {
803 Context c = mContext.createPackageContext(pkg, Context.CONTEXT_RESTRICTED);
804 Resources r = c.getResources();
805 resId = r.getIdentifier(resName, null, null);
806 if (resId == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800807 Slog.e(TAG, "couldn't resolve identifier pkg=" + pkg + " type=" + type
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700808 + " ident=" + ident);
809 return false;
810 }
811
812 res = r.openRawResource(resId);
Dianne Hackborn1afd1c92010-03-18 22:47:17 -0700813 if (WALLPAPER_FILE.exists()) {
814 WALLPAPER_FILE.delete();
815 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700816 fos = new FileOutputStream(WALLPAPER_FILE);
817
818 byte[] buffer = new byte[32768];
819 int amt;
820 while ((amt=res.read(buffer)) > 0) {
821 fos.write(buffer, 0, amt);
822 }
823 // mWallpaperObserver will notice the close and send the change broadcast
824
Joe Onorato8a9b2202010-02-26 18:56:32 -0800825 Slog.v(TAG, "Restored wallpaper: " + resName);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700826 return true;
827 } catch (NameNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800828 Slog.e(TAG, "Package name " + pkg + " not found");
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700829 } catch (Resources.NotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800830 Slog.e(TAG, "Resource not found: " + resId);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700831 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800832 Slog.e(TAG, "IOException while restoring wallpaper ", e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700833 } finally {
834 if (res != null) {
835 try {
836 res.close();
837 } catch (IOException ex) {}
838 }
839 if (fos != null) {
Dianne Hackborn8bdf5932010-10-15 12:54:40 -0700840 FileUtils.sync(fos);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700841 try {
842 fos.close();
843 } catch (IOException ex) {}
844 }
845 }
846 }
847 }
848 return false;
849 }
Dianne Hackborneb034652009-09-07 00:49:58 -0700850
851 @Override
852 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
853 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
854 != PackageManager.PERMISSION_GRANTED) {
855
856 pw.println("Permission Denial: can't dump wallpaper service from from pid="
857 + Binder.getCallingPid()
858 + ", uid=" + Binder.getCallingUid());
859 return;
860 }
861
862 synchronized (mLock) {
863 pw.println("Current Wallpaper Service state:");
864 pw.print(" mWidth="); pw.print(mWidth);
865 pw.print(" mHeight="); pw.println(mHeight);
866 pw.print(" mName="); pw.println(mName);
867 pw.print(" mWallpaperComponent="); pw.println(mWallpaperComponent);
868 if (mWallpaperConnection != null) {
869 WallpaperConnection conn = mWallpaperConnection;
870 pw.print(" Wallpaper connection ");
871 pw.print(conn); pw.println(":");
872 pw.print(" mInfo.component="); pw.println(conn.mInfo.getComponent());
873 pw.print(" mToken="); pw.println(conn.mToken);
874 pw.print(" mService="); pw.println(conn.mService);
875 pw.print(" mEngine="); pw.println(conn.mEngine);
876 pw.print(" mLastDiedTime=");
877 pw.println(mLastDiedTime - SystemClock.uptimeMillis());
878 }
879 }
880 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881}