blob: 643e937446c189571a577683de032467b1e6eed2 [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
Amith Yamasani4e2820c2012-08-28 22:17:23 -070022import android.app.AppGlobals;
Dianne Hackborn8cc6a502009-08-05 21:29:42 -070023import android.app.IWallpaperManager;
24import android.app.IWallpaperManagerCallback;
Dianne Hackborndd9b82c2009-09-03 00:18:47 -070025import android.app.PendingIntent;
Dianne Hackborneb034652009-09-07 00:49:58 -070026import android.app.WallpaperInfo;
Christopher Tate45281862010-03-05 15:46:30 -080027import android.app.backup.BackupManager;
Amith Yamasani37ce3a82012-02-06 12:04:42 -080028import android.app.backup.WallpaperBackupHelper;
Amith Yamasani13593602012-03-22 16:16:17 -070029import android.content.BroadcastReceiver;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070030import android.content.ComponentName;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.content.Context;
32import android.content.Intent;
Amith Yamasani13593602012-03-22 16:16:17 -070033import android.content.IntentFilter;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070034import android.content.ServiceConnection;
Amith Yamasani4e2820c2012-08-28 22:17:23 -070035import android.content.pm.IPackageManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.pm.PackageManager;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070037import android.content.pm.ResolveInfo;
38import android.content.pm.ServiceInfo;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070039import android.content.pm.PackageManager.NameNotFoundException;
40import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.os.Binder;
Dianne Hackborn284ac932009-08-28 10:34:25 -070042import android.os.Bundle;
Amith Yamasani13593602012-03-22 16:16:17 -070043import android.os.Environment;
Dianne Hackborn8bdf5932010-10-15 12:54:40 -070044import android.os.FileUtils;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070045import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.os.RemoteException;
47import android.os.FileObserver;
48import android.os.ParcelFileDescriptor;
49import android.os.RemoteCallbackList;
rpcraig554cb0c2012-07-05 06:41:43 -040050import android.os.SELinux;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070051import android.os.ServiceManager;
Dianne Hackborn0cd48872009-08-13 18:51:59 -070052import android.os.SystemClock;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070053import android.os.UserHandle;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070054import android.service.wallpaper.IWallpaperConnection;
55import android.service.wallpaper.IWallpaperEngine;
56import android.service.wallpaper.IWallpaperService;
57import android.service.wallpaper.WallpaperService;
Joe Onorato8a9b2202010-02-26 18:56:32 -080058import android.util.Slog;
Amith Yamasani37ce3a82012-02-06 12:04:42 -080059import android.util.SparseArray;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070060import android.util.Xml;
Dianne Hackborn44bc17c2011-04-20 18:18:51 -070061import android.view.Display;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070062import android.view.IWindowManager;
63import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
Dianne Hackborneb034652009-09-07 00:49:58 -070065import java.io.FileDescriptor;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070066import java.io.IOException;
67import java.io.InputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import java.io.File;
69import java.io.FileNotFoundException;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070070import java.io.FileInputStream;
71import java.io.FileOutputStream;
Dianne Hackborneb034652009-09-07 00:49:58 -070072import java.io.PrintWriter;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070073import java.util.List;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070074
75import org.xmlpull.v1.XmlPullParser;
76import org.xmlpull.v1.XmlPullParserException;
77import org.xmlpull.v1.XmlSerializer;
78
Dianne Hackborn21f1bd12010-02-19 17:02:21 -080079import com.android.internal.content.PackageMonitor;
Dianne Hackborn2269d1572010-02-24 19:54:22 -080080import com.android.internal.util.FastXmlSerializer;
Dianne Hackborn1afd1c92010-03-18 22:47:17 -070081import com.android.internal.util.JournaledFile;
Amith Yamasani37ce3a82012-02-06 12:04:42 -080082import com.android.server.am.ActivityManagerService;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
Dianne Hackborn8cc6a502009-08-05 21:29:42 -070084class WallpaperManagerService extends IWallpaperManager.Stub {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -070085 static final String TAG = "WallpaperService";
Dianne Hackborncbf15042009-08-18 18:29:09 -070086 static final boolean DEBUG = false;
Joe Onorato9bb8fd72009-07-28 18:24:51 -070087
Romain Guy407ec782011-08-24 17:06:58 -070088 final Object mLock = new Object[0];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089
Dianne Hackborn0cd48872009-08-13 18:51:59 -070090 /**
91 * Minimum time between crashes of a wallpaper service for us to consider
92 * restarting it vs. just reverting to the static wallpaper.
93 */
94 static final long MIN_WALLPAPER_CRASH_TIME = 10000;
95
Amith Yamasani37ce3a82012-02-06 12:04:42 -080096 static final File WALLPAPER_BASE_DIR = new File("/data/system/users");
Dianne Hackborn0cd48872009-08-13 18:51:59 -070097 static final String WALLPAPER = "wallpaper";
Amith Yamasani37ce3a82012-02-06 12:04:42 -080098 static final String WALLPAPER_INFO = "wallpaper_info.xml";
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 */
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800106 private class WallpaperObserver extends FileObserver {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700107
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800108 final WallpaperData mWallpaper;
109 final File mWallpaperDir;
110 final File mWallpaperFile;
111
112 public WallpaperObserver(WallpaperData wallpaper) {
113 super(getWallpaperDir(wallpaper.userId).getAbsolutePath(),
114 CLOSE_WRITE | DELETE | DELETE_SELF);
115 mWallpaperDir = getWallpaperDir(wallpaper.userId);
116 mWallpaper = wallpaper;
117 mWallpaperFile = new File(mWallpaperDir, WALLPAPER);
118 }
119
120 @Override
121 public void onEvent(int event, String path) {
122 if (path == null) {
123 return;
124 }
125 synchronized (mLock) {
126 // changing the wallpaper means we'll need to back up the new one
127 long origId = Binder.clearCallingIdentity();
128 BackupManager bm = new BackupManager(mContext);
129 bm.dataChanged();
130 Binder.restoreCallingIdentity(origId);
131
132 File changedFile = new File(mWallpaperDir, path);
133 if (mWallpaperFile.equals(changedFile)) {
134 notifyCallbacksLocked(mWallpaper);
135 if (mWallpaper.wallpaperComponent == null || event != CLOSE_WRITE
136 || mWallpaper.imageWallpaperPending) {
137 if (event == CLOSE_WRITE) {
138 mWallpaper.imageWallpaperPending = false;
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700139 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800140 bindWallpaperComponentLocked(mWallpaper.imageWallpaperComponent, true,
141 false, mWallpaper);
142 saveSettingsLocked(mWallpaper);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 }
144 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800145 }
146 }
147 }
148
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700149 final Context mContext;
150 final IWindowManager mIWindowManager;
Amith Yamasani4e2820c2012-08-28 22:17:23 -0700151 final IPackageManager mIPackageManager;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800152 final MyPackageMonitor mMonitor;
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800153 WallpaperData mLastWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800155 SparseArray<WallpaperData> mWallpaperMap = new SparseArray<WallpaperData>();
Dianne Hackborn07213e62011-08-24 20:05:39 -0700156
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800157 int mCurrentUserId;
Dianne Hackborn07213e62011-08-24 20:05:39 -0700158
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800159 static class WallpaperData {
160
161 int userId;
162
163 File wallpaperFile;
164
165 /**
166 * Client is currently writing a new image wallpaper.
167 */
168 boolean imageWallpaperPending;
169
170 /**
171 * Resource name if using a picture from the wallpaper gallery
172 */
173 String name = "";
174
175 /**
176 * The component name of the currently set live wallpaper.
177 */
178 ComponentName wallpaperComponent;
179
180 /**
181 * The component name of the wallpaper that should be set next.
182 */
183 ComponentName nextWallpaperComponent;
184
185 /**
186 * Name of the component used to display bitmap wallpapers from either the gallery or
187 * built-in wallpapers.
188 */
189 ComponentName imageWallpaperComponent = new ComponentName("com.android.systemui",
190 "com.android.systemui.ImageWallpaper");
191
192 WallpaperConnection connection;
193 long lastDiedTime;
194 boolean wallpaperUpdating;
195 WallpaperObserver wallpaperObserver;
196
197 /**
198 * List of callbacks registered they should each be notified when the wallpaper is changed.
199 */
200 private RemoteCallbackList<IWallpaperManagerCallback> callbacks
201 = new RemoteCallbackList<IWallpaperManagerCallback>();
202
203 int width = -1;
204 int height = -1;
205
206 WallpaperData(int userId) {
207 this.userId = userId;
208 wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER);
209 }
210 }
211
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700212 class WallpaperConnection extends IWallpaperConnection.Stub
213 implements ServiceConnection {
Dianne Hackborneb034652009-09-07 00:49:58 -0700214 final WallpaperInfo mInfo;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700215 final Binder mToken = new Binder();
216 IWallpaperService mService;
217 IWallpaperEngine mEngine;
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800218 WallpaperData mWallpaper;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800220 public WallpaperConnection(WallpaperInfo info, WallpaperData wallpaper) {
Dianne Hackborneb034652009-09-07 00:49:58 -0700221 mInfo = info;
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800222 mWallpaper = wallpaper;
Dianne Hackborneb034652009-09-07 00:49:58 -0700223 }
224
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700225 public void onServiceConnected(ComponentName name, IBinder service) {
226 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800227 if (mWallpaper.connection == this) {
228 mWallpaper.lastDiedTime = SystemClock.uptimeMillis();
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700229 mService = IWallpaperService.Stub.asInterface(service);
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800230 attachServiceLocked(this, mWallpaper);
Dianne Hackborneb034652009-09-07 00:49:58 -0700231 // XXX should probably do saveSettingsLocked() later
232 // when we have an engine, but I'm not sure about
233 // locking there and anyway we always need to be able to
234 // recover if there is something wrong.
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800235 saveSettingsLocked(mWallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700236 }
237 }
238 }
239
240 public void onServiceDisconnected(ComponentName name) {
241 synchronized (mLock) {
242 mService = null;
243 mEngine = null;
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800244 if (mWallpaper.connection == this) {
245 Slog.w(TAG, "Wallpaper service gone: " + mWallpaper.wallpaperComponent);
246 if (!mWallpaper.wallpaperUpdating
247 && (mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME)
248 > SystemClock.uptimeMillis()
249 && mWallpaper.userId == mCurrentUserId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800250 Slog.w(TAG, "Reverting to built-in wallpaper!");
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800251 clearWallpaperLocked(true, mWallpaper.userId);
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700252 }
253 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700254 }
255 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800256
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700257 public void attachEngine(IWallpaperEngine engine) {
258 mEngine = engine;
259 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800260
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700261 public ParcelFileDescriptor setWallpaper(String name) {
262 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800263 if (mWallpaper.connection == this) {
264 return updateWallpaperBitmapLocked(name, mWallpaper);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700265 }
266 return null;
267 }
268 }
269 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800270
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800271 class MyPackageMonitor extends PackageMonitor {
272 @Override
273 public void onPackageUpdateFinished(String packageName, int uid) {
274 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800275 for (int i = 0; i < mWallpaperMap.size(); i++) {
276 WallpaperData wallpaper = mWallpaperMap.valueAt(i);
277 if (wallpaper.wallpaperComponent != null
278 && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
279 wallpaper.wallpaperUpdating = false;
280 ComponentName comp = wallpaper.wallpaperComponent;
281 clearWallpaperComponentLocked(wallpaper);
282 // Do this only for the current user's wallpaper
283 if (wallpaper.userId == mCurrentUserId
284 && !bindWallpaperComponentLocked(comp, false, false, wallpaper)) {
285 Slog.w(TAG, "Wallpaper no longer available; reverting to default");
286 clearWallpaperLocked(false, wallpaper.userId);
287 }
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700288 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800289 }
290 }
291 }
292
293 @Override
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700294 public void onPackageModified(String packageName) {
295 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800296 for (int i = 0; i < mWallpaperMap.size(); i++) {
297 WallpaperData wallpaper = mWallpaperMap.valueAt(i);
298 if (wallpaper.wallpaperComponent == null
299 || !wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
300 continue;
301 }
Dianne Hackbornd0d75032012-04-19 23:12:09 -0700302 doPackagesChangedLocked(true, wallpaper);
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700303 }
304 }
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700305 }
306
307 @Override
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800308 public void onPackageUpdateStarted(String packageName, int uid) {
309 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800310 for (int i = 0; i < mWallpaperMap.size(); i++) {
311 WallpaperData wallpaper = mWallpaperMap.valueAt(i);
312 if (wallpaper.wallpaperComponent != null
313 && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
314 wallpaper.wallpaperUpdating = true;
315 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800316 }
317 }
318 }
319
320 @Override
321 public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
Dianne Hackbornd0d75032012-04-19 23:12:09 -0700322 synchronized (mLock) {
323 boolean changed = false;
324 for (int i = 0; i < mWallpaperMap.size(); i++) {
325 WallpaperData wallpaper = mWallpaperMap.valueAt(i);
326 boolean res = doPackagesChangedLocked(doit, wallpaper);
327 changed |= res;
328 }
329 return changed;
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800330 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800331 }
332
333 @Override
334 public void onSomePackagesChanged() {
Dianne Hackbornd0d75032012-04-19 23:12:09 -0700335 synchronized (mLock) {
336 for (int i = 0; i < mWallpaperMap.size(); i++) {
337 WallpaperData wallpaper = mWallpaperMap.valueAt(i);
338 doPackagesChangedLocked(true, wallpaper);
339 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800340 }
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800341 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800342
Dianne Hackbornd0d75032012-04-19 23:12:09 -0700343 boolean doPackagesChangedLocked(boolean doit, WallpaperData wallpaper) {
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800344 boolean changed = false;
Dianne Hackbornd0d75032012-04-19 23:12:09 -0700345 if (wallpaper.wallpaperComponent != null) {
346 int change = isPackageDisappearing(wallpaper.wallpaperComponent
347 .getPackageName());
348 if (change == PACKAGE_PERMANENT_CHANGE
349 || change == PACKAGE_TEMPORARY_CHANGE) {
350 changed = true;
351 if (doit) {
352 Slog.w(TAG, "Wallpaper uninstalled, removing: "
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800353 + wallpaper.wallpaperComponent);
354 clearWallpaperLocked(false, wallpaper.userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800355 }
356 }
Dianne Hackbornd0d75032012-04-19 23:12:09 -0700357 }
358 if (wallpaper.nextWallpaperComponent != null) {
359 int change = isPackageDisappearing(wallpaper.nextWallpaperComponent
360 .getPackageName());
361 if (change == PACKAGE_PERMANENT_CHANGE
362 || change == PACKAGE_TEMPORARY_CHANGE) {
363 wallpaper.nextWallpaperComponent = null;
364 }
365 }
366 if (wallpaper.wallpaperComponent != null
367 && isPackageModified(wallpaper.wallpaperComponent.getPackageName())) {
368 try {
369 mContext.getPackageManager().getServiceInfo(
370 wallpaper.wallpaperComponent, 0);
371 } catch (NameNotFoundException e) {
372 Slog.w(TAG, "Wallpaper component gone, removing: "
373 + wallpaper.wallpaperComponent);
374 clearWallpaperLocked(false, wallpaper.userId);
375 }
376 }
377 if (wallpaper.nextWallpaperComponent != null
378 && isPackageModified(wallpaper.nextWallpaperComponent.getPackageName())) {
379 try {
380 mContext.getPackageManager().getServiceInfo(
381 wallpaper.nextWallpaperComponent, 0);
382 } catch (NameNotFoundException e) {
383 wallpaper.nextWallpaperComponent = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800384 }
385 }
386 return changed;
387 }
388 }
389
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700390 public WallpaperManagerService(Context context) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800391 if (DEBUG) Slog.v(TAG, "WallpaperService startup");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 mContext = context;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700393 mIWindowManager = IWindowManager.Stub.asInterface(
394 ServiceManager.getService(Context.WINDOW_SERVICE));
Amith Yamasani4e2820c2012-08-28 22:17:23 -0700395 mIPackageManager = AppGlobals.getPackageManager();
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800396 mMonitor = new MyPackageMonitor();
Dianne Hackbornd0d75032012-04-19 23:12:09 -0700397 mMonitor.register(context, null, true);
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800398 WALLPAPER_BASE_DIR.mkdirs();
399 loadSettingsLocked(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 }
401
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800402 private static File getWallpaperDir(int userId) {
403 return new File(WALLPAPER_BASE_DIR + "/" + userId);
404 }
405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800406 @Override
407 protected void finalize() throws Throwable {
408 super.finalize();
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800409 for (int i = 0; i < mWallpaperMap.size(); i++) {
410 WallpaperData wallpaper = mWallpaperMap.valueAt(i);
411 wallpaper.wallpaperObserver.stopWatching();
412 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 }
Amith Yamasani13593602012-03-22 16:16:17 -0700414
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700415 public void systemReady() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800416 if (DEBUG) Slog.v(TAG, "systemReady");
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800417 WallpaperData wallpaper = mWallpaperMap.get(0);
418 switchWallpaper(wallpaper);
419 wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper);
420 wallpaper.wallpaperObserver.startWatching();
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800421
Amith Yamasani13593602012-03-22 16:16:17 -0700422 IntentFilter userFilter = new IntentFilter();
423 userFilter.addAction(Intent.ACTION_USER_SWITCHED);
424 userFilter.addAction(Intent.ACTION_USER_REMOVED);
425 mContext.registerReceiver(new BroadcastReceiver() {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800426 @Override
Amith Yamasani13593602012-03-22 16:16:17 -0700427 public void onReceive(Context context, Intent intent) {
428 String action = intent.getAction();
429 if (Intent.ACTION_USER_SWITCHED.equals(action)) {
Amith Yamasani2a003292012-08-14 18:25:45 -0700430 switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
Amith Yamasani13593602012-03-22 16:16:17 -0700431 } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
Amith Yamasani2a003292012-08-14 18:25:45 -0700432 removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
Amith Yamasani13593602012-03-22 16:16:17 -0700433 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800434 }
Amith Yamasani13593602012-03-22 16:16:17 -0700435 }, userFilter);
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800436 }
437
438 String getName() {
439 return mWallpaperMap.get(0).name;
440 }
441
Amith Yamasani13593602012-03-22 16:16:17 -0700442 void removeUser(int userId) {
443 synchronized (mLock) {
444 WallpaperData wallpaper = mWallpaperMap.get(userId);
445 if (wallpaper != null) {
446 wallpaper.wallpaperObserver.stopWatching();
447 mWallpaperMap.remove(userId);
448 }
449 File wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER);
450 wallpaperFile.delete();
451 File wallpaperInfoFile = new File(getWallpaperDir(userId), WALLPAPER_INFO);
452 wallpaperInfoFile.delete();
453 }
454 }
455
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800456 void switchUser(int userId) {
457 synchronized (mLock) {
458 mCurrentUserId = userId;
459 WallpaperData wallpaper = mWallpaperMap.get(userId);
460 if (wallpaper == null) {
461 wallpaper = new WallpaperData(userId);
462 mWallpaperMap.put(userId, wallpaper);
463 loadSettingsLocked(userId);
464 wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper);
465 wallpaper.wallpaperObserver.startWatching();
466 }
467 switchWallpaper(wallpaper);
468 }
469 }
470
471 void switchWallpaper(WallpaperData wallpaper) {
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700472 synchronized (mLock) {
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700473 RuntimeException e = null;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700474 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800475 ComponentName cname = wallpaper.wallpaperComponent != null ?
476 wallpaper.wallpaperComponent : wallpaper.nextWallpaperComponent;
477 if (bindWallpaperComponentLocked(cname, true, false, wallpaper)) {
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700478 return;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700479 }
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700480 } catch (RuntimeException e1) {
481 e = e1;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700482 }
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700483 Slog.w(TAG, "Failure starting previous wallpaper", e);
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800484 clearWallpaperLocked(false, wallpaper.userId);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800485 }
486 }
487
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800488 public void clearWallpaper() {
489 if (DEBUG) Slog.v(TAG, "clearWallpaper");
490 synchronized (mLock) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700491 clearWallpaperLocked(false, UserHandle.getCallingUserId());
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800492 }
493 }
494
495 void clearWallpaperLocked(boolean defaultFailed, int userId) {
496 WallpaperData wallpaper = mWallpaperMap.get(userId);
497 File f = new File(getWallpaperDir(userId), WALLPAPER);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800498 if (f.exists()) {
499 f.delete();
500 }
501 final long ident = Binder.clearCallingIdentity();
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700502 RuntimeException e = null;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800503 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800504 wallpaper.imageWallpaperPending = false;
505 if (userId != mCurrentUserId) return;
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700506 if (bindWallpaperComponentLocked(defaultFailed
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800507 ? wallpaper.imageWallpaperComponent
508 : null, true, false, wallpaper)) {
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700509 return;
510 }
511 } catch (IllegalArgumentException e1) {
512 e = e1;
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800513 } finally {
514 Binder.restoreCallingIdentity(ident);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 }
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700516
517 // This can happen if the default wallpaper component doesn't
518 // exist. This should be a system configuration problem, but
519 // let's not let it crash the system and just live with no
520 // wallpaper.
521 Slog.e(TAG, "Default wallpaper component not found!", e);
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800522 clearWallpaperComponentLocked(wallpaper);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 }
524
525 public void setDimensionHints(int width, int height) throws RemoteException {
526 checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS);
527
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700528 int userId = UserHandle.getCallingUserId();
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800529 WallpaperData wallpaper = mWallpaperMap.get(userId);
530 if (wallpaper == null) {
531 throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 if (width <= 0 || height <= 0) {
534 throw new IllegalArgumentException("width and height must be > 0");
535 }
536
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700537 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800538 if (width != wallpaper.width || height != wallpaper.height) {
539 wallpaper.width = width;
540 wallpaper.height = height;
541 saveSettingsLocked(wallpaper);
542 if (mCurrentUserId != userId) return; // Don't change the properties now
543 if (wallpaper.connection != null) {
544 if (wallpaper.connection.mEngine != null) {
Dianne Hackborn284ac932009-08-28 10:34:25 -0700545 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800546 wallpaper.connection.mEngine.setDesiredSize(
Dianne Hackborn284ac932009-08-28 10:34:25 -0700547 width, height);
548 } catch (RemoteException e) {
549 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800550 notifyCallbacksLocked(wallpaper);
Dianne Hackborn284ac932009-08-28 10:34:25 -0700551 }
552 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 }
555 }
556
557 public int getWidthHint() throws RemoteException {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700558 synchronized (mLock) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700559 WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800560 return wallpaper.width;
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700561 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 }
563
564 public int getHeightHint() throws RemoteException {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700565 synchronized (mLock) {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700566 WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800567 return wallpaper.height;
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700568 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 }
570
Dianne Hackborn284ac932009-08-28 10:34:25 -0700571 public ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
572 Bundle outParams) {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700573 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800574 // This returns the current user's wallpaper, if called by a system service. Else it
575 // returns the wallpaper for the calling user.
576 int callingUid = Binder.getCallingUid();
577 int wallpaperUserId = 0;
578 if (callingUid == android.os.Process.SYSTEM_UID) {
579 wallpaperUserId = mCurrentUserId;
580 } else {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700581 wallpaperUserId = UserHandle.getUserId(callingUid);
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800582 }
583 WallpaperData wallpaper = mWallpaperMap.get(wallpaperUserId);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700584 try {
Dianne Hackborn284ac932009-08-28 10:34:25 -0700585 if (outParams != null) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800586 outParams.putInt("width", wallpaper.width);
587 outParams.putInt("height", wallpaper.height);
Dianne Hackborn284ac932009-08-28 10:34:25 -0700588 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800589 wallpaper.callbacks.register(cb);
590 File f = new File(getWallpaperDir(wallpaperUserId), WALLPAPER);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700591 if (!f.exists()) {
592 return null;
593 }
594 return ParcelFileDescriptor.open(f, MODE_READ_ONLY);
595 } catch (FileNotFoundException e) {
596 /* Shouldn't happen as we check to see if the file exists */
Joe Onorato8a9b2202010-02-26 18:56:32 -0800597 Slog.w(TAG, "Error getting wallpaper", e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700599 return null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 }
602
Dianne Hackborneb034652009-09-07 00:49:58 -0700603 public WallpaperInfo getWallpaperInfo() {
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700604 int userId = UserHandle.getCallingUserId();
Dianne Hackborneb034652009-09-07 00:49:58 -0700605 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800606 WallpaperData wallpaper = mWallpaperMap.get(userId);
607 if (wallpaper.connection != null) {
608 return wallpaper.connection.mInfo;
Dianne Hackborneb034652009-09-07 00:49:58 -0700609 }
610 return null;
611 }
612 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800613
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700614 public ParcelFileDescriptor setWallpaper(String name) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800615 if (DEBUG) Slog.v(TAG, "setWallpaper");
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700616 int userId = UserHandle.getCallingUserId();
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800617 WallpaperData wallpaper = mWallpaperMap.get(userId);
618 if (wallpaper == null) {
619 throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
620 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 checkPermission(android.Manifest.permission.SET_WALLPAPER);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700622 synchronized (mLock) {
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700623 final long ident = Binder.clearCallingIdentity();
624 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800625 ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name, wallpaper);
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700626 if (pfd != null) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800627 wallpaper.imageWallpaperPending = true;
Dianne Hackborn0cd48872009-08-13 18:51:59 -0700628 }
629 return pfd;
630 } finally {
631 Binder.restoreCallingIdentity(ident);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700632 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 }
634 }
635
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800636 ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700637 if (name == null) name = "";
638 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800639 File dir = getWallpaperDir(wallpaper.userId);
640 if (!dir.exists()) {
641 dir.mkdir();
Dianne Hackbornebac48c2011-11-29 18:01:50 -0800642 FileUtils.setPermissions(
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800643 dir.getPath(),
Dianne Hackbornebac48c2011-11-29 18:01:50 -0800644 FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
645 -1, -1);
646 }
rpcraig554cb0c2012-07-05 06:41:43 -0400647 File file = new File(dir, WALLPAPER);
648 ParcelFileDescriptor fd = ParcelFileDescriptor.open(file,
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700649 MODE_CREATE|MODE_READ_WRITE);
rpcraig554cb0c2012-07-05 06:41:43 -0400650 if (!SELinux.restorecon(file)) {
651 return null;
652 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800653 wallpaper.name = name;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700654 return fd;
655 } catch (FileNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800656 Slog.w(TAG, "Error setting wallpaper", e);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700657 }
658 return null;
659 }
660
661 public void setWallpaperComponent(ComponentName name) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800662 if (DEBUG) Slog.v(TAG, "setWallpaperComponent name=" + name);
Dianne Hackbornf02b60a2012-08-16 10:48:27 -0700663 int userId = UserHandle.getCallingUserId();
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800664 WallpaperData wallpaper = mWallpaperMap.get(userId);
665 if (wallpaper == null) {
666 throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
667 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700668 checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
669 synchronized (mLock) {
670 final long ident = Binder.clearCallingIdentity();
671 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800672 wallpaper.imageWallpaperPending = false;
673 bindWallpaperComponentLocked(name, false, true, wallpaper);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700674 } finally {
675 Binder.restoreCallingIdentity(ident);
676 }
677 }
678 }
679
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800680 boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force,
681 boolean fromUser, WallpaperData wallpaper) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800682 if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700683 // Has the component changed?
Dianne Hackborn9ea31632011-08-05 14:43:50 -0700684 if (!force) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800685 if (wallpaper.connection != null) {
686 if (wallpaper.wallpaperComponent == null) {
Dianne Hackborn9ea31632011-08-05 14:43:50 -0700687 if (componentName == null) {
688 if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: still using default");
689 // Still using default wallpaper.
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700690 return true;
Dianne Hackborn9ea31632011-08-05 14:43:50 -0700691 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800692 } else if (wallpaper.wallpaperComponent.equals(componentName)) {
Dianne Hackborn9ea31632011-08-05 14:43:50 -0700693 // Changing to same wallpaper.
694 if (DEBUG) Slog.v(TAG, "same wallpaper");
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700695 return true;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700696 }
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700697 }
698 }
699
700 try {
Mike Clerona428b2c2009-11-15 22:53:08 -0800701 if (componentName == null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800702 String defaultComponent =
703 mContext.getString(com.android.internal.R.string.default_wallpaper_component);
Mike Clerona428b2c2009-11-15 22:53:08 -0800704 if (defaultComponent != null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800705 // See if there is a default wallpaper component specified
Mike Clerona428b2c2009-11-15 22:53:08 -0800706 componentName = ComponentName.unflattenFromString(defaultComponent);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800707 if (DEBUG) Slog.v(TAG, "Use default component wallpaper:" + componentName);
Mike Cleron322b6ee2009-11-12 07:45:47 -0800708 }
Mike Clerona428b2c2009-11-15 22:53:08 -0800709 if (componentName == null) {
Mike Cleron322b6ee2009-11-12 07:45:47 -0800710 // Fall back to static image wallpaper
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800711 componentName = wallpaper.imageWallpaperComponent;
Mike Cleron322b6ee2009-11-12 07:45:47 -0800712 //clearWallpaperComponentLocked();
713 //return;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800714 if (DEBUG) Slog.v(TAG, "Using image wallpaper");
Mike Cleron322b6ee2009-11-12 07:45:47 -0800715 }
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700716 }
Amith Yamasani4e2820c2012-08-28 22:17:23 -0700717 int serviceUserId = wallpaper.userId;
718 ServiceInfo si = mIPackageManager.getServiceInfo(componentName,
719 PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS, serviceUserId);
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700720 if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700721 String msg = "Selected service does not require "
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700722 + android.Manifest.permission.BIND_WALLPAPER
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700723 + ": " + componentName;
724 if (fromUser) {
725 throw new SecurityException(msg);
726 }
727 Slog.w(TAG, msg);
728 return false;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700729 }
730
Dianne Hackborneb034652009-09-07 00:49:58 -0700731 WallpaperInfo wi = null;
732
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700733 Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800734 if (componentName != null && !componentName.equals(wallpaper.imageWallpaperComponent)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700735 // Make sure the selected service is actually a wallpaper service.
Amith Yamasani4e2820c2012-08-28 22:17:23 -0700736 List<ResolveInfo> ris =
737 mIPackageManager.queryIntentServices(intent,
738 intent.resolveTypeIfNeeded(mContext.getContentResolver()),
739 PackageManager.GET_META_DATA, serviceUserId);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700740 for (int i=0; i<ris.size(); i++) {
741 ServiceInfo rsi = ris.get(i).serviceInfo;
742 if (rsi.name.equals(si.name) &&
743 rsi.packageName.equals(si.packageName)) {
Dianne Hackborneb034652009-09-07 00:49:58 -0700744 try {
745 wi = new WallpaperInfo(mContext, ris.get(i));
746 } catch (XmlPullParserException e) {
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700747 if (fromUser) {
748 throw new IllegalArgumentException(e);
749 }
750 Slog.w(TAG, e);
751 return false;
Dianne Hackborneb034652009-09-07 00:49:58 -0700752 } catch (IOException e) {
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700753 if (fromUser) {
754 throw new IllegalArgumentException(e);
755 }
756 Slog.w(TAG, e);
757 return false;
Dianne Hackborneb034652009-09-07 00:49:58 -0700758 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700759 break;
760 }
761 }
Dianne Hackborneb034652009-09-07 00:49:58 -0700762 if (wi == null) {
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700763 String msg = "Selected service is not a wallpaper: "
764 + componentName;
765 if (fromUser) {
766 throw new SecurityException(msg);
767 }
768 Slog.w(TAG, msg);
769 return false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700770 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700771 }
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700772
773 // Bind the service!
Joe Onorato8a9b2202010-02-26 18:56:32 -0800774 if (DEBUG) Slog.v(TAG, "Binding to:" + componentName);
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800775 WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper);
Mike Clerona428b2c2009-11-15 22:53:08 -0800776 intent.setComponent(componentName);
Dianne Hackborndd9b82c2009-09-03 00:18:47 -0700777 intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
778 com.android.internal.R.string.wallpaper_binding_label);
779 intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
Dianne Hackborneb034652009-09-07 00:49:58 -0700780 mContext, 0,
781 Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
782 mContext.getText(com.android.internal.R.string.chooser_wallpaper)),
783 0));
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800784 if (!mContext.bindService(intent, newConn, Context.BIND_AUTO_CREATE, serviceUserId)) {
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700785 String msg = "Unable to bind service: "
786 + componentName;
787 if (fromUser) {
788 throw new IllegalArgumentException(msg);
789 }
790 Slog.w(TAG, msg);
791 return false;
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700792 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800793 if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) {
794 detachWallpaperLocked(mLastWallpaper);
795 }
796 wallpaper.wallpaperComponent = componentName;
797 wallpaper.connection = newConn;
798 wallpaper.lastDiedTime = SystemClock.uptimeMillis();
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700799 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800800 if (wallpaper.userId == mCurrentUserId) {
801 if (DEBUG)
802 Slog.v(TAG, "Adding window token: " + newConn.mToken);
803 mIWindowManager.addWindowToken(newConn.mToken,
804 WindowManager.LayoutParams.TYPE_WALLPAPER);
805 mLastWallpaper = wallpaper;
806 }
Dianne Hackbornf21adf62009-08-13 10:20:21 -0700807 } catch (RemoteException e) {
808 }
Amith Yamasani4e2820c2012-08-28 22:17:23 -0700809 } catch (RemoteException e) {
810 String msg = "Remote exception for " + componentName + "\n" + e;
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700811 if (fromUser) {
812 throw new IllegalArgumentException(msg);
813 }
814 Slog.w(TAG, msg);
815 return false;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700816 }
Dianne Hackborn80b902f2011-09-15 15:15:27 -0700817 return true;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700818 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800819
820 void detachWallpaperLocked(WallpaperData wallpaper) {
821 if (wallpaper.connection != null) {
822 if (wallpaper.connection.mEngine != null) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700823 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800824 wallpaper.connection.mEngine.destroy();
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700825 } catch (RemoteException e) {
826 }
827 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800828 mContext.unbindService(wallpaper.connection);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -0700829 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800830 if (DEBUG)
831 Slog.v(TAG, "Removing window token: " + wallpaper.connection.mToken);
832 mIWindowManager.removeWindowToken(wallpaper.connection.mToken);
Dianne Hackborne9e9bca2009-08-18 15:08:22 -0700833 } catch (RemoteException e) {
834 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800835 wallpaper.connection.mService = null;
836 wallpaper.connection.mEngine = null;
837 wallpaper.connection = null;
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700838 }
839 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800840
841 void clearWallpaperComponentLocked(WallpaperData wallpaper) {
842 wallpaper.wallpaperComponent = null;
843 detachWallpaperLocked(wallpaper);
844 }
845
846 void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700847 try {
Dianne Hackborn3be63c02009-08-20 19:31:38 -0700848 conn.mService.attach(conn, conn.mToken,
849 WindowManager.LayoutParams.TYPE_WALLPAPER, false,
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800850 wallpaper.width, wallpaper.height);
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700851 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800852 Slog.w(TAG, "Failed attaching wallpaper; clearing", e);
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800853 if (!wallpaper.wallpaperUpdating) {
854 bindWallpaperComponentLocked(null, false, false, wallpaper);
Dianne Hackborn21f1bd12010-02-19 17:02:21 -0800855 }
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700856 }
857 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800858
859 private void notifyCallbacksLocked(WallpaperData wallpaper) {
860 final int n = wallpaper.callbacks.beginBroadcast();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 for (int i = 0; i < n; i++) {
862 try {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800863 wallpaper.callbacks.getBroadcastItem(i).onWallpaperChanged();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 } catch (RemoteException e) {
865
866 // The RemoteCallbackList will take care of removing
867 // the dead object for us.
868 }
869 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800870 wallpaper.callbacks.finishBroadcast();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -0700872 mContext.sendBroadcastAsUser(intent, new UserHandle(mCurrentUserId));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800873 }
874
875 private void checkPermission(String permission) {
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700876 if (PackageManager.PERMISSION_GRANTED!= mContext.checkCallingOrSelfPermission(permission)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 throw new SecurityException("Access denied to process: " + Binder.getCallingPid()
878 + ", must have permission " + permission);
879 }
880 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700881
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800882 private static JournaledFile makeJournaledFile(int userId) {
Amith Yamasani13593602012-03-22 16:16:17 -0700883 final String base = getWallpaperDir(userId) + "/" + WALLPAPER_INFO;
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700884 return new JournaledFile(new File(base), new File(base + ".tmp"));
885 }
886
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800887 private void saveSettingsLocked(WallpaperData wallpaper) {
888 JournaledFile journal = makeJournaledFile(wallpaper.userId);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700889 FileOutputStream stream = null;
890 try {
891 stream = new FileOutputStream(journal.chooseForWrite(), false);
892 XmlSerializer out = new FastXmlSerializer();
893 out.setOutput(stream, "utf-8");
894 out.startDocument(null, true);
895
896 out.startTag(null, "wp");
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800897 out.attribute(null, "width", Integer.toString(wallpaper.width));
898 out.attribute(null, "height", Integer.toString(wallpaper.height));
899 out.attribute(null, "name", wallpaper.name);
900 if (wallpaper.wallpaperComponent != null
901 && !wallpaper.wallpaperComponent.equals(wallpaper.imageWallpaperComponent)) {
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700902 out.attribute(null, "component",
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800903 wallpaper.wallpaperComponent.flattenToShortString());
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700904 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700905 out.endTag(null, "wp");
906
907 out.endDocument();
908 stream.close();
909 journal.commit();
910 } catch (IOException e) {
911 try {
912 if (stream != null) {
913 stream.close();
914 }
915 } catch (IOException ex) {
916 // Ignore
917 }
918 journal.rollback();
919 }
920 }
921
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800922 private void migrateFromOld() {
923 File oldWallpaper = new File(WallpaperBackupHelper.WALLPAPER_IMAGE_KEY);
924 File oldInfo = new File(WallpaperBackupHelper.WALLPAPER_INFO_KEY);
925 if (oldWallpaper.exists()) {
926 File newWallpaper = new File(getWallpaperDir(0), WALLPAPER);
927 oldWallpaper.renameTo(newWallpaper);
928 }
929 if (oldInfo.exists()) {
930 File newInfo = new File(getWallpaperDir(0), WALLPAPER_INFO);
931 oldInfo.renameTo(newInfo);
932 }
933 }
934
935 private void loadSettingsLocked(int userId) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800936 if (DEBUG) Slog.v(TAG, "loadSettingsLocked");
Mike Clerona428b2c2009-11-15 22:53:08 -0800937
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800938 JournaledFile journal = makeJournaledFile(userId);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700939 FileInputStream stream = null;
940 File file = journal.chooseForRead();
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800941 if (!file.exists()) {
942 // This should only happen one time, when upgrading from a legacy system
943 migrateFromOld();
944 }
945 WallpaperData wallpaper = mWallpaperMap.get(userId);
946 if (wallpaper == null) {
947 wallpaper = new WallpaperData(userId);
948 mWallpaperMap.put(userId, wallpaper);
949 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700950 boolean success = false;
951 try {
952 stream = new FileInputStream(file);
953 XmlPullParser parser = Xml.newPullParser();
954 parser.setInput(stream, null);
955
956 int type;
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700957 do {
958 type = parser.next();
959 if (type == XmlPullParser.START_TAG) {
960 String tag = parser.getName();
961 if ("wp".equals(tag)) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800962 wallpaper.width = Integer.parseInt(parser.getAttributeValue(null, "width"));
963 wallpaper.height = Integer.parseInt(parser
964 .getAttributeValue(null, "height"));
965 wallpaper.name = parser.getAttributeValue(null, "name");
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700966 String comp = parser.getAttributeValue(null, "component");
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800967 wallpaper.nextWallpaperComponent = comp != null
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700968 ? ComponentName.unflattenFromString(comp)
969 : null;
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800970 if (wallpaper.nextWallpaperComponent == null
971 || "android".equals(wallpaper.nextWallpaperComponent
972 .getPackageName())) {
973 wallpaper.nextWallpaperComponent = wallpaper.imageWallpaperComponent;
Dianne Hackborn9ea31632011-08-05 14:43:50 -0700974 }
Mike Clerona428b2c2009-11-15 22:53:08 -0800975
976 if (DEBUG) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -0800977 Slog.v(TAG, "mWidth:" + wallpaper.width);
978 Slog.v(TAG, "mHeight:" + wallpaper.height);
979 Slog.v(TAG, "mName:" + wallpaper.name);
980 Slog.v(TAG, "mNextWallpaperComponent:"
981 + wallpaper.nextWallpaperComponent);
Mike Clerona428b2c2009-11-15 22:53:08 -0800982 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700983 }
984 }
985 } while (type != XmlPullParser.END_DOCUMENT);
986 success = true;
987 } catch (NullPointerException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800988 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700989 } catch (NumberFormatException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800990 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700991 } catch (XmlPullParserException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800992 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700993 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800994 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700995 } catch (IndexOutOfBoundsException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800996 Slog.w(TAG, "failed parsing " + file + " " + e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -0700997 }
998 try {
999 if (stream != null) {
1000 stream.close();
1001 }
1002 } catch (IOException e) {
1003 // Ignore
1004 }
1005
1006 if (!success) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001007 wallpaper.width = -1;
1008 wallpaper.height = -1;
1009 wallpaper.name = "";
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001010 }
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07001011
1012 // We always want to have some reasonable width hint.
1013 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
1014 Display d = wm.getDefaultDisplay();
1015 int baseSize = d.getMaximumSizeDimension();
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001016 if (wallpaper.width < baseSize) {
1017 wallpaper.width = baseSize;
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07001018 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001019 if (wallpaper.height < baseSize) {
1020 wallpaper.height = baseSize;
Dianne Hackborn44bc17c2011-04-20 18:18:51 -07001021 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001022 }
1023
Brad Fitzpatrick194b19a2010-09-14 11:30:29 -07001024 // Called by SystemBackupAgent after files are restored to disk.
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001025 void settingsRestored() {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001026 // TODO: If necessary, make it work for secondary users as well. This currently assumes
1027 // restores only to the primary user
Joe Onorato8a9b2202010-02-26 18:56:32 -08001028 if (DEBUG) Slog.v(TAG, "settingsRestored");
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001029 WallpaperData wallpaper = null;
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001030 boolean success = false;
1031 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001032 loadSettingsLocked(0);
1033 wallpaper = mWallpaperMap.get(0);
1034 if (wallpaper.nextWallpaperComponent != null
1035 && !wallpaper.nextWallpaperComponent.equals(wallpaper.imageWallpaperComponent)) {
1036 if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
1037 wallpaper)) {
Christopher Tatee3ab4d02009-12-16 14:03:31 -08001038 // No such live wallpaper or other failure; fall back to the default
1039 // live wallpaper (since the profile being restored indicated that the
1040 // user had selected a live rather than static one).
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001041 bindWallpaperComponentLocked(null, false, false, wallpaper);
Christopher Tatee3ab4d02009-12-16 14:03:31 -08001042 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001043 success = true;
1044 } else {
Mike Clerona428b2c2009-11-15 22:53:08 -08001045 // If there's a wallpaper name, we use that. If that can't be loaded, then we
1046 // use the default.
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001047 if ("".equals(wallpaper.name)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001048 if (DEBUG) Slog.v(TAG, "settingsRestored: name is empty");
Mike Clerona428b2c2009-11-15 22:53:08 -08001049 success = true;
1050 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001051 if (DEBUG) Slog.v(TAG, "settingsRestored: attempting to restore named resource");
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001052 success = restoreNamedResourceLocked(wallpaper);
Mike Clerona428b2c2009-11-15 22:53:08 -08001053 }
Joe Onorato8a9b2202010-02-26 18:56:32 -08001054 if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success);
Mike Clerona428b2c2009-11-15 22:53:08 -08001055 if (success) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001056 bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
1057 wallpaper);
Mike Clerona428b2c2009-11-15 22:53:08 -08001058 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001059 }
1060 }
1061
1062 if (!success) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001063 Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'");
1064 wallpaper.name = "";
1065 getWallpaperDir(0).delete();
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001066 }
Brad Fitzpatrick194b19a2010-09-14 11:30:29 -07001067
1068 synchronized (mLock) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001069 saveSettingsLocked(wallpaper);
Brad Fitzpatrick194b19a2010-09-14 11:30:29 -07001070 }
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001071 }
1072
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001073 boolean restoreNamedResourceLocked(WallpaperData wallpaper) {
1074 if (wallpaper.name.length() > 4 && "res:".equals(wallpaper.name.substring(0, 4))) {
1075 String resName = wallpaper.name.substring(4);
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001076
1077 String pkg = null;
1078 int colon = resName.indexOf(':');
1079 if (colon > 0) {
1080 pkg = resName.substring(0, colon);
1081 }
1082
1083 String ident = null;
1084 int slash = resName.lastIndexOf('/');
1085 if (slash > 0) {
1086 ident = resName.substring(slash+1);
1087 }
1088
1089 String type = null;
1090 if (colon > 0 && slash > 0 && (slash-colon) > 1) {
1091 type = resName.substring(colon+1, slash);
1092 }
1093
1094 if (pkg != null && ident != null && type != null) {
1095 int resId = -1;
1096 InputStream res = null;
1097 FileOutputStream fos = null;
1098 try {
1099 Context c = mContext.createPackageContext(pkg, Context.CONTEXT_RESTRICTED);
1100 Resources r = c.getResources();
1101 resId = r.getIdentifier(resName, null, null);
1102 if (resId == 0) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001103 Slog.e(TAG, "couldn't resolve identifier pkg=" + pkg + " type=" + type
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001104 + " ident=" + ident);
1105 return false;
1106 }
1107
1108 res = r.openRawResource(resId);
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001109 if (wallpaper.wallpaperFile.exists()) {
1110 wallpaper.wallpaperFile.delete();
Dianne Hackborn1afd1c92010-03-18 22:47:17 -07001111 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001112 fos = new FileOutputStream(wallpaper.wallpaperFile);
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001113
1114 byte[] buffer = new byte[32768];
1115 int amt;
1116 while ((amt=res.read(buffer)) > 0) {
1117 fos.write(buffer, 0, amt);
1118 }
1119 // mWallpaperObserver will notice the close and send the change broadcast
1120
Joe Onorato8a9b2202010-02-26 18:56:32 -08001121 Slog.v(TAG, "Restored wallpaper: " + resName);
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001122 return true;
1123 } catch (NameNotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001124 Slog.e(TAG, "Package name " + pkg + " not found");
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001125 } catch (Resources.NotFoundException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001126 Slog.e(TAG, "Resource not found: " + resId);
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001127 } catch (IOException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -08001128 Slog.e(TAG, "IOException while restoring wallpaper ", e);
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001129 } finally {
1130 if (res != null) {
1131 try {
1132 res.close();
1133 } catch (IOException ex) {}
1134 }
1135 if (fos != null) {
Dianne Hackborn8bdf5932010-10-15 12:54:40 -07001136 FileUtils.sync(fos);
Joe Onorato9bb8fd72009-07-28 18:24:51 -07001137 try {
1138 fos.close();
1139 } catch (IOException ex) {}
1140 }
1141 }
1142 }
1143 }
1144 return false;
1145 }
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001146
Dianne Hackborneb034652009-09-07 00:49:58 -07001147 @Override
1148 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1149 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
1150 != PackageManager.PERMISSION_GRANTED) {
1151
1152 pw.println("Permission Denial: can't dump wallpaper service from from pid="
1153 + Binder.getCallingPid()
1154 + ", uid=" + Binder.getCallingUid());
1155 return;
1156 }
1157
1158 synchronized (mLock) {
1159 pw.println("Current Wallpaper Service state:");
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001160 for (int i = 0; i < mWallpaperMap.size(); i++) {
1161 WallpaperData wallpaper = mWallpaperMap.valueAt(i);
1162 pw.println(" User " + wallpaper.userId + ":");
1163 pw.print(" mWidth=");
1164 pw.print(wallpaper.width);
1165 pw.print(" mHeight=");
1166 pw.println(wallpaper.height);
1167 pw.print(" mName=");
1168 pw.println(wallpaper.name);
1169 pw.print(" mWallpaperComponent=");
1170 pw.println(wallpaper.wallpaperComponent);
1171 if (wallpaper.connection != null) {
1172 WallpaperConnection conn = wallpaper.connection;
1173 pw.print(" Wallpaper connection ");
1174 pw.print(conn);
1175 pw.println(":");
1176 if (conn.mInfo != null) {
1177 pw.print(" mInfo.component=");
1178 pw.println(conn.mInfo.getComponent());
1179 }
1180 pw.print(" mToken=");
1181 pw.println(conn.mToken);
1182 pw.print(" mService=");
1183 pw.println(conn.mService);
1184 pw.print(" mEngine=");
1185 pw.println(conn.mEngine);
1186 pw.print(" mLastDiedTime=");
1187 pw.println(wallpaper.lastDiedTime - SystemClock.uptimeMillis());
1188 }
Dianne Hackborneb034652009-09-07 00:49:58 -07001189 }
1190 }
1191 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192}