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