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 | |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 19 | import static android.app.WallpaperManager.FLAG_LOCK; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 20 | import static android.app.WallpaperManager.FLAG_SYSTEM; |
| 21 | import static android.os.ParcelFileDescriptor.MODE_CREATE; |
| 22 | import static android.os.ParcelFileDescriptor.MODE_READ_ONLY; |
| 23 | import static android.os.ParcelFileDescriptor.MODE_READ_WRITE; |
| 24 | import static android.os.ParcelFileDescriptor.MODE_TRUNCATE; |
Christopher Tate | 111bd4a | 2009-06-24 17:29:38 -0700 | [diff] [blame] | 25 | |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 26 | import android.app.ActivityManager; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 27 | import android.app.ActivityManagerNative; |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 28 | import android.app.AppGlobals; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 29 | import android.app.AppOpsManager; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 30 | import android.app.IUserSwitchObserver; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 31 | import android.app.IWallpaperManager; |
| 32 | import android.app.IWallpaperManagerCallback; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 33 | import android.app.PendingIntent; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 34 | import android.app.WallpaperInfo; |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 35 | import android.app.WallpaperManager; |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 36 | import android.app.admin.DevicePolicyManager; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 37 | import android.app.backup.WallpaperBackupHelper; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 38 | import android.content.BroadcastReceiver; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 39 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.content.Intent; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 42 | import android.content.IntentFilter; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 43 | import android.content.ServiceConnection; |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 44 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 46 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 47 | import android.content.pm.ResolveInfo; |
| 48 | import android.content.pm.ServiceInfo; |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 49 | import android.content.pm.UserInfo; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 50 | import android.content.res.Resources; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 51 | import android.graphics.Bitmap; |
| 52 | import android.graphics.BitmapFactory; |
| 53 | import android.graphics.BitmapRegionDecoder; |
John Spurlock | 41f6464 | 2013-11-04 13:48:38 -0500 | [diff] [blame] | 54 | import android.graphics.Point; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 55 | import android.graphics.Rect; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | import android.os.Binder; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 57 | import android.os.Bundle; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 58 | import android.os.Environment; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 59 | import android.os.FileObserver; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 60 | import android.os.FileUtils; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 61 | import android.os.IBinder; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 62 | import android.os.IRemoteCallback; |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 63 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | import android.os.ParcelFileDescriptor; |
| 65 | import android.os.RemoteCallbackList; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 66 | import android.os.RemoteException; |
rpcraig | 554cb0c | 2012-07-05 06:41:43 -0400 | [diff] [blame] | 67 | import android.os.SELinux; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 68 | import android.os.ServiceManager; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 69 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 70 | import android.os.UserHandle; |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 71 | import android.os.UserManager; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 72 | import android.service.wallpaper.IWallpaperConnection; |
| 73 | import android.service.wallpaper.IWallpaperEngine; |
| 74 | import android.service.wallpaper.IWallpaperService; |
| 75 | import android.service.wallpaper.WallpaperService; |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 76 | import android.system.ErrnoException; |
| 77 | import android.system.Os; |
Filip Gruszczynski | 5dcc3ac | 2014-10-13 15:51:39 -0700 | [diff] [blame] | 78 | import android.util.EventLog; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 79 | import android.util.Slog; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 80 | import android.util.SparseArray; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 81 | import android.util.Xml; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 82 | import android.view.Display; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 83 | import android.view.IWindowManager; |
| 84 | import android.view.WindowManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 86 | import com.android.internal.R; |
| 87 | import com.android.internal.content.PackageMonitor; |
Christopher Tate | 190e853 | 2016-07-11 11:35:34 -0700 | [diff] [blame] | 88 | import com.android.internal.os.BackgroundThread; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 89 | import com.android.internal.util.FastXmlSerializer; |
| 90 | import com.android.internal.util.JournaledFile; |
| 91 | import com.android.server.EventLogTags; |
| 92 | import com.android.server.SystemService; |
| 93 | |
| 94 | import libcore.io.IoUtils; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 95 | |
| 96 | import org.xmlpull.v1.XmlPullParser; |
| 97 | import org.xmlpull.v1.XmlPullParserException; |
| 98 | import org.xmlpull.v1.XmlSerializer; |
| 99 | |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 100 | import java.io.BufferedOutputStream; |
| 101 | import java.io.File; |
| 102 | import java.io.FileDescriptor; |
| 103 | import java.io.FileInputStream; |
| 104 | import java.io.FileNotFoundException; |
| 105 | import java.io.FileOutputStream; |
| 106 | import java.io.IOException; |
| 107 | import java.io.InputStream; |
| 108 | import java.io.PrintWriter; |
| 109 | import java.nio.charset.StandardCharsets; |
| 110 | import java.util.Arrays; |
| 111 | import java.util.List; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 112 | |
Amith Yamasani | 09e9cdc | 2013-11-06 14:54:50 -0800 | [diff] [blame] | 113 | public class WallpaperManagerService extends IWallpaperManager.Stub { |
| 114 | static final String TAG = "WallpaperManagerService"; |
Joe Onorato | 7e1693a | 2016-02-01 17:45:03 -0800 | [diff] [blame] | 115 | static final boolean DEBUG = false; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 116 | |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 117 | public static class Lifecycle extends SystemService { |
| 118 | private WallpaperManagerService mService; |
| 119 | |
| 120 | public Lifecycle(Context context) { |
| 121 | super(context); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public void onStart() { |
| 126 | mService = new WallpaperManagerService(getContext()); |
| 127 | publishBinderService(Context.WALLPAPER_SERVICE, mService); |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public void onBootPhase(int phase) { |
| 132 | if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { |
| 133 | mService.systemReady(); |
Jeff Sharkey | 383f9fe | 2016-04-13 16:08:15 -0600 | [diff] [blame] | 134 | } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { |
| 135 | mService.switchUser(UserHandle.USER_SYSTEM, null); |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void onUnlockUser(int userHandle) { |
| 141 | mService.onUnlockUser(userHandle); |
| 142 | } |
| 143 | } |
| 144 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 145 | final Object mLock = new Object(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 147 | /** |
| 148 | * Minimum time between crashes of a wallpaper service for us to consider |
| 149 | * restarting it vs. just reverting to the static wallpaper. |
| 150 | */ |
| 151 | static final long MIN_WALLPAPER_CRASH_TIME = 10000; |
Filip Gruszczynski | 5dcc3ac | 2014-10-13 15:51:39 -0700 | [diff] [blame] | 152 | static final int MAX_WALLPAPER_COMPONENT_LOG_LENGTH = 128; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 153 | static final String WALLPAPER = "wallpaper_orig"; |
| 154 | static final String WALLPAPER_CROP = "wallpaper"; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 155 | static final String WALLPAPER_LOCK_ORIG = "wallpaper_lock_orig"; |
| 156 | static final String WALLPAPER_LOCK_CROP = "wallpaper_lock"; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 157 | static final String WALLPAPER_INFO = "wallpaper_info.xml"; |
Dianne Hackborn | bce0cbb | 2012-10-05 11:06:53 -0700 | [diff] [blame] | 158 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 159 | // All the various per-user state files we need to be aware of |
| 160 | static final String[] sPerUserFiles = new String[] { |
| 161 | WALLPAPER, WALLPAPER_CROP, |
| 162 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP, |
| 163 | WALLPAPER_INFO |
| 164 | }; |
| 165 | |
Dianne Hackborn | bce0cbb | 2012-10-05 11:06:53 -0700 | [diff] [blame] | 166 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | * Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks |
| 168 | * that the wallpaper has changed. The CREATE is triggered when there is no |
| 169 | * wallpaper set and is created for the first time. The CLOSE_WRITE is triggered |
Christopher Tate | 190e853 | 2016-07-11 11:35:34 -0700 | [diff] [blame] | 170 | * every time the wallpaper is changed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | */ |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 172 | private class WallpaperObserver extends FileObserver { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 173 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 174 | final int mUserId; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 175 | final WallpaperData mWallpaper; |
| 176 | final File mWallpaperDir; |
| 177 | final File mWallpaperFile; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 178 | final File mWallpaperLockFile; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 179 | |
| 180 | public WallpaperObserver(WallpaperData wallpaper) { |
| 181 | super(getWallpaperDir(wallpaper.userId).getAbsolutePath(), |
Christopher Tate | da058e2 | 2014-10-08 14:51:09 -0700 | [diff] [blame] | 182 | CLOSE_WRITE | MOVED_TO | DELETE | DELETE_SELF); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 183 | mUserId = wallpaper.userId; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 184 | mWallpaperDir = getWallpaperDir(wallpaper.userId); |
| 185 | mWallpaper = wallpaper; |
| 186 | mWallpaperFile = new File(mWallpaperDir, WALLPAPER); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 187 | mWallpaperLockFile = new File(mWallpaperDir, WALLPAPER_LOCK_ORIG); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 190 | private WallpaperData dataForEvent(boolean sysChanged, boolean lockChanged) { |
| 191 | WallpaperData wallpaper = null; |
| 192 | synchronized (mLock) { |
| 193 | if (lockChanged) { |
| 194 | wallpaper = mLockWallpaperMap.get(mUserId); |
| 195 | } |
| 196 | if (wallpaper == null) { |
| 197 | // no lock-specific wallpaper exists, or sys case, handled together |
| 198 | wallpaper = mWallpaperMap.get(mUserId); |
| 199 | } |
| 200 | } |
| 201 | return (wallpaper != null) ? wallpaper : mWallpaper; |
| 202 | } |
| 203 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 204 | @Override |
| 205 | public void onEvent(int event, String path) { |
| 206 | if (path == null) { |
| 207 | return; |
| 208 | } |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 209 | final boolean moved = (event == MOVED_TO); |
| 210 | final boolean written = (event == CLOSE_WRITE || moved); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 211 | final File changedFile = new File(mWallpaperDir, path); |
| 212 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 213 | // System and system+lock changes happen on the system wallpaper input file; |
| 214 | // lock-only changes happen on the dedicated lock wallpaper input file |
| 215 | final boolean sysWallpaperChanged = (mWallpaperFile.equals(changedFile)); |
| 216 | final boolean lockWallpaperChanged = (mWallpaperLockFile.equals(changedFile)); |
| 217 | WallpaperData wallpaper = dataForEvent(sysWallpaperChanged, lockWallpaperChanged); |
| 218 | |
| 219 | if (DEBUG) { |
| 220 | Slog.v(TAG, "Wallpaper file change: evt=" + event |
| 221 | + " path=" + path |
| 222 | + " sys=" + sysWallpaperChanged |
| 223 | + " lock=" + lockWallpaperChanged |
| 224 | + " imagePending=" + wallpaper.imageWallpaperPending |
| 225 | + " whichPending=0x" + Integer.toHexString(wallpaper.whichPending) |
| 226 | + " written=" + written); |
| 227 | } |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 228 | |
| 229 | if (moved && lockWallpaperChanged) { |
| 230 | // We just migrated sys -> lock to preserve imagery for an impending |
Christopher Tate | fa7d97f | 2016-06-30 12:21:57 -0700 | [diff] [blame] | 231 | // new system-only wallpaper. Tell keyguard about it and make sure it |
| 232 | // has the right SELinux label. |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 233 | if (DEBUG) { |
| 234 | Slog.i(TAG, "Sys -> lock MOVED_TO"); |
| 235 | } |
Christopher Tate | fa7d97f | 2016-06-30 12:21:57 -0700 | [diff] [blame] | 236 | SELinux.restorecon(changedFile); |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 237 | notifyLockWallpaperChanged(); |
| 238 | return; |
| 239 | } |
| 240 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 241 | synchronized (mLock) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 242 | if (sysWallpaperChanged || lockWallpaperChanged) { |
| 243 | notifyCallbacksLocked(wallpaper); |
| 244 | if (wallpaper.wallpaperComponent == null |
Christopher Tate | da058e2 | 2014-10-08 14:51:09 -0700 | [diff] [blame] | 245 | || event != CLOSE_WRITE // includes the MOVED_TO case |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 246 | || wallpaper.imageWallpaperPending) { |
Christopher Tate | da058e2 | 2014-10-08 14:51:09 -0700 | [diff] [blame] | 247 | if (written) { |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 248 | // The image source has finished writing the source image, |
| 249 | // so we now produce the crop rect (in the background), and |
| 250 | // only publish the new displayable (sub)image as a result |
| 251 | // of that work. |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 252 | if (DEBUG) { |
| 253 | Slog.v(TAG, "Wallpaper written; generating crop"); |
| 254 | } |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 255 | if (moved) { |
| 256 | // This is a restore, so generate the crop using any just-restored new |
| 257 | // crop guidelines, making sure to preserve our local dimension hints. |
Christopher Tate | fa7d97f | 2016-06-30 12:21:57 -0700 | [diff] [blame] | 258 | // We also make sure to reapply the correct SELinux label. |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 259 | if (DEBUG) { |
| 260 | Slog.v(TAG, "moved-to, therefore restore; reloading metadata"); |
| 261 | } |
Christopher Tate | fa7d97f | 2016-06-30 12:21:57 -0700 | [diff] [blame] | 262 | SELinux.restorecon(changedFile); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 263 | loadSettingsLocked(wallpaper.userId, true); |
| 264 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 265 | generateCrop(wallpaper); |
| 266 | if (DEBUG) { |
| 267 | Slog.v(TAG, "Crop done; invoking completion callback"); |
| 268 | } |
| 269 | wallpaper.imageWallpaperPending = false; |
| 270 | if (wallpaper.setComplete != null) { |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 271 | try { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 272 | wallpaper.setComplete.onWallpaperChanged(); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 273 | } catch (RemoteException e) { |
| 274 | // if this fails we don't really care; the setting app may just |
| 275 | // have crashed and that sort of thing is a fact of life. |
| 276 | } |
| 277 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 278 | if (sysWallpaperChanged) { |
| 279 | // If this was the system wallpaper, rebind... |
| 280 | bindWallpaperComponentLocked(mImageWallpaper, true, |
| 281 | false, wallpaper, null); |
| 282 | } |
| 283 | if (lockWallpaperChanged |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 284 | || (wallpaper.whichPending & FLAG_LOCK) != 0) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 285 | if (DEBUG) { |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 286 | Slog.i(TAG, "Lock-relevant wallpaper changed"); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 287 | } |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 288 | // either a lock-only wallpaper commit or a system+lock event. |
| 289 | // if it's system-plus-lock we need to wipe the lock bookkeeping; |
| 290 | // we're falling back to displaying the system wallpaper there. |
| 291 | if (!lockWallpaperChanged) { |
| 292 | mLockWallpaperMap.remove(wallpaper.userId); |
| 293 | } |
| 294 | // and in any case, tell keyguard about it |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 295 | notifyLockWallpaperChanged(); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 296 | } |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 297 | saveSettingsLocked(wallpaper.userId); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 298 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | } |
| 300 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 305 | void notifyLockWallpaperChanged() { |
| 306 | final IWallpaperManagerCallback cb = mKeyguardListener; |
| 307 | if (cb != null) { |
| 308 | try { |
| 309 | cb.onWallpaperChanged(); |
| 310 | } catch (RemoteException e) { |
| 311 | // Oh well it went away; no big deal |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 316 | /** |
| 317 | * Once a new wallpaper has been written via setWallpaper(...), it needs to be cropped |
| 318 | * for display. |
| 319 | */ |
| 320 | private void generateCrop(WallpaperData wallpaper) { |
| 321 | boolean success = false; |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 322 | |
| 323 | Rect cropHint = new Rect(wallpaper.cropHint); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 324 | |
| 325 | if (DEBUG) { |
| 326 | Slog.v(TAG, "Generating crop for new wallpaper(s): 0x" |
| 327 | + Integer.toHexString(wallpaper.whichPending) |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 328 | + " to " + wallpaper.cropFile.getName() |
| 329 | + " crop=(" + cropHint.width() + 'x' + cropHint.height() |
| 330 | + ") dim=(" + wallpaper.width + 'x' + wallpaper.height + ')'); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 331 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 332 | |
| 333 | // Analyse the source; needed in multiple cases |
| 334 | BitmapFactory.Options options = new BitmapFactory.Options(); |
| 335 | options.inJustDecodeBounds = true; |
| 336 | BitmapFactory.decodeFile(wallpaper.wallpaperFile.getAbsolutePath(), options); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 337 | if (options.outWidth <= 0 || options.outHeight <= 0) { |
Joe LaPenna | c298b16 | 2016-05-02 15:25:50 -0700 | [diff] [blame] | 338 | Slog.w(TAG, "Invalid wallpaper data"); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 339 | success = false; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 340 | } else { |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 341 | boolean needCrop = false; |
| 342 | boolean needScale = false; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 343 | |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 344 | // Empty crop means use the full image |
| 345 | if (cropHint.isEmpty()) { |
| 346 | cropHint.left = cropHint.top = 0; |
| 347 | cropHint.right = options.outWidth; |
| 348 | cropHint.bottom = options.outHeight; |
| 349 | } else { |
| 350 | // force the crop rect to lie within the measured bounds |
| 351 | cropHint.offset( |
| 352 | (cropHint.right > options.outWidth ? options.outWidth - cropHint.right : 0), |
| 353 | (cropHint.bottom > options.outHeight ? options.outHeight - cropHint.bottom : 0)); |
| 354 | |
| 355 | // Don't bother cropping if what we're left with is identity |
| 356 | needCrop = (options.outHeight >= cropHint.height() |
| 357 | && options.outWidth >= cropHint.width()); |
| 358 | } |
| 359 | |
| 360 | // scale if the crop height winds up not matching the recommended metrics |
| 361 | needScale = (wallpaper.height != cropHint.height()); |
| 362 | |
| 363 | if (DEBUG) { |
| 364 | Slog.v(TAG, "crop: w=" + cropHint.width() + " h=" + cropHint.height()); |
| 365 | Slog.v(TAG, "dims: w=" + wallpaper.width + " h=" + wallpaper.height); |
| 366 | Slog.v(TAG, "meas: w=" + options.outWidth + " h=" + options.outHeight); |
| 367 | Slog.v(TAG, "crop?=" + needCrop + " scale?=" + needScale); |
| 368 | } |
| 369 | |
| 370 | if (!needCrop && !needScale) { |
| 371 | // Simple case: the nominal crop fits what we want, so we take |
| 372 | // the whole thing and just copy the image file directly. |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 373 | if (DEBUG) { |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 374 | Slog.v(TAG, "Null crop of new wallpaper; copying"); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 375 | } |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 376 | success = FileUtils.copyFile(wallpaper.wallpaperFile, wallpaper.cropFile); |
| 377 | if (!success) { |
| 378 | wallpaper.cropFile.delete(); |
| 379 | // TODO: fall back to default wallpaper in this case |
| 380 | } |
| 381 | } else { |
| 382 | // Fancy case: crop and scale. First, we decode and scale down if appropriate. |
| 383 | FileOutputStream f = null; |
| 384 | BufferedOutputStream bos = null; |
| 385 | try { |
| 386 | BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance( |
| 387 | wallpaper.wallpaperFile.getAbsolutePath(), false); |
| 388 | |
| 389 | // This actually downsamples only by powers of two, but that's okay; we do |
| 390 | // a proper scaling blit later. This is to minimize transient RAM use. |
| 391 | // We calculate the largest power-of-two under the actual ratio rather than |
| 392 | // just let the decode take care of it because we also want to remap where the |
| 393 | // cropHint rectangle lies in the decoded [super]rect. |
| 394 | final BitmapFactory.Options scaler; |
| 395 | final int actualScale = cropHint.height() / wallpaper.height; |
| 396 | int scale = 1; |
| 397 | while (2*scale < actualScale) { |
| 398 | scale *= 2; |
| 399 | } |
| 400 | if (scale > 1) { |
| 401 | scaler = new BitmapFactory.Options(); |
| 402 | scaler.inSampleSize = scale; |
| 403 | if (DEBUG) { |
| 404 | Slog.v(TAG, "Downsampling cropped rect with scale " + scale); |
| 405 | } |
| 406 | } else { |
| 407 | scaler = null; |
| 408 | } |
| 409 | Bitmap cropped = decoder.decodeRegion(cropHint, scaler); |
| 410 | decoder.recycle(); |
| 411 | |
| 412 | if (cropped == null) { |
| 413 | Slog.e(TAG, "Could not decode new wallpaper"); |
| 414 | } else { |
| 415 | // We've got the extracted crop; now we want to scale it properly to |
| 416 | // the desired rectangle. That's a height-biased operation: make it |
| 417 | // fit the hinted height, and accept whatever width we end up with. |
| 418 | cropHint.offsetTo(0, 0); |
| 419 | cropHint.right /= scale; // adjust by downsampling factor |
| 420 | cropHint.bottom /= scale; |
| 421 | final float heightR = ((float)wallpaper.height) / ((float)cropHint.height()); |
| 422 | if (DEBUG) { |
| 423 | Slog.v(TAG, "scale " + heightR + ", extracting " + cropHint); |
| 424 | } |
| 425 | final int destWidth = (int)(cropHint.width() * heightR); |
| 426 | final Bitmap finalCrop = Bitmap.createScaledBitmap(cropped, |
| 427 | destWidth, wallpaper.height, true); |
| 428 | if (DEBUG) { |
| 429 | Slog.v(TAG, "Final extract:"); |
| 430 | Slog.v(TAG, " dims: w=" + wallpaper.width |
| 431 | + " h=" + wallpaper.height); |
| 432 | Slog.v(TAG, " out: w=" + finalCrop.getWidth() |
| 433 | + " h=" + finalCrop.getHeight()); |
| 434 | } |
| 435 | |
| 436 | f = new FileOutputStream(wallpaper.cropFile); |
| 437 | bos = new BufferedOutputStream(f, 32*1024); |
Christopher Tate | c484f54 | 2016-05-11 14:31:34 -0700 | [diff] [blame] | 438 | finalCrop.compress(Bitmap.CompressFormat.JPEG, 100, bos); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 439 | bos.flush(); // don't rely on the implicit flush-at-close when noting success |
| 440 | success = true; |
| 441 | } |
| 442 | } catch (Exception e) { |
| 443 | if (DEBUG) { |
| 444 | Slog.e(TAG, "Error decoding crop", e); |
| 445 | } |
| 446 | } finally { |
| 447 | IoUtils.closeQuietly(bos); |
| 448 | IoUtils.closeQuietly(f); |
| 449 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
| 453 | if (!success) { |
| 454 | Slog.e(TAG, "Unable to apply new wallpaper"); |
| 455 | wallpaper.cropFile.delete(); |
| 456 | } |
| 457 | |
| 458 | if (wallpaper.cropFile.exists()) { |
| 459 | boolean didRestorecon = SELinux.restorecon(wallpaper.cropFile.getAbsoluteFile()); |
| 460 | if (DEBUG) { |
| 461 | Slog.v(TAG, "restorecon() of crop file returned " + didRestorecon); |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 466 | final Context mContext; |
| 467 | final IWindowManager mIWindowManager; |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 468 | final IPackageManager mIPackageManager; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 469 | final MyPackageMonitor mMonitor; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 470 | final AppOpsManager mAppOpsManager; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 471 | WallpaperData mLastWallpaper; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 472 | IWallpaperManagerCallback mKeyguardListener; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 473 | boolean mWaitingForUnlock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 475 | /** |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 476 | * ID of the current wallpaper, changed every time anything sets a wallpaper. |
| 477 | * This is used for external detection of wallpaper update activity. |
| 478 | */ |
| 479 | int mWallpaperId; |
| 480 | |
| 481 | /** |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 482 | * Name of the component used to display bitmap wallpapers from either the gallery or |
| 483 | * built-in wallpapers. |
| 484 | */ |
| 485 | final ComponentName mImageWallpaper; |
| 486 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 487 | final SparseArray<WallpaperData> mWallpaperMap = new SparseArray<WallpaperData>(); |
| 488 | final SparseArray<WallpaperData> mLockWallpaperMap = new SparseArray<WallpaperData>(); |
Dianne Hackborn | 07213e6 | 2011-08-24 20:05:39 -0700 | [diff] [blame] | 489 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 490 | int mCurrentUserId; |
Dianne Hackborn | 07213e6 | 2011-08-24 20:05:39 -0700 | [diff] [blame] | 491 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 492 | static class WallpaperData { |
| 493 | |
| 494 | int userId; |
| 495 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 496 | final File wallpaperFile; // source image |
| 497 | final File cropFile; // eventual destination |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 498 | |
| 499 | /** |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 500 | * True while the client is writing a new wallpaper |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 501 | */ |
| 502 | boolean imageWallpaperPending; |
| 503 | |
| 504 | /** |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 505 | * Which new wallpapers are being written; mirrors the 'which' |
| 506 | * selector bit field to setWallpaper(). |
| 507 | */ |
| 508 | int whichPending; |
| 509 | |
| 510 | /** |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 511 | * Callback once the set + crop is finished |
| 512 | */ |
| 513 | IWallpaperManagerCallback setComplete; |
| 514 | |
| 515 | /** |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 516 | * Is the OS allowed to back up this wallpaper imagery? |
| 517 | */ |
| 518 | boolean allowBackup; |
| 519 | |
| 520 | /** |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 521 | * Resource name if using a picture from the wallpaper gallery |
| 522 | */ |
| 523 | String name = ""; |
| 524 | |
| 525 | /** |
| 526 | * The component name of the currently set live wallpaper. |
| 527 | */ |
| 528 | ComponentName wallpaperComponent; |
| 529 | |
| 530 | /** |
| 531 | * The component name of the wallpaper that should be set next. |
| 532 | */ |
| 533 | ComponentName nextWallpaperComponent; |
| 534 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 535 | /** |
| 536 | * The ID of this wallpaper |
| 537 | */ |
| 538 | int wallpaperId; |
| 539 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 540 | WallpaperConnection connection; |
| 541 | long lastDiedTime; |
| 542 | boolean wallpaperUpdating; |
| 543 | WallpaperObserver wallpaperObserver; |
| 544 | |
| 545 | /** |
| 546 | * List of callbacks registered they should each be notified when the wallpaper is changed. |
| 547 | */ |
| 548 | private RemoteCallbackList<IWallpaperManagerCallback> callbacks |
| 549 | = new RemoteCallbackList<IWallpaperManagerCallback>(); |
| 550 | |
| 551 | int width = -1; |
| 552 | int height = -1; |
| 553 | |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 554 | /** |
| 555 | * The crop hint supplied for displaying a subset of the source image |
| 556 | */ |
| 557 | final Rect cropHint = new Rect(0, 0, 0, 0); |
| 558 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 559 | final Rect padding = new Rect(0, 0, 0, 0); |
| 560 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 561 | WallpaperData(int userId, String inputFileName, String cropFileName) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 562 | this.userId = userId; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 563 | final File wallpaperDir = getWallpaperDir(userId); |
| 564 | wallpaperFile = new File(wallpaperDir, inputFileName); |
| 565 | cropFile = new File(wallpaperDir, cropFileName); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 566 | } |
| 567 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 568 | // Called during initialization of a given user's wallpaper bookkeeping |
Christopher Tate | 41297ff | 2016-03-10 16:46:15 -0800 | [diff] [blame] | 569 | boolean cropExists() { |
| 570 | return cropFile.exists(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 574 | int makeWallpaperIdLocked() { |
| 575 | do { |
| 576 | ++mWallpaperId; |
| 577 | } while (mWallpaperId == 0); |
| 578 | return mWallpaperId; |
| 579 | } |
| 580 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 581 | class WallpaperConnection extends IWallpaperConnection.Stub |
| 582 | implements ServiceConnection { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 583 | final WallpaperInfo mInfo; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 584 | final Binder mToken = new Binder(); |
| 585 | IWallpaperService mService; |
| 586 | IWallpaperEngine mEngine; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 587 | WallpaperData mWallpaper; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 588 | IRemoteCallback mReply; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | |
Michael Wright | 5203a8b | 2013-10-03 14:16:42 -0700 | [diff] [blame] | 590 | boolean mDimensionsChanged = false; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 591 | boolean mPaddingChanged = false; |
Michael Wright | 5203a8b | 2013-10-03 14:16:42 -0700 | [diff] [blame] | 592 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 593 | public WallpaperConnection(WallpaperInfo info, WallpaperData wallpaper) { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 594 | mInfo = info; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 595 | mWallpaper = wallpaper; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 596 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 597 | |
| 598 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 599 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 600 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 601 | if (mWallpaper.connection == this) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 602 | mService = IWallpaperService.Stub.asInterface(service); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 603 | attachServiceLocked(this, mWallpaper); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 604 | // XXX should probably do saveSettingsLocked() later |
| 605 | // when we have an engine, but I'm not sure about |
| 606 | // locking there and anyway we always need to be able to |
| 607 | // recover if there is something wrong. |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 608 | saveSettingsLocked(mWallpaper.userId); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 613 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 614 | public void onServiceDisconnected(ComponentName name) { |
| 615 | synchronized (mLock) { |
| 616 | mService = null; |
| 617 | mEngine = null; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 618 | if (mWallpaper.connection == this) { |
| 619 | Slog.w(TAG, "Wallpaper service gone: " + mWallpaper.wallpaperComponent); |
| 620 | if (!mWallpaper.wallpaperUpdating |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 621 | && mWallpaper.userId == mCurrentUserId) { |
Selim Cinek | ebebadb | 2014-03-05 22:17:26 +0100 | [diff] [blame] | 622 | // There is a race condition which causes |
| 623 | // {@link #mWallpaper.wallpaperUpdating} to be false even if it is |
| 624 | // currently updating since the broadcast notifying us is async. |
| 625 | // This race is overcome by the general rule that we only reset the |
| 626 | // wallpaper if its service was shut down twice |
| 627 | // during {@link #MIN_WALLPAPER_CRASH_TIME} millis. |
| 628 | if (mWallpaper.lastDiedTime != 0 |
| 629 | && mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME |
| 630 | > SystemClock.uptimeMillis()) { |
| 631 | Slog.w(TAG, "Reverting to built-in wallpaper!"); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 632 | clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, null); |
Selim Cinek | ebebadb | 2014-03-05 22:17:26 +0100 | [diff] [blame] | 633 | } else { |
| 634 | mWallpaper.lastDiedTime = SystemClock.uptimeMillis(); |
| 635 | } |
Filip Gruszczynski | 5a58943 | 2014-10-14 12:06:06 -0700 | [diff] [blame] | 636 | final String flattened = name.flattenToString(); |
Filip Gruszczynski | 5dcc3ac | 2014-10-13 15:51:39 -0700 | [diff] [blame] | 637 | EventLog.writeEvent(EventLogTags.WP_WALLPAPER_CRASHED, |
Filip Gruszczynski | 5a58943 | 2014-10-14 12:06:06 -0700 | [diff] [blame] | 638 | flattened.substring(0, Math.min(flattened.length(), |
| 639 | MAX_WALLPAPER_COMPONENT_LOG_LENGTH))); |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 640 | } |
| 641 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 642 | } |
| 643 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 644 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 645 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 646 | public void attachEngine(IWallpaperEngine engine) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 647 | synchronized (mLock) { |
| 648 | mEngine = engine; |
Michael Wright | 5203a8b | 2013-10-03 14:16:42 -0700 | [diff] [blame] | 649 | if (mDimensionsChanged) { |
| 650 | try { |
| 651 | mEngine.setDesiredSize(mWallpaper.width, mWallpaper.height); |
| 652 | } catch (RemoteException e) { |
| 653 | Slog.w(TAG, "Failed to set wallpaper dimensions", e); |
| 654 | } |
| 655 | mDimensionsChanged = false; |
| 656 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 657 | if (mPaddingChanged) { |
| 658 | try { |
| 659 | mEngine.setDisplayPadding(mWallpaper.padding); |
| 660 | } catch (RemoteException e) { |
| 661 | Slog.w(TAG, "Failed to set wallpaper padding", e); |
| 662 | } |
| 663 | mPaddingChanged = false; |
| 664 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 665 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 666 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 667 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 668 | @Override |
| 669 | public void engineShown(IWallpaperEngine engine) { |
| 670 | synchronized (mLock) { |
| 671 | if (mReply != null) { |
| 672 | long ident = Binder.clearCallingIdentity(); |
| 673 | try { |
| 674 | mReply.sendResult(null); |
| 675 | } catch (RemoteException e) { |
| 676 | Binder.restoreCallingIdentity(ident); |
| 677 | } |
| 678 | mReply = null; |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 684 | public ParcelFileDescriptor setWallpaper(String name) { |
| 685 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 686 | if (mWallpaper.connection == this) { |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 687 | return updateWallpaperBitmapLocked(name, mWallpaper, null); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 688 | } |
| 689 | return null; |
| 690 | } |
| 691 | } |
| 692 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 693 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 694 | class MyPackageMonitor extends PackageMonitor { |
| 695 | @Override |
| 696 | public void onPackageUpdateFinished(String packageName, int uid) { |
| 697 | synchronized (mLock) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 698 | if (mCurrentUserId != getChangingUserId()) { |
| 699 | return; |
| 700 | } |
| 701 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 702 | if (wallpaper != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 703 | if (wallpaper.wallpaperComponent != null |
| 704 | && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) { |
| 705 | wallpaper.wallpaperUpdating = false; |
| 706 | ComponentName comp = wallpaper.wallpaperComponent; |
| 707 | clearWallpaperComponentLocked(wallpaper); |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 708 | if (!bindWallpaperComponentLocked(comp, false, false, |
| 709 | wallpaper, null)) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 710 | Slog.w(TAG, "Wallpaper no longer available; reverting to default"); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 711 | clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 712 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 713 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | @Override |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 719 | public void onPackageModified(String packageName) { |
| 720 | synchronized (mLock) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 721 | if (mCurrentUserId != getChangingUserId()) { |
| 722 | return; |
| 723 | } |
| 724 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 725 | if (wallpaper != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 726 | if (wallpaper.wallpaperComponent == null |
| 727 | || !wallpaper.wallpaperComponent.getPackageName().equals(packageName)) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 728 | return; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 729 | } |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 730 | doPackagesChangedLocked(true, wallpaper); |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 731 | } |
| 732 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 736 | public void onPackageUpdateStarted(String packageName, int uid) { |
| 737 | synchronized (mLock) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 738 | if (mCurrentUserId != getChangingUserId()) { |
| 739 | return; |
| 740 | } |
| 741 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 742 | if (wallpaper != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 743 | if (wallpaper.wallpaperComponent != null |
| 744 | && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) { |
| 745 | wallpaper.wallpaperUpdating = true; |
| 746 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | @Override |
| 752 | public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 753 | synchronized (mLock) { |
| 754 | boolean changed = false; |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 755 | if (mCurrentUserId != getChangingUserId()) { |
| 756 | return false; |
| 757 | } |
| 758 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 759 | if (wallpaper != null) { |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 760 | boolean res = doPackagesChangedLocked(doit, wallpaper); |
| 761 | changed |= res; |
| 762 | } |
| 763 | return changed; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 764 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | @Override |
| 768 | public void onSomePackagesChanged() { |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 769 | synchronized (mLock) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 770 | if (mCurrentUserId != getChangingUserId()) { |
| 771 | return; |
| 772 | } |
| 773 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 774 | if (wallpaper != null) { |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 775 | doPackagesChangedLocked(true, wallpaper); |
| 776 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 777 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 778 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 779 | |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 780 | boolean doPackagesChangedLocked(boolean doit, WallpaperData wallpaper) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 781 | boolean changed = false; |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 782 | if (wallpaper.wallpaperComponent != null) { |
| 783 | int change = isPackageDisappearing(wallpaper.wallpaperComponent |
| 784 | .getPackageName()); |
| 785 | if (change == PACKAGE_PERMANENT_CHANGE |
| 786 | || change == PACKAGE_TEMPORARY_CHANGE) { |
| 787 | changed = true; |
| 788 | if (doit) { |
| 789 | Slog.w(TAG, "Wallpaper uninstalled, removing: " |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 790 | + wallpaper.wallpaperComponent); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 791 | clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 792 | } |
| 793 | } |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 794 | } |
| 795 | if (wallpaper.nextWallpaperComponent != null) { |
| 796 | int change = isPackageDisappearing(wallpaper.nextWallpaperComponent |
| 797 | .getPackageName()); |
| 798 | if (change == PACKAGE_PERMANENT_CHANGE |
| 799 | || change == PACKAGE_TEMPORARY_CHANGE) { |
| 800 | wallpaper.nextWallpaperComponent = null; |
| 801 | } |
| 802 | } |
| 803 | if (wallpaper.wallpaperComponent != null |
| 804 | && isPackageModified(wallpaper.wallpaperComponent.getPackageName())) { |
| 805 | try { |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 806 | mContext.getPackageManager().getServiceInfo(wallpaper.wallpaperComponent, |
| 807 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 808 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 809 | } catch (NameNotFoundException e) { |
| 810 | Slog.w(TAG, "Wallpaper component gone, removing: " |
| 811 | + wallpaper.wallpaperComponent); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 812 | clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null); |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | if (wallpaper.nextWallpaperComponent != null |
| 816 | && isPackageModified(wallpaper.nextWallpaperComponent.getPackageName())) { |
| 817 | try { |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 818 | mContext.getPackageManager().getServiceInfo(wallpaper.nextWallpaperComponent, |
| 819 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 820 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 821 | } catch (NameNotFoundException e) { |
| 822 | wallpaper.nextWallpaperComponent = null; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | return changed; |
| 826 | } |
| 827 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 828 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 829 | public WallpaperManagerService(Context context) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 830 | if (DEBUG) Slog.v(TAG, "WallpaperService startup"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | mContext = context; |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 832 | mImageWallpaper = ComponentName.unflattenFromString( |
| 833 | context.getResources().getString(R.string.image_wallpaper_component)); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 834 | mIWindowManager = IWindowManager.Stub.asInterface( |
| 835 | ServiceManager.getService(Context.WINDOW_SERVICE)); |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 836 | mIPackageManager = AppGlobals.getPackageManager(); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 837 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 838 | mMonitor = new MyPackageMonitor(); |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 839 | mMonitor.register(context, null, UserHandle.ALL, true); |
Xiaohui Chen | 233d94c | 2015-07-30 15:08:00 -0700 | [diff] [blame] | 840 | getWallpaperDir(UserHandle.USER_SYSTEM).mkdirs(); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 841 | loadSettingsLocked(UserHandle.USER_SYSTEM, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 843 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 844 | private static File getWallpaperDir(int userId) { |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 845 | return Environment.getUserSystemDirectory(userId); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 846 | } |
| 847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | @Override |
| 849 | protected void finalize() throws Throwable { |
| 850 | super.finalize(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 851 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 852 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
| 853 | wallpaper.wallpaperObserver.stopWatching(); |
| 854 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 856 | |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 857 | void systemReady() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 858 | if (DEBUG) Slog.v(TAG, "systemReady"); |
Xiaohui Chen | 233d94c | 2015-07-30 15:08:00 -0700 | [diff] [blame] | 859 | WallpaperData wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM); |
Christopher Tate | 2cdd3f2 | 2016-03-14 17:36:16 -0700 | [diff] [blame] | 860 | // If we think we're going to be using the system image wallpaper imagery, make |
| 861 | // sure we have something to render |
| 862 | if (mImageWallpaper.equals(wallpaper.nextWallpaperComponent)) { |
| 863 | // No crop file? Make sure we've finished the processing sequence if necessary |
| 864 | if (!wallpaper.cropExists()) { |
| 865 | if (DEBUG) { |
| 866 | Slog.i(TAG, "No crop; regenerating from source"); |
| 867 | } |
| 868 | generateCrop(wallpaper); |
| 869 | } |
| 870 | // Still nothing? Fall back to default. |
| 871 | if (!wallpaper.cropExists()) { |
| 872 | if (DEBUG) { |
| 873 | Slog.i(TAG, "Unable to regenerate crop; resetting"); |
| 874 | } |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 875 | clearWallpaperLocked(false, FLAG_SYSTEM, UserHandle.USER_SYSTEM, null); |
Christopher Tate | 2cdd3f2 | 2016-03-14 17:36:16 -0700 | [diff] [blame] | 876 | } |
| 877 | } else { |
| 878 | if (DEBUG) { |
| 879 | Slog.i(TAG, "Nondefault wallpaper component; gracefully ignoring"); |
| 880 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 881 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 882 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 883 | IntentFilter userFilter = new IntentFilter(); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 884 | userFilter.addAction(Intent.ACTION_USER_REMOVED); |
| 885 | mContext.registerReceiver(new BroadcastReceiver() { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 886 | @Override |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 887 | public void onReceive(Context context, Intent intent) { |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 888 | final String action = intent.getAction(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 889 | if (Intent.ACTION_USER_REMOVED.equals(action)) { |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 890 | onRemoveUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, |
| 891 | UserHandle.USER_NULL)); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 892 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 893 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 894 | }, userFilter); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 895 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 896 | try { |
| 897 | ActivityManagerNative.getDefault().registerUserSwitchObserver( |
| 898 | new IUserSwitchObserver.Stub() { |
| 899 | @Override |
| 900 | public void onUserSwitching(int newUserId, IRemoteCallback reply) { |
| 901 | switchUser(newUserId, reply); |
| 902 | } |
| 903 | |
| 904 | @Override |
| 905 | public void onUserSwitchComplete(int newUserId) throws RemoteException { |
| 906 | } |
Kenny Guy | 4297962 | 2015-04-13 18:03:05 +0000 | [diff] [blame] | 907 | |
| 908 | @Override |
| 909 | public void onForegroundProfileSwitch(int newProfileId) { |
| 910 | // Ignore. |
| 911 | } |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 912 | }, TAG); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 913 | } catch (RemoteException e) { |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 914 | e.rethrowAsRuntimeException(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 915 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 916 | } |
| 917 | |
Amith Yamasani | 09e9cdc | 2013-11-06 14:54:50 -0800 | [diff] [blame] | 918 | /** Called by SystemBackupAgent */ |
| 919 | public String getName() { |
| 920 | // Verify caller is the system |
| 921 | if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) { |
| 922 | throw new RuntimeException("getName() can only be called from the system process"); |
| 923 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 924 | synchronized (mLock) { |
| 925 | return mWallpaperMap.get(0).name; |
| 926 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 927 | } |
| 928 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 929 | void stopObserver(WallpaperData wallpaper) { |
| 930 | if (wallpaper != null) { |
| 931 | if (wallpaper.wallpaperObserver != null) { |
| 932 | wallpaper.wallpaperObserver.stopWatching(); |
| 933 | wallpaper.wallpaperObserver = null; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 934 | } |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 938 | void stopObserversLocked(int userId) { |
| 939 | stopObserver(mWallpaperMap.get(userId)); |
| 940 | stopObserver(mLockWallpaperMap.get(userId)); |
| 941 | mWallpaperMap.remove(userId); |
| 942 | mLockWallpaperMap.remove(userId); |
| 943 | } |
| 944 | |
Christopher Tate | 190e853 | 2016-07-11 11:35:34 -0700 | [diff] [blame] | 945 | void onUnlockUser(final int userId) { |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 946 | synchronized (mLock) { |
| 947 | if (mCurrentUserId == userId && mWaitingForUnlock) { |
| 948 | switchUser(userId, null); |
Christopher Tate | 190e853 | 2016-07-11 11:35:34 -0700 | [diff] [blame] | 949 | |
| 950 | // Make sure that the SELinux labeling of all the relevant files is correct. |
| 951 | // This corrects for mislabeling bugs that might have arisen from move-to |
| 952 | // operations involving the wallpaper files. This isn't timing-critical, |
| 953 | // so we do it in the background to avoid holding up the user unlock operation. |
| 954 | Runnable relabeler = new Runnable() { |
| 955 | @Override |
| 956 | public void run() { |
| 957 | final File wallpaperDir = getWallpaperDir(userId); |
| 958 | for (String filename : sPerUserFiles) { |
| 959 | File f = new File(wallpaperDir, filename); |
| 960 | if (f.exists()) { |
| 961 | SELinux.restorecon(f); |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | }; |
| 966 | BackgroundThread.getHandler().post(relabeler); |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | } |
| 970 | |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 971 | void onRemoveUser(int userId) { |
| 972 | if (userId < 1) return; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 973 | |
| 974 | final File wallpaperDir = getWallpaperDir(userId); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 975 | synchronized (mLock) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 976 | stopObserversLocked(userId); |
| 977 | for (String filename : sPerUserFiles) { |
| 978 | new File(wallpaperDir, filename).delete(); |
| 979 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 983 | void switchUser(int userId, IRemoteCallback reply) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 984 | synchronized (mLock) { |
| 985 | mCurrentUserId = userId; |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 986 | WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 987 | // Not started watching yet, in case wallpaper data was loaded for other reasons. |
| 988 | if (wallpaper.wallpaperObserver == null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 989 | wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper); |
| 990 | wallpaper.wallpaperObserver.startWatching(); |
| 991 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 992 | switchWallpaper(wallpaper, reply); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 996 | void switchWallpaper(WallpaperData wallpaper, IRemoteCallback reply) { |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 997 | synchronized (mLock) { |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 998 | mWaitingForUnlock = false; |
| 999 | final ComponentName cname = wallpaper.wallpaperComponent != null ? |
| 1000 | wallpaper.wallpaperComponent : wallpaper.nextWallpaperComponent; |
| 1001 | if (!bindWallpaperComponentLocked(cname, true, false, wallpaper, reply)) { |
| 1002 | // We failed to bind the desired wallpaper, but that might |
| 1003 | // happen if the wallpaper isn't direct-boot aware |
| 1004 | ServiceInfo si = null; |
| 1005 | try { |
| 1006 | si = mIPackageManager.getServiceInfo(cname, |
| 1007 | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, wallpaper.userId); |
| 1008 | } catch (RemoteException ignored) { |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1009 | } |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1010 | |
| 1011 | if (si == null) { |
| 1012 | Slog.w(TAG, "Failure starting previous wallpaper; clearing"); |
| 1013 | clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, reply); |
| 1014 | } else { |
| 1015 | Slog.w(TAG, "Wallpaper isn't direct boot aware; using fallback until unlocked"); |
| 1016 | // We might end up persisting the current wallpaper data |
| 1017 | // while locked, so pretend like the component was actually |
| 1018 | // bound into place |
| 1019 | wallpaper.wallpaperComponent = wallpaper.nextWallpaperComponent; |
| 1020 | final WallpaperData fallback = new WallpaperData(wallpaper.userId, |
| 1021 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 1022 | ensureSaneWallpaperData(fallback); |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1023 | bindWallpaperComponentLocked(mImageWallpaper, true, false, fallback, reply); |
| 1024 | mWaitingForUnlock = true; |
| 1025 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1026 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1030 | @Override |
| 1031 | public void clearWallpaper(String callingPackage, int which, int userId) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1032 | if (DEBUG) Slog.v(TAG, "clearWallpaper"); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1033 | checkPermission(android.Manifest.permission.SET_WALLPAPER); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1034 | if (!isWallpaperSupported(callingPackage) || !isSetWallpaperAllowed(callingPackage)) { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1035 | return; |
| 1036 | } |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1037 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| 1038 | Binder.getCallingUid(), userId, false, true, "clearWallpaper", null); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1039 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1040 | synchronized (mLock) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1041 | clearWallpaperLocked(false, which, userId, null); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1045 | void clearWallpaperLocked(boolean defaultFailed, int which, int userId, IRemoteCallback reply) { |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1046 | if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1047 | throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to read"); |
| 1048 | } |
| 1049 | |
| 1050 | WallpaperData wallpaper = null; |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1051 | if (which == FLAG_LOCK) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1052 | wallpaper = mLockWallpaperMap.get(userId); |
| 1053 | if (wallpaper == null) { |
| 1054 | // It's already gone; we're done. |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1055 | if (DEBUG) { |
| 1056 | Slog.i(TAG, "Lock wallpaper already cleared"); |
| 1057 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1058 | return; |
| 1059 | } |
| 1060 | } else { |
| 1061 | wallpaper = mWallpaperMap.get(userId); |
| 1062 | if (wallpaper == null) { |
| 1063 | // Might need to bring it in the first time to establish our rewrite |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1064 | loadSettingsLocked(userId, false); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1065 | wallpaper = mWallpaperMap.get(userId); |
| 1066 | } |
| 1067 | } |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1068 | if (wallpaper == null) { |
| 1069 | return; |
| 1070 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1071 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1072 | final long ident = Binder.clearCallingIdentity(); |
| 1073 | try { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1074 | if (wallpaper.wallpaperFile.exists()) { |
| 1075 | wallpaper.wallpaperFile.delete(); |
| 1076 | wallpaper.cropFile.delete(); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1077 | if (which == FLAG_LOCK) { |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1078 | mLockWallpaperMap.remove(userId); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1079 | final IWallpaperManagerCallback cb = mKeyguardListener; |
| 1080 | if (cb != null) { |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1081 | if (DEBUG) { |
| 1082 | Slog.i(TAG, "Notifying keyguard of lock wallpaper clear"); |
| 1083 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1084 | try { |
| 1085 | cb.onWallpaperChanged(); |
| 1086 | } catch (RemoteException e) { |
| 1087 | // Oh well it went away; no big deal |
| 1088 | } |
| 1089 | } |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1090 | saveSettingsLocked(userId); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1091 | return; |
| 1092 | } |
| 1093 | } |
| 1094 | |
Christopher Tate | ecd827a | 2014-09-05 17:42:34 -0700 | [diff] [blame] | 1095 | RuntimeException e = null; |
| 1096 | try { |
| 1097 | wallpaper.imageWallpaperPending = false; |
| 1098 | if (userId != mCurrentUserId) return; |
| 1099 | if (bindWallpaperComponentLocked(defaultFailed |
| 1100 | ? mImageWallpaper |
| 1101 | : null, true, false, wallpaper, reply)) { |
| 1102 | return; |
| 1103 | } |
| 1104 | } catch (IllegalArgumentException e1) { |
| 1105 | e = e1; |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1106 | } |
Christopher Tate | ecd827a | 2014-09-05 17:42:34 -0700 | [diff] [blame] | 1107 | |
| 1108 | // This can happen if the default wallpaper component doesn't |
| 1109 | // exist. This should be a system configuration problem, but |
| 1110 | // let's not let it crash the system and just live with no |
| 1111 | // wallpaper. |
| 1112 | Slog.e(TAG, "Default wallpaper component not found!", e); |
| 1113 | clearWallpaperComponentLocked(wallpaper); |
| 1114 | if (reply != null) { |
| 1115 | try { |
| 1116 | reply.sendResult(null); |
| 1117 | } catch (RemoteException e1) { |
| 1118 | } |
| 1119 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1120 | } finally { |
| 1121 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | public boolean hasNamedWallpaper(String name) { |
| 1126 | synchronized (mLock) { |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 1127 | List<UserInfo> users; |
| 1128 | long ident = Binder.clearCallingIdentity(); |
| 1129 | try { |
| 1130 | users = ((UserManager) mContext.getSystemService(Context.USER_SERVICE)).getUsers(); |
| 1131 | } finally { |
| 1132 | Binder.restoreCallingIdentity(ident); |
| 1133 | } |
| 1134 | for (UserInfo user: users) { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1135 | // ignore managed profiles |
| 1136 | if (user.isManagedProfile()) { |
| 1137 | continue; |
| 1138 | } |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 1139 | WallpaperData wd = mWallpaperMap.get(user.id); |
| 1140 | if (wd == null) { |
| 1141 | // User hasn't started yet, so load her settings to peek at the wallpaper |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1142 | loadSettingsLocked(user.id, false); |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 1143 | wd = mWallpaperMap.get(user.id); |
| 1144 | } |
| 1145 | if (wd != null && name.equals(wd.name)) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1146 | return true; |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
John Spurlock | 41f6464 | 2013-11-04 13:48:38 -0500 | [diff] [blame] | 1153 | private Point getDefaultDisplaySize() { |
| 1154 | Point p = new Point(); |
John Spurlock | d6e836c | 2013-11-18 14:14:49 -0500 | [diff] [blame] | 1155 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1156 | Display d = wm.getDefaultDisplay(); |
| 1157 | d.getRealSize(p); |
John Spurlock | 41f6464 | 2013-11-04 13:48:38 -0500 | [diff] [blame] | 1158 | return p; |
| 1159 | } |
| 1160 | |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1161 | public void setDimensionHints(int width, int height, String callingPackage) |
| 1162 | throws RemoteException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1164 | if (!isWallpaperSupported(callingPackage)) { |
| 1165 | return; |
| 1166 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1167 | synchronized (mLock) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1168 | int userId = UserHandle.getCallingUserId(); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1169 | WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1170 | if (width <= 0 || height <= 0) { |
| 1171 | throw new IllegalArgumentException("width and height must be > 0"); |
| 1172 | } |
John Spurlock | 41f6464 | 2013-11-04 13:48:38 -0500 | [diff] [blame] | 1173 | // Make sure it is at least as large as the display. |
| 1174 | Point displaySize = getDefaultDisplaySize(); |
| 1175 | width = Math.max(width, displaySize.x); |
| 1176 | height = Math.max(height, displaySize.y); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1177 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1178 | if (width != wallpaper.width || height != wallpaper.height) { |
| 1179 | wallpaper.width = width; |
| 1180 | wallpaper.height = height; |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1181 | saveSettingsLocked(userId); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1182 | if (mCurrentUserId != userId) return; // Don't change the properties now |
| 1183 | if (wallpaper.connection != null) { |
| 1184 | if (wallpaper.connection.mEngine != null) { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1185 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1186 | wallpaper.connection.mEngine.setDesiredSize( |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1187 | width, height); |
| 1188 | } catch (RemoteException e) { |
| 1189 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1190 | notifyCallbacksLocked(wallpaper); |
Michael Wright | 5203a8b | 2013-10-03 14:16:42 -0700 | [diff] [blame] | 1191 | } else if (wallpaper.connection.mService != null) { |
| 1192 | // We've attached to the service but the engine hasn't attached back to us |
| 1193 | // yet. This means it will be created with the previous dimensions, so we |
| 1194 | // need to update it to the new dimensions once it attaches. |
| 1195 | wallpaper.connection.mDimensionsChanged = true; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1196 | } |
| 1197 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1198 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | public int getWidthHint() throws RemoteException { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1203 | synchronized (mLock) { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1204 | WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId()); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1205 | if (wallpaper != null) { |
| 1206 | return wallpaper.width; |
| 1207 | } else { |
| 1208 | return 0; |
| 1209 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1210 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | public int getHeightHint() throws RemoteException { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1214 | synchronized (mLock) { |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 1215 | WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId()); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1216 | if (wallpaper != null) { |
| 1217 | return wallpaper.height; |
| 1218 | } else { |
| 1219 | return 0; |
| 1220 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1221 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | } |
| 1223 | |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1224 | public void setDisplayPadding(Rect padding, String callingPackage) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1225 | checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1226 | if (!isWallpaperSupported(callingPackage)) { |
| 1227 | return; |
| 1228 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1229 | synchronized (mLock) { |
| 1230 | int userId = UserHandle.getCallingUserId(); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1231 | WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1232 | if (padding.left < 0 || padding.top < 0 || padding.right < 0 || padding.bottom < 0) { |
| 1233 | throw new IllegalArgumentException("padding must be positive: " + padding); |
| 1234 | } |
| 1235 | |
| 1236 | if (!padding.equals(wallpaper.padding)) { |
| 1237 | wallpaper.padding.set(padding); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1238 | saveSettingsLocked(userId); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1239 | if (mCurrentUserId != userId) return; // Don't change the properties now |
| 1240 | if (wallpaper.connection != null) { |
| 1241 | if (wallpaper.connection.mEngine != null) { |
| 1242 | try { |
| 1243 | wallpaper.connection.mEngine.setDisplayPadding(padding); |
| 1244 | } catch (RemoteException e) { |
| 1245 | } |
| 1246 | notifyCallbacksLocked(wallpaper); |
| 1247 | } else if (wallpaper.connection.mService != null) { |
| 1248 | // We've attached to the service but the engine hasn't attached back to us |
| 1249 | // yet. This means it will be created with the previous dimensions, so we |
| 1250 | // need to update it to the new dimensions once it attaches. |
| 1251 | wallpaper.connection.mPaddingChanged = true; |
| 1252 | } |
| 1253 | } |
| 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | |
Yorke Lee | dcd93cc | 2016-01-08 14:12:55 -0800 | [diff] [blame] | 1258 | @Override |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1259 | public ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb, final int which, |
| 1260 | Bundle outParams, int wallpaperUserId) { |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1261 | wallpaperUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| 1262 | Binder.getCallingUid(), wallpaperUserId, false, true, "getWallpaper", null); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1263 | |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1264 | if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1265 | throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to read"); |
| 1266 | } |
| 1267 | |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1268 | synchronized (mLock) { |
Vadim Tryshev | 8cde079 | 2016-02-19 17:02:15 -0800 | [diff] [blame] | 1269 | final SparseArray<WallpaperData> whichSet = |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1270 | (which == FLAG_LOCK) ? mLockWallpaperMap : mWallpaperMap; |
Vadim Tryshev | 8cde079 | 2016-02-19 17:02:15 -0800 | [diff] [blame] | 1271 | WallpaperData wallpaper = whichSet.get(wallpaperUserId); |
| 1272 | if (wallpaper == null) { |
| 1273 | // common case, this is the first lookup post-boot of the system or |
| 1274 | // unified lock, so we bring up the saved state lazily now and recheck. |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1275 | loadSettingsLocked(wallpaperUserId, false); |
Vadim Tryshev | 8cde079 | 2016-02-19 17:02:15 -0800 | [diff] [blame] | 1276 | wallpaper = whichSet.get(wallpaperUserId); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1277 | if (wallpaper == null) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1278 | return null; |
| 1279 | } |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1280 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1281 | try { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1282 | if (outParams != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1283 | outParams.putInt("width", wallpaper.width); |
| 1284 | outParams.putInt("height", wallpaper.height); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1285 | } |
Christopher Tate | ea6724a | 2016-02-18 18:39:19 -0800 | [diff] [blame] | 1286 | if (cb != null) { |
| 1287 | wallpaper.callbacks.register(cb); |
| 1288 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1289 | if (!wallpaper.cropFile.exists()) { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1290 | return null; |
| 1291 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1292 | return ParcelFileDescriptor.open(wallpaper.cropFile, MODE_READ_ONLY); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1293 | } catch (FileNotFoundException e) { |
| 1294 | /* Shouldn't happen as we check to see if the file exists */ |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1295 | Slog.w(TAG, "Error getting wallpaper", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1297 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | } |
| 1300 | |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1301 | @Override |
Jorim Jaggi | e31f6b8 | 2016-07-01 16:15:09 -0700 | [diff] [blame] | 1302 | public WallpaperInfo getWallpaperInfo(int userId) { |
| 1303 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| 1304 | Binder.getCallingUid(), userId, false, true, "getWallpaperIdForUser", null); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1305 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1306 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1307 | if (wallpaper != null && wallpaper.connection != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1308 | return wallpaper.connection.mInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1309 | } |
| 1310 | return null; |
| 1311 | } |
| 1312 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1313 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1314 | @Override |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1315 | public int getWallpaperIdForUser(int which, int userId) { |
| 1316 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| 1317 | Binder.getCallingUid(), userId, false, true, "getWallpaperIdForUser", null); |
| 1318 | |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1319 | if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1320 | throw new IllegalArgumentException("Must specify exactly one kind of wallpaper"); |
| 1321 | } |
| 1322 | |
| 1323 | final SparseArray<WallpaperData> map = |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1324 | (which == FLAG_LOCK) ? mLockWallpaperMap : mWallpaperMap; |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1325 | synchronized (mLock) { |
| 1326 | WallpaperData wallpaper = map.get(userId); |
| 1327 | if (wallpaper != null) { |
| 1328 | return wallpaper.wallpaperId; |
| 1329 | } |
| 1330 | } |
| 1331 | return -1; |
| 1332 | } |
| 1333 | |
| 1334 | @Override |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1335 | public boolean setLockWallpaperCallback(IWallpaperManagerCallback cb) { |
| 1336 | checkPermission(android.Manifest.permission.INTERNAL_SYSTEM_WINDOW); |
| 1337 | synchronized (mLock) { |
| 1338 | mKeyguardListener = cb; |
| 1339 | } |
| 1340 | return true; |
| 1341 | } |
| 1342 | |
| 1343 | @Override |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1344 | public ParcelFileDescriptor setWallpaper(String name, String callingPackage, |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1345 | Rect cropHint, boolean allowBackup, Bundle extras, int which, |
| 1346 | IWallpaperManagerCallback completion) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1347 | checkPermission(android.Manifest.permission.SET_WALLPAPER); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1348 | |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1349 | if ((which & (FLAG_LOCK|FLAG_SYSTEM)) == 0) { |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1350 | final String msg = "Must specify a valid wallpaper category to set"; |
| 1351 | Slog.e(TAG, msg); |
| 1352 | throw new IllegalArgumentException(msg); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1353 | } |
| 1354 | |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1355 | if (!isWallpaperSupported(callingPackage) || !isSetWallpaperAllowed(callingPackage)) { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1356 | return null; |
| 1357 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1358 | |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1359 | // "null" means the no-op crop, preserving the full input image |
| 1360 | if (cropHint == null) { |
| 1361 | cropHint = new Rect(0, 0, 0, 0); |
| 1362 | } else { |
| 1363 | if (cropHint.isEmpty() |
| 1364 | || cropHint.left < 0 |
| 1365 | || cropHint.top < 0) { |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1366 | throw new IllegalArgumentException("Invalid crop rect supplied: " + cropHint); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1370 | final int userId = UserHandle.getCallingUserId(); |
| 1371 | |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1372 | synchronized (mLock) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1373 | if (DEBUG) Slog.v(TAG, "setWallpaper which=0x" + Integer.toHexString(which)); |
| 1374 | WallpaperData wallpaper; |
| 1375 | |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 1376 | /* If we're setting system but not lock, and lock is currently sharing the system |
| 1377 | * wallpaper, we need to migrate that image over to being lock-only before |
| 1378 | * the caller here writes new bitmap data. |
| 1379 | */ |
| 1380 | if (which == FLAG_SYSTEM && mLockWallpaperMap.get(userId) == null) { |
| 1381 | if (DEBUG) { |
| 1382 | Slog.i(TAG, "Migrating system->lock to preserve"); |
| 1383 | } |
| 1384 | migrateSystemToLockWallpaperLocked(userId); |
| 1385 | } |
| 1386 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1387 | wallpaper = getWallpaperSafeLocked(userId, which); |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 1388 | final long ident = Binder.clearCallingIdentity(); |
| 1389 | try { |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1390 | ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name, wallpaper, extras); |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 1391 | if (pfd != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1392 | wallpaper.imageWallpaperPending = true; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1393 | wallpaper.whichPending = which; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1394 | wallpaper.setComplete = completion; |
| 1395 | wallpaper.cropHint.set(cropHint); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1396 | if ((which & FLAG_SYSTEM) != 0) { |
| 1397 | wallpaper.allowBackup = allowBackup; |
| 1398 | } |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 1399 | } |
| 1400 | return pfd; |
| 1401 | } finally { |
| 1402 | Binder.restoreCallingIdentity(ident); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1403 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | } |
| 1405 | } |
| 1406 | |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 1407 | private void migrateSystemToLockWallpaperLocked(int userId) { |
| 1408 | WallpaperData sysWP = mWallpaperMap.get(userId); |
| 1409 | if (sysWP == null) { |
| 1410 | if (DEBUG) { |
| 1411 | Slog.i(TAG, "No system wallpaper? Not tracking for lock-only"); |
| 1412 | } |
| 1413 | return; |
| 1414 | } |
| 1415 | |
| 1416 | // We know a-priori that there is no lock-only wallpaper currently |
| 1417 | WallpaperData lockWP = new WallpaperData(userId, |
| 1418 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); |
| 1419 | lockWP.wallpaperId = sysWP.wallpaperId; |
| 1420 | lockWP.cropHint.set(sysWP.cropHint); |
| 1421 | lockWP.width = sysWP.width; |
| 1422 | lockWP.height = sysWP.height; |
| 1423 | lockWP.allowBackup = false; |
| 1424 | |
| 1425 | // Migrate the bitmap files outright; no need to copy |
| 1426 | try { |
| 1427 | Os.rename(sysWP.wallpaperFile.getAbsolutePath(), lockWP.wallpaperFile.getAbsolutePath()); |
| 1428 | Os.rename(sysWP.cropFile.getAbsolutePath(), lockWP.cropFile.getAbsolutePath()); |
| 1429 | } catch (ErrnoException e) { |
| 1430 | Slog.e(TAG, "Can't migrate system wallpaper: " + e.getMessage()); |
| 1431 | lockWP.wallpaperFile.delete(); |
| 1432 | lockWP.cropFile.delete(); |
| 1433 | return; |
| 1434 | } |
| 1435 | |
| 1436 | mLockWallpaperMap.put(userId, lockWP); |
| 1437 | } |
| 1438 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1439 | ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper, |
| 1440 | Bundle extras) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1441 | if (name == null) name = ""; |
| 1442 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1443 | File dir = getWallpaperDir(wallpaper.userId); |
| 1444 | if (!dir.exists()) { |
| 1445 | dir.mkdir(); |
Dianne Hackborn | ebac48c | 2011-11-29 18:01:50 -0800 | [diff] [blame] | 1446 | FileUtils.setPermissions( |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1447 | dir.getPath(), |
Dianne Hackborn | ebac48c | 2011-11-29 18:01:50 -0800 | [diff] [blame] | 1448 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 1449 | -1, -1); |
| 1450 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1451 | ParcelFileDescriptor fd = ParcelFileDescriptor.open(wallpaper.wallpaperFile, |
Christopher Tate | 90f86ba | 2014-09-11 12:37:19 -0700 | [diff] [blame] | 1452 | MODE_CREATE|MODE_READ_WRITE|MODE_TRUNCATE); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1453 | if (!SELinux.restorecon(wallpaper.wallpaperFile)) { |
rpcraig | 554cb0c | 2012-07-05 06:41:43 -0400 | [diff] [blame] | 1454 | return null; |
| 1455 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1456 | wallpaper.name = name; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1457 | wallpaper.wallpaperId = makeWallpaperIdLocked(); |
| 1458 | if (extras != null) { |
| 1459 | extras.putInt(WallpaperManager.EXTRA_NEW_WALLPAPER_ID, wallpaper.wallpaperId); |
| 1460 | } |
| 1461 | if (DEBUG) { |
| 1462 | Slog.v(TAG, "updateWallpaperBitmapLocked() : id=" + wallpaper.wallpaperId |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1463 | + " name=" + name + " file=" + wallpaper.wallpaperFile.getName()); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1464 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1465 | return fd; |
| 1466 | } catch (FileNotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1467 | Slog.w(TAG, "Error setting wallpaper", e); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1468 | } |
| 1469 | return null; |
| 1470 | } |
| 1471 | |
Christopher Tate | d57d17c | 2016-03-25 13:41:46 -0700 | [diff] [blame] | 1472 | @Override |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 1473 | public void setWallpaperComponentChecked(ComponentName name, String callingPackage, |
| 1474 | int userId) { |
| 1475 | |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1476 | if (isWallpaperSupported(callingPackage) && isSetWallpaperAllowed(callingPackage)) { |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 1477 | setWallpaperComponent(name, userId); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | // ToDo: Remove this version of the function |
Christopher Tate | d57d17c | 2016-03-25 13:41:46 -0700 | [diff] [blame] | 1482 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1483 | public void setWallpaperComponent(ComponentName name) { |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 1484 | setWallpaperComponent(name, UserHandle.getCallingUserId()); |
| 1485 | } |
| 1486 | |
| 1487 | private void setWallpaperComponent(ComponentName name, int userId) { |
| 1488 | userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId, |
| 1489 | false /* all */, true /* full */, "changing live wallpaper", null /* pkg */); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1490 | checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT); |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 1491 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1492 | synchronized (mLock) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1493 | if (DEBUG) Slog.v(TAG, "setWallpaperComponent name=" + name); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1494 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 1495 | if (wallpaper == null) { |
| 1496 | throw new IllegalStateException("Wallpaper not yet initialized for user " + userId); |
| 1497 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1498 | final long ident = Binder.clearCallingIdentity(); |
| 1499 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1500 | wallpaper.imageWallpaperPending = false; |
Christopher Tate | d57d17c | 2016-03-25 13:41:46 -0700 | [diff] [blame] | 1501 | if (bindWallpaperComponentLocked(name, false, true, wallpaper, null)) { |
| 1502 | wallpaper.wallpaperId = makeWallpaperIdLocked(); |
Sunny Goyal | 0572e18 | 2016-03-31 11:05:51 -0700 | [diff] [blame] | 1503 | notifyCallbacksLocked(wallpaper); |
Christopher Tate | d57d17c | 2016-03-25 13:41:46 -0700 | [diff] [blame] | 1504 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1505 | } finally { |
| 1506 | Binder.restoreCallingIdentity(ident); |
| 1507 | } |
| 1508 | } |
| 1509 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1510 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1511 | boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1512 | boolean fromUser, WallpaperData wallpaper, IRemoteCallback reply) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1513 | if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName); |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1514 | // Has the component changed? |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 1515 | if (!force) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1516 | if (wallpaper.connection != null) { |
| 1517 | if (wallpaper.wallpaperComponent == null) { |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 1518 | if (componentName == null) { |
| 1519 | if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: still using default"); |
| 1520 | // Still using default wallpaper. |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1521 | return true; |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 1522 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1523 | } else if (wallpaper.wallpaperComponent.equals(componentName)) { |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 1524 | // Changing to same wallpaper. |
| 1525 | if (DEBUG) Slog.v(TAG, "same wallpaper"); |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1526 | return true; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1527 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1528 | } |
| 1529 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1530 | |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1531 | try { |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1532 | if (componentName == null) { |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 1533 | componentName = WallpaperManager.getDefaultWallpaperComponent(mContext); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1534 | if (componentName == null) { |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 1535 | // Fall back to static image wallpaper |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 1536 | componentName = mImageWallpaper; |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 1537 | //clearWallpaperComponentLocked(); |
| 1538 | //return; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1539 | if (DEBUG) Slog.v(TAG, "Using image wallpaper"); |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 1540 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1541 | } |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 1542 | int serviceUserId = wallpaper.userId; |
| 1543 | ServiceInfo si = mIPackageManager.getServiceInfo(componentName, |
| 1544 | PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS, serviceUserId); |
Christopher Tate | 9095220 | 2013-09-08 13:01:28 -0700 | [diff] [blame] | 1545 | if (si == null) { |
| 1546 | // The wallpaper component we're trying to use doesn't exist |
| 1547 | Slog.w(TAG, "Attempted wallpaper " + componentName + " is unavailable"); |
| 1548 | return false; |
| 1549 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1550 | if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1551 | String msg = "Selected service does not require " |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1552 | + android.Manifest.permission.BIND_WALLPAPER |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1553 | + ": " + componentName; |
| 1554 | if (fromUser) { |
| 1555 | throw new SecurityException(msg); |
| 1556 | } |
| 1557 | Slog.w(TAG, msg); |
| 1558 | return false; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1559 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1560 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1561 | WallpaperInfo wi = null; |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1562 | |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1563 | Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 1564 | if (componentName != null && !componentName.equals(mImageWallpaper)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1565 | // Make sure the selected service is actually a wallpaper service. |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 1566 | List<ResolveInfo> ris = |
| 1567 | mIPackageManager.queryIntentServices(intent, |
| 1568 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 1569 | PackageManager.GET_META_DATA, serviceUserId).getList(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1570 | for (int i=0; i<ris.size(); i++) { |
| 1571 | ServiceInfo rsi = ris.get(i).serviceInfo; |
| 1572 | if (rsi.name.equals(si.name) && |
| 1573 | rsi.packageName.equals(si.packageName)) { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1574 | try { |
| 1575 | wi = new WallpaperInfo(mContext, ris.get(i)); |
| 1576 | } catch (XmlPullParserException e) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1577 | if (fromUser) { |
| 1578 | throw new IllegalArgumentException(e); |
| 1579 | } |
| 1580 | Slog.w(TAG, e); |
| 1581 | return false; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1582 | } catch (IOException e) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1583 | if (fromUser) { |
| 1584 | throw new IllegalArgumentException(e); |
| 1585 | } |
| 1586 | Slog.w(TAG, e); |
| 1587 | return false; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1588 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1589 | break; |
| 1590 | } |
| 1591 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1592 | if (wi == null) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1593 | String msg = "Selected service is not a wallpaper: " |
| 1594 | + componentName; |
| 1595 | if (fromUser) { |
| 1596 | throw new SecurityException(msg); |
| 1597 | } |
| 1598 | Slog.w(TAG, msg); |
| 1599 | return false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1600 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1601 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1602 | |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1603 | // Bind the service! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1604 | if (DEBUG) Slog.v(TAG, "Binding to:" + componentName); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1605 | WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1606 | intent.setComponent(componentName); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 1607 | intent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 1608 | com.android.internal.R.string.wallpaper_binding_label); |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1609 | intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser( |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1610 | mContext, 0, |
| 1611 | Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER), |
| 1612 | mContext.getText(com.android.internal.R.string.chooser_wallpaper)), |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 1613 | 0, null, new UserHandle(serviceUserId))); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 1614 | if (!mContext.bindServiceAsUser(intent, newConn, |
Dianne Hackborn | d69e4c1 | 2015-04-24 09:54:54 -0700 | [diff] [blame] | 1615 | Context.BIND_AUTO_CREATE | Context.BIND_SHOWING_UI |
| 1616 | | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 1617 | new UserHandle(serviceUserId))) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1618 | String msg = "Unable to bind service: " |
| 1619 | + componentName; |
| 1620 | if (fromUser) { |
| 1621 | throw new IllegalArgumentException(msg); |
| 1622 | } |
| 1623 | Slog.w(TAG, msg); |
| 1624 | return false; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1625 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1626 | if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) { |
| 1627 | detachWallpaperLocked(mLastWallpaper); |
| 1628 | } |
| 1629 | wallpaper.wallpaperComponent = componentName; |
| 1630 | wallpaper.connection = newConn; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1631 | newConn.mReply = reply; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1632 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1633 | if (wallpaper.userId == mCurrentUserId) { |
| 1634 | if (DEBUG) |
| 1635 | Slog.v(TAG, "Adding window token: " + newConn.mToken); |
| 1636 | mIWindowManager.addWindowToken(newConn.mToken, |
| 1637 | WindowManager.LayoutParams.TYPE_WALLPAPER); |
| 1638 | mLastWallpaper = wallpaper; |
| 1639 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1640 | } catch (RemoteException e) { |
| 1641 | } |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 1642 | } catch (RemoteException e) { |
| 1643 | String msg = "Remote exception for " + componentName + "\n" + e; |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1644 | if (fromUser) { |
| 1645 | throw new IllegalArgumentException(msg); |
| 1646 | } |
| 1647 | Slog.w(TAG, msg); |
| 1648 | return false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1649 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1650 | return true; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1651 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1652 | |
| 1653 | void detachWallpaperLocked(WallpaperData wallpaper) { |
| 1654 | if (wallpaper.connection != null) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1655 | if (wallpaper.connection.mReply != null) { |
| 1656 | try { |
| 1657 | wallpaper.connection.mReply.sendResult(null); |
| 1658 | } catch (RemoteException e) { |
| 1659 | } |
| 1660 | wallpaper.connection.mReply = null; |
| 1661 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1662 | if (wallpaper.connection.mEngine != null) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1663 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1664 | wallpaper.connection.mEngine.destroy(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1665 | } catch (RemoteException e) { |
| 1666 | } |
| 1667 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1668 | mContext.unbindService(wallpaper.connection); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1669 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1670 | if (DEBUG) |
| 1671 | Slog.v(TAG, "Removing window token: " + wallpaper.connection.mToken); |
| 1672 | mIWindowManager.removeWindowToken(wallpaper.connection.mToken); |
Dianne Hackborn | e9e9bca | 2009-08-18 15:08:22 -0700 | [diff] [blame] | 1673 | } catch (RemoteException e) { |
| 1674 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1675 | wallpaper.connection.mService = null; |
| 1676 | wallpaper.connection.mEngine = null; |
| 1677 | wallpaper.connection = null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1678 | } |
| 1679 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1680 | |
| 1681 | void clearWallpaperComponentLocked(WallpaperData wallpaper) { |
| 1682 | wallpaper.wallpaperComponent = null; |
| 1683 | detachWallpaperLocked(wallpaper); |
| 1684 | } |
| 1685 | |
| 1686 | void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1687 | try { |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1688 | conn.mService.attach(conn, conn.mToken, |
| 1689 | WindowManager.LayoutParams.TYPE_WALLPAPER, false, |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1690 | wallpaper.width, wallpaper.height, wallpaper.padding); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1691 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1692 | Slog.w(TAG, "Failed attaching wallpaper; clearing", e); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1693 | if (!wallpaper.wallpaperUpdating) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1694 | bindWallpaperComponentLocked(null, false, false, wallpaper, null); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1695 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1696 | } |
| 1697 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1698 | |
| 1699 | private void notifyCallbacksLocked(WallpaperData wallpaper) { |
| 1700 | final int n = wallpaper.callbacks.beginBroadcast(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | for (int i = 0; i < n; i++) { |
| 1702 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1703 | wallpaper.callbacks.getBroadcastItem(i).onWallpaperChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1704 | } catch (RemoteException e) { |
| 1705 | |
| 1706 | // The RemoteCallbackList will take care of removing |
| 1707 | // the dead object for us. |
| 1708 | } |
| 1709 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1710 | wallpaper.callbacks.finishBroadcast(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 1712 | mContext.sendBroadcastAsUser(intent, new UserHandle(mCurrentUserId)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | private void checkPermission(String permission) { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1716 | if (PackageManager.PERMISSION_GRANTED!= mContext.checkCallingOrSelfPermission(permission)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1717 | throw new SecurityException("Access denied to process: " + Binder.getCallingPid() |
| 1718 | + ", must have permission " + permission); |
| 1719 | } |
| 1720 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1721 | |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1722 | /** |
| 1723 | * Certain user types do not support wallpapers (e.g. managed profiles). The check is |
| 1724 | * implemented through through the OP_WRITE_WALLPAPER AppOp. |
| 1725 | */ |
| 1726 | public boolean isWallpaperSupported(String callingPackage) { |
| 1727 | return mAppOpsManager.checkOpNoThrow(AppOpsManager.OP_WRITE_WALLPAPER, Binder.getCallingUid(), |
| 1728 | callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 1729 | } |
| 1730 | |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1731 | @Override |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1732 | public boolean isSetWallpaperAllowed(String callingPackage) { |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1733 | final PackageManager pm = mContext.getPackageManager(); |
| 1734 | String[] uidPackages = pm.getPackagesForUid(Binder.getCallingUid()); |
| 1735 | boolean uidMatchPackage = Arrays.asList(uidPackages).contains(callingPackage); |
| 1736 | if (!uidMatchPackage) { |
| 1737 | return false; // callingPackage was faked. |
| 1738 | } |
| 1739 | |
| 1740 | final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); |
| 1741 | if (dpm.isDeviceOwnerApp(callingPackage) || dpm.isProfileOwnerApp(callingPackage)) { |
| 1742 | return true; |
| 1743 | } |
| 1744 | final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
| 1745 | return !um.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER); |
| 1746 | } |
| 1747 | |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1748 | @Override |
| 1749 | public boolean isWallpaperBackupEligible(int userId) { |
| 1750 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 1751 | throw new SecurityException("Only the system may call isWallpaperBackupEligible"); |
| 1752 | } |
| 1753 | |
| 1754 | WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); |
| 1755 | return (wallpaper != null) ? wallpaper.allowBackup : false; |
| 1756 | } |
| 1757 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1758 | private static JournaledFile makeJournaledFile(int userId) { |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 1759 | final String base = new File(getWallpaperDir(userId), WALLPAPER_INFO).getAbsolutePath(); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1760 | return new JournaledFile(new File(base), new File(base + ".tmp")); |
| 1761 | } |
| 1762 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1763 | private void saveSettingsLocked(int userId) { |
| 1764 | JournaledFile journal = makeJournaledFile(userId); |
| 1765 | FileOutputStream fstream = null; |
| 1766 | BufferedOutputStream stream = null; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1767 | try { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1768 | XmlSerializer out = new FastXmlSerializer(); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1769 | fstream = new FileOutputStream(journal.chooseForWrite(), false); |
| 1770 | stream = new BufferedOutputStream(fstream); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 1771 | out.setOutput(stream, StandardCharsets.UTF_8.name()); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1772 | out.startDocument(null, true); |
| 1773 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1774 | WallpaperData wallpaper; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1775 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1776 | wallpaper = mWallpaperMap.get(userId); |
| 1777 | if (wallpaper != null) { |
| 1778 | writeWallpaperAttributes(out, "wp", wallpaper); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1779 | } |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1780 | wallpaper = mLockWallpaperMap.get(userId); |
| 1781 | if (wallpaper != null) { |
| 1782 | writeWallpaperAttributes(out, "kwp", wallpaper); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1783 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1784 | |
| 1785 | out.endDocument(); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1786 | |
| 1787 | stream.flush(); // also flushes fstream |
| 1788 | FileUtils.sync(fstream); |
| 1789 | stream.close(); // also closes fstream |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1790 | journal.commit(); |
| 1791 | } catch (IOException e) { |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1792 | IoUtils.closeQuietly(stream); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1793 | journal.rollback(); |
| 1794 | } |
| 1795 | } |
| 1796 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1797 | private void writeWallpaperAttributes(XmlSerializer out, String tag, WallpaperData wallpaper) |
| 1798 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 1799 | out.startTag(null, tag); |
| 1800 | out.attribute(null, "id", Integer.toString(wallpaper.wallpaperId)); |
| 1801 | out.attribute(null, "width", Integer.toString(wallpaper.width)); |
| 1802 | out.attribute(null, "height", Integer.toString(wallpaper.height)); |
| 1803 | |
| 1804 | out.attribute(null, "cropLeft", Integer.toString(wallpaper.cropHint.left)); |
| 1805 | out.attribute(null, "cropTop", Integer.toString(wallpaper.cropHint.top)); |
| 1806 | out.attribute(null, "cropRight", Integer.toString(wallpaper.cropHint.right)); |
| 1807 | out.attribute(null, "cropBottom", Integer.toString(wallpaper.cropHint.bottom)); |
| 1808 | |
| 1809 | if (wallpaper.padding.left != 0) { |
| 1810 | out.attribute(null, "paddingLeft", Integer.toString(wallpaper.padding.left)); |
| 1811 | } |
| 1812 | if (wallpaper.padding.top != 0) { |
| 1813 | out.attribute(null, "paddingTop", Integer.toString(wallpaper.padding.top)); |
| 1814 | } |
| 1815 | if (wallpaper.padding.right != 0) { |
| 1816 | out.attribute(null, "paddingRight", Integer.toString(wallpaper.padding.right)); |
| 1817 | } |
| 1818 | if (wallpaper.padding.bottom != 0) { |
| 1819 | out.attribute(null, "paddingBottom", Integer.toString(wallpaper.padding.bottom)); |
| 1820 | } |
| 1821 | |
| 1822 | out.attribute(null, "name", wallpaper.name); |
| 1823 | if (wallpaper.wallpaperComponent != null |
| 1824 | && !wallpaper.wallpaperComponent.equals(mImageWallpaper)) { |
| 1825 | out.attribute(null, "component", |
| 1826 | wallpaper.wallpaperComponent.flattenToShortString()); |
| 1827 | } |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1828 | |
| 1829 | if (wallpaper.allowBackup) { |
| 1830 | out.attribute(null, "backup", "true"); |
| 1831 | } |
| 1832 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 1833 | out.endTag(null, tag); |
| 1834 | } |
| 1835 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1836 | private void migrateFromOld() { |
| 1837 | File oldWallpaper = new File(WallpaperBackupHelper.WALLPAPER_IMAGE_KEY); |
| 1838 | File oldInfo = new File(WallpaperBackupHelper.WALLPAPER_INFO_KEY); |
| 1839 | if (oldWallpaper.exists()) { |
| 1840 | File newWallpaper = new File(getWallpaperDir(0), WALLPAPER); |
| 1841 | oldWallpaper.renameTo(newWallpaper); |
| 1842 | } |
| 1843 | if (oldInfo.exists()) { |
| 1844 | File newInfo = new File(getWallpaperDir(0), WALLPAPER_INFO); |
| 1845 | oldInfo.renameTo(newInfo); |
| 1846 | } |
| 1847 | } |
| 1848 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1849 | private int getAttributeInt(XmlPullParser parser, String name, int defValue) { |
| 1850 | String value = parser.getAttributeValue(null, name); |
| 1851 | if (value == null) { |
| 1852 | return defValue; |
| 1853 | } |
| 1854 | return Integer.parseInt(value); |
| 1855 | } |
| 1856 | |
Xiaohui Chen | ac53194 | 2015-05-13 13:20:52 -0700 | [diff] [blame] | 1857 | /** |
| 1858 | * Sometimes it is expected the wallpaper map may not have a user's data. E.g. This could |
| 1859 | * happen during user switch. The async user switch observer may not have received |
| 1860 | * the event yet. We use this safe method when we don't care about this ordering and just |
| 1861 | * want to update the data. The data is going to be applied when the user switch observer |
| 1862 | * is eventually executed. |
| 1863 | */ |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1864 | private WallpaperData getWallpaperSafeLocked(int userId, int which) { |
| 1865 | // We're setting either just system (work with the system wallpaper), |
| 1866 | // both (also work with the system wallpaper), or just the lock |
| 1867 | // wallpaper (update against the existing lock wallpaper if any). |
| 1868 | // Combined or just-system operations use the 'system' WallpaperData |
| 1869 | // for this use; lock-only operations use the dedicated one. |
| 1870 | final SparseArray<WallpaperData> whichSet = |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1871 | (which == FLAG_LOCK) ? mLockWallpaperMap : mWallpaperMap; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1872 | WallpaperData wallpaper = whichSet.get(userId); |
Xiaohui Chen | ac53194 | 2015-05-13 13:20:52 -0700 | [diff] [blame] | 1873 | if (wallpaper == null) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1874 | // common case, this is the first lookup post-boot of the system or |
| 1875 | // unified lock, so we bring up the saved state lazily now and recheck. |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1876 | loadSettingsLocked(userId, false); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1877 | wallpaper = whichSet.get(userId); |
| 1878 | // if it's still null here, this is a lock-only operation and there is not |
| 1879 | // yet a lock-only wallpaper set for this user, so we need to establish |
| 1880 | // it now. |
| 1881 | if (wallpaper == null) { |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1882 | if (which == FLAG_LOCK) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1883 | wallpaper = new WallpaperData(userId, |
| 1884 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); |
| 1885 | mLockWallpaperMap.put(userId, wallpaper); |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 1886 | ensureSaneWallpaperData(wallpaper); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1887 | } else { |
| 1888 | // sanity fallback: we're in bad shape, but establishing a known |
| 1889 | // valid system+lock WallpaperData will keep us from dying. |
| 1890 | Slog.wtf(TAG, "Didn't find wallpaper in non-lock case!"); |
| 1891 | wallpaper = new WallpaperData(userId, WALLPAPER, WALLPAPER_CROP); |
| 1892 | mWallpaperMap.put(userId, wallpaper); |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 1893 | ensureSaneWallpaperData(wallpaper); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1894 | } |
| 1895 | } |
Xiaohui Chen | ac53194 | 2015-05-13 13:20:52 -0700 | [diff] [blame] | 1896 | } |
| 1897 | return wallpaper; |
| 1898 | } |
| 1899 | |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1900 | private void loadSettingsLocked(int userId, boolean keepDimensionHints) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1901 | if (DEBUG) Slog.v(TAG, "loadSettingsLocked"); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1902 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1903 | JournaledFile journal = makeJournaledFile(userId); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1904 | FileInputStream stream = null; |
| 1905 | File file = journal.chooseForRead(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1906 | if (!file.exists()) { |
| 1907 | // This should only happen one time, when upgrading from a legacy system |
| 1908 | migrateFromOld(); |
| 1909 | } |
| 1910 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 1911 | if (wallpaper == null) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1912 | wallpaper = new WallpaperData(userId, WALLPAPER, WALLPAPER_CROP); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1913 | wallpaper.allowBackup = true; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1914 | mWallpaperMap.put(userId, wallpaper); |
Christopher Tate | 41297ff | 2016-03-10 16:46:15 -0800 | [diff] [blame] | 1915 | if (!wallpaper.cropExists()) { |
| 1916 | generateCrop(wallpaper); |
| 1917 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1918 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1919 | boolean success = false; |
| 1920 | try { |
| 1921 | stream = new FileInputStream(file); |
| 1922 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 1923 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1924 | |
| 1925 | int type; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1926 | do { |
| 1927 | type = parser.next(); |
| 1928 | if (type == XmlPullParser.START_TAG) { |
| 1929 | String tag = parser.getName(); |
| 1930 | if ("wp".equals(tag)) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1931 | // Common to system + lock wallpapers |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1932 | parseWallpaperAttributes(parser, wallpaper, keepDimensionHints); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1933 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1934 | // A system wallpaper might also be a live wallpaper |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1935 | String comp = parser.getAttributeValue(null, "component"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1936 | wallpaper.nextWallpaperComponent = comp != null |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1937 | ? ComponentName.unflattenFromString(comp) |
| 1938 | : null; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1939 | if (wallpaper.nextWallpaperComponent == null |
| 1940 | || "android".equals(wallpaper.nextWallpaperComponent |
| 1941 | .getPackageName())) { |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 1942 | wallpaper.nextWallpaperComponent = mImageWallpaper; |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 1943 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1944 | |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1945 | if (DEBUG) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1946 | Slog.v(TAG, "mWidth:" + wallpaper.width); |
| 1947 | Slog.v(TAG, "mHeight:" + wallpaper.height); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1948 | Slog.v(TAG, "cropRect:" + wallpaper.cropHint); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1949 | Slog.v(TAG, "mName:" + wallpaper.name); |
| 1950 | Slog.v(TAG, "mNextWallpaperComponent:" |
| 1951 | + wallpaper.nextWallpaperComponent); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 1952 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1953 | } else if ("kwp".equals(tag)) { |
| 1954 | // keyguard-specific wallpaper for this user |
| 1955 | WallpaperData lockWallpaper = mLockWallpaperMap.get(userId); |
| 1956 | if (lockWallpaper == null) { |
| 1957 | lockWallpaper = new WallpaperData(userId, |
| 1958 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); |
| 1959 | mLockWallpaperMap.put(userId, lockWallpaper); |
| 1960 | } |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1961 | parseWallpaperAttributes(parser, lockWallpaper, false); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1962 | } |
| 1963 | } |
| 1964 | } while (type != XmlPullParser.END_DOCUMENT); |
| 1965 | success = true; |
Dianne Hackborn | 13579ed | 2012-11-28 18:05:36 -0800 | [diff] [blame] | 1966 | } catch (FileNotFoundException e) { |
| 1967 | Slog.w(TAG, "no current wallpaper -- first boot?"); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1968 | } catch (NullPointerException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1969 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1970 | } catch (NumberFormatException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1971 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1972 | } catch (XmlPullParserException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1973 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1974 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1975 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1976 | } catch (IndexOutOfBoundsException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1977 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1978 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1979 | IoUtils.closeQuietly(stream); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1980 | |
| 1981 | if (!success) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1982 | wallpaper.width = -1; |
| 1983 | wallpaper.height = -1; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1984 | wallpaper.cropHint.set(0, 0, 0, 0); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1985 | wallpaper.padding.set(0, 0, 0, 0); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1986 | wallpaper.name = ""; |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 1987 | |
| 1988 | mLockWallpaperMap.remove(userId); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1989 | } else { |
| 1990 | if (wallpaper.wallpaperId <= 0) { |
| 1991 | wallpaper.wallpaperId = makeWallpaperIdLocked(); |
| 1992 | if (DEBUG) { |
| 1993 | Slog.w(TAG, "Didn't set wallpaper id in loadSettingsLocked(" + userId |
| 1994 | + "); now " + wallpaper.wallpaperId); |
| 1995 | } |
| 1996 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 1997 | } |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 1998 | |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 1999 | ensureSaneWallpaperData(wallpaper); |
| 2000 | WallpaperData lockWallpaper = mLockWallpaperMap.get(userId); |
| 2001 | if (lockWallpaper != null) { |
| 2002 | ensureSaneWallpaperData(lockWallpaper); |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | private void ensureSaneWallpaperData(WallpaperData wallpaper) { |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 2007 | // We always want to have some reasonable width hint. |
John Spurlock | 7ea91ec | 2013-11-04 13:48:38 -0500 | [diff] [blame] | 2008 | int baseSize = getMaximumSizeDimension(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2009 | if (wallpaper.width < baseSize) { |
| 2010 | wallpaper.width = baseSize; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 2011 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2012 | if (wallpaper.height < baseSize) { |
| 2013 | wallpaper.height = baseSize; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 2014 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2015 | // and crop, if not previously specified |
| 2016 | if (wallpaper.cropHint.width() <= 0 |
| 2017 | || wallpaper.cropHint.height() <= 0) { |
| 2018 | wallpaper.cropHint.set(0, 0, wallpaper.width, wallpaper.height); |
| 2019 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2022 | private void parseWallpaperAttributes(XmlPullParser parser, WallpaperData wallpaper, |
| 2023 | boolean keepDimensionHints) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2024 | final String idString = parser.getAttributeValue(null, "id"); |
| 2025 | if (idString != null) { |
| 2026 | final int id = wallpaper.wallpaperId = Integer.parseInt(idString); |
| 2027 | if (id > mWallpaperId) { |
| 2028 | mWallpaperId = id; |
| 2029 | } |
| 2030 | } else { |
| 2031 | wallpaper.wallpaperId = makeWallpaperIdLocked(); |
| 2032 | } |
| 2033 | |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2034 | if (!keepDimensionHints) { |
| 2035 | wallpaper.width = Integer.parseInt(parser.getAttributeValue(null, "width")); |
| 2036 | wallpaper.height = Integer.parseInt(parser |
| 2037 | .getAttributeValue(null, "height")); |
| 2038 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2039 | wallpaper.cropHint.left = getAttributeInt(parser, "cropLeft", 0); |
| 2040 | wallpaper.cropHint.top = getAttributeInt(parser, "cropTop", 0); |
| 2041 | wallpaper.cropHint.right = getAttributeInt(parser, "cropRight", 0); |
| 2042 | wallpaper.cropHint.bottom = getAttributeInt(parser, "cropBottom", 0); |
| 2043 | wallpaper.padding.left = getAttributeInt(parser, "paddingLeft", 0); |
| 2044 | wallpaper.padding.top = getAttributeInt(parser, "paddingTop", 0); |
| 2045 | wallpaper.padding.right = getAttributeInt(parser, "paddingRight", 0); |
| 2046 | wallpaper.padding.bottom = getAttributeInt(parser, "paddingBottom", 0); |
| 2047 | wallpaper.name = parser.getAttributeValue(null, "name"); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2048 | wallpaper.allowBackup = "true".equals(parser.getAttributeValue(null, "backup")); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2049 | } |
| 2050 | |
John Spurlock | 7ea91ec | 2013-11-04 13:48:38 -0500 | [diff] [blame] | 2051 | private int getMaximumSizeDimension() { |
| 2052 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
| 2053 | Display d = wm.getDefaultDisplay(); |
| 2054 | return d.getMaximumSizeDimension(); |
| 2055 | } |
| 2056 | |
Brad Fitzpatrick | 194b19a | 2010-09-14 11:30:29 -0700 | [diff] [blame] | 2057 | // Called by SystemBackupAgent after files are restored to disk. |
Amith Yamasani | 09e9cdc | 2013-11-06 14:54:50 -0800 | [diff] [blame] | 2058 | public void settingsRestored() { |
| 2059 | // Verify caller is the system |
| 2060 | if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) { |
| 2061 | throw new RuntimeException("settingsRestored() can only be called from the system process"); |
| 2062 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2063 | // TODO: If necessary, make it work for secondary users as well. This currently assumes |
| 2064 | // restores only to the primary user |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2065 | if (DEBUG) Slog.v(TAG, "settingsRestored"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2066 | WallpaperData wallpaper = null; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2067 | boolean success = false; |
| 2068 | synchronized (mLock) { |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2069 | loadSettingsLocked(UserHandle.USER_SYSTEM, false); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2070 | wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2071 | wallpaper.wallpaperId = makeWallpaperIdLocked(); // always bump id at restore |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2072 | wallpaper.allowBackup = true; // by definition if it was restored |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2073 | if (wallpaper.nextWallpaperComponent != null |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 2074 | && !wallpaper.nextWallpaperComponent.equals(mImageWallpaper)) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2075 | if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2076 | wallpaper, null)) { |
Christopher Tate | e3ab4d0 | 2009-12-16 14:03:31 -0800 | [diff] [blame] | 2077 | // No such live wallpaper or other failure; fall back to the default |
| 2078 | // live wallpaper (since the profile being restored indicated that the |
| 2079 | // user had selected a live rather than static one). |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2080 | bindWallpaperComponentLocked(null, false, false, wallpaper, null); |
Christopher Tate | e3ab4d0 | 2009-12-16 14:03:31 -0800 | [diff] [blame] | 2081 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2082 | success = true; |
| 2083 | } else { |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 2084 | // If there's a wallpaper name, we use that. If that can't be loaded, then we |
| 2085 | // use the default. |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2086 | if ("".equals(wallpaper.name)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2087 | if (DEBUG) Slog.v(TAG, "settingsRestored: name is empty"); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 2088 | success = true; |
| 2089 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2090 | if (DEBUG) Slog.v(TAG, "settingsRestored: attempting to restore named resource"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2091 | success = restoreNamedResourceLocked(wallpaper); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 2092 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2093 | if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success |
| 2094 | + " id=" + wallpaper.wallpaperId); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 2095 | if (success) { |
Christopher Tate | 41297ff | 2016-03-10 16:46:15 -0800 | [diff] [blame] | 2096 | generateCrop(wallpaper); // based on the new image + metadata |
| 2097 | bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, true, false, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2098 | wallpaper, null); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 2099 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | if (!success) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2104 | Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'"); |
| 2105 | wallpaper.name = ""; |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2106 | getWallpaperDir(UserHandle.USER_SYSTEM).delete(); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2107 | } |
Brad Fitzpatrick | 194b19a | 2010-09-14 11:30:29 -0700 | [diff] [blame] | 2108 | |
| 2109 | synchronized (mLock) { |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2110 | saveSettingsLocked(UserHandle.USER_SYSTEM); |
Brad Fitzpatrick | 194b19a | 2010-09-14 11:30:29 -0700 | [diff] [blame] | 2111 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2114 | // Restore the named resource bitmap to both source + crop files |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2115 | boolean restoreNamedResourceLocked(WallpaperData wallpaper) { |
| 2116 | if (wallpaper.name.length() > 4 && "res:".equals(wallpaper.name.substring(0, 4))) { |
| 2117 | String resName = wallpaper.name.substring(4); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2118 | |
| 2119 | String pkg = null; |
| 2120 | int colon = resName.indexOf(':'); |
| 2121 | if (colon > 0) { |
| 2122 | pkg = resName.substring(0, colon); |
| 2123 | } |
| 2124 | |
| 2125 | String ident = null; |
| 2126 | int slash = resName.lastIndexOf('/'); |
| 2127 | if (slash > 0) { |
| 2128 | ident = resName.substring(slash+1); |
| 2129 | } |
| 2130 | |
| 2131 | String type = null; |
| 2132 | if (colon > 0 && slash > 0 && (slash-colon) > 1) { |
| 2133 | type = resName.substring(colon+1, slash); |
| 2134 | } |
| 2135 | |
| 2136 | if (pkg != null && ident != null && type != null) { |
| 2137 | int resId = -1; |
| 2138 | InputStream res = null; |
| 2139 | FileOutputStream fos = null; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2140 | FileOutputStream cos = null; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2141 | try { |
| 2142 | Context c = mContext.createPackageContext(pkg, Context.CONTEXT_RESTRICTED); |
| 2143 | Resources r = c.getResources(); |
| 2144 | resId = r.getIdentifier(resName, null, null); |
| 2145 | if (resId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2146 | Slog.e(TAG, "couldn't resolve identifier pkg=" + pkg + " type=" + type |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2147 | + " ident=" + ident); |
| 2148 | return false; |
| 2149 | } |
| 2150 | |
| 2151 | res = r.openRawResource(resId); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2152 | if (wallpaper.wallpaperFile.exists()) { |
| 2153 | wallpaper.wallpaperFile.delete(); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2154 | wallpaper.cropFile.delete(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 2155 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2156 | fos = new FileOutputStream(wallpaper.wallpaperFile); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2157 | cos = new FileOutputStream(wallpaper.cropFile); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2158 | |
| 2159 | byte[] buffer = new byte[32768]; |
| 2160 | int amt; |
| 2161 | while ((amt=res.read(buffer)) > 0) { |
| 2162 | fos.write(buffer, 0, amt); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2163 | cos.write(buffer, 0, amt); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2164 | } |
| 2165 | // mWallpaperObserver will notice the close and send the change broadcast |
| 2166 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2167 | Slog.v(TAG, "Restored wallpaper: " + resName); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2168 | return true; |
| 2169 | } catch (NameNotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2170 | Slog.e(TAG, "Package name " + pkg + " not found"); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2171 | } catch (Resources.NotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2172 | Slog.e(TAG, "Resource not found: " + resId); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2173 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2174 | Slog.e(TAG, "IOException while restoring wallpaper ", e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2175 | } finally { |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2176 | IoUtils.closeQuietly(res); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2177 | if (fos != null) { |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 2178 | FileUtils.sync(fos); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2179 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2180 | if (cos != null) { |
| 2181 | FileUtils.sync(cos); |
| 2182 | } |
| 2183 | IoUtils.closeQuietly(fos); |
| 2184 | IoUtils.closeQuietly(cos); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | } |
| 2188 | return false; |
| 2189 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2190 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2191 | @Override |
| 2192 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 2193 | if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 2194 | != PackageManager.PERMISSION_GRANTED) { |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2195 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2196 | pw.println("Permission Denial: can't dump wallpaper service from from pid=" |
| 2197 | + Binder.getCallingPid() |
| 2198 | + ", uid=" + Binder.getCallingUid()); |
| 2199 | return; |
| 2200 | } |
| 2201 | |
| 2202 | synchronized (mLock) { |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 2203 | pw.println("System wallpaper state:"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2204 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 2205 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2206 | pw.print(" User "); pw.print(wallpaper.userId); |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 2207 | pw.print(": id="); pw.println(wallpaper.wallpaperId); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2208 | pw.print(" mWidth="); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2209 | pw.print(wallpaper.width); |
| 2210 | pw.print(" mHeight="); |
| 2211 | pw.println(wallpaper.height); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2212 | pw.print(" mCropHint="); pw.println(wallpaper.cropHint); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2213 | pw.print(" mPadding="); pw.println(wallpaper.padding); |
| 2214 | pw.print(" mName="); pw.println(wallpaper.name); |
| 2215 | pw.print(" mWallpaperComponent="); pw.println(wallpaper.wallpaperComponent); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2216 | if (wallpaper.connection != null) { |
| 2217 | WallpaperConnection conn = wallpaper.connection; |
| 2218 | pw.print(" Wallpaper connection "); |
| 2219 | pw.print(conn); |
| 2220 | pw.println(":"); |
| 2221 | if (conn.mInfo != null) { |
| 2222 | pw.print(" mInfo.component="); |
| 2223 | pw.println(conn.mInfo.getComponent()); |
| 2224 | } |
| 2225 | pw.print(" mToken="); |
| 2226 | pw.println(conn.mToken); |
| 2227 | pw.print(" mService="); |
| 2228 | pw.println(conn.mService); |
| 2229 | pw.print(" mEngine="); |
| 2230 | pw.println(conn.mEngine); |
| 2231 | pw.print(" mLastDiedTime="); |
| 2232 | pw.println(wallpaper.lastDiedTime - SystemClock.uptimeMillis()); |
| 2233 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2234 | } |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 2235 | pw.println("Lock wallpaper state:"); |
| 2236 | for (int i = 0; i < mLockWallpaperMap.size(); i++) { |
| 2237 | WallpaperData wallpaper = mLockWallpaperMap.valueAt(i); |
| 2238 | pw.print(" User "); pw.print(wallpaper.userId); |
| 2239 | pw.print(": id="); pw.println(wallpaper.wallpaperId); |
| 2240 | pw.print(" mWidth="); pw.print(wallpaper.width); |
| 2241 | pw.print(" mHeight="); pw.println(wallpaper.height); |
| 2242 | pw.print(" mCropHint="); pw.println(wallpaper.cropHint); |
| 2243 | pw.print(" mPadding="); pw.println(wallpaper.padding); |
| 2244 | pw.print(" mName="); pw.println(wallpaper.name); |
| 2245 | } |
| 2246 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2247 | } |
| 2248 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2249 | } |