The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Amith Yamasani | 09e9cdc | 2013-11-06 14:54:50 -0800 | [diff] [blame] | 17 | package com.android.server.wallpaper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 19 | import static android.app.WallpaperManager.FLAG_LOCK; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 20 | import static android.app.WallpaperManager.FLAG_SYSTEM; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 21 | import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AUTO; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 22 | import static android.os.ParcelFileDescriptor.MODE_CREATE; |
| 23 | import static android.os.ParcelFileDescriptor.MODE_READ_ONLY; |
| 24 | import static android.os.ParcelFileDescriptor.MODE_READ_WRITE; |
| 25 | import static android.os.ParcelFileDescriptor.MODE_TRUNCATE; |
Wale Ogunwale | ac2561e | 2016-11-01 15:43:46 -0700 | [diff] [blame] | 26 | import static android.view.Display.DEFAULT_DISPLAY; |
| 27 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Christopher Tate | 111bd4a | 2009-06-24 17:29:38 -0700 | [diff] [blame] | 28 | |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 29 | import android.annotation.NonNull; |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 30 | import android.app.ActivityManager; |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 31 | import android.app.AppGlobals; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 32 | import android.app.AppOpsManager; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 33 | import android.app.IWallpaperManager; |
| 34 | import android.app.IWallpaperManagerCallback; |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 35 | import android.app.PendingIntent; |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 36 | import android.app.UserSwitchObserver; |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 37 | import android.app.WallpaperColors; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 38 | import android.app.WallpaperInfo; |
Jeff Sharkey | 28f0877 | 2014-04-16 09:41:58 -0700 | [diff] [blame] | 39 | import android.app.WallpaperManager; |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 40 | import android.app.WallpaperManager.SetWallpaperFlags; |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 41 | import android.app.admin.DevicePolicyManager; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 42 | import android.app.backup.WallpaperBackupHelper; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 43 | import android.content.BroadcastReceiver; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 44 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.content.Context; |
| 46 | import android.content.Intent; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 47 | import android.content.IntentFilter; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 48 | import android.content.ServiceConnection; |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 49 | import android.content.pm.IPackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | import android.content.pm.PackageManager; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 51 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 52 | import android.content.pm.ResolveInfo; |
| 53 | import android.content.pm.ServiceInfo; |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 54 | import android.content.pm.UserInfo; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 55 | import android.content.res.Resources; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 56 | import android.graphics.Bitmap; |
| 57 | import android.graphics.BitmapFactory; |
| 58 | import android.graphics.BitmapRegionDecoder; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 59 | import android.graphics.Color; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 60 | import android.graphics.Rect; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 61 | import android.hardware.display.DisplayManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | import android.os.Binder; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 63 | import android.os.Bundle; |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 64 | import android.os.Debug; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 65 | import android.os.Environment; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 66 | import android.os.FileObserver; |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 67 | import android.os.FileUtils; |
Christopher Tate | c349e59f | 2017-05-05 17:37:43 -0700 | [diff] [blame] | 68 | import android.os.Handler; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 69 | import android.os.IBinder; |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 70 | import android.os.IInterface; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 71 | import android.os.IRemoteCallback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | import android.os.ParcelFileDescriptor; |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 73 | import android.os.Process; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | import android.os.RemoteCallbackList; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 75 | import android.os.RemoteException; |
rpcraig | 554cb0c | 2012-07-05 06:41:43 -0400 | [diff] [blame] | 76 | import android.os.SELinux; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 77 | import android.os.SystemClock; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 78 | import android.os.UserHandle; |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 79 | import android.os.UserManager; |
Bookatz | cfc5d19 | 2019-11-05 17:25:53 -0800 | [diff] [blame] | 80 | import android.os.UserManagerInternal; |
Jeff Sharkey | 859856d | 2019-03-25 11:44:11 -0600 | [diff] [blame] | 81 | import android.os.storage.StorageManager; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 82 | import android.service.wallpaper.IWallpaperConnection; |
| 83 | import android.service.wallpaper.IWallpaperEngine; |
| 84 | import android.service.wallpaper.IWallpaperService; |
| 85 | import android.service.wallpaper.WallpaperService; |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 86 | import android.system.ErrnoException; |
| 87 | import android.system.Os; |
Filip Gruszczynski | 5dcc3ac | 2014-10-13 15:51:39 -0700 | [diff] [blame] | 88 | import android.util.EventLog; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 89 | import android.util.Slog; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 90 | import android.util.SparseArray; |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 91 | import android.util.SparseBooleanArray; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 92 | import android.util.Xml; |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 93 | import android.view.Display; |
Valentin Iftime | 3047bb1 | 2018-12-28 17:02:19 +0100 | [diff] [blame] | 94 | import android.view.DisplayInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 96 | import com.android.internal.R; |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 97 | import com.android.internal.annotations.VisibleForTesting; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 98 | import com.android.internal.content.PackageMonitor; |
Christopher Tate | 190e853 | 2016-07-11 11:35:34 -0700 | [diff] [blame] | 99 | import com.android.internal.os.BackgroundThread; |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 100 | import com.android.internal.util.DumpUtils; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 101 | import com.android.internal.util.FastXmlSerializer; |
| 102 | import com.android.internal.util.JournaledFile; |
| 103 | import com.android.server.EventLogTags; |
Adrian Roos | c3f915e | 2016-09-06 11:40:53 -0700 | [diff] [blame] | 104 | import com.android.server.FgThread; |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 105 | import com.android.server.LocalServices; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 106 | import com.android.server.SystemService; |
Felipe Leme | 4e2cbb5 | 2019-12-02 16:46:49 -0800 | [diff] [blame] | 107 | import com.android.server.utils.TimingsTraceAndSlog; |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 108 | import com.android.server.wm.WindowManagerInternal; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 109 | |
| 110 | import libcore.io.IoUtils; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 111 | |
| 112 | import org.xmlpull.v1.XmlPullParser; |
| 113 | import org.xmlpull.v1.XmlPullParserException; |
| 114 | import org.xmlpull.v1.XmlSerializer; |
| 115 | |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 116 | import java.io.BufferedOutputStream; |
| 117 | import java.io.File; |
| 118 | import java.io.FileDescriptor; |
| 119 | import java.io.FileInputStream; |
| 120 | import java.io.FileNotFoundException; |
| 121 | import java.io.FileOutputStream; |
| 122 | import java.io.IOException; |
| 123 | import java.io.InputStream; |
| 124 | import java.io.PrintWriter; |
| 125 | import java.nio.charset.StandardCharsets; |
Lucas Dupin | fb3ab2a | 2017-08-08 14:17:30 -0400 | [diff] [blame] | 126 | import java.util.ArrayList; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 127 | import java.util.Arrays; |
| 128 | import java.util.List; |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 129 | import java.util.Objects; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 130 | import java.util.function.Consumer; |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 131 | import java.util.function.Predicate; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 132 | |
Daichi Hirono | 4bbf852 | 2017-12-06 10:34:18 +0900 | [diff] [blame] | 133 | public class WallpaperManagerService extends IWallpaperManager.Stub |
| 134 | implements IWallpaperManagerService { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 135 | private static final String TAG = "WallpaperManagerService"; |
| 136 | private static final boolean DEBUG = false; |
| 137 | private static final boolean DEBUG_LIVE = true; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 138 | |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 139 | // This 100MB limitation is defined in RecordingCanvas. |
| 140 | private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; |
| 141 | |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 142 | public static class Lifecycle extends SystemService { |
Daichi Hirono | 4bbf852 | 2017-12-06 10:34:18 +0900 | [diff] [blame] | 143 | private IWallpaperManagerService mService; |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 144 | |
| 145 | public Lifecycle(Context context) { |
| 146 | super(context); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void onStart() { |
Daichi Hirono | 4bbf852 | 2017-12-06 10:34:18 +0900 | [diff] [blame] | 151 | try { |
| 152 | final Class<? extends IWallpaperManagerService> klass = |
| 153 | (Class<? extends IWallpaperManagerService>)Class.forName( |
| 154 | getContext().getResources().getString( |
| 155 | R.string.config_wallpaperManagerServiceName)); |
| 156 | mService = klass.getConstructor(Context.class).newInstance(getContext()); |
| 157 | publishBinderService(Context.WALLPAPER_SERVICE, mService); |
| 158 | } catch (Exception exp) { |
| 159 | Slog.wtf(TAG, "Failed to instantiate WallpaperManagerService", exp); |
| 160 | } |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void onBootPhase(int phase) { |
Daichi Hirono | 4bbf852 | 2017-12-06 10:34:18 +0900 | [diff] [blame] | 165 | if (mService != null) { |
| 166 | mService.onBootPhase(phase); |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public void onUnlockUser(int userHandle) { |
Daichi Hirono | 4bbf852 | 2017-12-06 10:34:18 +0900 | [diff] [blame] | 172 | if (mService != null) { |
| 173 | mService.onUnlockUser(userHandle); |
| 174 | } |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 178 | private final Object mLock = new Object(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 180 | /** |
| 181 | * Minimum time between crashes of a wallpaper service for us to consider |
| 182 | * restarting it vs. just reverting to the static wallpaper. |
| 183 | */ |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 184 | private static final long MIN_WALLPAPER_CRASH_TIME = 10000; |
| 185 | private static final int MAX_WALLPAPER_COMPONENT_LOG_LENGTH = 128; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 186 | static final String WALLPAPER = "wallpaper_orig"; |
| 187 | static final String WALLPAPER_CROP = "wallpaper"; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 188 | static final String WALLPAPER_LOCK_ORIG = "wallpaper_lock_orig"; |
| 189 | static final String WALLPAPER_LOCK_CROP = "wallpaper_lock"; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 190 | static final String WALLPAPER_INFO = "wallpaper_info.xml"; |
Dianne Hackborn | bce0cbb | 2012-10-05 11:06:53 -0700 | [diff] [blame] | 191 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 192 | // All the various per-user state files we need to be aware of |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 193 | private static final String[] sPerUserFiles = new String[] { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 194 | WALLPAPER, WALLPAPER_CROP, |
| 195 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP, |
| 196 | WALLPAPER_INFO |
| 197 | }; |
| 198 | |
Dianne Hackborn | bce0cbb | 2012-10-05 11:06:53 -0700 | [diff] [blame] | 199 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | * Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks |
| 201 | * that the wallpaper has changed. The CREATE is triggered when there is no |
| 202 | * wallpaper set and is created for the first time. The CLOSE_WRITE is triggered |
Christopher Tate | 190e853 | 2016-07-11 11:35:34 -0700 | [diff] [blame] | 203 | * every time the wallpaper is changed. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | */ |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 205 | private class WallpaperObserver extends FileObserver { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 206 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 207 | final int mUserId; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 208 | final WallpaperData mWallpaper; |
| 209 | final File mWallpaperDir; |
| 210 | final File mWallpaperFile; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 211 | final File mWallpaperLockFile; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 212 | |
| 213 | public WallpaperObserver(WallpaperData wallpaper) { |
| 214 | super(getWallpaperDir(wallpaper.userId).getAbsolutePath(), |
Christopher Tate | da058e2 | 2014-10-08 14:51:09 -0700 | [diff] [blame] | 215 | CLOSE_WRITE | MOVED_TO | DELETE | DELETE_SELF); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 216 | mUserId = wallpaper.userId; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 217 | mWallpaperDir = getWallpaperDir(wallpaper.userId); |
| 218 | mWallpaper = wallpaper; |
| 219 | mWallpaperFile = new File(mWallpaperDir, WALLPAPER); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 220 | mWallpaperLockFile = new File(mWallpaperDir, WALLPAPER_LOCK_ORIG); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 223 | private WallpaperData dataForEvent(boolean sysChanged, boolean lockChanged) { |
| 224 | WallpaperData wallpaper = null; |
| 225 | synchronized (mLock) { |
| 226 | if (lockChanged) { |
| 227 | wallpaper = mLockWallpaperMap.get(mUserId); |
| 228 | } |
| 229 | if (wallpaper == null) { |
| 230 | // no lock-specific wallpaper exists, or sys case, handled together |
| 231 | wallpaper = mWallpaperMap.get(mUserId); |
| 232 | } |
| 233 | } |
| 234 | return (wallpaper != null) ? wallpaper : mWallpaper; |
| 235 | } |
| 236 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 237 | @Override |
| 238 | public void onEvent(int event, String path) { |
| 239 | if (path == null) { |
| 240 | return; |
| 241 | } |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 242 | final boolean moved = (event == MOVED_TO); |
| 243 | final boolean written = (event == CLOSE_WRITE || moved); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 244 | final File changedFile = new File(mWallpaperDir, path); |
| 245 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 246 | // System and system+lock changes happen on the system wallpaper input file; |
| 247 | // lock-only changes happen on the dedicated lock wallpaper input file |
| 248 | final boolean sysWallpaperChanged = (mWallpaperFile.equals(changedFile)); |
| 249 | final boolean lockWallpaperChanged = (mWallpaperLockFile.equals(changedFile)); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 250 | int notifyColorsWhich = 0; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 251 | WallpaperData wallpaper = dataForEvent(sysWallpaperChanged, lockWallpaperChanged); |
| 252 | |
| 253 | if (DEBUG) { |
| 254 | Slog.v(TAG, "Wallpaper file change: evt=" + event |
| 255 | + " path=" + path |
| 256 | + " sys=" + sysWallpaperChanged |
| 257 | + " lock=" + lockWallpaperChanged |
| 258 | + " imagePending=" + wallpaper.imageWallpaperPending |
| 259 | + " whichPending=0x" + Integer.toHexString(wallpaper.whichPending) |
| 260 | + " written=" + written); |
| 261 | } |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 262 | |
| 263 | if (moved && lockWallpaperChanged) { |
| 264 | // We just migrated sys -> lock to preserve imagery for an impending |
Christopher Tate | fa7d97f | 2016-06-30 12:21:57 -0700 | [diff] [blame] | 265 | // new system-only wallpaper. Tell keyguard about it and make sure it |
| 266 | // has the right SELinux label. |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 267 | if (DEBUG) { |
| 268 | Slog.i(TAG, "Sys -> lock MOVED_TO"); |
| 269 | } |
Christopher Tate | fa7d97f | 2016-06-30 12:21:57 -0700 | [diff] [blame] | 270 | SELinux.restorecon(changedFile); |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 271 | notifyLockWallpaperChanged(); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 272 | notifyWallpaperColorsChanged(wallpaper, FLAG_LOCK); |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 273 | return; |
| 274 | } |
| 275 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 276 | synchronized (mLock) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 277 | if (sysWallpaperChanged || lockWallpaperChanged) { |
| 278 | notifyCallbacksLocked(wallpaper); |
| 279 | if (wallpaper.wallpaperComponent == null |
Christopher Tate | da058e2 | 2014-10-08 14:51:09 -0700 | [diff] [blame] | 280 | || event != CLOSE_WRITE // includes the MOVED_TO case |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 281 | || wallpaper.imageWallpaperPending) { |
Christopher Tate | da058e2 | 2014-10-08 14:51:09 -0700 | [diff] [blame] | 282 | if (written) { |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 283 | // The image source has finished writing the source image, |
| 284 | // so we now produce the crop rect (in the background), and |
| 285 | // only publish the new displayable (sub)image as a result |
| 286 | // of that work. |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 287 | if (DEBUG) { |
| 288 | Slog.v(TAG, "Wallpaper written; generating crop"); |
| 289 | } |
Christopher Tate | ebadfb1 | 2016-07-25 14:50:08 -0700 | [diff] [blame] | 290 | SELinux.restorecon(changedFile); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 291 | if (moved) { |
| 292 | // This is a restore, so generate the crop using any just-restored new |
| 293 | // crop guidelines, making sure to preserve our local dimension hints. |
Christopher Tate | fa7d97f | 2016-06-30 12:21:57 -0700 | [diff] [blame] | 294 | // We also make sure to reapply the correct SELinux label. |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 295 | if (DEBUG) { |
| 296 | Slog.v(TAG, "moved-to, therefore restore; reloading metadata"); |
| 297 | } |
| 298 | loadSettingsLocked(wallpaper.userId, true); |
| 299 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 300 | generateCrop(wallpaper); |
| 301 | if (DEBUG) { |
| 302 | Slog.v(TAG, "Crop done; invoking completion callback"); |
| 303 | } |
| 304 | wallpaper.imageWallpaperPending = false; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 305 | if (sysWallpaperChanged) { |
| 306 | // If this was the system wallpaper, rebind... |
| 307 | bindWallpaperComponentLocked(mImageWallpaper, true, |
| 308 | false, wallpaper, null); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 309 | notifyColorsWhich |= FLAG_SYSTEM; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 310 | } |
| 311 | if (lockWallpaperChanged |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 312 | || (wallpaper.whichPending & FLAG_LOCK) != 0) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 313 | if (DEBUG) { |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 314 | Slog.i(TAG, "Lock-relevant wallpaper changed"); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 315 | } |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 316 | // either a lock-only wallpaper commit or a system+lock event. |
| 317 | // if it's system-plus-lock we need to wipe the lock bookkeeping; |
| 318 | // we're falling back to displaying the system wallpaper there. |
| 319 | if (!lockWallpaperChanged) { |
| 320 | mLockWallpaperMap.remove(wallpaper.userId); |
| 321 | } |
| 322 | // and in any case, tell keyguard about it |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 323 | notifyLockWallpaperChanged(); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 324 | notifyColorsWhich |= FLAG_LOCK; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 325 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 326 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 327 | saveSettingsLocked(wallpaper.userId); |
Christopher Tate | 8efbe0d | 2017-08-29 16:50:13 -0700 | [diff] [blame] | 328 | |
| 329 | // Publish completion *after* we've persisted the changes |
| 330 | if (wallpaper.setComplete != null) { |
| 331 | try { |
| 332 | wallpaper.setComplete.onWallpaperChanged(); |
| 333 | } catch (RemoteException e) { |
| 334 | // if this fails we don't really care; the setting app may just |
| 335 | // have crashed and that sort of thing is a fact of life. |
| 336 | } |
| 337 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 338 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | } |
| 340 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 341 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 342 | |
| 343 | // Outside of the lock since it will synchronize itself |
| 344 | if (notifyColorsWhich != 0) { |
| 345 | notifyWallpaperColorsChanged(wallpaper, notifyColorsWhich); |
| 346 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 350 | private void notifyLockWallpaperChanged() { |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 351 | final IWallpaperManagerCallback cb = mKeyguardListener; |
| 352 | if (cb != null) { |
| 353 | try { |
| 354 | cb.onWallpaperChanged(); |
| 355 | } catch (RemoteException e) { |
| 356 | // Oh well it went away; no big deal |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 361 | private void notifyWallpaperColorsChanged(@NonNull WallpaperData wallpaper, int which) { |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 362 | if (wallpaper.connection != null) { |
| 363 | wallpaper.connection.forEachDisplayConnector(connector -> { |
| 364 | notifyWallpaperColorsChangedOnDisplay(wallpaper, which, connector.mDisplayId); |
| 365 | }); |
| 366 | } else { // Lock wallpaper does not have WallpaperConnection. |
| 367 | notifyWallpaperColorsChangedOnDisplay(wallpaper, which, DEFAULT_DISPLAY); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | private RemoteCallbackList<IWallpaperManagerCallback> getWallpaperCallbacks(int userId, |
| 372 | int displayId) { |
| 373 | RemoteCallbackList<IWallpaperManagerCallback> listeners = null; |
| 374 | final SparseArray<RemoteCallbackList<IWallpaperManagerCallback>> displayListeners = |
| 375 | mColorsChangedListeners.get(userId); |
| 376 | if (displayListeners != null) { |
| 377 | listeners = displayListeners.get(displayId); |
| 378 | } |
| 379 | return listeners; |
| 380 | } |
| 381 | |
| 382 | private void notifyWallpaperColorsChangedOnDisplay(@NonNull WallpaperData wallpaper, int which, |
| 383 | int displayId) { |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 384 | boolean needsExtraction; |
| 385 | synchronized (mLock) { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 386 | final RemoteCallbackList<IWallpaperManagerCallback> currentUserColorListeners = |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 387 | getWallpaperCallbacks(wallpaper.userId, displayId); |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 388 | final RemoteCallbackList<IWallpaperManagerCallback> userAllColorListeners = |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 389 | getWallpaperCallbacks(UserHandle.USER_ALL, displayId); |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 390 | // No-op until someone is listening to it. |
| 391 | if (emptyCallbackList(currentUserColorListeners) && |
| 392 | emptyCallbackList(userAllColorListeners)) { |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 393 | return; |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 394 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 395 | |
| 396 | if (DEBUG) { |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 397 | Slog.v(TAG, "notifyWallpaperColorsChangedOnDisplay " + which); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | needsExtraction = wallpaper.primaryColors == null; |
| 401 | } |
| 402 | |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 403 | // Let's notify the current values, it's fine if it's null, it just means |
| 404 | // that we don't know yet. |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 405 | notifyColorListeners(wallpaper.primaryColors, which, wallpaper.userId, displayId); |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 406 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 407 | if (needsExtraction) { |
| 408 | extractColors(wallpaper); |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 409 | synchronized (mLock) { |
| 410 | // Don't need to notify if nothing changed. |
| 411 | if (wallpaper.primaryColors == null) { |
| 412 | return; |
| 413 | } |
| 414 | } |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 415 | notifyColorListeners(wallpaper.primaryColors, which, wallpaper.userId, displayId); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 416 | } |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 417 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 418 | |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 419 | private static <T extends IInterface> boolean emptyCallbackList(RemoteCallbackList<T> list) { |
| 420 | return (list == null || list.getRegisteredCallbackCount() == 0); |
| 421 | } |
| 422 | |
| 423 | private void notifyColorListeners(@NonNull WallpaperColors wallpaperColors, int which, |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 424 | int userId, int displayId) { |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 425 | final IWallpaperManagerCallback keyguardListener; |
Lucas Dupin | fb3ab2a | 2017-08-08 14:17:30 -0400 | [diff] [blame] | 426 | final ArrayList<IWallpaperManagerCallback> colorListeners = new ArrayList<>(); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 427 | synchronized (mLock) { |
Lucas Dupin | fb3ab2a | 2017-08-08 14:17:30 -0400 | [diff] [blame] | 428 | final RemoteCallbackList<IWallpaperManagerCallback> currentUserColorListeners = |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 429 | getWallpaperCallbacks(userId, displayId); |
Lucas Dupin | fb3ab2a | 2017-08-08 14:17:30 -0400 | [diff] [blame] | 430 | final RemoteCallbackList<IWallpaperManagerCallback> userAllColorListeners = |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 431 | getWallpaperCallbacks(UserHandle.USER_ALL, displayId); |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 432 | keyguardListener = mKeyguardListener; |
Lucas Dupin | fb3ab2a | 2017-08-08 14:17:30 -0400 | [diff] [blame] | 433 | |
| 434 | if (currentUserColorListeners != null) { |
| 435 | final int count = currentUserColorListeners.beginBroadcast(); |
| 436 | for (int i = 0; i < count; i++) { |
| 437 | colorListeners.add(currentUserColorListeners.getBroadcastItem(i)); |
| 438 | } |
| 439 | currentUserColorListeners.finishBroadcast(); |
| 440 | } |
| 441 | |
| 442 | if (userAllColorListeners != null) { |
| 443 | final int count = userAllColorListeners.beginBroadcast(); |
| 444 | for (int i = 0; i < count; i++) { |
| 445 | colorListeners.add(userAllColorListeners.getBroadcastItem(i)); |
| 446 | } |
| 447 | userAllColorListeners.finishBroadcast(); |
| 448 | } |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 449 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 450 | |
Lucas Dupin | fb3ab2a | 2017-08-08 14:17:30 -0400 | [diff] [blame] | 451 | final int count = colorListeners.size(); |
| 452 | for (int i = 0; i < count; i++) { |
| 453 | try { |
| 454 | colorListeners.get(i).onWallpaperColorsChanged(wallpaperColors, which, userId); |
| 455 | } catch (RemoteException e) { |
| 456 | // Callback is gone, it's not necessary to unregister it since |
| 457 | // RemoteCallbackList#getBroadcastItem will take care of it. |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 461 | // Only shows Keyguard on default display |
| 462 | if (keyguardListener != null && displayId == DEFAULT_DISPLAY) { |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 463 | try { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 464 | keyguardListener.onWallpaperColorsChanged(wallpaperColors, which, userId); |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 465 | } catch (RemoteException e) { |
| 466 | // Oh well it went away; no big deal |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
Lucas Dupin | bcae585 | 2017-05-03 12:42:58 -0700 | [diff] [blame] | 471 | /** |
| 472 | * We can easily extract colors from an ImageWallpaper since it's only a bitmap. |
Lucas Dupin | 284836b | 2017-06-23 15:28:41 -0700 | [diff] [blame] | 473 | * In this case, using the crop is more than enough. Live wallpapers are just ignored. |
Lucas Dupin | bcae585 | 2017-05-03 12:42:58 -0700 | [diff] [blame] | 474 | * |
| 475 | * @param wallpaper a wallpaper representation |
| 476 | */ |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 477 | private void extractColors(WallpaperData wallpaper) { |
| 478 | String cropFile = null; |
wilsonshih | 31d70a1 | 2019-01-14 12:42:35 +0800 | [diff] [blame] | 479 | boolean defaultImageWallpaper = false; |
Lucas Dupin | 284836b | 2017-06-23 15:28:41 -0700 | [diff] [blame] | 480 | int wallpaperId; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 481 | |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 482 | if (wallpaper.equals(mFallbackWallpaper)) { |
wilsonshih | fa24e4f | 2019-02-22 10:29:19 +0800 | [diff] [blame] | 483 | synchronized (mLock) { |
| 484 | if (mFallbackWallpaper.primaryColors != null) return; |
| 485 | } |
| 486 | final WallpaperColors colors = extractDefaultImageWallpaperColors(); |
| 487 | synchronized (mLock) { |
| 488 | mFallbackWallpaper.primaryColors = colors; |
| 489 | } |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 490 | return; |
| 491 | } |
| 492 | |
Lucas Dupin | bcae585 | 2017-05-03 12:42:58 -0700 | [diff] [blame] | 493 | synchronized (mLock) { |
Lucas Dupin | 284836b | 2017-06-23 15:28:41 -0700 | [diff] [blame] | 494 | // Not having a wallpaperComponent means it's a lock screen wallpaper. |
| 495 | final boolean imageWallpaper = mImageWallpaper.equals(wallpaper.wallpaperComponent) |
Lucas Dupin | bcae585 | 2017-05-03 12:42:58 -0700 | [diff] [blame] | 496 | || wallpaper.wallpaperComponent == null; |
Lucas Dupin | 284836b | 2017-06-23 15:28:41 -0700 | [diff] [blame] | 497 | if (imageWallpaper && wallpaper.cropFile != null && wallpaper.cropFile.exists()) { |
| 498 | cropFile = wallpaper.cropFile.getAbsolutePath(); |
wilsonshih | 31d70a1 | 2019-01-14 12:42:35 +0800 | [diff] [blame] | 499 | } else if (imageWallpaper && !wallpaper.cropExists() && !wallpaper.sourceExists()) { |
| 500 | defaultImageWallpaper = true; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 501 | } |
| 502 | wallpaperId = wallpaper.wallpaperId; |
| 503 | } |
| 504 | |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 505 | WallpaperColors colors = null; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 506 | if (cropFile != null) { |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 507 | Bitmap bitmap = BitmapFactory.decodeFile(cropFile); |
Lucas Dupin | 284836b | 2017-06-23 15:28:41 -0700 | [diff] [blame] | 508 | if (bitmap != null) { |
Lucas Dupin | b5e5053 | 2018-05-24 16:33:14 +0000 | [diff] [blame] | 509 | colors = WallpaperColors.fromBitmap(bitmap); |
Lucas Dupin | 284836b | 2017-06-23 15:28:41 -0700 | [diff] [blame] | 510 | bitmap.recycle(); |
| 511 | } |
wilsonshih | 31d70a1 | 2019-01-14 12:42:35 +0800 | [diff] [blame] | 512 | } else if (defaultImageWallpaper) { |
| 513 | // There is no crop and source file because this is default image wallpaper. |
wilsonshih | fa24e4f | 2019-02-22 10:29:19 +0800 | [diff] [blame] | 514 | colors = extractDefaultImageWallpaperColors(); |
Lucas Dupin | bcae585 | 2017-05-03 12:42:58 -0700 | [diff] [blame] | 515 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 516 | |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 517 | if (colors == null) { |
Lucas Dupin | bcae585 | 2017-05-03 12:42:58 -0700 | [diff] [blame] | 518 | Slog.w(TAG, "Cannot extract colors because wallpaper could not be read."); |
| 519 | return; |
| 520 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 521 | |
Lucas Dupin | bcae585 | 2017-05-03 12:42:58 -0700 | [diff] [blame] | 522 | synchronized (mLock) { |
| 523 | if (wallpaper.wallpaperId == wallpaperId) { |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 524 | wallpaper.primaryColors = colors; |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 525 | // Now that we have the colors, let's save them into the xml |
| 526 | // to avoid having to run this again. |
| 527 | saveSettingsLocked(wallpaper.userId); |
Lucas Dupin | bcae585 | 2017-05-03 12:42:58 -0700 | [diff] [blame] | 528 | } else { |
| 529 | Slog.w(TAG, "Not setting primary colors since wallpaper changed"); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
wilsonshih | fa24e4f | 2019-02-22 10:29:19 +0800 | [diff] [blame] | 534 | private WallpaperColors extractDefaultImageWallpaperColors() { |
| 535 | if (DEBUG) Slog.d(TAG, "Extract default image wallpaper colors"); |
| 536 | |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 537 | synchronized (mLock) { |
wilsonshih | fa24e4f | 2019-02-22 10:29:19 +0800 | [diff] [blame] | 538 | if (mCacheDefaultImageWallpaperColors != null) return mCacheDefaultImageWallpaperColors; |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 539 | } |
| 540 | |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 541 | WallpaperColors colors = null; |
wilsonshih | fa24e4f | 2019-02-22 10:29:19 +0800 | [diff] [blame] | 542 | try (InputStream is = WallpaperManager.openDefaultWallpaper(mContext, FLAG_SYSTEM)) { |
| 543 | if (is == null) { |
| 544 | Slog.w(TAG, "Can't open default wallpaper stream"); |
| 545 | return null; |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 546 | } |
wilsonshih | fa24e4f | 2019-02-22 10:29:19 +0800 | [diff] [blame] | 547 | |
| 548 | final BitmapFactory.Options options = new BitmapFactory.Options(); |
| 549 | final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); |
| 550 | if (bitmap != null) { |
| 551 | colors = WallpaperColors.fromBitmap(bitmap); |
| 552 | bitmap.recycle(); |
| 553 | } |
| 554 | } catch (OutOfMemoryError e) { |
| 555 | Slog.w(TAG, "Can't decode default wallpaper stream", e); |
| 556 | } catch (IOException e) { |
| 557 | Slog.w(TAG, "Can't close default wallpaper stream", e); |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | if (colors == null) { |
| 561 | Slog.e(TAG, "Extract default image wallpaper colors failed"); |
wilsonshih | fa24e4f | 2019-02-22 10:29:19 +0800 | [diff] [blame] | 562 | } else { |
| 563 | synchronized (mLock) { |
| 564 | mCacheDefaultImageWallpaperColors = colors; |
| 565 | } |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 566 | } |
| 567 | |
wilsonshih | fa24e4f | 2019-02-22 10:29:19 +0800 | [diff] [blame] | 568 | return colors; |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 569 | } |
| 570 | |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 571 | /** |
| 572 | * Once a new wallpaper has been written via setWallpaper(...), it needs to be cropped |
| 573 | * for display. |
| 574 | */ |
| 575 | private void generateCrop(WallpaperData wallpaper) { |
| 576 | boolean success = false; |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 577 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 578 | // Only generate crop for default display. |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 579 | final DisplayData wpData = getDisplayDataOrCreate(DEFAULT_DISPLAY); |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 580 | final Rect cropHint = new Rect(wallpaper.cropHint); |
| 581 | final DisplayInfo displayInfo = new DisplayInfo(); |
| 582 | mDisplayManager.getDisplay(DEFAULT_DISPLAY).getDisplayInfo(displayInfo); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 583 | |
| 584 | if (DEBUG) { |
| 585 | Slog.v(TAG, "Generating crop for new wallpaper(s): 0x" |
| 586 | + Integer.toHexString(wallpaper.whichPending) |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 587 | + " to " + wallpaper.cropFile.getName() |
| 588 | + " crop=(" + cropHint.width() + 'x' + cropHint.height() |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 589 | + ") dim=(" + wpData.mWidth + 'x' + wpData.mHeight + ')'); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 590 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 591 | |
| 592 | // Analyse the source; needed in multiple cases |
| 593 | BitmapFactory.Options options = new BitmapFactory.Options(); |
| 594 | options.inJustDecodeBounds = true; |
| 595 | BitmapFactory.decodeFile(wallpaper.wallpaperFile.getAbsolutePath(), options); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 596 | if (options.outWidth <= 0 || options.outHeight <= 0) { |
Joe LaPenna | c298b16 | 2016-05-02 15:25:50 -0700 | [diff] [blame] | 597 | Slog.w(TAG, "Invalid wallpaper data"); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 598 | success = false; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 599 | } else { |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 600 | boolean needCrop = false; |
| 601 | boolean needScale = false; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 602 | |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 603 | // Empty crop means use the full image |
| 604 | if (cropHint.isEmpty()) { |
| 605 | cropHint.left = cropHint.top = 0; |
| 606 | cropHint.right = options.outWidth; |
| 607 | cropHint.bottom = options.outHeight; |
| 608 | } else { |
| 609 | // force the crop rect to lie within the measured bounds |
| 610 | cropHint.offset( |
| 611 | (cropHint.right > options.outWidth ? options.outWidth - cropHint.right : 0), |
| 612 | (cropHint.bottom > options.outHeight ? options.outHeight - cropHint.bottom : 0)); |
| 613 | |
Adrian Roos | 5c97ff2 | 2016-08-31 10:25:38 -0700 | [diff] [blame] | 614 | // If the crop hint was larger than the image we just overshot. Patch things up. |
| 615 | if (cropHint.left < 0) { |
| 616 | cropHint.left = 0; |
| 617 | } |
| 618 | if (cropHint.top < 0) { |
| 619 | cropHint.top = 0; |
| 620 | } |
| 621 | |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 622 | // Don't bother cropping if what we're left with is identity |
Christopher Tate | ebadfb1 | 2016-07-25 14:50:08 -0700 | [diff] [blame] | 623 | needCrop = (options.outHeight > cropHint.height() |
Adrian Roos | 5c97ff2 | 2016-08-31 10:25:38 -0700 | [diff] [blame] | 624 | || options.outWidth > cropHint.width()); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | // scale if the crop height winds up not matching the recommended metrics |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 628 | needScale = wpData.mHeight != cropHint.height() |
| 629 | || cropHint.height() > GLHelper.getMaxTextureSize() |
| 630 | || cropHint.width() > GLHelper.getMaxTextureSize(); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 631 | |
Valentin Iftime | 3047bb1 | 2018-12-28 17:02:19 +0100 | [diff] [blame] | 632 | //make sure screen aspect ratio is preserved if width is scaled under screen size |
| 633 | if (needScale) { |
Valentin Iftime | 3047bb1 | 2018-12-28 17:02:19 +0100 | [diff] [blame] | 634 | final float scaleByHeight = (float) wpData.mHeight / (float) cropHint.height(); |
| 635 | final int newWidth = (int) (cropHint.width() * scaleByHeight); |
| 636 | if (newWidth < displayInfo.logicalWidth) { |
| 637 | final float screenAspectRatio = |
| 638 | (float) displayInfo.logicalHeight / (float) displayInfo.logicalWidth; |
| 639 | cropHint.bottom = (int) (cropHint.width() * screenAspectRatio); |
| 640 | needCrop = true; |
| 641 | } |
| 642 | } |
| 643 | |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 644 | if (DEBUG) { |
| 645 | Slog.v(TAG, "crop: w=" + cropHint.width() + " h=" + cropHint.height()); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 646 | Slog.v(TAG, "dims: w=" + wpData.mWidth + " h=" + wpData.mHeight); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 647 | Slog.v(TAG, "meas: w=" + options.outWidth + " h=" + options.outHeight); |
| 648 | Slog.v(TAG, "crop?=" + needCrop + " scale?=" + needScale); |
| 649 | } |
| 650 | |
| 651 | if (!needCrop && !needScale) { |
| 652 | // Simple case: the nominal crop fits what we want, so we take |
| 653 | // the whole thing and just copy the image file directly. |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 654 | |
| 655 | // TODO: It is not accurate to estimate bitmap size without decoding it, |
| 656 | // may be we can try to remove this optimized way in the future, |
| 657 | // that means, we will always go into the 'else' block. |
| 658 | |
| 659 | // This is just a quick estimation, may be smaller than it is. |
| 660 | long estimateSize = options.outWidth * options.outHeight * 4; |
| 661 | |
| 662 | // A bitmap over than MAX_BITMAP_SIZE will make drawBitmap() fail. |
| 663 | // Please see: RecordingCanvas#throwIfCannotDraw. |
| 664 | if (estimateSize < MAX_BITMAP_SIZE) { |
| 665 | success = FileUtils.copyFile(wallpaper.wallpaperFile, wallpaper.cropFile); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 666 | } |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 667 | |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 668 | if (!success) { |
| 669 | wallpaper.cropFile.delete(); |
| 670 | // TODO: fall back to default wallpaper in this case |
| 671 | } |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 672 | |
| 673 | if (DEBUG) { |
| 674 | Slog.v(TAG, "Null crop of new wallpaper, estimate size=" |
| 675 | + estimateSize + ", success=" + success); |
| 676 | } |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 677 | } else { |
| 678 | // Fancy case: crop and scale. First, we decode and scale down if appropriate. |
| 679 | FileOutputStream f = null; |
| 680 | BufferedOutputStream bos = null; |
| 681 | try { |
| 682 | BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance( |
| 683 | wallpaper.wallpaperFile.getAbsolutePath(), false); |
| 684 | |
| 685 | // This actually downsamples only by powers of two, but that's okay; we do |
| 686 | // a proper scaling blit later. This is to minimize transient RAM use. |
| 687 | // We calculate the largest power-of-two under the actual ratio rather than |
| 688 | // just let the decode take care of it because we also want to remap where the |
| 689 | // cropHint rectangle lies in the decoded [super]rect. |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 690 | final int actualScale = cropHint.height() / wpData.mHeight; |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 691 | int scale = 1; |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 692 | while (2 * scale <= actualScale) { |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 693 | scale *= 2; |
| 694 | } |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 695 | options.inSampleSize = scale; |
| 696 | options.inJustDecodeBounds = false; |
| 697 | |
| 698 | final Rect estimateCrop = new Rect(cropHint); |
| 699 | estimateCrop.scale(1f / options.inSampleSize); |
| 700 | final float hRatio = (float) wpData.mHeight / estimateCrop.height(); |
| 701 | final int destHeight = (int) (estimateCrop.height() * hRatio); |
| 702 | final int destWidth = (int) (estimateCrop.width() * hRatio); |
| 703 | |
| 704 | // We estimated an invalid crop, try to adjust the cropHint to get a valid one. |
| 705 | if (destWidth > GLHelper.getMaxTextureSize()) { |
| 706 | int newHeight = (int) (wpData.mHeight / hRatio); |
| 707 | int newWidth = (int) (wpData.mWidth / hRatio); |
| 708 | |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 709 | if (DEBUG) { |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 710 | Slog.v(TAG, "Invalid crop dimensions, trying to adjust."); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 711 | } |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 712 | |
| 713 | estimateCrop.set(cropHint); |
| 714 | estimateCrop.left += (cropHint.width() - newWidth) / 2; |
| 715 | estimateCrop.top += (cropHint.height() - newHeight) / 2; |
| 716 | estimateCrop.right = estimateCrop.left + newWidth; |
| 717 | estimateCrop.bottom = estimateCrop.top + newHeight; |
| 718 | cropHint.set(estimateCrop); |
| 719 | estimateCrop.scale(1f / options.inSampleSize); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 720 | } |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 721 | |
| 722 | // We've got the safe cropHint; now we want to scale it properly to |
| 723 | // the desired rectangle. |
| 724 | // That's a height-biased operation: make it fit the hinted height. |
| 725 | final int safeHeight = (int) (estimateCrop.height() * hRatio); |
| 726 | final int safeWidth = (int) (estimateCrop.width() * hRatio); |
| 727 | |
| 728 | if (DEBUG) { |
| 729 | Slog.v(TAG, "Decode parameters:"); |
| 730 | Slog.v(TAG, " cropHint=" + cropHint + ", estimateCrop=" + estimateCrop); |
| 731 | Slog.v(TAG, " down sampling=" + options.inSampleSize |
| 732 | + ", hRatio=" + hRatio); |
| 733 | Slog.v(TAG, " dest=" + destWidth + "x" + destHeight); |
| 734 | Slog.v(TAG, " safe=" + safeWidth + "x" + safeHeight); |
| 735 | Slog.v(TAG, " maxTextureSize=" + GLHelper.getMaxTextureSize()); |
| 736 | } |
| 737 | |
| 738 | Bitmap cropped = decoder.decodeRegion(cropHint, options); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 739 | decoder.recycle(); |
| 740 | |
| 741 | if (cropped == null) { |
| 742 | Slog.e(TAG, "Could not decode new wallpaper"); |
| 743 | } else { |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 744 | // We are safe to create final crop with safe dimensions now. |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 745 | final Bitmap finalCrop = Bitmap.createScaledBitmap(cropped, |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 746 | safeWidth, safeHeight, true); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 747 | if (DEBUG) { |
| 748 | Slog.v(TAG, "Final extract:"); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 749 | Slog.v(TAG, " dims: w=" + wpData.mWidth |
| 750 | + " h=" + wpData.mHeight); |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 751 | Slog.v(TAG, " out: w=" + finalCrop.getWidth() |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 752 | + " h=" + finalCrop.getHeight()); |
| 753 | } |
| 754 | |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 755 | // A bitmap over than MAX_BITMAP_SIZE will make drawBitmap() fail. |
| 756 | // Please see: RecordingCanvas#throwIfCannotDraw. |
| 757 | if (finalCrop.getByteCount() > MAX_BITMAP_SIZE) { |
| 758 | throw new RuntimeException( |
| 759 | "Too large bitmap, limit=" + MAX_BITMAP_SIZE); |
| 760 | } |
| 761 | |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 762 | f = new FileOutputStream(wallpaper.cropFile); |
| 763 | bos = new BufferedOutputStream(f, 32*1024); |
Christopher Tate | c484f54 | 2016-05-11 14:31:34 -0700 | [diff] [blame] | 764 | finalCrop.compress(Bitmap.CompressFormat.JPEG, 100, bos); |
Christopher Tate | 1a96b63 | 2016-03-22 15:25:42 -0700 | [diff] [blame] | 765 | bos.flush(); // don't rely on the implicit flush-at-close when noting success |
| 766 | success = true; |
| 767 | } |
| 768 | } catch (Exception e) { |
| 769 | if (DEBUG) { |
| 770 | Slog.e(TAG, "Error decoding crop", e); |
| 771 | } |
| 772 | } finally { |
| 773 | IoUtils.closeQuietly(bos); |
| 774 | IoUtils.closeQuietly(f); |
| 775 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
| 779 | if (!success) { |
| 780 | Slog.e(TAG, "Unable to apply new wallpaper"); |
| 781 | wallpaper.cropFile.delete(); |
| 782 | } |
| 783 | |
| 784 | if (wallpaper.cropFile.exists()) { |
| 785 | boolean didRestorecon = SELinux.restorecon(wallpaper.cropFile.getAbsoluteFile()); |
| 786 | if (DEBUG) { |
| 787 | Slog.v(TAG, "restorecon() of crop file returned " + didRestorecon); |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 792 | private final Context mContext; |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 793 | private final WindowManagerInternal mWindowManagerInternal; |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 794 | private final IPackageManager mIPackageManager; |
| 795 | private final MyPackageMonitor mMonitor; |
| 796 | private final AppOpsManager mAppOpsManager; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 797 | |
| 798 | private final DisplayManager mDisplayManager; |
| 799 | private final DisplayManager.DisplayListener mDisplayListener = |
| 800 | new DisplayManager.DisplayListener() { |
| 801 | |
| 802 | @Override |
| 803 | public void onDisplayAdded(int displayId) { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | @Override |
| 807 | public void onDisplayRemoved(int displayId) { |
| 808 | synchronized (mLock) { |
| 809 | if (mLastWallpaper != null) { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 810 | WallpaperData targetWallpaper = null; |
| 811 | if (mLastWallpaper.connection.containsDisplay(displayId)) { |
| 812 | targetWallpaper = mLastWallpaper; |
| 813 | } else if (mFallbackWallpaper.connection.containsDisplay(displayId)) { |
| 814 | targetWallpaper = mFallbackWallpaper; |
| 815 | } |
| 816 | if (targetWallpaper == null) return; |
| 817 | WallpaperConnection.DisplayConnector connector = |
| 818 | targetWallpaper.connection.getDisplayConnectorOrCreate(displayId); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 819 | if (connector == null) return; |
| 820 | connector.disconnectLocked(); |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 821 | targetWallpaper.connection.removeDisplayConnector(displayId); |
| 822 | removeDisplayData(displayId); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 823 | } |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 824 | for (int i = mColorsChangedListeners.size() - 1; i >= 0; i--) { |
| 825 | final SparseArray<RemoteCallbackList<IWallpaperManagerCallback>> callbacks = |
| 826 | mColorsChangedListeners.valueAt(i); |
| 827 | callbacks.delete(displayId); |
| 828 | } |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | |
| 832 | @Override |
| 833 | public void onDisplayChanged(int displayId) { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 834 | } |
| 835 | }; |
| 836 | |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 837 | /** |
| 838 | * Map of color listeners per user id. |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 839 | * The first key will be the id of a user or UserHandle.USER_ALL - for wildcard listeners. |
| 840 | * The secondary key will be the display id, which means which display the listener is |
| 841 | * interested in. |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 842 | */ |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 843 | private final SparseArray<SparseArray<RemoteCallbackList<IWallpaperManagerCallback>>> |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 844 | mColorsChangedListeners; |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 845 | protected WallpaperData mLastWallpaper; |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 846 | private IWallpaperManagerCallback mKeyguardListener; |
| 847 | private boolean mWaitingForUnlock; |
| 848 | private boolean mShuttingDown; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 849 | |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 850 | /** |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 851 | * ID of the current wallpaper, changed every time anything sets a wallpaper. |
| 852 | * This is used for external detection of wallpaper update activity. |
| 853 | */ |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 854 | private int mWallpaperId; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 855 | |
| 856 | /** |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 857 | * Name of the component used to display bitmap wallpapers from either the gallery or |
| 858 | * built-in wallpapers. |
| 859 | */ |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 860 | private final ComponentName mImageWallpaper; |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 861 | |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 862 | /** |
wilsonshih | fa24e4f | 2019-02-22 10:29:19 +0800 | [diff] [blame] | 863 | * Default image wallpaper shall never changed after system service started, caching it when we |
| 864 | * first read the image file. |
| 865 | */ |
| 866 | private WallpaperColors mCacheDefaultImageWallpaperColors; |
| 867 | |
| 868 | /** |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 869 | * Name of the default wallpaper component; might be different from mImageWallpaper |
| 870 | */ |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 871 | private final ComponentName mDefaultWallpaperComponent; |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 872 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 873 | private final SparseArray<WallpaperData> mWallpaperMap = new SparseArray<WallpaperData>(); |
| 874 | private final SparseArray<WallpaperData> mLockWallpaperMap = new SparseArray<WallpaperData>(); |
Dianne Hackborn | 07213e6 | 2011-08-24 20:05:39 -0700 | [diff] [blame] | 875 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 876 | private SparseArray<DisplayData> mDisplayDatas = new SparseArray<>(); |
| 877 | |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 878 | protected WallpaperData mFallbackWallpaper; |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 879 | |
| 880 | private final SparseBooleanArray mUserRestorecon = new SparseBooleanArray(); |
| 881 | private int mCurrentUserId = UserHandle.USER_NULL; |
| 882 | private boolean mInAmbientMode; |
Dianne Hackborn | 07213e6 | 2011-08-24 20:05:39 -0700 | [diff] [blame] | 883 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 884 | static class WallpaperData { |
| 885 | |
| 886 | int userId; |
| 887 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 888 | final File wallpaperFile; // source image |
| 889 | final File cropFile; // eventual destination |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 890 | |
| 891 | /** |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 892 | * True while the client is writing a new wallpaper |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 893 | */ |
| 894 | boolean imageWallpaperPending; |
| 895 | |
| 896 | /** |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 897 | * Which new wallpapers are being written; mirrors the 'which' |
| 898 | * selector bit field to setWallpaper(). |
| 899 | */ |
| 900 | int whichPending; |
| 901 | |
| 902 | /** |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 903 | * Callback once the set + crop is finished |
| 904 | */ |
| 905 | IWallpaperManagerCallback setComplete; |
| 906 | |
| 907 | /** |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 908 | * Is the OS allowed to back up this wallpaper imagery? |
| 909 | */ |
| 910 | boolean allowBackup; |
| 911 | |
| 912 | /** |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 913 | * Resource name if using a picture from the wallpaper gallery |
| 914 | */ |
| 915 | String name = ""; |
| 916 | |
| 917 | /** |
| 918 | * The component name of the currently set live wallpaper. |
| 919 | */ |
| 920 | ComponentName wallpaperComponent; |
| 921 | |
| 922 | /** |
| 923 | * The component name of the wallpaper that should be set next. |
| 924 | */ |
| 925 | ComponentName nextWallpaperComponent; |
| 926 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 927 | /** |
| 928 | * The ID of this wallpaper |
| 929 | */ |
| 930 | int wallpaperId; |
| 931 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 932 | /** |
| 933 | * Primary colors histogram |
| 934 | */ |
| 935 | WallpaperColors primaryColors; |
| 936 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 937 | WallpaperConnection connection; |
| 938 | long lastDiedTime; |
| 939 | boolean wallpaperUpdating; |
| 940 | WallpaperObserver wallpaperObserver; |
| 941 | |
| 942 | /** |
| 943 | * List of callbacks registered they should each be notified when the wallpaper is changed. |
| 944 | */ |
| 945 | private RemoteCallbackList<IWallpaperManagerCallback> callbacks |
| 946 | = new RemoteCallbackList<IWallpaperManagerCallback>(); |
| 947 | |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 948 | /** |
| 949 | * The crop hint supplied for displaying a subset of the source image |
| 950 | */ |
| 951 | final Rect cropHint = new Rect(0, 0, 0, 0); |
| 952 | |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 953 | WallpaperData(int userId, File wallpaperDir, String inputFileName, String cropFileName) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 954 | this.userId = userId; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 955 | wallpaperFile = new File(wallpaperDir, inputFileName); |
| 956 | cropFile = new File(wallpaperDir, cropFileName); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 957 | } |
| 958 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 959 | // Called during initialization of a given user's wallpaper bookkeeping |
Christopher Tate | 41297ff | 2016-03-10 16:46:15 -0800 | [diff] [blame] | 960 | boolean cropExists() { |
| 961 | return cropFile.exists(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 962 | } |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 963 | |
| 964 | boolean sourceExists() { |
| 965 | return wallpaperFile.exists(); |
| 966 | } |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 967 | } |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 968 | |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 969 | @VisibleForTesting |
| 970 | static final class DisplayData { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 971 | int mWidth = -1; |
| 972 | int mHeight = -1; |
| 973 | final Rect mPadding = new Rect(0, 0, 0, 0); |
| 974 | final int mDisplayId; |
| 975 | |
| 976 | DisplayData(int displayId) { |
| 977 | mDisplayId = displayId; |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 978 | } |
| 979 | } |
| 980 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 981 | private void removeDisplayData(int displayId) { |
| 982 | mDisplayDatas.remove(displayId); |
| 983 | } |
| 984 | |
| 985 | private DisplayData getDisplayDataOrCreate(int displayId) { |
| 986 | DisplayData wpdData = mDisplayDatas.get(displayId); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 987 | if (wpdData == null) { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 988 | wpdData = new DisplayData(displayId); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 989 | ensureSaneWallpaperDisplaySize(wpdData, displayId); |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 990 | mDisplayDatas.append(displayId, wpdData); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 991 | } |
| 992 | return wpdData; |
| 993 | } |
| 994 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 995 | private void ensureSaneWallpaperDisplaySize(DisplayData wpdData, int displayId) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 996 | // We always want to have some reasonable width hint. |
| 997 | final int baseSize = getMaximumSizeDimension(displayId); |
| 998 | if (wpdData.mWidth < baseSize) { |
| 999 | wpdData.mWidth = baseSize; |
| 1000 | } |
| 1001 | if (wpdData.mHeight < baseSize) { |
| 1002 | wpdData.mHeight = baseSize; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | private int getMaximumSizeDimension(int displayId) { |
| 1007 | Display display = mDisplayManager.getDisplay(displayId); |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1008 | if (display == null) { |
| 1009 | Slog.w(TAG, "Invalid displayId=" + displayId + " " + Debug.getCallers(4)); |
| 1010 | display = mDisplayManager.getDisplay(DEFAULT_DISPLAY); |
| 1011 | } |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1012 | return display.getMaximumSizeDimension(); |
| 1013 | } |
| 1014 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1015 | void forEachDisplayData(Consumer<DisplayData> action) { |
| 1016 | for (int i = mDisplayDatas.size() - 1; i >= 0; i--) { |
| 1017 | final DisplayData wpdData = mDisplayDatas.valueAt(i); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1018 | action.accept(wpdData); |
| 1019 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1020 | } |
| 1021 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1022 | int makeWallpaperIdLocked() { |
| 1023 | do { |
| 1024 | ++mWallpaperId; |
| 1025 | } while (mWallpaperId == 0); |
| 1026 | return mWallpaperId; |
| 1027 | } |
| 1028 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1029 | private boolean supportsMultiDisplay(WallpaperConnection connection) { |
| 1030 | if (connection != null) { |
| 1031 | return connection.mInfo == null // This is image wallpaper |
| 1032 | || connection.mInfo.supportsMultipleDisplays(); |
| 1033 | } |
| 1034 | return false; |
| 1035 | } |
| 1036 | |
| 1037 | private void updateFallbackConnection() { |
| 1038 | if (mLastWallpaper == null || mFallbackWallpaper == null) return; |
| 1039 | final WallpaperConnection systemConnection = mLastWallpaper.connection; |
| 1040 | final WallpaperConnection fallbackConnection = mFallbackWallpaper.connection; |
wilsonshih | 78268c3 | 2018-12-18 20:48:28 +0800 | [diff] [blame] | 1041 | if (fallbackConnection == null) { |
| 1042 | Slog.w(TAG, "Fallback wallpaper connection has not been created yet!!"); |
| 1043 | return; |
| 1044 | } |
wilsonshih | 507ada5 | 2019-01-19 11:22:09 +0800 | [diff] [blame] | 1045 | if (supportsMultiDisplay(systemConnection)) { |
| 1046 | if (fallbackConnection.mDisplayConnector.size() != 0) { |
| 1047 | fallbackConnection.forEachDisplayConnector(connector -> { |
| 1048 | if (connector.mEngine != null) { |
| 1049 | connector.disconnectLocked(); |
| 1050 | } |
| 1051 | }); |
| 1052 | fallbackConnection.mDisplayConnector.clear(); |
| 1053 | } |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1054 | } else { |
| 1055 | fallbackConnection.appendConnectorWithCondition(display -> |
| 1056 | fallbackConnection.isUsableDisplay(display) |
| 1057 | && display.getDisplayId() != DEFAULT_DISPLAY |
| 1058 | && !fallbackConnection.containsDisplay(display.getDisplayId())); |
| 1059 | fallbackConnection.forEachDisplayConnector(connector -> { |
| 1060 | if (connector.mEngine == null) { |
| 1061 | connector.connectLocked(fallbackConnection, mFallbackWallpaper); |
| 1062 | } |
| 1063 | }); |
| 1064 | } |
| 1065 | } |
| 1066 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1067 | class WallpaperConnection extends IWallpaperConnection.Stub |
| 1068 | implements ServiceConnection { |
Adrian Roos | c3f915e | 2016-09-06 11:40:53 -0700 | [diff] [blame] | 1069 | |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1070 | /** |
| 1071 | * Collect needed info for a display. |
| 1072 | */ |
| 1073 | private final class DisplayConnector { |
| 1074 | final int mDisplayId; |
| 1075 | final Binder mToken = new Binder(); |
| 1076 | IWallpaperEngine mEngine; |
| 1077 | boolean mDimensionsChanged; |
| 1078 | boolean mPaddingChanged; |
| 1079 | |
| 1080 | DisplayConnector(int displayId) { |
| 1081 | mDisplayId = displayId; |
| 1082 | } |
| 1083 | |
| 1084 | void ensureStatusHandled() { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1085 | final DisplayData wpdData = getDisplayDataOrCreate(mDisplayId); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1086 | if (mDimensionsChanged) { |
| 1087 | try { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1088 | mEngine.setDesiredSize(wpdData.mWidth, wpdData.mHeight); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1089 | } catch (RemoteException e) { |
| 1090 | Slog.w(TAG, "Failed to set wallpaper dimensions", e); |
| 1091 | } |
| 1092 | mDimensionsChanged = false; |
| 1093 | } |
| 1094 | if (mPaddingChanged) { |
| 1095 | try { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1096 | mEngine.setDisplayPadding(wpdData.mPadding); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1097 | } catch (RemoteException e) { |
| 1098 | Slog.w(TAG, "Failed to set wallpaper padding", e); |
| 1099 | } |
| 1100 | mPaddingChanged = false; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | void connectLocked(WallpaperConnection connection, WallpaperData wallpaper) { |
wilsonshih | 674a4a0 | 2018-12-19 11:47:25 +0800 | [diff] [blame] | 1105 | if (connection.mService == null) { |
| 1106 | Slog.w(TAG, "WallpaperService is not connected yet"); |
| 1107 | return; |
| 1108 | } |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1109 | if (DEBUG) Slog.v(TAG, "Adding window token: " + mToken); |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 1110 | mWindowManagerInternal.addWindowToken(mToken, TYPE_WALLPAPER, mDisplayId); |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1111 | final DisplayData wpdData = getDisplayDataOrCreate(mDisplayId); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1112 | try { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1113 | connection.mService.attach(connection, mToken, TYPE_WALLPAPER, false, |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1114 | wpdData.mWidth, wpdData.mHeight, |
| 1115 | wpdData.mPadding, mDisplayId); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1116 | } catch (RemoteException e) { |
| 1117 | Slog.w(TAG, "Failed attaching wallpaper on display", e); |
wilsonshih | 674a4a0 | 2018-12-19 11:47:25 +0800 | [diff] [blame] | 1118 | if (wallpaper != null && !wallpaper.wallpaperUpdating |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1119 | && connection.getConnectedEngineSize() == 0) { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1120 | bindWallpaperComponentLocked(null /* componentName */, false /* force */, |
| 1121 | false /* fromUser */, wallpaper, null /* reply */); |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | void disconnectLocked() { |
| 1127 | if (DEBUG) Slog.v(TAG, "Removing window token: " + mToken); |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 1128 | mWindowManagerInternal.removeWindowToken(mToken, false/* removeWindows */, |
| 1129 | mDisplayId); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1130 | try { |
| 1131 | if (mEngine != null) { |
| 1132 | mEngine.destroy(); |
| 1133 | } |
| 1134 | } catch (RemoteException e) { |
| 1135 | } |
| 1136 | mEngine = null; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * A map for each display. |
| 1142 | * Use {@link #getDisplayConnectorOrCreate(int displayId)} to ensure the display is usable. |
| 1143 | */ |
| 1144 | private SparseArray<DisplayConnector> mDisplayConnector = new SparseArray<>(); |
| 1145 | |
Adrian Roos | c3f915e | 2016-09-06 11:40:53 -0700 | [diff] [blame] | 1146 | /** Time in milliseconds until we expect the wallpaper to reconnect (unless we're in the |
| 1147 | * middle of an update). If exceeded, the wallpaper gets reset to the system default. */ |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1148 | private static final long WALLPAPER_RECONNECT_TIMEOUT_MS = 10000; |
Adrian Roos | c3f915e | 2016-09-06 11:40:53 -0700 | [diff] [blame] | 1149 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1150 | final WallpaperInfo mInfo; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1151 | IWallpaperService mService; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1152 | WallpaperData mWallpaper; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1153 | final int mClientUid; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1154 | IRemoteCallback mReply; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | |
Adrian Roos | c3f915e | 2016-09-06 11:40:53 -0700 | [diff] [blame] | 1156 | private Runnable mResetRunnable = () -> { |
| 1157 | synchronized (mLock) { |
Christopher Tate | 762dfd1 | 2016-10-10 17:44:48 -0700 | [diff] [blame] | 1158 | if (mShuttingDown) { |
| 1159 | // Don't expect wallpaper services to relaunch during shutdown |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1160 | if (DEBUG_LIVE) { |
Christopher Tate | 762dfd1 | 2016-10-10 17:44:48 -0700 | [diff] [blame] | 1161 | Slog.i(TAG, "Ignoring relaunch timeout during shutdown"); |
| 1162 | } |
| 1163 | return; |
| 1164 | } |
| 1165 | |
Adrian Roos | c3f915e | 2016-09-06 11:40:53 -0700 | [diff] [blame] | 1166 | if (!mWallpaper.wallpaperUpdating |
| 1167 | && mWallpaper.userId == mCurrentUserId) { |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1168 | Slog.w(TAG, "Wallpaper reconnect timed out for " + mWallpaper.wallpaperComponent |
| 1169 | + ", reverting to built-in wallpaper!"); |
Adrian Roos | c3f915e | 2016-09-06 11:40:53 -0700 | [diff] [blame] | 1170 | clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, |
| 1171 | null); |
| 1172 | } |
| 1173 | } |
| 1174 | }; |
| 1175 | |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1176 | WallpaperConnection(WallpaperInfo info, WallpaperData wallpaper, int clientUid) { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1177 | mInfo = info; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1178 | mWallpaper = wallpaper; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1179 | mClientUid = clientUid; |
| 1180 | initDisplayState(); |
| 1181 | } |
| 1182 | |
| 1183 | private void initDisplayState() { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1184 | // Do not initialize fallback wallpaper |
| 1185 | if (!mWallpaper.equals(mFallbackWallpaper)) { |
| 1186 | if (supportsMultiDisplay(this)) { |
| 1187 | // The system wallpaper is image wallpaper or it can supports multiple displays. |
| 1188 | appendConnectorWithCondition(this::isUsableDisplay); |
| 1189 | } else { |
| 1190 | // The system wallpaper does not support multiple displays, so just attach it on |
| 1191 | // default display. |
| 1192 | mDisplayConnector.append(DEFAULT_DISPLAY, |
| 1193 | new DisplayConnector(DEFAULT_DISPLAY)); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1198 | private void appendConnectorWithCondition(Predicate<Display> tester) { |
| 1199 | final Display[] displays = mDisplayManager.getDisplays(); |
| 1200 | for (Display display : displays) { |
| 1201 | if (tester.test(display)) { |
| 1202 | final int displayId = display.getDisplayId(); |
wilsonshih | 674a4a0 | 2018-12-19 11:47:25 +0800 | [diff] [blame] | 1203 | final DisplayConnector connector = mDisplayConnector.get(displayId); |
| 1204 | if (connector == null) { |
| 1205 | mDisplayConnector.append(displayId, |
| 1206 | new DisplayConnector(displayId)); |
| 1207 | } |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | } |
| 1211 | |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1212 | private boolean isUsableDisplay(Display display) { |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 1213 | if (display == null || !display.hasAccess(mClientUid)) { |
| 1214 | return false; |
| 1215 | } |
| 1216 | final int displayId = display.getDisplayId(); |
wilsonshih | 0d5792e | 2019-07-04 11:23:54 +0800 | [diff] [blame] | 1217 | if (displayId == DEFAULT_DISPLAY) { |
| 1218 | return true; |
| 1219 | } |
| 1220 | |
| 1221 | final long ident = Binder.clearCallingIdentity(); |
| 1222 | try { |
| 1223 | return mWindowManagerInternal.shouldShowSystemDecorOnDisplay(displayId); |
| 1224 | } finally { |
| 1225 | Binder.restoreCallingIdentity(ident); |
| 1226 | } |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | void forEachDisplayConnector(Consumer<DisplayConnector> action) { |
| 1230 | for (int i = mDisplayConnector.size() - 1; i >= 0; i--) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1231 | final DisplayConnector connector = mDisplayConnector.valueAt(i); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1232 | action.accept(connector); |
| 1233 | } |
| 1234 | } |
| 1235 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1236 | int getConnectedEngineSize() { |
| 1237 | int engineSize = 0; |
| 1238 | for (int i = mDisplayConnector.size() - 1; i >= 0; i--) { |
| 1239 | final DisplayConnector connector = mDisplayConnector.valueAt(i); |
| 1240 | if (connector.mEngine != null) engineSize++; |
| 1241 | } |
| 1242 | return engineSize; |
| 1243 | } |
| 1244 | |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1245 | DisplayConnector getDisplayConnectorOrCreate(int displayId) { |
| 1246 | DisplayConnector connector = mDisplayConnector.get(displayId); |
| 1247 | if (connector == null) { |
| 1248 | final Display display = mDisplayManager.getDisplay(displayId); |
| 1249 | if (isUsableDisplay(display)) { |
| 1250 | connector = new DisplayConnector(displayId); |
| 1251 | mDisplayConnector.append(displayId, connector); |
| 1252 | } |
| 1253 | } |
| 1254 | return connector; |
| 1255 | } |
| 1256 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1257 | boolean containsDisplay(int displayId) { |
| 1258 | return mDisplayConnector.get(displayId) != null; |
| 1259 | } |
| 1260 | |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1261 | void removeDisplayConnector(int displayId) { |
| 1262 | final DisplayConnector connector = mDisplayConnector.get(displayId); |
| 1263 | if (connector != null) { |
| 1264 | mDisplayConnector.remove(displayId); |
| 1265 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1266 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1267 | |
| 1268 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1269 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 1270 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1271 | if (mWallpaper.connection == this) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1272 | mService = IWallpaperService.Stub.asInterface(service); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1273 | attachServiceLocked(this, mWallpaper); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 1274 | // XXX should probably do saveSettingsLocked() later |
| 1275 | // when we have an engine, but I'm not sure about |
| 1276 | // locking there and anyway we always need to be able to |
| 1277 | // recover if there is something wrong. |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1278 | if (!mWallpaper.equals(mFallbackWallpaper)) { |
| 1279 | saveSettingsLocked(mWallpaper.userId); |
| 1280 | } |
Adrian Roos | c3f915e | 2016-09-06 11:40:53 -0700 | [diff] [blame] | 1281 | FgThread.getHandler().removeCallbacks(mResetRunnable); |
wilsonshih | b875302 | 2019-10-09 20:50:44 +0800 | [diff] [blame] | 1282 | mContext.getMainThreadHandler().removeCallbacks(this::tryToRebind); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | } |
| 1286 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1287 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1288 | public void onServiceDisconnected(ComponentName name) { |
| 1289 | synchronized (mLock) { |
Christopher Tate | c349e59f | 2017-05-05 17:37:43 -0700 | [diff] [blame] | 1290 | Slog.w(TAG, "Wallpaper service gone: " + name); |
| 1291 | if (!Objects.equals(name, mWallpaper.wallpaperComponent)) { |
| 1292 | Slog.e(TAG, "Does not match expected wallpaper component " |
| 1293 | + mWallpaper.wallpaperComponent); |
| 1294 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1295 | mService = null; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1296 | forEachDisplayConnector(connector -> connector.mEngine = null); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1297 | if (mWallpaper.connection == this) { |
Christopher Tate | c349e59f | 2017-05-05 17:37:43 -0700 | [diff] [blame] | 1298 | // There is an inherent ordering race between this callback and the |
| 1299 | // package monitor that receives notice that a package is being updated, |
| 1300 | // so we cannot quite trust at this moment that we know for sure that |
| 1301 | // this is not an update. If we think this is a genuine non-update |
| 1302 | // wallpaper outage, we do our "wait for reset" work as a continuation, |
| 1303 | // a short time in the future, specifically to allow any pending package |
| 1304 | // update message on this same looper thread to be processed. |
| 1305 | if (!mWallpaper.wallpaperUpdating) { |
| 1306 | mContext.getMainThreadHandler().postDelayed(() -> processDisconnect(this), |
| 1307 | 1000); |
| 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | |
Tetsutoki Shiozawa | 0691921 | 2018-02-02 14:18:43 +0900 | [diff] [blame] | 1313 | public void scheduleTimeoutLocked() { |
| 1314 | // If we didn't reset it right away, do so after we couldn't connect to |
| 1315 | // it for an extended amount of time to avoid having a black wallpaper. |
| 1316 | final Handler fgHandler = FgThread.getHandler(); |
| 1317 | fgHandler.removeCallbacks(mResetRunnable); |
| 1318 | fgHandler.postDelayed(mResetRunnable, WALLPAPER_RECONNECT_TIMEOUT_MS); |
| 1319 | if (DEBUG_LIVE) { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1320 | Slog.i(TAG, |
| 1321 | "Started wallpaper reconnect timeout for " + mWallpaper.wallpaperComponent); |
Tetsutoki Shiozawa | 0691921 | 2018-02-02 14:18:43 +0900 | [diff] [blame] | 1322 | } |
| 1323 | } |
| 1324 | |
wilsonshih | b875302 | 2019-10-09 20:50:44 +0800 | [diff] [blame] | 1325 | private void tryToRebind() { |
| 1326 | synchronized (mLock) { |
| 1327 | if (mWallpaper.wallpaperUpdating) { |
| 1328 | return; |
| 1329 | } |
| 1330 | final ComponentName wpService = mWallpaper.wallpaperComponent; |
| 1331 | // The broadcast of package update could be delayed after service disconnected. Try |
| 1332 | // to re-bind the service for 10 seconds. |
| 1333 | if (bindWallpaperComponentLocked( |
| 1334 | wpService, true, false, mWallpaper, null)) { |
| 1335 | mWallpaper.connection.scheduleTimeoutLocked(); |
| 1336 | } else if (SystemClock.uptimeMillis() - mWallpaper.lastDiedTime |
| 1337 | < WALLPAPER_RECONNECT_TIMEOUT_MS) { |
| 1338 | // Bind fail without timeout, schedule rebind |
| 1339 | Slog.w(TAG, "Rebind fail! Try again later"); |
| 1340 | mContext.getMainThreadHandler().postDelayed(this::tryToRebind, 1000); |
| 1341 | } else { |
| 1342 | // Timeout |
| 1343 | Slog.w(TAG, "Reverting to built-in wallpaper!"); |
| 1344 | clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, null); |
| 1345 | final String flattened = wpService.flattenToString(); |
| 1346 | EventLog.writeEvent(EventLogTags.WP_WALLPAPER_CRASHED, |
| 1347 | flattened.substring(0, Math.min(flattened.length(), |
| 1348 | MAX_WALLPAPER_COMPONENT_LOG_LENGTH))); |
| 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | |
Christopher Tate | c349e59f | 2017-05-05 17:37:43 -0700 | [diff] [blame] | 1353 | private void processDisconnect(final ServiceConnection connection) { |
| 1354 | synchronized (mLock) { |
| 1355 | // The wallpaper disappeared. If this isn't a system-default one, track |
| 1356 | // crashes and fall back to default if it continues to misbehave. |
| 1357 | if (connection == mWallpaper.connection) { |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1358 | final ComponentName wpService = mWallpaper.wallpaperComponent; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1359 | if (!mWallpaper.wallpaperUpdating |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1360 | && mWallpaper.userId == mCurrentUserId |
| 1361 | && !Objects.equals(mDefaultWallpaperComponent, wpService) |
| 1362 | && !Objects.equals(mImageWallpaper, wpService)) { |
Selim Cinek | ebebadb | 2014-03-05 22:17:26 +0100 | [diff] [blame] | 1363 | // There is a race condition which causes |
| 1364 | // {@link #mWallpaper.wallpaperUpdating} to be false even if it is |
| 1365 | // currently updating since the broadcast notifying us is async. |
| 1366 | // This race is overcome by the general rule that we only reset the |
| 1367 | // wallpaper if its service was shut down twice |
| 1368 | // during {@link #MIN_WALLPAPER_CRASH_TIME} millis. |
| 1369 | if (mWallpaper.lastDiedTime != 0 |
| 1370 | && mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME |
Christopher Tate | c349e59f | 2017-05-05 17:37:43 -0700 | [diff] [blame] | 1371 | > SystemClock.uptimeMillis()) { |
Selim Cinek | ebebadb | 2014-03-05 22:17:26 +0100 | [diff] [blame] | 1372 | Slog.w(TAG, "Reverting to built-in wallpaper!"); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1373 | clearWallpaperLocked(true, FLAG_SYSTEM, mWallpaper.userId, null); |
Selim Cinek | ebebadb | 2014-03-05 22:17:26 +0100 | [diff] [blame] | 1374 | } else { |
| 1375 | mWallpaper.lastDiedTime = SystemClock.uptimeMillis(); |
wilsonshih | b875302 | 2019-10-09 20:50:44 +0800 | [diff] [blame] | 1376 | tryToRebind(); |
Selim Cinek | ebebadb | 2014-03-05 22:17:26 +0100 | [diff] [blame] | 1377 | } |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 1378 | } |
Christopher Tate | c349e59f | 2017-05-05 17:37:43 -0700 | [diff] [blame] | 1379 | } else { |
| 1380 | if (DEBUG_LIVE) { |
| 1381 | Slog.i(TAG, "Wallpaper changed during disconnect tracking; ignoring"); |
| 1382 | } |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 1383 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1384 | } |
| 1385 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1386 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 1387 | /** |
| 1388 | * Called by a live wallpaper if its colors have changed. |
| 1389 | * @param primaryColors representation of wallpaper primary colors |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 1390 | * @param displayId for which display |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 1391 | */ |
| 1392 | @Override |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 1393 | public void onWallpaperColorsChanged(WallpaperColors primaryColors, int displayId) { |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 1394 | int which; |
| 1395 | synchronized (mLock) { |
| 1396 | // Do not broadcast changes on ImageWallpaper since it's handled |
| 1397 | // internally by this class. |
| 1398 | if (mImageWallpaper.equals(mWallpaper.wallpaperComponent)) { |
| 1399 | return; |
| 1400 | } |
| 1401 | |
| 1402 | mWallpaper.primaryColors = primaryColors; |
| 1403 | |
| 1404 | // Live wallpapers always are system wallpapers. |
| 1405 | which = FLAG_SYSTEM; |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 1406 | // It's also the lock screen wallpaper when we don't have a bitmap in there. |
| 1407 | if (displayId == DEFAULT_DISPLAY) { |
| 1408 | final WallpaperData lockedWallpaper = mLockWallpaperMap.get(mWallpaper.userId); |
| 1409 | if (lockedWallpaper == null) { |
| 1410 | which |= FLAG_LOCK; |
| 1411 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 1412 | } |
| 1413 | } |
| 1414 | if (which != 0) { |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 1415 | notifyWallpaperColorsChangedOnDisplay(mWallpaper, which, displayId); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 1416 | } |
| 1417 | } |
| 1418 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1419 | @Override |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1420 | public void attachEngine(IWallpaperEngine engine, int displayId) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1421 | synchronized (mLock) { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1422 | final DisplayConnector connector = getDisplayConnectorOrCreate(displayId); |
| 1423 | if (connector == null) { |
Michael Wright | 5203a8b | 2013-10-03 14:16:42 -0700 | [diff] [blame] | 1424 | try { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1425 | engine.destroy(); |
Michael Wright | 5203a8b | 2013-10-03 14:16:42 -0700 | [diff] [blame] | 1426 | } catch (RemoteException e) { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1427 | Slog.w(TAG, "Failed to destroy engine", e); |
Michael Wright | 5203a8b | 2013-10-03 14:16:42 -0700 | [diff] [blame] | 1428 | } |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1429 | return; |
Michael Wright | 5203a8b | 2013-10-03 14:16:42 -0700 | [diff] [blame] | 1430 | } |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1431 | connector.mEngine = engine; |
| 1432 | connector.ensureStatusHandled(); |
| 1433 | |
| 1434 | // TODO(multi-display) TBD. |
| 1435 | if (mInfo != null && mInfo.supportsAmbientMode() && displayId == DEFAULT_DISPLAY) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1436 | try { |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 1437 | connector.mEngine.setInAmbientMode(mInAmbientMode, 0L /* duration */); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1438 | } catch (RemoteException e) { |
| 1439 | Slog.w(TAG, "Failed to set ambient mode state", e); |
| 1440 | } |
| 1441 | } |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 1442 | try { |
| 1443 | // This will trigger onComputeColors in the wallpaper engine. |
| 1444 | // It's fine to be locked in here since the binder is oneway. |
| 1445 | connector.mEngine.requestWallpaperColors(); |
| 1446 | } catch (RemoteException e) { |
| 1447 | Slog.w(TAG, "Failed to request wallpaper colors", e); |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 1448 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1449 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1450 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1451 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1452 | @Override |
| 1453 | public void engineShown(IWallpaperEngine engine) { |
| 1454 | synchronized (mLock) { |
| 1455 | if (mReply != null) { |
| 1456 | long ident = Binder.clearCallingIdentity(); |
| 1457 | try { |
| 1458 | mReply.sendResult(null); |
| 1459 | } catch (RemoteException e) { |
| 1460 | Binder.restoreCallingIdentity(ident); |
| 1461 | } |
| 1462 | mReply = null; |
| 1463 | } |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1468 | public ParcelFileDescriptor setWallpaper(String name) { |
| 1469 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1470 | if (mWallpaper.connection == this) { |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 1471 | return updateWallpaperBitmapLocked(name, mWallpaper, null); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1472 | } |
| 1473 | return null; |
| 1474 | } |
| 1475 | } |
| 1476 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1477 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1478 | class MyPackageMonitor extends PackageMonitor { |
| 1479 | @Override |
| 1480 | public void onPackageUpdateFinished(String packageName, int uid) { |
| 1481 | synchronized (mLock) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 1482 | if (mCurrentUserId != getChangingUserId()) { |
| 1483 | return; |
| 1484 | } |
| 1485 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 1486 | if (wallpaper != null) { |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1487 | final ComponentName wpService = wallpaper.wallpaperComponent; |
| 1488 | if (wpService != null && wpService.getPackageName().equals(packageName)) { |
| 1489 | if (DEBUG_LIVE) { |
| 1490 | Slog.i(TAG, "Wallpaper " + wpService + " update has finished"); |
| 1491 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1492 | wallpaper.wallpaperUpdating = false; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1493 | clearWallpaperComponentLocked(wallpaper); |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1494 | if (!bindWallpaperComponentLocked(wpService, false, false, |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 1495 | wallpaper, null)) { |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1496 | Slog.w(TAG, "Wallpaper " + wpService |
| 1497 | + " no longer available; reverting to default"); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1498 | clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1499 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1500 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | @Override |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1506 | public void onPackageModified(String packageName) { |
| 1507 | synchronized (mLock) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 1508 | if (mCurrentUserId != getChangingUserId()) { |
| 1509 | return; |
| 1510 | } |
| 1511 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 1512 | if (wallpaper != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1513 | if (wallpaper.wallpaperComponent == null |
| 1514 | || !wallpaper.wallpaperComponent.getPackageName().equals(packageName)) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 1515 | return; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1516 | } |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1517 | doPackagesChangedLocked(true, wallpaper); |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1518 | } |
| 1519 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | @Override |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1523 | public void onPackageUpdateStarted(String packageName, int uid) { |
| 1524 | synchronized (mLock) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 1525 | if (mCurrentUserId != getChangingUserId()) { |
| 1526 | return; |
| 1527 | } |
| 1528 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 1529 | if (wallpaper != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1530 | if (wallpaper.wallpaperComponent != null |
| 1531 | && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) { |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1532 | if (DEBUG_LIVE) { |
| 1533 | Slog.i(TAG, "Wallpaper service " + wallpaper.wallpaperComponent |
| 1534 | + " is updating"); |
| 1535 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1536 | wallpaper.wallpaperUpdating = true; |
Adrian Roos | c3f915e | 2016-09-06 11:40:53 -0700 | [diff] [blame] | 1537 | if (wallpaper.connection != null) { |
| 1538 | FgThread.getHandler().removeCallbacks( |
| 1539 | wallpaper.connection.mResetRunnable); |
| 1540 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1541 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | @Override |
| 1547 | public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) { |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1548 | synchronized (mLock) { |
| 1549 | boolean changed = false; |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 1550 | if (mCurrentUserId != getChangingUserId()) { |
| 1551 | return false; |
| 1552 | } |
| 1553 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 1554 | if (wallpaper != null) { |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1555 | boolean res = doPackagesChangedLocked(doit, wallpaper); |
| 1556 | changed |= res; |
| 1557 | } |
| 1558 | return changed; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1559 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | @Override |
| 1563 | public void onSomePackagesChanged() { |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1564 | synchronized (mLock) { |
Dianne Hackborn | c72fc67 | 2012-09-20 13:12:03 -0700 | [diff] [blame] | 1565 | if (mCurrentUserId != getChangingUserId()) { |
| 1566 | return; |
| 1567 | } |
| 1568 | WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId); |
| 1569 | if (wallpaper != null) { |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1570 | doPackagesChangedLocked(true, wallpaper); |
| 1571 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1572 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1573 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1574 | |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1575 | boolean doPackagesChangedLocked(boolean doit, WallpaperData wallpaper) { |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1576 | boolean changed = false; |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1577 | if (wallpaper.wallpaperComponent != null) { |
| 1578 | int change = isPackageDisappearing(wallpaper.wallpaperComponent |
| 1579 | .getPackageName()); |
| 1580 | if (change == PACKAGE_PERMANENT_CHANGE |
| 1581 | || change == PACKAGE_TEMPORARY_CHANGE) { |
| 1582 | changed = true; |
| 1583 | if (doit) { |
| 1584 | Slog.w(TAG, "Wallpaper uninstalled, removing: " |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1585 | + wallpaper.wallpaperComponent); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1586 | clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1587 | } |
| 1588 | } |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1589 | } |
| 1590 | if (wallpaper.nextWallpaperComponent != null) { |
| 1591 | int change = isPackageDisappearing(wallpaper.nextWallpaperComponent |
| 1592 | .getPackageName()); |
| 1593 | if (change == PACKAGE_PERMANENT_CHANGE |
| 1594 | || change == PACKAGE_TEMPORARY_CHANGE) { |
| 1595 | wallpaper.nextWallpaperComponent = null; |
| 1596 | } |
| 1597 | } |
| 1598 | if (wallpaper.wallpaperComponent != null |
| 1599 | && isPackageModified(wallpaper.wallpaperComponent.getPackageName())) { |
| 1600 | try { |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1601 | mContext.getPackageManager().getServiceInfo(wallpaper.wallpaperComponent, |
| 1602 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 1603 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1604 | } catch (NameNotFoundException e) { |
| 1605 | Slog.w(TAG, "Wallpaper component gone, removing: " |
| 1606 | + wallpaper.wallpaperComponent); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1607 | clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, null); |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | if (wallpaper.nextWallpaperComponent != null |
| 1611 | && isPackageModified(wallpaper.nextWallpaperComponent.getPackageName())) { |
| 1612 | try { |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1613 | mContext.getPackageManager().getServiceInfo(wallpaper.nextWallpaperComponent, |
| 1614 | PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 1615 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE); |
Dianne Hackborn | d0d7503 | 2012-04-19 23:12:09 -0700 | [diff] [blame] | 1616 | } catch (NameNotFoundException e) { |
| 1617 | wallpaper.nextWallpaperComponent = null; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1618 | } |
| 1619 | } |
| 1620 | return changed; |
| 1621 | } |
| 1622 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1623 | |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 1624 | @VisibleForTesting |
| 1625 | WallpaperData getCurrentWallpaperData(@SetWallpaperFlags int which, int userId) { |
| 1626 | synchronized (mLock) { |
| 1627 | final SparseArray<WallpaperData> wallpaperDataMap = |
| 1628 | which == FLAG_SYSTEM ? mWallpaperMap : mLockWallpaperMap; |
| 1629 | return wallpaperDataMap.get(userId); |
| 1630 | } |
| 1631 | } |
| 1632 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1633 | public WallpaperManagerService(Context context) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1634 | if (DEBUG) Slog.v(TAG, "WallpaperService startup"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1635 | mContext = context; |
Christopher Tate | 762dfd1 | 2016-10-10 17:44:48 -0700 | [diff] [blame] | 1636 | mShuttingDown = false; |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 1637 | mImageWallpaper = ComponentName.unflattenFromString( |
| 1638 | context.getResources().getString(R.string.image_wallpaper_component)); |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 1639 | mDefaultWallpaperComponent = WallpaperManager.getDefaultWallpaperComponent(context); |
Andrii Kulian | dd98961 | 2019-02-21 12:13:28 -0800 | [diff] [blame] | 1640 | mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class); |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 1641 | mIPackageManager = AppGlobals.getPackageManager(); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1642 | mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1643 | mDisplayManager = mContext.getSystemService(DisplayManager.class); |
| 1644 | mDisplayManager.registerDisplayListener(mDisplayListener, null /* handler */); |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1645 | mMonitor = new MyPackageMonitor(); |
Jaekyun Seok | ad7d90f | 2018-04-04 01:57:18 +0900 | [diff] [blame] | 1646 | mColorsChangedListeners = new SparseArray<>(); |
wilsonshih | 643bf13 | 2019-02-27 12:49:19 +0800 | [diff] [blame] | 1647 | |
| 1648 | LocalServices.addService(WallpaperManagerInternal.class, new LocalService()); |
| 1649 | } |
| 1650 | |
| 1651 | private final class LocalService extends WallpaperManagerInternal { |
| 1652 | @Override |
| 1653 | public void onDisplayReady(int displayId) { |
| 1654 | onDisplayReadyInternal(displayId); |
| 1655 | } |
Jaekyun Seok | ad7d90f | 2018-04-04 01:57:18 +0900 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | void initialize() { |
| 1659 | mMonitor.register(mContext, null, UserHandle.ALL, true); |
Xiaohui Chen | 233d94c | 2015-07-30 15:08:00 -0700 | [diff] [blame] | 1660 | getWallpaperDir(UserHandle.USER_SYSTEM).mkdirs(); |
Christopher Tate | f717b93 | 2017-09-11 15:52:54 -0700 | [diff] [blame] | 1661 | |
| 1662 | // Initialize state from the persistent store, then guarantee that the |
| 1663 | // WallpaperData for the system imagery is instantiated & active, creating |
| 1664 | // it from defaults if necessary. |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1665 | loadSettingsLocked(UserHandle.USER_SYSTEM, false); |
Christopher Tate | f717b93 | 2017-09-11 15:52:54 -0700 | [diff] [blame] | 1666 | getWallpaperSafeLocked(UserHandle.USER_SYSTEM, FLAG_SYSTEM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 1668 | |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 1669 | File getWallpaperDir(int userId) { |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 1670 | return Environment.getUserSystemDirectory(userId); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1671 | } |
| 1672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | @Override |
| 1674 | protected void finalize() throws Throwable { |
| 1675 | super.finalize(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1676 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 1677 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
| 1678 | wallpaper.wallpaperObserver.stopWatching(); |
| 1679 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1680 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1681 | |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1682 | void systemReady() { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 1683 | if (DEBUG) Slog.v(TAG, "systemReady"); |
Jaekyun Seok | ad7d90f | 2018-04-04 01:57:18 +0900 | [diff] [blame] | 1684 | initialize(); |
| 1685 | |
Xiaohui Chen | 233d94c | 2015-07-30 15:08:00 -0700 | [diff] [blame] | 1686 | WallpaperData wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM); |
Christopher Tate | 2cdd3f2 | 2016-03-14 17:36:16 -0700 | [diff] [blame] | 1687 | // If we think we're going to be using the system image wallpaper imagery, make |
| 1688 | // sure we have something to render |
| 1689 | if (mImageWallpaper.equals(wallpaper.nextWallpaperComponent)) { |
| 1690 | // No crop file? Make sure we've finished the processing sequence if necessary |
| 1691 | if (!wallpaper.cropExists()) { |
| 1692 | if (DEBUG) { |
| 1693 | Slog.i(TAG, "No crop; regenerating from source"); |
| 1694 | } |
| 1695 | generateCrop(wallpaper); |
| 1696 | } |
| 1697 | // Still nothing? Fall back to default. |
| 1698 | if (!wallpaper.cropExists()) { |
| 1699 | if (DEBUG) { |
| 1700 | Slog.i(TAG, "Unable to regenerate crop; resetting"); |
| 1701 | } |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1702 | clearWallpaperLocked(false, FLAG_SYSTEM, UserHandle.USER_SYSTEM, null); |
Christopher Tate | 2cdd3f2 | 2016-03-14 17:36:16 -0700 | [diff] [blame] | 1703 | } |
| 1704 | } else { |
| 1705 | if (DEBUG) { |
| 1706 | Slog.i(TAG, "Nondefault wallpaper component; gracefully ignoring"); |
| 1707 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 1708 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1709 | |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1710 | IntentFilter userFilter = new IntentFilter(); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1711 | userFilter.addAction(Intent.ACTION_USER_REMOVED); |
| 1712 | mContext.registerReceiver(new BroadcastReceiver() { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1713 | @Override |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1714 | public void onReceive(Context context, Intent intent) { |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1715 | final String action = intent.getAction(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1716 | if (Intent.ACTION_USER_REMOVED.equals(action)) { |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 1717 | onRemoveUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, |
| 1718 | UserHandle.USER_NULL)); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1719 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1720 | } |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1721 | }, userFilter); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 1722 | |
Christopher Tate | 762dfd1 | 2016-10-10 17:44:48 -0700 | [diff] [blame] | 1723 | final IntentFilter shutdownFilter = new IntentFilter(Intent.ACTION_SHUTDOWN); |
| 1724 | mContext.registerReceiver(new BroadcastReceiver() { |
| 1725 | @Override |
| 1726 | public void onReceive(Context context, Intent intent) { |
| 1727 | if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) { |
| 1728 | if (DEBUG) { |
| 1729 | Slog.i(TAG, "Shutting down"); |
| 1730 | } |
| 1731 | synchronized (mLock) { |
| 1732 | mShuttingDown = true; |
| 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | }, shutdownFilter); |
| 1737 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1738 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 1739 | ActivityManager.getService().registerUserSwitchObserver( |
Sudheer Shanka | 2c4522c | 2016-08-27 20:53:28 -0700 | [diff] [blame] | 1740 | new UserSwitchObserver() { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1741 | @Override |
| 1742 | public void onUserSwitching(int newUserId, IRemoteCallback reply) { |
| 1743 | switchUser(newUserId, reply); |
| 1744 | } |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1745 | }, TAG); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1746 | } catch (RemoteException e) { |
Fyodor Kupolov | 0b77ef9 | 2016-06-20 17:16:52 -0700 | [diff] [blame] | 1747 | e.rethrowAsRuntimeException(); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1748 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1749 | } |
| 1750 | |
Amith Yamasani | 09e9cdc | 2013-11-06 14:54:50 -0800 | [diff] [blame] | 1751 | /** Called by SystemBackupAgent */ |
| 1752 | public String getName() { |
| 1753 | // Verify caller is the system |
| 1754 | if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) { |
| 1755 | throw new RuntimeException("getName() can only be called from the system process"); |
| 1756 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1757 | synchronized (mLock) { |
| 1758 | return mWallpaperMap.get(0).name; |
| 1759 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1760 | } |
| 1761 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1762 | void stopObserver(WallpaperData wallpaper) { |
| 1763 | if (wallpaper != null) { |
| 1764 | if (wallpaper.wallpaperObserver != null) { |
| 1765 | wallpaper.wallpaperObserver.stopWatching(); |
| 1766 | wallpaper.wallpaperObserver = null; |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1767 | } |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 1768 | } |
| 1769 | } |
| 1770 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1771 | void stopObserversLocked(int userId) { |
| 1772 | stopObserver(mWallpaperMap.get(userId)); |
| 1773 | stopObserver(mLockWallpaperMap.get(userId)); |
| 1774 | mWallpaperMap.remove(userId); |
| 1775 | mLockWallpaperMap.remove(userId); |
| 1776 | } |
| 1777 | |
Daichi Hirono | 4bbf852 | 2017-12-06 10:34:18 +0900 | [diff] [blame] | 1778 | @Override |
| 1779 | public void onBootPhase(int phase) { |
| 1780 | if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) { |
| 1781 | systemReady(); |
| 1782 | } else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) { |
| 1783 | switchUser(UserHandle.USER_SYSTEM, null); |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | @Override |
| 1788 | public void onUnlockUser(final int userId) { |
Felipe Leme | 4e2cbb5 | 2019-12-02 16:46:49 -0800 | [diff] [blame] | 1789 | TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG); |
| 1790 | t.traceBegin("on-unlock-user-" + userId); |
| 1791 | try { |
| 1792 | synchronized (mLock) { |
| 1793 | if (mCurrentUserId == userId) { |
| 1794 | if (mWaitingForUnlock) { |
| 1795 | // the desired wallpaper is not direct-boot aware, load it now |
| 1796 | final WallpaperData systemWallpaper = |
| 1797 | getWallpaperSafeLocked(userId, FLAG_SYSTEM); |
| 1798 | switchWallpaper(systemWallpaper, null); |
| 1799 | notifyCallbacksLocked(systemWallpaper); |
| 1800 | } |
Christopher Tate | 190e853 | 2016-07-11 11:35:34 -0700 | [diff] [blame] | 1801 | |
Felipe Leme | 4e2cbb5 | 2019-12-02 16:46:49 -0800 | [diff] [blame] | 1802 | // Make sure that the SELinux labeling of all the relevant files is correct. |
| 1803 | // This corrects for mislabeling bugs that might have arisen from move-to |
| 1804 | // operations involving the wallpaper files. This isn't timing-critical, |
| 1805 | // so we do it in the background to avoid holding up the user unlock operation. |
| 1806 | if (!mUserRestorecon.get(userId)) { |
| 1807 | mUserRestorecon.put(userId, true); |
| 1808 | Runnable relabeler = () -> { |
Christopher Tate | 38a5dc3 | 2016-07-20 15:10:18 -0700 | [diff] [blame] | 1809 | final File wallpaperDir = getWallpaperDir(userId); |
| 1810 | for (String filename : sPerUserFiles) { |
| 1811 | File f = new File(wallpaperDir, filename); |
| 1812 | if (f.exists()) { |
| 1813 | SELinux.restorecon(f); |
| 1814 | } |
Christopher Tate | 190e853 | 2016-07-11 11:35:34 -0700 | [diff] [blame] | 1815 | } |
Felipe Leme | 4e2cbb5 | 2019-12-02 16:46:49 -0800 | [diff] [blame] | 1816 | }; |
| 1817 | BackgroundThread.getHandler().post(relabeler); |
| 1818 | } |
Christopher Tate | 38a5dc3 | 2016-07-20 15:10:18 -0700 | [diff] [blame] | 1819 | } |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1820 | } |
Felipe Leme | 4e2cbb5 | 2019-12-02 16:46:49 -0800 | [diff] [blame] | 1821 | } finally { |
| 1822 | t.traceEnd(); |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 1826 | void onRemoveUser(int userId) { |
| 1827 | if (userId < 1) return; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1828 | |
| 1829 | final File wallpaperDir = getWallpaperDir(userId); |
Amith Yamasani | 756901d | 2012-10-12 12:30:07 -0700 | [diff] [blame] | 1830 | synchronized (mLock) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1831 | stopObserversLocked(userId); |
| 1832 | for (String filename : sPerUserFiles) { |
| 1833 | new File(wallpaperDir, filename).delete(); |
| 1834 | } |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 1835 | mUserRestorecon.delete(userId); |
Amith Yamasani | 1359360 | 2012-03-22 16:16:17 -0700 | [diff] [blame] | 1836 | } |
| 1837 | } |
| 1838 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1839 | void switchUser(int userId, IRemoteCallback reply) { |
Felipe Leme | 4e2cbb5 | 2019-12-02 16:46:49 -0800 | [diff] [blame] | 1840 | TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG); |
| 1841 | t.traceBegin("switch-user-" + userId); |
| 1842 | try { |
| 1843 | final WallpaperData systemWallpaper; |
| 1844 | final WallpaperData lockWallpaper; |
| 1845 | synchronized (mLock) { |
| 1846 | if (mCurrentUserId == userId) { |
| 1847 | return; |
| 1848 | } |
| 1849 | mCurrentUserId = userId; |
| 1850 | systemWallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); |
| 1851 | final WallpaperData tmpLockWallpaper = mLockWallpaperMap.get(userId); |
| 1852 | lockWallpaper = tmpLockWallpaper == null ? systemWallpaper : tmpLockWallpaper; |
| 1853 | // Not started watching yet, in case wallpaper data was loaded for other reasons. |
| 1854 | if (systemWallpaper.wallpaperObserver == null) { |
| 1855 | systemWallpaper.wallpaperObserver = new WallpaperObserver(systemWallpaper); |
| 1856 | systemWallpaper.wallpaperObserver.startWatching(); |
| 1857 | } |
| 1858 | switchWallpaper(systemWallpaper, reply); |
Jaekyun Seok | ad7d90f | 2018-04-04 01:57:18 +0900 | [diff] [blame] | 1859 | } |
Lucas Dupin | 9272d45 | 2017-09-14 14:15:42 -0700 | [diff] [blame] | 1860 | |
Felipe Leme | 4e2cbb5 | 2019-12-02 16:46:49 -0800 | [diff] [blame] | 1861 | // Offload color extraction to another thread since switchUser will be called |
| 1862 | // from the main thread. |
| 1863 | FgThread.getHandler().post(() -> { |
| 1864 | notifyWallpaperColorsChanged(systemWallpaper, FLAG_SYSTEM); |
| 1865 | notifyWallpaperColorsChanged(lockWallpaper, FLAG_LOCK); |
| 1866 | notifyWallpaperColorsChanged(mFallbackWallpaper, FLAG_SYSTEM); |
| 1867 | }); |
| 1868 | } finally { |
| 1869 | t.traceEnd(); |
| 1870 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1871 | } |
| 1872 | |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 1873 | void switchWallpaper(WallpaperData wallpaper, IRemoteCallback reply) { |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1874 | synchronized (mLock) { |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1875 | mWaitingForUnlock = false; |
| 1876 | final ComponentName cname = wallpaper.wallpaperComponent != null ? |
| 1877 | wallpaper.wallpaperComponent : wallpaper.nextWallpaperComponent; |
| 1878 | if (!bindWallpaperComponentLocked(cname, true, false, wallpaper, reply)) { |
| 1879 | // We failed to bind the desired wallpaper, but that might |
| 1880 | // happen if the wallpaper isn't direct-boot aware |
| 1881 | ServiceInfo si = null; |
| 1882 | try { |
| 1883 | si = mIPackageManager.getServiceInfo(cname, |
| 1884 | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, wallpaper.userId); |
| 1885 | } catch (RemoteException ignored) { |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1886 | } |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1887 | |
| 1888 | if (si == null) { |
| 1889 | Slog.w(TAG, "Failure starting previous wallpaper; clearing"); |
| 1890 | clearWallpaperLocked(false, FLAG_SYSTEM, wallpaper.userId, reply); |
| 1891 | } else { |
| 1892 | Slog.w(TAG, "Wallpaper isn't direct boot aware; using fallback until unlocked"); |
| 1893 | // We might end up persisting the current wallpaper data |
| 1894 | // while locked, so pretend like the component was actually |
| 1895 | // bound into place |
| 1896 | wallpaper.wallpaperComponent = wallpaper.nextWallpaperComponent; |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 1897 | final WallpaperData fallback = |
| 1898 | new WallpaperData(wallpaper.userId, getWallpaperDir(wallpaper.userId), |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1899 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1900 | ensureSaneWallpaperData(fallback, DEFAULT_DISPLAY); |
Jeff Sharkey | 1cab76a | 2016-04-12 18:23:31 -0600 | [diff] [blame] | 1901 | bindWallpaperComponentLocked(mImageWallpaper, true, false, fallback, reply); |
| 1902 | mWaitingForUnlock = true; |
| 1903 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 1904 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1905 | } |
| 1906 | } |
| 1907 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1908 | @Override |
| 1909 | public void clearWallpaper(String callingPackage, int which, int userId) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1910 | if (DEBUG) Slog.v(TAG, "clearWallpaper"); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1911 | checkPermission(android.Manifest.permission.SET_WALLPAPER); |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 1912 | if (!isWallpaperSupported(callingPackage) || !isSetWallpaperAllowed(callingPackage)) { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1913 | return; |
| 1914 | } |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 1915 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| 1916 | Binder.getCallingUid(), userId, false, true, "clearWallpaper", null); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1917 | |
Lucas Dupin | 41f6942 | 2017-05-03 15:26:22 -0700 | [diff] [blame] | 1918 | WallpaperData data = null; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1919 | synchronized (mLock) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1920 | clearWallpaperLocked(false, which, userId, null); |
Lucas Dupin | 41f6942 | 2017-05-03 15:26:22 -0700 | [diff] [blame] | 1921 | |
| 1922 | if (which == FLAG_LOCK) { |
| 1923 | data = mLockWallpaperMap.get(userId); |
| 1924 | } |
| 1925 | if (which == FLAG_SYSTEM || data == null) { |
| 1926 | data = mWallpaperMap.get(userId); |
| 1927 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1928 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 1929 | |
| 1930 | // When clearing a wallpaper, broadcast new valid colors |
Lucas Dupin | 41f6942 | 2017-05-03 15:26:22 -0700 | [diff] [blame] | 1931 | if (data != null) { |
| 1932 | notifyWallpaperColorsChanged(data, which); |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 1933 | notifyWallpaperColorsChanged(mFallbackWallpaper, FLAG_SYSTEM); |
Lucas Dupin | 41f6942 | 2017-05-03 15:26:22 -0700 | [diff] [blame] | 1934 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 1935 | } |
| 1936 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1937 | void clearWallpaperLocked(boolean defaultFailed, int which, int userId, IRemoteCallback reply) { |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1938 | if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
Christopher Tate | 105540d | 2018-03-21 13:03:09 -0700 | [diff] [blame] | 1939 | throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to clear"); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | WallpaperData wallpaper = null; |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1943 | if (which == FLAG_LOCK) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1944 | wallpaper = mLockWallpaperMap.get(userId); |
| 1945 | if (wallpaper == null) { |
| 1946 | // It's already gone; we're done. |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1947 | if (DEBUG) { |
| 1948 | Slog.i(TAG, "Lock wallpaper already cleared"); |
| 1949 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1950 | return; |
| 1951 | } |
| 1952 | } else { |
| 1953 | wallpaper = mWallpaperMap.get(userId); |
| 1954 | if (wallpaper == null) { |
| 1955 | // Might need to bring it in the first time to establish our rewrite |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 1956 | loadSettingsLocked(userId, false); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1957 | wallpaper = mWallpaperMap.get(userId); |
| 1958 | } |
| 1959 | } |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1960 | if (wallpaper == null) { |
| 1961 | return; |
| 1962 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1963 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 1964 | final long ident = Binder.clearCallingIdentity(); |
| 1965 | try { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1966 | if (wallpaper.wallpaperFile.exists()) { |
| 1967 | wallpaper.wallpaperFile.delete(); |
| 1968 | wallpaper.cropFile.delete(); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 1969 | if (which == FLAG_LOCK) { |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1970 | mLockWallpaperMap.remove(userId); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1971 | final IWallpaperManagerCallback cb = mKeyguardListener; |
| 1972 | if (cb != null) { |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1973 | if (DEBUG) { |
| 1974 | Slog.i(TAG, "Notifying keyguard of lock wallpaper clear"); |
| 1975 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1976 | try { |
| 1977 | cb.onWallpaperChanged(); |
| 1978 | } catch (RemoteException e) { |
| 1979 | // Oh well it went away; no big deal |
| 1980 | } |
| 1981 | } |
Christopher Tate | 79a2457 | 2016-03-02 14:42:44 -0800 | [diff] [blame] | 1982 | saveSettingsLocked(userId); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 1983 | return; |
| 1984 | } |
| 1985 | } |
| 1986 | |
Christopher Tate | ecd827a | 2014-09-05 17:42:34 -0700 | [diff] [blame] | 1987 | RuntimeException e = null; |
| 1988 | try { |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 1989 | wallpaper.primaryColors = null; |
Christopher Tate | ecd827a | 2014-09-05 17:42:34 -0700 | [diff] [blame] | 1990 | wallpaper.imageWallpaperPending = false; |
| 1991 | if (userId != mCurrentUserId) return; |
| 1992 | if (bindWallpaperComponentLocked(defaultFailed |
| 1993 | ? mImageWallpaper |
| 1994 | : null, true, false, wallpaper, reply)) { |
| 1995 | return; |
| 1996 | } |
| 1997 | } catch (IllegalArgumentException e1) { |
| 1998 | e = e1; |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 1999 | } |
Christopher Tate | ecd827a | 2014-09-05 17:42:34 -0700 | [diff] [blame] | 2000 | |
| 2001 | // This can happen if the default wallpaper component doesn't |
| 2002 | // exist. This should be a system configuration problem, but |
| 2003 | // let's not let it crash the system and just live with no |
| 2004 | // wallpaper. |
| 2005 | Slog.e(TAG, "Default wallpaper component not found!", e); |
| 2006 | clearWallpaperComponentLocked(wallpaper); |
| 2007 | if (reply != null) { |
| 2008 | try { |
| 2009 | reply.sendResult(null); |
| 2010 | } catch (RemoteException e1) { |
| 2011 | } |
| 2012 | } |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 2013 | } finally { |
| 2014 | Binder.restoreCallingIdentity(ident); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2015 | } |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | public boolean hasNamedWallpaper(String name) { |
| 2019 | synchronized (mLock) { |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 2020 | List<UserInfo> users; |
| 2021 | long ident = Binder.clearCallingIdentity(); |
| 2022 | try { |
| 2023 | users = ((UserManager) mContext.getSystemService(Context.USER_SERVICE)).getUsers(); |
| 2024 | } finally { |
| 2025 | Binder.restoreCallingIdentity(ident); |
| 2026 | } |
| 2027 | for (UserInfo user: users) { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2028 | // ignore managed profiles |
| 2029 | if (user.isManagedProfile()) { |
| 2030 | continue; |
| 2031 | } |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 2032 | WallpaperData wd = mWallpaperMap.get(user.id); |
| 2033 | if (wd == null) { |
| 2034 | // User hasn't started yet, so load her settings to peek at the wallpaper |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2035 | loadSettingsLocked(user.id, false); |
Amith Yamasani | 6474c4c | 2012-10-04 14:55:42 -0700 | [diff] [blame] | 2036 | wd = mWallpaperMap.get(user.id); |
| 2037 | } |
| 2038 | if (wd != null && name.equals(wd.name)) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2039 | return true; |
| 2040 | } |
| 2041 | } |
| 2042 | } |
| 2043 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2046 | private boolean isValidDisplay(int displayId) { |
| 2047 | return mDisplayManager.getDisplay(displayId) != null; |
| 2048 | } |
| 2049 | |
| 2050 | /** |
| 2051 | * Sets the dimension hint for the wallpaper. These hints indicate the desired |
| 2052 | * minimum width and height for the wallpaper in a particular display. |
| 2053 | */ |
| 2054 | public void setDimensionHints(int width, int height, String callingPackage, int displayId) |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2055 | throws RemoteException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2056 | checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2057 | if (!isWallpaperSupported(callingPackage)) { |
| 2058 | return; |
| 2059 | } |
Ahan Wu | 32c6a7c | 2019-10-03 12:36:59 +0800 | [diff] [blame] | 2060 | |
| 2061 | // Make sure both width and height are not larger than max texture size. |
| 2062 | width = Math.min(width, GLHelper.getMaxTextureSize()); |
| 2063 | height = Math.min(height, GLHelper.getMaxTextureSize()); |
| 2064 | |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2065 | synchronized (mLock) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2066 | int userId = UserHandle.getCallingUserId(); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 2067 | WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2068 | if (width <= 0 || height <= 0) { |
| 2069 | throw new IllegalArgumentException("width and height must be > 0"); |
| 2070 | } |
| 2071 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2072 | if (!isValidDisplay(displayId)) { |
| 2073 | throw new IllegalArgumentException("Cannot find display with id=" + displayId); |
| 2074 | } |
| 2075 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2076 | final DisplayData wpdData = getDisplayDataOrCreate(displayId); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2077 | if (width != wpdData.mWidth || height != wpdData.mHeight) { |
| 2078 | wpdData.mWidth = width; |
| 2079 | wpdData.mHeight = height; |
| 2080 | if (displayId == DEFAULT_DISPLAY) saveSettingsLocked(userId); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2081 | if (mCurrentUserId != userId) return; // Don't change the properties now |
| 2082 | if (wallpaper.connection != null) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2083 | final WallpaperConnection.DisplayConnector connector = wallpaper.connection |
| 2084 | .getDisplayConnectorOrCreate(displayId); |
| 2085 | final IWallpaperEngine engine = connector != null ? connector.mEngine : null; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2086 | if (engine != null) { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2087 | try { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2088 | engine.setDesiredSize(width, height); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2089 | } catch (RemoteException e) { |
| 2090 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2091 | notifyCallbacksLocked(wallpaper); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2092 | } else if (wallpaper.connection.mService != null && connector != null) { |
Michael Wright | 5203a8b | 2013-10-03 14:16:42 -0700 | [diff] [blame] | 2093 | // We've attached to the service but the engine hasn't attached back to us |
| 2094 | // yet. This means it will be created with the previous dimensions, so we |
| 2095 | // need to update it to the new dimensions once it attaches. |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2096 | connector.mDimensionsChanged = true; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2097 | } |
| 2098 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2099 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2103 | /** |
| 2104 | * Returns the desired minimum width for the wallpaper in a particular display. |
| 2105 | */ |
| 2106 | public int getWidthHint(int displayId) throws RemoteException { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2107 | synchronized (mLock) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2108 | if (!isValidDisplay(displayId)) { |
| 2109 | throw new IllegalArgumentException("Cannot find display with id=" + displayId); |
| 2110 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2111 | WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId()); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2112 | if (wallpaper != null) { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2113 | final DisplayData wpdData = getDisplayDataOrCreate(displayId); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2114 | return wpdData.mWidth; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2115 | } else { |
| 2116 | return 0; |
| 2117 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2118 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2119 | } |
| 2120 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2121 | /** |
| 2122 | * Returns the desired minimum height for the wallpaper in a particular display. |
| 2123 | */ |
| 2124 | public int getHeightHint(int displayId) throws RemoteException { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2125 | synchronized (mLock) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2126 | if (!isValidDisplay(displayId)) { |
| 2127 | throw new IllegalArgumentException("Cannot find display with id=" + displayId); |
| 2128 | } |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 2129 | WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId()); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2130 | if (wallpaper != null) { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2131 | final DisplayData wpdData = getDisplayDataOrCreate(displayId); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2132 | return wpdData.mHeight; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2133 | } else { |
| 2134 | return 0; |
| 2135 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2136 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2137 | } |
| 2138 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2139 | /** |
| 2140 | * Sets extra padding that we would like the wallpaper to have outside of the display. |
| 2141 | */ |
| 2142 | public void setDisplayPadding(Rect padding, String callingPackage, int displayId) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2143 | checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2144 | if (!isWallpaperSupported(callingPackage)) { |
| 2145 | return; |
| 2146 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2147 | synchronized (mLock) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2148 | if (!isValidDisplay(displayId)) { |
| 2149 | throw new IllegalArgumentException("Cannot find display with id=" + displayId); |
| 2150 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2151 | int userId = UserHandle.getCallingUserId(); |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 2152 | WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2153 | if (padding.left < 0 || padding.top < 0 || padding.right < 0 || padding.bottom < 0) { |
| 2154 | throw new IllegalArgumentException("padding must be positive: " + padding); |
| 2155 | } |
| 2156 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2157 | final DisplayData wpdData = getDisplayDataOrCreate(displayId); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2158 | if (!padding.equals(wpdData.mPadding)) { |
| 2159 | wpdData.mPadding.set(padding); |
| 2160 | if (displayId == DEFAULT_DISPLAY) saveSettingsLocked(userId); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2161 | if (mCurrentUserId != userId) return; // Don't change the properties now |
| 2162 | if (wallpaper.connection != null) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2163 | final WallpaperConnection.DisplayConnector connector = wallpaper.connection |
| 2164 | .getDisplayConnectorOrCreate(displayId); |
| 2165 | final IWallpaperEngine engine = connector != null ? connector.mEngine : null; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2166 | if (engine != null) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2167 | try { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2168 | engine.setDisplayPadding(padding); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2169 | } catch (RemoteException e) { |
| 2170 | } |
| 2171 | notifyCallbacksLocked(wallpaper); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2172 | } else if (wallpaper.connection.mService != null && connector != null) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2173 | // We've attached to the service but the engine hasn't attached back to us |
| 2174 | // yet. This means it will be created with the previous dimensions, so we |
| 2175 | // need to update it to the new dimensions once it attaches. |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2176 | connector.mPaddingChanged = true; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2177 | } |
| 2178 | } |
| 2179 | } |
| 2180 | } |
| 2181 | } |
| 2182 | |
Santiago Etchebehere | 44a2831 | 2020-01-14 15:27:11 -0800 | [diff] [blame] | 2183 | /** |
| 2184 | * Called when the wallpaper needs to zoom out. |
| 2185 | * |
| 2186 | * @param zoom from 0 to 1 (inclusive) where 1 means fully zoomed out, 0 means fully zoomed in. |
| 2187 | * @param callingPackage package name calling this API. |
| 2188 | * @param displayId id of the display whose zoom is updating. |
| 2189 | */ |
| 2190 | public void setWallpaperZoomOut(float zoom, String callingPackage, int displayId) { |
| 2191 | if (!isWallpaperSupported(callingPackage)) { |
| 2192 | return; |
| 2193 | } |
| 2194 | synchronized (mLock) { |
| 2195 | if (!isValidDisplay(displayId)) { |
| 2196 | throw new IllegalArgumentException("Cannot find display with id=" + displayId); |
| 2197 | } |
| 2198 | int userId = UserHandle.getCallingUserId(); |
| 2199 | if (mCurrentUserId != userId) { |
| 2200 | return; // Don't change the properties now |
| 2201 | } |
| 2202 | WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); |
| 2203 | if (zoom < 0 || zoom > 1f) { |
| 2204 | throw new IllegalArgumentException("zoom must be between 0 and one: " + zoom); |
| 2205 | } |
| 2206 | |
| 2207 | if (wallpaper.connection != null) { |
| 2208 | final WallpaperConnection.DisplayConnector connector = wallpaper.connection |
| 2209 | .getDisplayConnectorOrCreate(displayId); |
| 2210 | final IWallpaperEngine engine = connector != null ? connector.mEngine : null; |
| 2211 | if (engine != null) { |
| 2212 | try { |
| 2213 | engine.setZoomOut(zoom); |
| 2214 | } catch (RemoteException e) { |
| 2215 | if (DEBUG) { |
| 2216 | Slog.w(TAG, "Couldn't set wallpaper zoom", e); |
| 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | } |
| 2222 | } |
| 2223 | |
Philip P. Moltmann | 41ff0f6 | 2019-11-15 10:55:52 -0800 | [diff] [blame] | 2224 | @Deprecated |
Yorke Lee | dcd93cc | 2016-01-08 14:12:55 -0800 | [diff] [blame] | 2225 | @Override |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 2226 | public ParcelFileDescriptor getWallpaper(String callingPkg, IWallpaperManagerCallback cb, |
| 2227 | final int which, Bundle outParams, int wallpaperUserId) { |
Philip P. Moltmann | 41ff0f6 | 2019-11-15 10:55:52 -0800 | [diff] [blame] | 2228 | return getWallpaperWithFeature(callingPkg, null, cb, which, outParams, wallpaperUserId); |
| 2229 | } |
| 2230 | |
| 2231 | @Override |
| 2232 | public ParcelFileDescriptor getWallpaperWithFeature(String callingPkg, String callingFeatureId, |
| 2233 | IWallpaperManagerCallback cb, final int which, Bundle outParams, int wallpaperUserId) { |
Christopher Tate | 8a71c48 | 2017-08-14 16:45:03 -0700 | [diff] [blame] | 2234 | final int hasPrivilege = mContext.checkCallingOrSelfPermission( |
| 2235 | android.Manifest.permission.READ_WALLPAPER_INTERNAL); |
| 2236 | if (hasPrivilege != PackageManager.PERMISSION_GRANTED) { |
Jeff Sharkey | 859856d | 2019-03-25 11:44:11 -0600 | [diff] [blame] | 2237 | mContext.getSystemService(StorageManager.class).checkPermissionReadImages(true, |
Philip P. Moltmann | 41ff0f6 | 2019-11-15 10:55:52 -0800 | [diff] [blame] | 2238 | Binder.getCallingPid(), Binder.getCallingUid(), callingPkg, callingFeatureId); |
Christopher Tate | 8a71c48 | 2017-08-14 16:45:03 -0700 | [diff] [blame] | 2239 | } |
Christopher Tate | 93252de | 2017-06-15 14:48:41 -0700 | [diff] [blame] | 2240 | |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 2241 | wallpaperUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| 2242 | Binder.getCallingUid(), wallpaperUserId, false, true, "getWallpaper", null); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2243 | |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 2244 | if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2245 | throw new IllegalArgumentException("Must specify exactly one kind of wallpaper to read"); |
| 2246 | } |
| 2247 | |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2248 | synchronized (mLock) { |
Vadim Tryshev | 8cde079 | 2016-02-19 17:02:15 -0800 | [diff] [blame] | 2249 | final SparseArray<WallpaperData> whichSet = |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 2250 | (which == FLAG_LOCK) ? mLockWallpaperMap : mWallpaperMap; |
Vadim Tryshev | 8cde079 | 2016-02-19 17:02:15 -0800 | [diff] [blame] | 2251 | WallpaperData wallpaper = whichSet.get(wallpaperUserId); |
| 2252 | if (wallpaper == null) { |
Christopher Tate | f717b93 | 2017-09-11 15:52:54 -0700 | [diff] [blame] | 2253 | // There is no established wallpaper imagery of this type (expected |
| 2254 | // only for lock wallpapers; a system WallpaperData is established at |
| 2255 | // user switch) |
| 2256 | return null; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2257 | } |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2258 | // Only for default display. |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2259 | final DisplayData wpdData = getDisplayDataOrCreate(DEFAULT_DISPLAY); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2260 | try { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2261 | if (outParams != null) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2262 | outParams.putInt("width", wpdData.mWidth); |
| 2263 | outParams.putInt("height", wpdData.mHeight); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 2264 | } |
Christopher Tate | ea6724a | 2016-02-18 18:39:19 -0800 | [diff] [blame] | 2265 | if (cb != null) { |
| 2266 | wallpaper.callbacks.register(cb); |
| 2267 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2268 | if (!wallpaper.cropFile.exists()) { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2269 | return null; |
| 2270 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2271 | return ParcelFileDescriptor.open(wallpaper.cropFile, MODE_READ_ONLY); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2272 | } catch (FileNotFoundException e) { |
| 2273 | /* Shouldn't happen as we check to see if the file exists */ |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2274 | Slog.w(TAG, "Error getting wallpaper", e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2275 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2276 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2277 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2278 | } |
| 2279 | |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 2280 | @Override |
Jorim Jaggi | e31f6b8 | 2016-07-01 16:15:09 -0700 | [diff] [blame] | 2281 | public WallpaperInfo getWallpaperInfo(int userId) { |
| 2282 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
Christopher Tate | f717b93 | 2017-09-11 15:52:54 -0700 | [diff] [blame] | 2283 | Binder.getCallingUid(), userId, false, true, "getWallpaperInfo", null); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2284 | synchronized (mLock) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2285 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2286 | if (wallpaper != null && wallpaper.connection != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2287 | return wallpaper.connection.mInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2288 | } |
| 2289 | return null; |
| 2290 | } |
| 2291 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2292 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2293 | @Override |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 2294 | public int getWallpaperIdForUser(int which, int userId) { |
| 2295 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), |
| 2296 | Binder.getCallingUid(), userId, false, true, "getWallpaperIdForUser", null); |
| 2297 | |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 2298 | if (which != FLAG_SYSTEM && which != FLAG_LOCK) { |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 2299 | throw new IllegalArgumentException("Must specify exactly one kind of wallpaper"); |
| 2300 | } |
| 2301 | |
| 2302 | final SparseArray<WallpaperData> map = |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 2303 | (which == FLAG_LOCK) ? mLockWallpaperMap : mWallpaperMap; |
Christopher Tate | e409f0e | 2016-03-21 14:53:15 -0700 | [diff] [blame] | 2304 | synchronized (mLock) { |
| 2305 | WallpaperData wallpaper = map.get(userId); |
| 2306 | if (wallpaper != null) { |
| 2307 | return wallpaper.wallpaperId; |
| 2308 | } |
| 2309 | } |
| 2310 | return -1; |
| 2311 | } |
| 2312 | |
| 2313 | @Override |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2314 | public void registerWallpaperColorsCallback(IWallpaperManagerCallback cb, int userId, |
| 2315 | int displayId) { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2316 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 2317 | userId, true, true, "registerWallpaperColorsCallback", null); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2318 | synchronized (mLock) { |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2319 | SparseArray<RemoteCallbackList<IWallpaperManagerCallback>> |
| 2320 | userDisplayColorsChangedListeners = mColorsChangedListeners.get(userId); |
| 2321 | if (userDisplayColorsChangedListeners == null) { |
| 2322 | userDisplayColorsChangedListeners = new SparseArray<>(); |
| 2323 | mColorsChangedListeners.put(userId, userDisplayColorsChangedListeners); |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2324 | } |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2325 | RemoteCallbackList<IWallpaperManagerCallback> displayChangedListeners = |
| 2326 | userDisplayColorsChangedListeners.get(displayId); |
| 2327 | if (displayChangedListeners == null) { |
| 2328 | displayChangedListeners = new RemoteCallbackList<>(); |
| 2329 | userDisplayColorsChangedListeners.put(displayId, displayChangedListeners); |
| 2330 | } |
| 2331 | displayChangedListeners.register(cb); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | @Override |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2336 | public void unregisterWallpaperColorsCallback(IWallpaperManagerCallback cb, int userId, |
| 2337 | int displayId) { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2338 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 2339 | userId, true, true, "unregisterWallpaperColorsCallback", null); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2340 | synchronized (mLock) { |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2341 | SparseArray<RemoteCallbackList<IWallpaperManagerCallback>> |
| 2342 | userDisplayColorsChangedListeners = mColorsChangedListeners.get(userId); |
| 2343 | if (userDisplayColorsChangedListeners != null) { |
| 2344 | RemoteCallbackList<IWallpaperManagerCallback> displayChangedListeners = |
| 2345 | userDisplayColorsChangedListeners.get(displayId); |
| 2346 | if (displayChangedListeners != null) { |
| 2347 | displayChangedListeners.unregister(cb); |
| 2348 | } |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2349 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2350 | } |
| 2351 | } |
| 2352 | |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 2353 | /** |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2354 | * TODO(multi-display) Extends this method with specific display. |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 2355 | * Propagate ambient state to wallpaper engine. |
| 2356 | * |
| 2357 | * @param inAmbientMode {@code true} when in ambient mode, {@code false} otherwise. |
| 2358 | * @param animationDuration Duration of the animation, or 0 when immediate. |
| 2359 | */ |
| 2360 | public void setInAmbientMode(boolean inAmbientMode, long animationDuration) { |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 2361 | final IWallpaperEngine engine; |
| 2362 | synchronized (mLock) { |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 2363 | mInAmbientMode = inAmbientMode; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 2364 | final WallpaperData data = mWallpaperMap.get(mCurrentUserId); |
Ahan Wu | 723a80e | 2018-11-07 20:39:32 +0800 | [diff] [blame] | 2365 | // The wallpaper info is null for image wallpaper, also use the engine in this case. |
Ahan Wu | 67e7f10 | 2019-01-14 20:38:14 +0800 | [diff] [blame] | 2366 | if (data != null && data.connection != null && (data.connection.mInfo == null |
| 2367 | || data.connection.mInfo.supportsAmbientMode())) { |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2368 | // TODO(multi-display) Extends this method with specific display. |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2369 | engine = data.connection.getDisplayConnectorOrCreate(DEFAULT_DISPLAY).mEngine; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 2370 | } else { |
| 2371 | engine = null; |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | if (engine != null) { |
| 2376 | try { |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 2377 | engine.setInAmbientMode(inAmbientMode, animationDuration); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 2378 | } catch (RemoteException e) { |
| 2379 | // Cannot talk to wallpaper engine. |
| 2380 | } |
| 2381 | } |
| 2382 | } |
| 2383 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2384 | @Override |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2385 | public boolean setLockWallpaperCallback(IWallpaperManagerCallback cb) { |
| 2386 | checkPermission(android.Manifest.permission.INTERNAL_SYSTEM_WINDOW); |
| 2387 | synchronized (mLock) { |
| 2388 | mKeyguardListener = cb; |
| 2389 | } |
| 2390 | return true; |
| 2391 | } |
| 2392 | |
| 2393 | @Override |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2394 | public WallpaperColors getWallpaperColors(int which, int userId, int displayId) |
| 2395 | throws RemoteException { |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2396 | if (which != FLAG_LOCK && which != FLAG_SYSTEM) { |
| 2397 | throw new IllegalArgumentException("which should be either FLAG_LOCK or FLAG_SYSTEM"); |
| 2398 | } |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2399 | userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), |
| 2400 | userId, false, true, "getWallpaperColors", null); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2401 | |
| 2402 | WallpaperData wallpaperData = null; |
| 2403 | boolean shouldExtract; |
| 2404 | |
| 2405 | synchronized (mLock) { |
| 2406 | if (which == FLAG_LOCK) { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2407 | wallpaperData = mLockWallpaperMap.get(userId); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | // Try to get the system wallpaper anyway since it might |
| 2411 | // also be the lock screen wallpaper |
| 2412 | if (wallpaperData == null) { |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2413 | wallpaperData = findWallpaperAtDisplay(userId, displayId); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | if (wallpaperData == null) { |
| 2417 | return null; |
| 2418 | } |
| 2419 | shouldExtract = wallpaperData.primaryColors == null; |
| 2420 | } |
| 2421 | |
| 2422 | if (shouldExtract) { |
| 2423 | extractColors(wallpaperData); |
| 2424 | } |
| 2425 | |
| 2426 | synchronized (mLock) { |
Lucas Dupin | 4b4c530 | 2018-06-24 18:22:10 -0700 | [diff] [blame] | 2427 | return wallpaperData.primaryColors; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2428 | } |
| 2429 | } |
| 2430 | |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2431 | private WallpaperData findWallpaperAtDisplay(int userId, int displayId) { |
| 2432 | if (mFallbackWallpaper != null && mFallbackWallpaper.connection != null |
| 2433 | && mFallbackWallpaper.connection.containsDisplay(displayId)) { |
| 2434 | return mFallbackWallpaper; |
| 2435 | } else { |
| 2436 | return mWallpaperMap.get(userId); |
| 2437 | } |
| 2438 | } |
| 2439 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2440 | @Override |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2441 | public ParcelFileDescriptor setWallpaper(String name, String callingPackage, |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2442 | Rect cropHint, boolean allowBackup, Bundle extras, int which, |
Jorim Jaggi | 6c902d0 | 2016-08-18 10:44:54 -0700 | [diff] [blame] | 2443 | IWallpaperManagerCallback completion, int userId) { |
| 2444 | userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId, |
| 2445 | false /* all */, true /* full */, "changing wallpaper", null /* pkg */); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2446 | checkPermission(android.Manifest.permission.SET_WALLPAPER); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2447 | |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 2448 | if ((which & (FLAG_LOCK|FLAG_SYSTEM)) == 0) { |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 2449 | final String msg = "Must specify a valid wallpaper category to set"; |
| 2450 | Slog.e(TAG, msg); |
| 2451 | throw new IllegalArgumentException(msg); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2452 | } |
| 2453 | |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 2454 | if (!isWallpaperSupported(callingPackage) || !isSetWallpaperAllowed(callingPackage)) { |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2455 | return null; |
| 2456 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2457 | |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2458 | // "null" means the no-op crop, preserving the full input image |
| 2459 | if (cropHint == null) { |
| 2460 | cropHint = new Rect(0, 0, 0, 0); |
| 2461 | } else { |
| 2462 | if (cropHint.isEmpty() |
| 2463 | || cropHint.left < 0 |
| 2464 | || cropHint.top < 0) { |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 2465 | throw new IllegalArgumentException("Invalid crop rect supplied: " + cropHint); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2466 | } |
| 2467 | } |
| 2468 | |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2469 | synchronized (mLock) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2470 | if (DEBUG) Slog.v(TAG, "setWallpaper which=0x" + Integer.toHexString(which)); |
| 2471 | WallpaperData wallpaper; |
| 2472 | |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 2473 | /* If we're setting system but not lock, and lock is currently sharing the system |
| 2474 | * wallpaper, we need to migrate that image over to being lock-only before |
| 2475 | * the caller here writes new bitmap data. |
| 2476 | */ |
| 2477 | if (which == FLAG_SYSTEM && mLockWallpaperMap.get(userId) == null) { |
| 2478 | if (DEBUG) { |
| 2479 | Slog.i(TAG, "Migrating system->lock to preserve"); |
| 2480 | } |
| 2481 | migrateSystemToLockWallpaperLocked(userId); |
| 2482 | } |
| 2483 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2484 | wallpaper = getWallpaperSafeLocked(userId, which); |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 2485 | final long ident = Binder.clearCallingIdentity(); |
| 2486 | try { |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2487 | ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name, wallpaper, extras); |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 2488 | if (pfd != null) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2489 | wallpaper.imageWallpaperPending = true; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2490 | wallpaper.whichPending = which; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2491 | wallpaper.setComplete = completion; |
| 2492 | wallpaper.cropHint.set(cropHint); |
Christopher Tate | c613c63 | 2016-08-12 14:13:02 -0700 | [diff] [blame] | 2493 | wallpaper.allowBackup = allowBackup; |
Dianne Hackborn | 0cd4887 | 2009-08-13 18:51:59 -0700 | [diff] [blame] | 2494 | } |
| 2495 | return pfd; |
| 2496 | } finally { |
| 2497 | Binder.restoreCallingIdentity(ident); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2498 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2499 | } |
| 2500 | } |
| 2501 | |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 2502 | private void migrateSystemToLockWallpaperLocked(int userId) { |
| 2503 | WallpaperData sysWP = mWallpaperMap.get(userId); |
| 2504 | if (sysWP == null) { |
| 2505 | if (DEBUG) { |
| 2506 | Slog.i(TAG, "No system wallpaper? Not tracking for lock-only"); |
| 2507 | } |
| 2508 | return; |
| 2509 | } |
| 2510 | |
| 2511 | // We know a-priori that there is no lock-only wallpaper currently |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 2512 | WallpaperData lockWP = new WallpaperData(userId, getWallpaperDir(userId), |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 2513 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); |
| 2514 | lockWP.wallpaperId = sysWP.wallpaperId; |
| 2515 | lockWP.cropHint.set(sysWP.cropHint); |
Christopher Tate | edd8dc8 | 2016-10-12 15:17:58 -0700 | [diff] [blame] | 2516 | lockWP.allowBackup = sysWP.allowBackup; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2517 | lockWP.primaryColors = sysWP.primaryColors; |
Christopher Tate | 8347b63 | 2016-04-29 18:59:18 -0700 | [diff] [blame] | 2518 | |
| 2519 | // Migrate the bitmap files outright; no need to copy |
| 2520 | try { |
| 2521 | Os.rename(sysWP.wallpaperFile.getAbsolutePath(), lockWP.wallpaperFile.getAbsolutePath()); |
| 2522 | Os.rename(sysWP.cropFile.getAbsolutePath(), lockWP.cropFile.getAbsolutePath()); |
| 2523 | } catch (ErrnoException e) { |
| 2524 | Slog.e(TAG, "Can't migrate system wallpaper: " + e.getMessage()); |
| 2525 | lockWP.wallpaperFile.delete(); |
| 2526 | lockWP.cropFile.delete(); |
| 2527 | return; |
| 2528 | } |
| 2529 | |
| 2530 | mLockWallpaperMap.put(userId, lockWP); |
| 2531 | } |
| 2532 | |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2533 | ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper, |
| 2534 | Bundle extras) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2535 | if (name == null) name = ""; |
| 2536 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2537 | File dir = getWallpaperDir(wallpaper.userId); |
| 2538 | if (!dir.exists()) { |
| 2539 | dir.mkdir(); |
Dianne Hackborn | ebac48c | 2011-11-29 18:01:50 -0800 | [diff] [blame] | 2540 | FileUtils.setPermissions( |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2541 | dir.getPath(), |
Dianne Hackborn | ebac48c | 2011-11-29 18:01:50 -0800 | [diff] [blame] | 2542 | FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH, |
| 2543 | -1, -1); |
| 2544 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2545 | ParcelFileDescriptor fd = ParcelFileDescriptor.open(wallpaper.wallpaperFile, |
Christopher Tate | 90f86ba | 2014-09-11 12:37:19 -0700 | [diff] [blame] | 2546 | MODE_CREATE|MODE_READ_WRITE|MODE_TRUNCATE); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2547 | if (!SELinux.restorecon(wallpaper.wallpaperFile)) { |
rpcraig | 554cb0c | 2012-07-05 06:41:43 -0400 | [diff] [blame] | 2548 | return null; |
| 2549 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2550 | wallpaper.name = name; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2551 | wallpaper.wallpaperId = makeWallpaperIdLocked(); |
| 2552 | if (extras != null) { |
| 2553 | extras.putInt(WallpaperManager.EXTRA_NEW_WALLPAPER_ID, wallpaper.wallpaperId); |
| 2554 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2555 | // Nullify field to require new computation |
| 2556 | wallpaper.primaryColors = null; |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2557 | if (DEBUG) { |
| 2558 | Slog.v(TAG, "updateWallpaperBitmapLocked() : id=" + wallpaper.wallpaperId |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 2559 | + " name=" + name + " file=" + wallpaper.wallpaperFile.getName()); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2560 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2561 | return fd; |
| 2562 | } catch (FileNotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2563 | Slog.w(TAG, "Error setting wallpaper", e); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2564 | } |
| 2565 | return null; |
| 2566 | } |
| 2567 | |
Christopher Tate | d57d17c | 2016-03-25 13:41:46 -0700 | [diff] [blame] | 2568 | @Override |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 2569 | public void setWallpaperComponentChecked(ComponentName name, String callingPackage, |
| 2570 | int userId) { |
| 2571 | |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 2572 | if (isWallpaperSupported(callingPackage) && isSetWallpaperAllowed(callingPackage)) { |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 2573 | setWallpaperComponent(name, userId); |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | // ToDo: Remove this version of the function |
Christopher Tate | d57d17c | 2016-03-25 13:41:46 -0700 | [diff] [blame] | 2578 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2579 | public void setWallpaperComponent(ComponentName name) { |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 2580 | setWallpaperComponent(name, UserHandle.getCallingUserId()); |
| 2581 | } |
| 2582 | |
| 2583 | private void setWallpaperComponent(ComponentName name, int userId) { |
| 2584 | userId = ActivityManager.handleIncomingUser(getCallingPid(), getCallingUid(), userId, |
| 2585 | false /* all */, true /* full */, "changing live wallpaper", null /* pkg */); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2586 | checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT); |
Adrian Roos | 40ea083 | 2016-07-14 14:19:55 -0700 | [diff] [blame] | 2587 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2588 | int which = FLAG_SYSTEM; |
| 2589 | boolean shouldNotifyColors = false; |
| 2590 | WallpaperData wallpaper; |
| 2591 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2592 | synchronized (mLock) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2593 | if (DEBUG) Slog.v(TAG, "setWallpaperComponent name=" + name); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2594 | wallpaper = mWallpaperMap.get(userId); |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2595 | if (wallpaper == null) { |
| 2596 | throw new IllegalStateException("Wallpaper not yet initialized for user " + userId); |
| 2597 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2598 | final long ident = Binder.clearCallingIdentity(); |
Christopher Tate | 7cd0010 | 2016-12-19 14:38:44 -0800 | [diff] [blame] | 2599 | |
| 2600 | // Live wallpapers can't be specified for keyguard. If we're using a static |
| 2601 | // system+lock image currently, migrate the system wallpaper to be a lock-only |
| 2602 | // image as part of making a different live component active as the system |
| 2603 | // wallpaper. |
| 2604 | if (mImageWallpaper.equals(wallpaper.wallpaperComponent)) { |
| 2605 | if (mLockWallpaperMap.get(userId) == null) { |
| 2606 | // We're using the static imagery and there is no lock-specific image in place, |
| 2607 | // therefore it's a shared system+lock image that we need to migrate. |
| 2608 | migrateSystemToLockWallpaperLocked(userId); |
| 2609 | } |
| 2610 | } |
| 2611 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2612 | // New live wallpaper is also a lock wallpaper if nothing is set |
| 2613 | if (mLockWallpaperMap.get(userId) == null) { |
| 2614 | which |= FLAG_LOCK; |
| 2615 | } |
| 2616 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2617 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2618 | wallpaper.imageWallpaperPending = false; |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2619 | boolean same = changingToSame(name, wallpaper); |
Christopher Tate | d57d17c | 2016-03-25 13:41:46 -0700 | [diff] [blame] | 2620 | if (bindWallpaperComponentLocked(name, false, true, wallpaper, null)) { |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2621 | if (!same) { |
| 2622 | wallpaper.primaryColors = null; |
| 2623 | } |
Christopher Tate | d57d17c | 2016-03-25 13:41:46 -0700 | [diff] [blame] | 2624 | wallpaper.wallpaperId = makeWallpaperIdLocked(); |
Sunny Goyal | 0572e18 | 2016-03-31 11:05:51 -0700 | [diff] [blame] | 2625 | notifyCallbacksLocked(wallpaper); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2626 | shouldNotifyColors = true; |
Christopher Tate | d57d17c | 2016-03-25 13:41:46 -0700 | [diff] [blame] | 2627 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2628 | } finally { |
| 2629 | Binder.restoreCallingIdentity(ident); |
| 2630 | } |
| 2631 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2632 | |
| 2633 | if (shouldNotifyColors) { |
| 2634 | notifyWallpaperColorsChanged(wallpaper, which); |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 2635 | notifyWallpaperColorsChanged(mFallbackWallpaper, FLAG_SYSTEM); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2636 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2637 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2638 | |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2639 | private boolean changingToSame(ComponentName componentName, WallpaperData wallpaper) { |
| 2640 | if (wallpaper.connection != null) { |
| 2641 | if (wallpaper.wallpaperComponent == null) { |
| 2642 | if (componentName == null) { |
| 2643 | if (DEBUG) Slog.v(TAG, "changingToSame: still using default"); |
| 2644 | // Still using default wallpaper. |
| 2645 | return true; |
| 2646 | } |
| 2647 | } else if (wallpaper.wallpaperComponent.equals(componentName)) { |
| 2648 | // Changing to same wallpaper. |
| 2649 | if (DEBUG) Slog.v(TAG, "same wallpaper"); |
| 2650 | return true; |
| 2651 | } |
| 2652 | } |
| 2653 | return false; |
| 2654 | } |
| 2655 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2656 | private boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2657 | boolean fromUser, WallpaperData wallpaper, IRemoteCallback reply) { |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 2658 | if (DEBUG_LIVE) { |
| 2659 | Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName); |
| 2660 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2661 | // Has the component changed? |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 2662 | if (!force && changingToSame(componentName, wallpaper)) { |
| 2663 | return true; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2664 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2665 | |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2666 | try { |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 2667 | if (componentName == null) { |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 2668 | componentName = mDefaultWallpaperComponent; |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 2669 | if (componentName == null) { |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 2670 | // Fall back to static image wallpaper |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 2671 | componentName = mImageWallpaper; |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 2672 | //clearWallpaperComponentLocked(); |
| 2673 | //return; |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 2674 | if (DEBUG_LIVE) Slog.v(TAG, "No default component; using image wallpaper"); |
Mike Cleron | 322b6ee | 2009-11-12 07:45:47 -0800 | [diff] [blame] | 2675 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2676 | } |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 2677 | int serviceUserId = wallpaper.userId; |
| 2678 | ServiceInfo si = mIPackageManager.getServiceInfo(componentName, |
| 2679 | PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS, serviceUserId); |
Christopher Tate | 9095220 | 2013-09-08 13:01:28 -0700 | [diff] [blame] | 2680 | if (si == null) { |
| 2681 | // The wallpaper component we're trying to use doesn't exist |
| 2682 | Slog.w(TAG, "Attempted wallpaper " + componentName + " is unavailable"); |
| 2683 | return false; |
| 2684 | } |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2685 | if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) { |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 2686 | String msg = "Selected service does not have " |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2687 | + android.Manifest.permission.BIND_WALLPAPER |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 2688 | + ": " + componentName; |
| 2689 | if (fromUser) { |
| 2690 | throw new SecurityException(msg); |
| 2691 | } |
| 2692 | Slog.w(TAG, msg); |
| 2693 | return false; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2694 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2695 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2696 | WallpaperInfo wi = null; |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2697 | |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2698 | Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE); |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 2699 | if (componentName != null && !componentName.equals(mImageWallpaper)) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2700 | // Make sure the selected service is actually a wallpaper service. |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 2701 | List<ResolveInfo> ris = |
| 2702 | mIPackageManager.queryIntentServices(intent, |
| 2703 | intent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 2704 | PackageManager.GET_META_DATA, serviceUserId).getList(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2705 | for (int i=0; i<ris.size(); i++) { |
| 2706 | ServiceInfo rsi = ris.get(i).serviceInfo; |
| 2707 | if (rsi.name.equals(si.name) && |
| 2708 | rsi.packageName.equals(si.packageName)) { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2709 | try { |
| 2710 | wi = new WallpaperInfo(mContext, ris.get(i)); |
| 2711 | } catch (XmlPullParserException e) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 2712 | if (fromUser) { |
| 2713 | throw new IllegalArgumentException(e); |
| 2714 | } |
| 2715 | Slog.w(TAG, e); |
| 2716 | return false; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2717 | } catch (IOException e) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 2718 | if (fromUser) { |
| 2719 | throw new IllegalArgumentException(e); |
| 2720 | } |
| 2721 | Slog.w(TAG, e); |
| 2722 | return false; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2723 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2724 | break; |
| 2725 | } |
| 2726 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2727 | if (wi == null) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 2728 | String msg = "Selected service is not a wallpaper: " |
| 2729 | + componentName; |
| 2730 | if (fromUser) { |
| 2731 | throw new SecurityException(msg); |
| 2732 | } |
| 2733 | Slog.w(TAG, msg); |
| 2734 | return false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2735 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2736 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2737 | |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 2738 | if (wi != null && wi.supportsAmbientMode()) { |
| 2739 | final int hasPrivilege = mIPackageManager.checkPermission( |
| 2740 | android.Manifest.permission.AMBIENT_WALLPAPER, wi.getPackageName(), |
| 2741 | serviceUserId); |
| 2742 | if (hasPrivilege != PackageManager.PERMISSION_GRANTED) { |
| 2743 | String msg = "Selected service does not have " |
| 2744 | + android.Manifest.permission.AMBIENT_WALLPAPER |
| 2745 | + ": " + componentName; |
| 2746 | if (fromUser) { |
| 2747 | throw new SecurityException(msg); |
| 2748 | } |
| 2749 | Slog.w(TAG, msg); |
| 2750 | return false; |
| 2751 | } |
| 2752 | } |
| 2753 | |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2754 | // Bind the service! |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 2755 | if (DEBUG) Slog.v(TAG, "Binding to:" + componentName); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2756 | final int componentUid = mIPackageManager.getPackageUid(componentName.getPackageName(), |
| 2757 | MATCH_DIRECT_BOOT_AUTO, wallpaper.userId); |
| 2758 | WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper, componentUid); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 2759 | intent.setComponent(componentName); |
Dianne Hackborn | dd9b82c | 2009-09-03 00:18:47 -0700 | [diff] [blame] | 2760 | intent.putExtra(Intent.EXTRA_CLIENT_LABEL, |
| 2761 | com.android.internal.R.string.wallpaper_binding_label); |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 2762 | intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser( |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 2763 | mContext, 0, |
| 2764 | Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER), |
| 2765 | mContext.getText(com.android.internal.R.string.chooser_wallpaper)), |
Dianne Hackborn | 4120375 | 2012-08-31 14:05:51 -0700 | [diff] [blame] | 2766 | 0, null, new UserHandle(serviceUserId))); |
Dianne Hackborn | c823051 | 2013-07-13 21:32:12 -0700 | [diff] [blame] | 2767 | if (!mContext.bindServiceAsUser(intent, newConn, |
Dianne Hackborn | d69e4c1 | 2015-04-24 09:54:54 -0700 | [diff] [blame] | 2768 | Context.BIND_AUTO_CREATE | Context.BIND_SHOWING_UI |
Amith Yamasani | c45a990 | 2019-04-05 16:29:30 -0700 | [diff] [blame] | 2769 | | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE |
| 2770 | | Context.BIND_INCLUDE_CAPABILITIES, |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 2771 | new UserHandle(serviceUserId))) { |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 2772 | String msg = "Unable to bind service: " |
| 2773 | + componentName; |
| 2774 | if (fromUser) { |
| 2775 | throw new IllegalArgumentException(msg); |
| 2776 | } |
| 2777 | Slog.w(TAG, msg); |
| 2778 | return false; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2779 | } |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2780 | if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null |
| 2781 | && !wallpaper.equals(mFallbackWallpaper)) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2782 | detachWallpaperLocked(mLastWallpaper); |
| 2783 | } |
| 2784 | wallpaper.wallpaperComponent = componentName; |
| 2785 | wallpaper.connection = newConn; |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2786 | newConn.mReply = reply; |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2787 | if (wallpaper.userId == mCurrentUserId && !wallpaper.equals(mFallbackWallpaper)) { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2788 | mLastWallpaper = wallpaper; |
Dianne Hackborn | f21adf6 | 2009-08-13 10:20:21 -0700 | [diff] [blame] | 2789 | } |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2790 | updateFallbackConnection(); |
Amith Yamasani | 4e2820c | 2012-08-28 22:17:23 -0700 | [diff] [blame] | 2791 | } catch (RemoteException e) { |
| 2792 | String msg = "Remote exception for " + componentName + "\n" + e; |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 2793 | if (fromUser) { |
| 2794 | throw new IllegalArgumentException(msg); |
| 2795 | } |
| 2796 | Slog.w(TAG, msg); |
| 2797 | return false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2798 | } |
Dianne Hackborn | 80b902f | 2011-09-15 15:15:27 -0700 | [diff] [blame] | 2799 | return true; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2800 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2801 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2802 | private void detachWallpaperLocked(WallpaperData wallpaper) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2803 | if (wallpaper.connection != null) { |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 2804 | if (wallpaper.connection.mReply != null) { |
| 2805 | try { |
| 2806 | wallpaper.connection.mReply.sendResult(null); |
| 2807 | } catch (RemoteException e) { |
| 2808 | } |
| 2809 | wallpaper.connection.mReply = null; |
| 2810 | } |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 2811 | try { |
Keun young Park | e3d2fea | 2019-03-29 17:42:32 -0700 | [diff] [blame] | 2812 | // It can be null if user switching happens before service connection. |
| 2813 | if (wallpaper.connection.mService != null) { |
| 2814 | wallpaper.connection.mService.detach(); |
| 2815 | } |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 2816 | } catch (RemoteException e) { |
| 2817 | Slog.w(TAG, "Failed detaching wallpaper service ", e); |
| 2818 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2819 | mContext.unbindService(wallpaper.connection); |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2820 | wallpaper.connection.forEachDisplayConnector( |
| 2821 | WallpaperConnection.DisplayConnector::disconnectLocked); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2822 | wallpaper.connection.mService = null; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2823 | wallpaper.connection.mDisplayConnector.clear(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2824 | wallpaper.connection = null; |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2825 | if (wallpaper == mLastWallpaper) mLastWallpaper = null; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2826 | } |
| 2827 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2828 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2829 | private void clearWallpaperComponentLocked(WallpaperData wallpaper) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2830 | wallpaper.wallpaperComponent = null; |
| 2831 | detachWallpaperLocked(wallpaper); |
| 2832 | } |
| 2833 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2834 | private void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 2835 | conn.forEachDisplayConnector(connector-> connector.connectLocked(conn, wallpaper)); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 2836 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2837 | |
| 2838 | private void notifyCallbacksLocked(WallpaperData wallpaper) { |
| 2839 | final int n = wallpaper.callbacks.beginBroadcast(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | for (int i = 0; i < n; i++) { |
| 2841 | try { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2842 | wallpaper.callbacks.getBroadcastItem(i).onWallpaperChanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2843 | } catch (RemoteException e) { |
| 2844 | |
| 2845 | // The RemoteCallbackList will take care of removing |
| 2846 | // the dead object for us. |
| 2847 | } |
| 2848 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 2849 | wallpaper.callbacks.finishBroadcast(); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2852 | mContext.sendBroadcastAsUser(intent, new UserHandle(mCurrentUserId)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | private void checkPermission(String permission) { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2856 | if (PackageManager.PERMISSION_GRANTED!= mContext.checkCallingOrSelfPermission(permission)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | throw new SecurityException("Access denied to process: " + Binder.getCallingPid() |
| 2858 | + ", must have permission " + permission); |
| 2859 | } |
| 2860 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2861 | |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 2862 | /** |
| 2863 | * Certain user types do not support wallpapers (e.g. managed profiles). The check is |
| 2864 | * implemented through through the OP_WRITE_WALLPAPER AppOp. |
| 2865 | */ |
| 2866 | public boolean isWallpaperSupported(String callingPackage) { |
| 2867 | return mAppOpsManager.checkOpNoThrow(AppOpsManager.OP_WRITE_WALLPAPER, Binder.getCallingUid(), |
| 2868 | callingPackage) == AppOpsManager.MODE_ALLOWED; |
| 2869 | } |
| 2870 | |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2871 | @Override |
Christopher Tate | 98d609c | 2016-05-18 17:31:58 -0700 | [diff] [blame] | 2872 | public boolean isSetWallpaperAllowed(String callingPackage) { |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2873 | final PackageManager pm = mContext.getPackageManager(); |
| 2874 | String[] uidPackages = pm.getPackagesForUid(Binder.getCallingUid()); |
| 2875 | boolean uidMatchPackage = Arrays.asList(uidPackages).contains(callingPackage); |
| 2876 | if (!uidMatchPackage) { |
| 2877 | return false; // callingPackage was faked. |
| 2878 | } |
| 2879 | |
Bookatz | cfc5d19 | 2019-11-05 17:25:53 -0800 | [diff] [blame] | 2880 | // TODO(b/144048540): DPM needs to take into account the userId, not just the package. |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2881 | final DevicePolicyManager dpm = mContext.getSystemService(DevicePolicyManager.class); |
| 2882 | if (dpm.isDeviceOwnerApp(callingPackage) || dpm.isProfileOwnerApp(callingPackage)) { |
| 2883 | return true; |
| 2884 | } |
Bookatz | cfc5d19 | 2019-11-05 17:25:53 -0800 | [diff] [blame] | 2885 | final int callingUserId = UserHandle.getCallingUserId(); |
| 2886 | final long ident = Binder.clearCallingIdentity(); |
| 2887 | try { |
| 2888 | UserManagerInternal umi = LocalServices.getService(UserManagerInternal.class); |
| 2889 | return !umi.hasUserRestriction(UserManager.DISALLOW_SET_WALLPAPER, callingUserId); |
| 2890 | } finally { |
| 2891 | Binder.restoreCallingIdentity(ident); |
| 2892 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 2893 | } |
| 2894 | |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2895 | @Override |
Christopher Tate | 6172266 | 2016-08-10 16:13:14 -0700 | [diff] [blame] | 2896 | public boolean isWallpaperBackupEligible(int which, int userId) { |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2897 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2898 | throw new SecurityException("Only the system may call isWallpaperBackupEligible"); |
| 2899 | } |
| 2900 | |
Christopher Tate | 6172266 | 2016-08-10 16:13:14 -0700 | [diff] [blame] | 2901 | WallpaperData wallpaper = (which == FLAG_LOCK) |
Christopher Tate | f7d1b5d | 2016-08-19 11:21:07 -0700 | [diff] [blame] | 2902 | ? mLockWallpaperMap.get(userId) |
| 2903 | : mWallpaperMap.get(userId); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 2904 | return (wallpaper != null) ? wallpaper.allowBackup : false; |
| 2905 | } |
| 2906 | |
wilsonshih | 643bf13 | 2019-02-27 12:49:19 +0800 | [diff] [blame] | 2907 | private void onDisplayReadyInternal(int displayId) { |
| 2908 | synchronized (mLock) { |
| 2909 | if (mLastWallpaper == null) { |
| 2910 | return; |
| 2911 | } |
| 2912 | if (supportsMultiDisplay(mLastWallpaper.connection)) { |
| 2913 | final WallpaperConnection.DisplayConnector connector = |
| 2914 | mLastWallpaper.connection.getDisplayConnectorOrCreate(displayId); |
| 2915 | if (connector == null) return; |
| 2916 | connector.connectLocked(mLastWallpaper.connection, mLastWallpaper); |
| 2917 | return; |
| 2918 | } |
| 2919 | // System wallpaper does not support multiple displays, attach this display to |
| 2920 | // the fallback wallpaper. |
| 2921 | if (mFallbackWallpaper != null) { |
| 2922 | final WallpaperConnection.DisplayConnector connector = mFallbackWallpaper |
| 2923 | .connection.getDisplayConnectorOrCreate(displayId); |
| 2924 | if (connector == null) return; |
| 2925 | connector.connectLocked(mFallbackWallpaper.connection, mFallbackWallpaper); |
| 2926 | } else { |
| 2927 | Slog.w(TAG, "No wallpaper can be added to the new display"); |
| 2928 | } |
| 2929 | } |
| 2930 | } |
| 2931 | |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 2932 | private JournaledFile makeJournaledFile(int userId) { |
Amith Yamasani | 61f5737 | 2012-08-31 12:12:28 -0700 | [diff] [blame] | 2933 | final String base = new File(getWallpaperDir(userId), WALLPAPER_INFO).getAbsolutePath(); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2934 | return new JournaledFile(new File(base), new File(base + ".tmp")); |
| 2935 | } |
| 2936 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2937 | private void saveSettingsLocked(int userId) { |
| 2938 | JournaledFile journal = makeJournaledFile(userId); |
| 2939 | FileOutputStream fstream = null; |
| 2940 | BufferedOutputStream stream = null; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2941 | try { |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2942 | XmlSerializer out = new FastXmlSerializer(); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2943 | fstream = new FileOutputStream(journal.chooseForWrite(), false); |
| 2944 | stream = new BufferedOutputStream(fstream); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 2945 | out.setOutput(stream, StandardCharsets.UTF_8.name()); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2946 | out.startDocument(null, true); |
| 2947 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2948 | WallpaperData wallpaper; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 2949 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2950 | wallpaper = mWallpaperMap.get(userId); |
| 2951 | if (wallpaper != null) { |
| 2952 | writeWallpaperAttributes(out, "wp", wallpaper); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2953 | } |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2954 | wallpaper = mLockWallpaperMap.get(userId); |
| 2955 | if (wallpaper != null) { |
| 2956 | writeWallpaperAttributes(out, "kwp", wallpaper); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 2957 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2958 | |
| 2959 | out.endDocument(); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2960 | |
| 2961 | stream.flush(); // also flushes fstream |
| 2962 | FileUtils.sync(fstream); |
| 2963 | stream.close(); // also closes fstream |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2964 | journal.commit(); |
| 2965 | } catch (IOException e) { |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 2966 | IoUtils.closeQuietly(stream); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 2967 | journal.rollback(); |
| 2968 | } |
| 2969 | } |
| 2970 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2971 | private void writeWallpaperAttributes(XmlSerializer out, String tag, WallpaperData wallpaper) |
| 2972 | throws IllegalArgumentException, IllegalStateException, IOException { |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2973 | if (DEBUG) { |
Christopher Tate | f717b93 | 2017-09-11 15:52:54 -0700 | [diff] [blame] | 2974 | Slog.v(TAG, "writeWallpaperAttributes id=" + wallpaper.wallpaperId); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 2975 | } |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 2976 | final DisplayData wpdData = getDisplayDataOrCreate(DEFAULT_DISPLAY); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2977 | out.startTag(null, tag); |
| 2978 | out.attribute(null, "id", Integer.toString(wallpaper.wallpaperId)); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2979 | out.attribute(null, "width", Integer.toString(wpdData.mWidth)); |
| 2980 | out.attribute(null, "height", Integer.toString(wpdData.mHeight)); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2981 | |
| 2982 | out.attribute(null, "cropLeft", Integer.toString(wallpaper.cropHint.left)); |
| 2983 | out.attribute(null, "cropTop", Integer.toString(wallpaper.cropHint.top)); |
| 2984 | out.attribute(null, "cropRight", Integer.toString(wallpaper.cropHint.right)); |
| 2985 | out.attribute(null, "cropBottom", Integer.toString(wallpaper.cropHint.bottom)); |
| 2986 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2987 | if (wpdData.mPadding.left != 0) { |
| 2988 | out.attribute(null, "paddingLeft", Integer.toString(wpdData.mPadding.left)); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2989 | } |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2990 | if (wpdData.mPadding.top != 0) { |
| 2991 | out.attribute(null, "paddingTop", Integer.toString(wpdData.mPadding.top)); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2992 | } |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2993 | if (wpdData.mPadding.right != 0) { |
| 2994 | out.attribute(null, "paddingRight", Integer.toString(wpdData.mPadding.right)); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2995 | } |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 2996 | if (wpdData.mPadding.bottom != 0) { |
| 2997 | out.attribute(null, "paddingBottom", Integer.toString(wpdData.mPadding.bottom)); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 2998 | } |
| 2999 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 3000 | if (wallpaper.primaryColors != null) { |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 3001 | int colorsCount = wallpaper.primaryColors.getMainColors().size(); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 3002 | out.attribute(null, "colorsCount", Integer.toString(colorsCount)); |
| 3003 | if (colorsCount > 0) { |
| 3004 | for (int i = 0; i < colorsCount; i++) { |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 3005 | final Color wc = wallpaper.primaryColors.getMainColors().get(i); |
| 3006 | out.attribute(null, "colorValue"+i, Integer.toString(wc.toArgb())); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 3007 | } |
| 3008 | } |
Lucas Dupin | 75ec379 | 2017-06-29 14:07:18 -0700 | [diff] [blame] | 3009 | out.attribute(null, "colorHints", |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 3010 | Integer.toString(wallpaper.primaryColors.getColorHints())); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 3013 | out.attribute(null, "name", wallpaper.name); |
| 3014 | if (wallpaper.wallpaperComponent != null |
| 3015 | && !wallpaper.wallpaperComponent.equals(mImageWallpaper)) { |
| 3016 | out.attribute(null, "component", |
| 3017 | wallpaper.wallpaperComponent.flattenToShortString()); |
| 3018 | } |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3019 | |
| 3020 | if (wallpaper.allowBackup) { |
| 3021 | out.attribute(null, "backup", "true"); |
| 3022 | } |
| 3023 | |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 3024 | out.endTag(null, tag); |
| 3025 | } |
| 3026 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3027 | private void migrateFromOld() { |
Christopher Tate | 9f22443 | 2017-08-01 16:32:49 -0700 | [diff] [blame] | 3028 | // Pre-N, what existed is the one we're now using as the display crop |
| 3029 | File preNWallpaper = new File(getWallpaperDir(0), WALLPAPER_CROP); |
| 3030 | // In the very-long-ago, imagery lived with the settings app |
| 3031 | File originalWallpaper = new File(WallpaperBackupHelper.WALLPAPER_IMAGE_KEY); |
| 3032 | File newWallpaper = new File(getWallpaperDir(0), WALLPAPER); |
| 3033 | |
| 3034 | // Migrations from earlier wallpaper image storage schemas |
| 3035 | if (preNWallpaper.exists()) { |
| 3036 | if (!newWallpaper.exists()) { |
| 3037 | // we've got the 'wallpaper' crop file but not the nominal source image, |
| 3038 | // so do the simple "just take everything" straight copy of legacy data |
| 3039 | if (DEBUG) { |
| 3040 | Slog.i(TAG, "Migrating wallpaper schema"); |
| 3041 | } |
| 3042 | FileUtils.copyFile(preNWallpaper, newWallpaper); |
| 3043 | } // else we're in the usual modern case: both source & crop exist |
| 3044 | } else if (originalWallpaper.exists()) { |
| 3045 | // VERY old schema; make sure things exist and are in the right place |
| 3046 | if (DEBUG) { |
| 3047 | Slog.i(TAG, "Migrating antique wallpaper schema"); |
| 3048 | } |
| 3049 | File oldInfo = new File(WallpaperBackupHelper.WALLPAPER_INFO_KEY); |
| 3050 | if (oldInfo.exists()) { |
| 3051 | File newInfo = new File(getWallpaperDir(0), WALLPAPER_INFO); |
| 3052 | oldInfo.renameTo(newInfo); |
| 3053 | } |
| 3054 | |
| 3055 | FileUtils.copyFile(originalWallpaper, preNWallpaper); |
| 3056 | originalWallpaper.renameTo(newWallpaper); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3057 | } |
| 3058 | } |
| 3059 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3060 | private int getAttributeInt(XmlPullParser parser, String name, int defValue) { |
| 3061 | String value = parser.getAttributeValue(null, name); |
| 3062 | if (value == null) { |
| 3063 | return defValue; |
| 3064 | } |
| 3065 | return Integer.parseInt(value); |
| 3066 | } |
| 3067 | |
Xiaohui Chen | ac53194 | 2015-05-13 13:20:52 -0700 | [diff] [blame] | 3068 | /** |
| 3069 | * Sometimes it is expected the wallpaper map may not have a user's data. E.g. This could |
| 3070 | * happen during user switch. The async user switch observer may not have received |
| 3071 | * the event yet. We use this safe method when we don't care about this ordering and just |
| 3072 | * want to update the data. The data is going to be applied when the user switch observer |
| 3073 | * is eventually executed. |
Christopher Tate | f717b93 | 2017-09-11 15:52:54 -0700 | [diff] [blame] | 3074 | * |
| 3075 | * Important: this method loads settings to initialize the given user's wallpaper data if |
| 3076 | * there is no current in-memory state. |
Xiaohui Chen | ac53194 | 2015-05-13 13:20:52 -0700 | [diff] [blame] | 3077 | */ |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3078 | private WallpaperData getWallpaperSafeLocked(int userId, int which) { |
| 3079 | // We're setting either just system (work with the system wallpaper), |
| 3080 | // both (also work with the system wallpaper), or just the lock |
| 3081 | // wallpaper (update against the existing lock wallpaper if any). |
| 3082 | // Combined or just-system operations use the 'system' WallpaperData |
| 3083 | // for this use; lock-only operations use the dedicated one. |
| 3084 | final SparseArray<WallpaperData> whichSet = |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 3085 | (which == FLAG_LOCK) ? mLockWallpaperMap : mWallpaperMap; |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3086 | WallpaperData wallpaper = whichSet.get(userId); |
Xiaohui Chen | ac53194 | 2015-05-13 13:20:52 -0700 | [diff] [blame] | 3087 | if (wallpaper == null) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3088 | // common case, this is the first lookup post-boot of the system or |
| 3089 | // unified lock, so we bring up the saved state lazily now and recheck. |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3090 | loadSettingsLocked(userId, false); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3091 | wallpaper = whichSet.get(userId); |
| 3092 | // if it's still null here, this is a lock-only operation and there is not |
| 3093 | // yet a lock-only wallpaper set for this user, so we need to establish |
| 3094 | // it now. |
| 3095 | if (wallpaper == null) { |
Christopher Tate | edf7d04 | 2016-03-29 18:24:25 -0700 | [diff] [blame] | 3096 | if (which == FLAG_LOCK) { |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 3097 | wallpaper = new WallpaperData(userId, getWallpaperDir(userId), |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3098 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); |
| 3099 | mLockWallpaperMap.put(userId, wallpaper); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3100 | ensureSaneWallpaperData(wallpaper, DEFAULT_DISPLAY); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3101 | } else { |
| 3102 | // sanity fallback: we're in bad shape, but establishing a known |
| 3103 | // valid system+lock WallpaperData will keep us from dying. |
| 3104 | Slog.wtf(TAG, "Didn't find wallpaper in non-lock case!"); |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 3105 | wallpaper = new WallpaperData(userId, getWallpaperDir(userId), |
| 3106 | WALLPAPER, WALLPAPER_CROP); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3107 | mWallpaperMap.put(userId, wallpaper); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3108 | ensureSaneWallpaperData(wallpaper, DEFAULT_DISPLAY); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3109 | } |
| 3110 | } |
Xiaohui Chen | ac53194 | 2015-05-13 13:20:52 -0700 | [diff] [blame] | 3111 | } |
| 3112 | return wallpaper; |
| 3113 | } |
| 3114 | |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3115 | private void loadSettingsLocked(int userId, boolean keepDimensionHints) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3116 | JournaledFile journal = makeJournaledFile(userId); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3117 | FileInputStream stream = null; |
| 3118 | File file = journal.chooseForRead(); |
Christopher Tate | 9f22443 | 2017-08-01 16:32:49 -0700 | [diff] [blame] | 3119 | |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3120 | WallpaperData wallpaper = mWallpaperMap.get(userId); |
| 3121 | if (wallpaper == null) { |
Christopher Tate | 9f22443 | 2017-08-01 16:32:49 -0700 | [diff] [blame] | 3122 | // Do this once per boot |
| 3123 | migrateFromOld(); |
| 3124 | |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 3125 | wallpaper = new WallpaperData(userId, getWallpaperDir(userId), |
| 3126 | WALLPAPER, WALLPAPER_CROP); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3127 | wallpaper.allowBackup = true; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3128 | mWallpaperMap.put(userId, wallpaper); |
Christopher Tate | 41297ff | 2016-03-10 16:46:15 -0800 | [diff] [blame] | 3129 | if (!wallpaper.cropExists()) { |
Christopher Tate | 2a6c55f | 2017-03-31 12:28:30 -0700 | [diff] [blame] | 3130 | if (wallpaper.sourceExists()) { |
| 3131 | generateCrop(wallpaper); |
| 3132 | } else { |
| 3133 | Slog.i(TAG, "No static wallpaper imagery; defaults will be shown"); |
| 3134 | } |
Christopher Tate | 41297ff | 2016-03-10 16:46:15 -0800 | [diff] [blame] | 3135 | } |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3136 | initializeFallbackWallpaper(); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3137 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3138 | boolean success = false; |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3139 | final DisplayData wpdData = getDisplayDataOrCreate(DEFAULT_DISPLAY); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3140 | try { |
| 3141 | stream = new FileInputStream(file); |
| 3142 | XmlPullParser parser = Xml.newPullParser(); |
Wojciech Staszkiewicz | 9e9e2e7 | 2015-05-08 14:58:46 +0100 | [diff] [blame] | 3143 | parser.setInput(stream, StandardCharsets.UTF_8.name()); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3144 | |
| 3145 | int type; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3146 | do { |
| 3147 | type = parser.next(); |
| 3148 | if (type == XmlPullParser.START_TAG) { |
| 3149 | String tag = parser.getName(); |
| 3150 | if ("wp".equals(tag)) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3151 | // Common to system + lock wallpapers |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3152 | parseWallpaperAttributes(parser, wallpaper, keepDimensionHints); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 3153 | |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3154 | // A system wallpaper might also be a live wallpaper |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3155 | String comp = parser.getAttributeValue(null, "component"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3156 | wallpaper.nextWallpaperComponent = comp != null |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 3157 | ? ComponentName.unflattenFromString(comp) |
| 3158 | : null; |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3159 | if (wallpaper.nextWallpaperComponent == null |
| 3160 | || "android".equals(wallpaper.nextWallpaperComponent |
| 3161 | .getPackageName())) { |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 3162 | wallpaper.nextWallpaperComponent = mImageWallpaper; |
Dianne Hackborn | 9ea3163 | 2011-08-05 14:43:50 -0700 | [diff] [blame] | 3163 | } |
Oleksandr Peletskyi | f251981 | 2016-01-26 20:16:06 +0100 | [diff] [blame] | 3164 | |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 3165 | if (DEBUG) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3166 | Slog.v(TAG, "mWidth:" + wpdData.mWidth); |
| 3167 | Slog.v(TAG, "mHeight:" + wpdData.mHeight); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3168 | Slog.v(TAG, "cropRect:" + wallpaper.cropHint); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 3169 | Slog.v(TAG, "primaryColors:" + wallpaper.primaryColors); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3170 | Slog.v(TAG, "mName:" + wallpaper.name); |
| 3171 | Slog.v(TAG, "mNextWallpaperComponent:" |
| 3172 | + wallpaper.nextWallpaperComponent); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 3173 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3174 | } else if ("kwp".equals(tag)) { |
| 3175 | // keyguard-specific wallpaper for this user |
| 3176 | WallpaperData lockWallpaper = mLockWallpaperMap.get(userId); |
| 3177 | if (lockWallpaper == null) { |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 3178 | lockWallpaper = new WallpaperData(userId, getWallpaperDir(userId), |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3179 | WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP); |
| 3180 | mLockWallpaperMap.put(userId, lockWallpaper); |
| 3181 | } |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3182 | parseWallpaperAttributes(parser, lockWallpaper, false); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3183 | } |
| 3184 | } |
| 3185 | } while (type != XmlPullParser.END_DOCUMENT); |
| 3186 | success = true; |
Dianne Hackborn | 13579ed | 2012-11-28 18:05:36 -0800 | [diff] [blame] | 3187 | } catch (FileNotFoundException e) { |
| 3188 | Slog.w(TAG, "no current wallpaper -- first boot?"); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3189 | } catch (NullPointerException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3190 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3191 | } catch (NumberFormatException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3192 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3193 | } catch (XmlPullParserException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3194 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3195 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3196 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3197 | } catch (IndexOutOfBoundsException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3198 | Slog.w(TAG, "failed parsing " + file + " " + e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3199 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 3200 | IoUtils.closeQuietly(stream); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3201 | |
| 3202 | if (!success) { |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3203 | wallpaper.cropHint.set(0, 0, 0, 0); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3204 | wpdData.mPadding.set(0, 0, 0, 0); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3205 | wallpaper.name = ""; |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 3206 | |
| 3207 | mLockWallpaperMap.remove(userId); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 3208 | } else { |
| 3209 | if (wallpaper.wallpaperId <= 0) { |
| 3210 | wallpaper.wallpaperId = makeWallpaperIdLocked(); |
| 3211 | if (DEBUG) { |
| 3212 | Slog.w(TAG, "Didn't set wallpaper id in loadSettingsLocked(" + userId |
| 3213 | + "); now " + wallpaper.wallpaperId); |
| 3214 | } |
| 3215 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3216 | } |
Dianne Hackborn | 44bc17c | 2011-04-20 18:18:51 -0700 | [diff] [blame] | 3217 | |
wilsonshih | d9173df | 2018-11-29 11:52:15 +0800 | [diff] [blame] | 3218 | ensureSaneWallpaperDisplaySize(wpdData, DEFAULT_DISPLAY); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3219 | ensureSaneWallpaperData(wallpaper, DEFAULT_DISPLAY); |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 3220 | WallpaperData lockWallpaper = mLockWallpaperMap.get(userId); |
| 3221 | if (lockWallpaper != null) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3222 | ensureSaneWallpaperData(lockWallpaper, DEFAULT_DISPLAY); |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 3223 | } |
| 3224 | } |
| 3225 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3226 | private void initializeFallbackWallpaper() { |
| 3227 | if (mFallbackWallpaper == null) { |
| 3228 | if (DEBUG) Slog.d(TAG, "Initialize fallback wallpaper"); |
wilsonshih | 999ec10 | 2019-05-17 18:47:50 +0800 | [diff] [blame] | 3229 | final int systemUserId = UserHandle.USER_SYSTEM; |
| 3230 | mFallbackWallpaper = new WallpaperData(systemUserId, getWallpaperDir(systemUserId), |
| 3231 | WALLPAPER, WALLPAPER_CROP); |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3232 | mFallbackWallpaper.allowBackup = false; |
| 3233 | mFallbackWallpaper.wallpaperId = makeWallpaperIdLocked(); |
| 3234 | bindWallpaperComponentLocked(mImageWallpaper, true, false, mFallbackWallpaper, null); |
| 3235 | } |
| 3236 | } |
| 3237 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3238 | private void ensureSaneWallpaperData(WallpaperData wallpaper, int displayId) { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3239 | final DisplayData size = getDisplayDataOrCreate(displayId); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3240 | |
| 3241 | if (displayId == DEFAULT_DISPLAY) { |
| 3242 | // crop, if not previously specified |
| 3243 | if (wallpaper.cropHint.width() <= 0 |
| 3244 | || wallpaper.cropHint.height() <= 0) { |
| 3245 | wallpaper.cropHint.set(0, 0, size.mWidth, size.mHeight); |
| 3246 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3247 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3250 | private void parseWallpaperAttributes(XmlPullParser parser, WallpaperData wallpaper, |
| 3251 | boolean keepDimensionHints) { |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3252 | final String idString = parser.getAttributeValue(null, "id"); |
| 3253 | if (idString != null) { |
| 3254 | final int id = wallpaper.wallpaperId = Integer.parseInt(idString); |
| 3255 | if (id > mWallpaperId) { |
| 3256 | mWallpaperId = id; |
| 3257 | } |
| 3258 | } else { |
| 3259 | wallpaper.wallpaperId = makeWallpaperIdLocked(); |
| 3260 | } |
| 3261 | |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3262 | final DisplayData wpData = getDisplayDataOrCreate(DEFAULT_DISPLAY); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3263 | |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3264 | if (!keepDimensionHints) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3265 | wpData.mWidth = Integer.parseInt(parser.getAttributeValue(null, "width")); |
| 3266 | wpData.mHeight = Integer.parseInt(parser.getAttributeValue(null, "height")); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3267 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3268 | wallpaper.cropHint.left = getAttributeInt(parser, "cropLeft", 0); |
| 3269 | wallpaper.cropHint.top = getAttributeInt(parser, "cropTop", 0); |
| 3270 | wallpaper.cropHint.right = getAttributeInt(parser, "cropRight", 0); |
| 3271 | wallpaper.cropHint.bottom = getAttributeInt(parser, "cropBottom", 0); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3272 | wpData.mPadding.left = getAttributeInt(parser, "paddingLeft", 0); |
| 3273 | wpData.mPadding.top = getAttributeInt(parser, "paddingTop", 0); |
| 3274 | wpData.mPadding.right = getAttributeInt(parser, "paddingRight", 0); |
| 3275 | wpData.mPadding.bottom = getAttributeInt(parser, "paddingBottom", 0); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 3276 | int colorsCount = getAttributeInt(parser, "colorsCount", 0); |
| 3277 | if (colorsCount > 0) { |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 3278 | Color primary = null, secondary = null, tertiary = null; |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 3279 | for (int i = 0; i < colorsCount; i++) { |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 3280 | Color color = Color.valueOf(getAttributeInt(parser, "colorValue" + i, 0)); |
| 3281 | if (i == 0) { |
| 3282 | primary = color; |
| 3283 | } else if (i == 1) { |
| 3284 | secondary = color; |
| 3285 | } else if (i == 2) { |
| 3286 | tertiary = color; |
| 3287 | } else { |
| 3288 | break; |
| 3289 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 3290 | } |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 3291 | int colorHints = getAttributeInt(parser, "colorHints", 0); |
| 3292 | wallpaper.primaryColors = new WallpaperColors(primary, secondary, tertiary, colorHints); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 3293 | } |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3294 | wallpaper.name = parser.getAttributeValue(null, "name"); |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3295 | wallpaper.allowBackup = "true".equals(parser.getAttributeValue(null, "backup")); |
Christopher Tate | be132e6 | 2016-02-10 12:59:49 -0800 | [diff] [blame] | 3296 | } |
| 3297 | |
Brad Fitzpatrick | 194b19a | 2010-09-14 11:30:29 -0700 | [diff] [blame] | 3298 | // Called by SystemBackupAgent after files are restored to disk. |
Amith Yamasani | 09e9cdc | 2013-11-06 14:54:50 -0800 | [diff] [blame] | 3299 | public void settingsRestored() { |
| 3300 | // Verify caller is the system |
| 3301 | if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) { |
| 3302 | throw new RuntimeException("settingsRestored() can only be called from the system process"); |
| 3303 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3304 | // TODO: If necessary, make it work for secondary users as well. This currently assumes |
| 3305 | // restores only to the primary user |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3306 | if (DEBUG) Slog.v(TAG, "settingsRestored"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3307 | WallpaperData wallpaper = null; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3308 | boolean success = false; |
| 3309 | synchronized (mLock) { |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3310 | loadSettingsLocked(UserHandle.USER_SYSTEM, false); |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 3311 | wallpaper = mWallpaperMap.get(UserHandle.USER_SYSTEM); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 3312 | wallpaper.wallpaperId = makeWallpaperIdLocked(); // always bump id at restore |
Christopher Tate | d7faf53 | 2016-02-25 12:43:38 -0800 | [diff] [blame] | 3313 | wallpaper.allowBackup = true; // by definition if it was restored |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3314 | if (wallpaper.nextWallpaperComponent != null |
Justin Koh | 29c3016 | 2014-09-05 17:10:10 -0700 | [diff] [blame] | 3315 | && !wallpaper.nextWallpaperComponent.equals(mImageWallpaper)) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3316 | if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 3317 | wallpaper, null)) { |
Christopher Tate | e3ab4d0 | 2009-12-16 14:03:31 -0800 | [diff] [blame] | 3318 | // No such live wallpaper or other failure; fall back to the default |
| 3319 | // live wallpaper (since the profile being restored indicated that the |
| 3320 | // user had selected a live rather than static one). |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 3321 | bindWallpaperComponentLocked(null, false, false, wallpaper, null); |
Christopher Tate | e3ab4d0 | 2009-12-16 14:03:31 -0800 | [diff] [blame] | 3322 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3323 | success = true; |
| 3324 | } else { |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 3325 | // If there's a wallpaper name, we use that. If that can't be loaded, then we |
| 3326 | // use the default. |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3327 | if ("".equals(wallpaper.name)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3328 | if (DEBUG) Slog.v(TAG, "settingsRestored: name is empty"); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 3329 | success = true; |
| 3330 | } else { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3331 | if (DEBUG) Slog.v(TAG, "settingsRestored: attempting to restore named resource"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3332 | success = restoreNamedResourceLocked(wallpaper); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 3333 | } |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 3334 | if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success |
| 3335 | + " id=" + wallpaper.wallpaperId); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 3336 | if (success) { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3337 | generateCrop(wallpaper); // based on the new image + metadata |
Christopher Tate | 41297ff | 2016-03-10 16:46:15 -0800 | [diff] [blame] | 3338 | bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, true, false, |
Dianne Hackborn | 5dc5a00 | 2012-09-15 19:33:48 -0700 | [diff] [blame] | 3339 | wallpaper, null); |
Mike Cleron | a428b2c | 2009-11-15 22:53:08 -0800 | [diff] [blame] | 3340 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3341 | } |
| 3342 | } |
| 3343 | |
| 3344 | if (!success) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3345 | Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'"); |
| 3346 | wallpaper.name = ""; |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 3347 | getWallpaperDir(UserHandle.USER_SYSTEM).delete(); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3348 | } |
Brad Fitzpatrick | 194b19a | 2010-09-14 11:30:29 -0700 | [diff] [blame] | 3349 | |
| 3350 | synchronized (mLock) { |
Christopher Tate | db27b84 | 2016-02-25 14:39:17 -0800 | [diff] [blame] | 3351 | saveSettingsLocked(UserHandle.USER_SYSTEM); |
Brad Fitzpatrick | 194b19a | 2010-09-14 11:30:29 -0700 | [diff] [blame] | 3352 | } |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3353 | } |
| 3354 | |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3355 | // Restore the named resource bitmap to both source + crop files |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3356 | private boolean restoreNamedResourceLocked(WallpaperData wallpaper) { |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3357 | if (wallpaper.name.length() > 4 && "res:".equals(wallpaper.name.substring(0, 4))) { |
| 3358 | String resName = wallpaper.name.substring(4); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3359 | |
| 3360 | String pkg = null; |
| 3361 | int colon = resName.indexOf(':'); |
| 3362 | if (colon > 0) { |
| 3363 | pkg = resName.substring(0, colon); |
| 3364 | } |
| 3365 | |
| 3366 | String ident = null; |
| 3367 | int slash = resName.lastIndexOf('/'); |
| 3368 | if (slash > 0) { |
| 3369 | ident = resName.substring(slash+1); |
| 3370 | } |
| 3371 | |
| 3372 | String type = null; |
| 3373 | if (colon > 0 && slash > 0 && (slash-colon) > 1) { |
| 3374 | type = resName.substring(colon+1, slash); |
| 3375 | } |
| 3376 | |
| 3377 | if (pkg != null && ident != null && type != null) { |
| 3378 | int resId = -1; |
| 3379 | InputStream res = null; |
| 3380 | FileOutputStream fos = null; |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3381 | FileOutputStream cos = null; |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3382 | try { |
| 3383 | Context c = mContext.createPackageContext(pkg, Context.CONTEXT_RESTRICTED); |
| 3384 | Resources r = c.getResources(); |
| 3385 | resId = r.getIdentifier(resName, null, null); |
| 3386 | if (resId == 0) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3387 | Slog.e(TAG, "couldn't resolve identifier pkg=" + pkg + " type=" + type |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3388 | + " ident=" + ident); |
| 3389 | return false; |
| 3390 | } |
| 3391 | |
| 3392 | res = r.openRawResource(resId); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3393 | if (wallpaper.wallpaperFile.exists()) { |
| 3394 | wallpaper.wallpaperFile.delete(); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3395 | wallpaper.cropFile.delete(); |
Dianne Hackborn | 1afd1c9 | 2010-03-18 22:47:17 -0700 | [diff] [blame] | 3396 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3397 | fos = new FileOutputStream(wallpaper.wallpaperFile); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3398 | cos = new FileOutputStream(wallpaper.cropFile); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3399 | |
| 3400 | byte[] buffer = new byte[32768]; |
| 3401 | int amt; |
| 3402 | while ((amt=res.read(buffer)) > 0) { |
| 3403 | fos.write(buffer, 0, amt); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3404 | cos.write(buffer, 0, amt); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3405 | } |
| 3406 | // mWallpaperObserver will notice the close and send the change broadcast |
| 3407 | |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3408 | Slog.v(TAG, "Restored wallpaper: " + resName); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3409 | return true; |
| 3410 | } catch (NameNotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3411 | Slog.e(TAG, "Package name " + pkg + " not found"); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3412 | } catch (Resources.NotFoundException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3413 | Slog.e(TAG, "Resource not found: " + resId); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3414 | } catch (IOException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 3415 | Slog.e(TAG, "IOException while restoring wallpaper ", e); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3416 | } finally { |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 3417 | IoUtils.closeQuietly(res); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3418 | if (fos != null) { |
Dianne Hackborn | 8bdf593 | 2010-10-15 12:54:40 -0700 | [diff] [blame] | 3419 | FileUtils.sync(fos); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3420 | } |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3421 | if (cos != null) { |
| 3422 | FileUtils.sync(cos); |
| 3423 | } |
| 3424 | IoUtils.closeQuietly(fos); |
| 3425 | IoUtils.closeQuietly(cos); |
Joe Onorato | 9bb8fd7 | 2009-07-28 18:24:51 -0700 | [diff] [blame] | 3426 | } |
| 3427 | } |
| 3428 | } |
| 3429 | return false; |
| 3430 | } |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3431 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 3432 | @Override |
| 3433 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Jeff Sharkey | fe9a53b | 2017-03-31 14:08:23 -0600 | [diff] [blame] | 3434 | if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 3435 | |
Felipe Leme | 9584cb6c | 2020-01-17 13:30:36 -0800 | [diff] [blame] | 3436 | pw.print("mDefaultWallpaperComponent="); pw.println(mDefaultWallpaperComponent); |
| 3437 | pw.print("mImageWallpaper="); pw.println(mImageWallpaper); |
| 3438 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 3439 | synchronized (mLock) { |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 3440 | pw.println("System wallpaper state:"); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3441 | for (int i = 0; i < mWallpaperMap.size(); i++) { |
| 3442 | WallpaperData wallpaper = mWallpaperMap.valueAt(i); |
Christopher Tate | ad3c259 | 2016-01-20 18:13:17 -0800 | [diff] [blame] | 3443 | pw.print(" User "); pw.print(wallpaper.userId); |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3444 | pw.print(": id="); pw.println(wallpaper.wallpaperId); |
| 3445 | pw.println(" Display state:"); |
| 3446 | forEachDisplayData(wpSize -> { |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3447 | pw.print(" displayId="); |
| 3448 | pw.println(wpSize.mDisplayId); |
| 3449 | pw.print(" mWidth="); |
| 3450 | pw.print(wpSize.mWidth); |
| 3451 | pw.print(" mHeight="); |
| 3452 | pw.println(wpSize.mHeight); |
| 3453 | pw.print(" mPadding="); pw.println(wpSize.mPadding); |
| 3454 | }); |
Christopher Tate | 1e1e2e0 | 2016-01-25 15:34:36 -0800 | [diff] [blame] | 3455 | pw.print(" mCropHint="); pw.println(wallpaper.cropHint); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3456 | pw.print(" mName="); pw.println(wallpaper.name); |
Bryan Mawhinney | 0fa54f4 | 2017-07-06 17:09:37 +0100 | [diff] [blame] | 3457 | pw.print(" mAllowBackup="); pw.println(wallpaper.allowBackup); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 3458 | pw.print(" mWallpaperComponent="); pw.println(wallpaper.wallpaperComponent); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3459 | if (wallpaper.connection != null) { |
| 3460 | WallpaperConnection conn = wallpaper.connection; |
| 3461 | pw.print(" Wallpaper connection "); |
| 3462 | pw.print(conn); |
| 3463 | pw.println(":"); |
| 3464 | if (conn.mInfo != null) { |
| 3465 | pw.print(" mInfo.component="); |
| 3466 | pw.println(conn.mInfo.getComponent()); |
| 3467 | } |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 3468 | conn.forEachDisplayConnector(connector -> { |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3469 | pw.print(" mDisplayId="); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 3470 | pw.println(connector.mDisplayId); |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3471 | pw.print(" mToken="); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 3472 | pw.println(connector.mToken); |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3473 | pw.print(" mEngine="); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 3474 | pw.println(connector.mEngine); |
| 3475 | }); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3476 | pw.print(" mService="); |
| 3477 | pw.println(conn.mService); |
Amith Yamasani | 37ce3a8 | 2012-02-06 12:04:42 -0800 | [diff] [blame] | 3478 | pw.print(" mLastDiedTime="); |
| 3479 | pw.println(wallpaper.lastDiedTime - SystemClock.uptimeMillis()); |
| 3480 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 3481 | } |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 3482 | pw.println("Lock wallpaper state:"); |
| 3483 | for (int i = 0; i < mLockWallpaperMap.size(); i++) { |
| 3484 | WallpaperData wallpaper = mLockWallpaperMap.valueAt(i); |
| 3485 | pw.print(" User "); pw.print(wallpaper.userId); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 3486 | pw.print(": id="); pw.println(wallpaper.wallpaperId); |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 3487 | pw.print(" mCropHint="); pw.println(wallpaper.cropHint); |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 3488 | pw.print(" mName="); pw.println(wallpaper.name); |
Bryan Mawhinney | 0fa54f4 | 2017-07-06 17:09:37 +0100 | [diff] [blame] | 3489 | pw.print(" mAllowBackup="); pw.println(wallpaper.allowBackup); |
Adrian Roos | c28e3a9 | 2016-04-14 10:47:52 -0700 | [diff] [blame] | 3490 | } |
wilsonshih | a282bf7 | 2018-11-30 12:48:05 +0800 | [diff] [blame] | 3491 | pw.println("Fallback wallpaper state:"); |
| 3492 | pw.print(" User "); pw.print(mFallbackWallpaper.userId); |
| 3493 | pw.print(": id="); pw.println(mFallbackWallpaper.wallpaperId); |
| 3494 | pw.print(" mCropHint="); pw.println(mFallbackWallpaper.cropHint); |
| 3495 | pw.print(" mName="); pw.println(mFallbackWallpaper.name); |
| 3496 | pw.print(" mAllowBackup="); pw.println(mFallbackWallpaper.allowBackup); |
| 3497 | if (mFallbackWallpaper.connection != null) { |
| 3498 | WallpaperConnection conn = mFallbackWallpaper.connection; |
| 3499 | pw.print(" Fallback Wallpaper connection "); |
| 3500 | pw.print(conn); |
| 3501 | pw.println(":"); |
| 3502 | if (conn.mInfo != null) { |
| 3503 | pw.print(" mInfo.component="); |
| 3504 | pw.println(conn.mInfo.getComponent()); |
| 3505 | } |
| 3506 | conn.forEachDisplayConnector(connector -> { |
| 3507 | pw.print(" mDisplayId="); |
| 3508 | pw.println(connector.mDisplayId); |
| 3509 | pw.print(" mToken="); |
| 3510 | pw.println(connector.mToken); |
| 3511 | pw.print(" mEngine="); |
| 3512 | pw.println(connector.mEngine); |
| 3513 | }); |
| 3514 | pw.print(" mService="); |
| 3515 | pw.println(conn.mService); |
| 3516 | pw.print(" mLastDiedTime="); |
| 3517 | pw.println(mFallbackWallpaper.lastDiedTime - SystemClock.uptimeMillis()); |
| 3518 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 3519 | } |
| 3520 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3521 | } |