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