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