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