Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
| 17 | package android.service.wallpaper; |
| 18 | |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 20 | import android.annotation.SdkConstant; |
| 21 | import android.annotation.SdkConstant.SdkConstantType; |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 22 | import android.annotation.SystemApi; |
Mathew Inwood | e380737 | 2018-08-10 09:51:03 +0100 | [diff] [blame] | 23 | import android.annotation.UnsupportedAppUsage; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 24 | import android.app.Service; |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 25 | import android.app.WallpaperColors; |
Lucas Dupin | 8f09a50 | 2018-07-27 16:47:45 +0800 | [diff] [blame] | 26 | import android.app.WallpaperInfo; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 27 | import android.app.WallpaperManager; |
wilsonshih | 8ccb9ce | 2018-12-04 11:44:31 +0800 | [diff] [blame] | 28 | import android.content.Context; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 29 | import android.content.Intent; |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 30 | import android.content.res.TypedArray; |
| 31 | import android.graphics.Bitmap; |
| 32 | import android.graphics.Canvas; |
Mathias Agopian | 62bf4a0 | 2010-09-08 16:32:27 -0700 | [diff] [blame] | 33 | import android.graphics.PixelFormat; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 34 | import android.graphics.Rect; |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 35 | import android.graphics.drawable.Drawable; |
Jeff Brown | 3d110b2 | 2014-11-21 19:01:13 -0800 | [diff] [blame] | 36 | import android.hardware.display.DisplayManager; |
| 37 | import android.hardware.display.DisplayManager.DisplayListener; |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 38 | import android.os.Build; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 39 | import android.os.Bundle; |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 40 | import android.os.Handler; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 41 | import android.os.IBinder; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 42 | import android.os.Looper; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 43 | import android.os.Message; |
| 44 | import android.os.RemoteException; |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 45 | import android.os.SystemClock; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 46 | import android.util.Log; |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 47 | import android.util.MergedConfiguration; |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 48 | import android.view.Display; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 49 | import android.view.DisplayCutout; |
Valentin Iftime | 6239e53 | 2018-08-24 17:17:26 +0200 | [diff] [blame] | 50 | import android.view.DisplayInfo; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 51 | import android.view.Gravity; |
| 52 | import android.view.IWindowSession; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 53 | import android.view.InputChannel; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 54 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 55 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 56 | import android.view.InputEventReceiver; |
wilsonshih | 8ccb9ce | 2018-12-04 11:44:31 +0800 | [diff] [blame] | 57 | import android.view.InsetsState; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 58 | import android.view.MotionEvent; |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 59 | import android.view.SurfaceControl; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 60 | import android.view.SurfaceHolder; |
| 61 | import android.view.View; |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 62 | import android.view.ViewGroup; |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 63 | import android.view.WindowInsets; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 64 | import android.view.WindowManager; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 65 | import android.view.WindowManagerGlobal; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 66 | |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 67 | import com.android.internal.annotations.VisibleForTesting; |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 68 | import com.android.internal.os.HandlerCaller; |
| 69 | import com.android.internal.view.BaseIWindow; |
| 70 | import com.android.internal.view.BaseSurfaceHolder; |
| 71 | |
Dianne Hackborn | 527de8e | 2011-08-22 16:10:36 -0700 | [diff] [blame] | 72 | import java.io.FileDescriptor; |
| 73 | import java.io.PrintWriter; |
Dianne Hackborn | af1f42b | 2009-11-20 16:27:27 -0800 | [diff] [blame] | 74 | import java.util.ArrayList; |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 75 | import java.util.concurrent.atomic.AtomicBoolean; |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 76 | import java.util.function.Supplier; |
Dianne Hackborn | af1f42b | 2009-11-20 16:27:27 -0800 | [diff] [blame] | 77 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 78 | /** |
| 79 | * A wallpaper service is responsible for showing a live wallpaper behind |
Dianne Hackborn | 23ef7b4 | 2009-11-18 18:20:39 -0800 | [diff] [blame] | 80 | * applications that would like to sit on top of it. This service object |
| 81 | * itself does very little -- its only purpose is to generate instances of |
Dianne Hackborn | e4260f4 | 2009-11-18 21:15:59 -0800 | [diff] [blame] | 82 | * {@link Engine} as needed. Implementing a wallpaper thus |
Dianne Hackborn | 23ef7b4 | 2009-11-18 18:20:39 -0800 | [diff] [blame] | 83 | * involves subclassing from this, subclassing an Engine implementation, |
| 84 | * and implementing {@link #onCreateEngine()} to return a new instance of |
| 85 | * your engine. |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 86 | */ |
| 87 | public abstract class WallpaperService extends Service { |
| 88 | /** |
| 89 | * The {@link Intent} that must be declared as handled by the service. |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 90 | * To be supported, the service must also require the |
| 91 | * {@link android.Manifest.permission#BIND_WALLPAPER} permission so |
| 92 | * that other applications can not abuse it. |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 93 | */ |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 94 | @SdkConstant(SdkConstantType.SERVICE_ACTION) |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 95 | public static final String SERVICE_INTERFACE = |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 96 | "android.service.wallpaper.WallpaperService"; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 97 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 98 | /** |
| 99 | * Name under which a WallpaperService component publishes information |
| 100 | * about itself. This meta-data must reference an XML resource containing |
| 101 | * a <code><{@link android.R.styleable#Wallpaper wallpaper}></code> |
| 102 | * tag. |
| 103 | */ |
| 104 | public static final String SERVICE_META_DATA = "android.service.wallpaper"; |
Craig Mautner | b1ef369 | 2012-11-16 17:31:04 -0800 | [diff] [blame] | 105 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 106 | static final String TAG = "WallpaperService"; |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 107 | static final boolean DEBUG = false; |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 108 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 109 | private static final int DO_ATTACH = 10; |
| 110 | private static final int DO_DETACH = 20; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 111 | private static final int DO_SET_DESIRED_SIZE = 30; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 112 | private static final int DO_SET_DISPLAY_PADDING = 40; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 113 | private static final int DO_IN_AMBIENT_MODE = 50; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 114 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 115 | private static final int MSG_UPDATE_SURFACE = 10000; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 116 | private static final int MSG_VISIBILITY_CHANGED = 10010; |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 117 | private static final int MSG_WALLPAPER_OFFSETS = 10020; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 118 | private static final int MSG_WALLPAPER_COMMAND = 10025; |
Mathew Inwood | e380737 | 2018-08-10 09:51:03 +0100 | [diff] [blame] | 119 | @UnsupportedAppUsage |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 120 | private static final int MSG_WINDOW_RESIZED = 10030; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 121 | private static final int MSG_WINDOW_MOVED = 10035; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 122 | private static final int MSG_TOUCH_EVENT = 10040; |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 123 | private static final int MSG_REQUEST_WALLPAPER_COLORS = 10050; |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 124 | |
| 125 | private static final int NOTIFY_COLORS_RATE_LIMIT_MS = 1000; |
| 126 | |
Dianne Hackborn | af1f42b | 2009-11-20 16:27:27 -0800 | [diff] [blame] | 127 | private final ArrayList<Engine> mActiveEngines |
| 128 | = new ArrayList<Engine>(); |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 129 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 130 | static final class WallpaperCommand { |
| 131 | String action; |
| 132 | int x; |
| 133 | int y; |
| 134 | int z; |
| 135 | Bundle extras; |
| 136 | boolean sync; |
| 137 | } |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 138 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 139 | /** |
| 140 | * The actual implementation of a wallpaper. A wallpaper service may |
| 141 | * have multiple instances running (for example as a real wallpaper |
| 142 | * and as a preview), each of which is represented by its own Engine |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 143 | * instance. You must implement {@link WallpaperService#onCreateEngine()} |
| 144 | * to return your concrete Engine implementation. |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 145 | */ |
| 146 | public class Engine { |
| 147 | IWallpaperEngineWrapper mIWallpaperEngine; |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 148 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 149 | // Copies from mIWallpaperEngine. |
| 150 | HandlerCaller mCaller; |
| 151 | IWallpaperConnection mConnection; |
| 152 | IBinder mWindowToken; |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 153 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 154 | boolean mInitializing = true; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 155 | boolean mVisible; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 156 | boolean mReportedVisible; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 157 | boolean mDestroyed; |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 158 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 159 | // Current window state. |
| 160 | boolean mCreated; |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 161 | boolean mSurfaceCreated; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 162 | boolean mIsCreating; |
| 163 | boolean mDrawingAllowed; |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 164 | boolean mOffsetsChanged; |
Jeff Sharkey | 35be756 | 2012-04-18 19:16:15 -0700 | [diff] [blame] | 165 | boolean mFixedSizeAllowed; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 166 | int mWidth; |
| 167 | int mHeight; |
| 168 | int mFormat; |
| 169 | int mType; |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 170 | int mCurWidth; |
| 171 | int mCurHeight; |
Lucas Dupin | 6155aa4 | 2018-09-05 11:15:52 -0700 | [diff] [blame] | 172 | int mWindowFlags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 173 | int mWindowPrivateFlags = |
| 174 | WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 175 | int mCurWindowFlags = mWindowFlags; |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 176 | int mCurWindowPrivateFlags = mWindowPrivateFlags; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 177 | final Rect mVisibleInsets = new Rect(); |
| 178 | final Rect mWinFrame = new Rect(); |
| 179 | final Rect mContentInsets = new Rect(); |
Adrian Roos | fa10423 | 2014-06-20 16:10:14 -0700 | [diff] [blame] | 180 | final Rect mStableInsets = new Rect(); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 181 | final Rect mDispatchedContentInsets = new Rect(); |
| 182 | final Rect mDispatchedStableInsets = new Rect(); |
| 183 | final Rect mFinalSystemInsets = new Rect(); |
| 184 | final Rect mFinalStableInsets = new Rect(); |
Jorim Jaggi | 2e95a48 | 2016-01-14 17:36:55 -0800 | [diff] [blame] | 185 | final Rect mBackdropFrame = new Rect(); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 186 | final DisplayCutout.ParcelableWrapper mDisplayCutout = |
| 187 | new DisplayCutout.ParcelableWrapper(); |
| 188 | DisplayCutout mDispatchedDisplayCutout = DisplayCutout.NO_CUTOUT; |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 189 | final InsetsState mInsetsState = new InsetsState(); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 190 | final MergedConfiguration mMergedConfiguration = new MergedConfiguration(); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 191 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 192 | final WindowManager.LayoutParams mLayout |
| 193 | = new WindowManager.LayoutParams(); |
| 194 | IWindowSession mSession; |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 195 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 196 | final Object mLock = new Object(); |
| 197 | boolean mOffsetMessageEnqueued; |
Mathew Inwood | 31755f9 | 2018-12-20 13:53:36 +0000 | [diff] [blame] | 198 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 199 | float mPendingXOffset; |
| 200 | float mPendingYOffset; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 201 | float mPendingXOffsetStep; |
| 202 | float mPendingYOffsetStep; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 203 | boolean mPendingSync; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 204 | MotionEvent mPendingMove; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 205 | boolean mIsInAmbientMode; |
Jeff Brown | 3d110b2 | 2014-11-21 19:01:13 -0800 | [diff] [blame] | 206 | |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 207 | // Needed for throttling onComputeColors. |
| 208 | private long mLastColorInvalidation; |
| 209 | private final Runnable mNotifyColorsChanged = this::notifyColorsChanged; |
Lucas Dupin | 416fe95 | 2017-08-14 10:58:40 -0700 | [diff] [blame] | 210 | private final Supplier<Long> mClockFunction; |
| 211 | private final Handler mHandler; |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 212 | |
wilsonshih | 8ccb9ce | 2018-12-04 11:44:31 +0800 | [diff] [blame] | 213 | private Display mDisplay; |
| 214 | private Context mDisplayContext; |
Filip Gruszczynski | 4544b92 | 2015-04-16 13:18:58 -0700 | [diff] [blame] | 215 | private int mDisplayState; |
Jeff Brown | 3d110b2 | 2014-11-21 19:01:13 -0800 | [diff] [blame] | 216 | |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 217 | SurfaceControl mSurfaceControl = new SurfaceControl(); |
| 218 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 219 | final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() { |
Mathias Agopian | 62bf4a0 | 2010-09-08 16:32:27 -0700 | [diff] [blame] | 220 | { |
Jeff Brown | 2457237 | 2011-06-09 19:05:15 -0700 | [diff] [blame] | 221 | mRequestedFormat = PixelFormat.RGBX_8888; |
Mathias Agopian | 62bf4a0 | 2010-09-08 16:32:27 -0700 | [diff] [blame] | 222 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 223 | |
| 224 | @Override |
| 225 | public boolean onAllowLockCanvas() { |
| 226 | return mDrawingAllowed; |
| 227 | } |
| 228 | |
| 229 | @Override |
| 230 | public void onRelayoutContainer() { |
| 231 | Message msg = mCaller.obtainMessage(MSG_UPDATE_SURFACE); |
| 232 | mCaller.sendMessage(msg); |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void onUpdateSurface() { |
| 237 | Message msg = mCaller.obtainMessage(MSG_UPDATE_SURFACE); |
| 238 | mCaller.sendMessage(msg); |
| 239 | } |
| 240 | |
| 241 | public boolean isCreating() { |
| 242 | return mIsCreating; |
| 243 | } |
| 244 | |
Dianne Hackborn | a48a37f | 2011-02-01 16:30:38 -0800 | [diff] [blame] | 245 | @Override |
| 246 | public void setFixedSize(int width, int height) { |
Jeff Sharkey | 35be756 | 2012-04-18 19:16:15 -0700 | [diff] [blame] | 247 | if (!mFixedSizeAllowed) { |
Dianne Hackborn | a48a37f | 2011-02-01 16:30:38 -0800 | [diff] [blame] | 248 | // Regular apps can't do this. It can only work for |
| 249 | // certain designs of window animations, so you can't |
| 250 | // rely on it. |
| 251 | throw new UnsupportedOperationException( |
| 252 | "Wallpapers currently only support sizing from layout"); |
| 253 | } |
Michael Jurka | b8f939f | 2011-02-01 20:50:30 -0800 | [diff] [blame] | 254 | super.setFixedSize(width, height); |
Dianne Hackborn | a48a37f | 2011-02-01 16:30:38 -0800 | [diff] [blame] | 255 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 256 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 257 | public void setKeepScreenOn(boolean screenOn) { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 258 | throw new UnsupportedOperationException( |
| 259 | "Wallpapers do not support keep screen on"); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 260 | } |
Filip Gruszczynski | 4544b92 | 2015-04-16 13:18:58 -0700 | [diff] [blame] | 261 | |
John Reck | 6bc7014 | 2016-10-26 16:49:17 -0700 | [diff] [blame] | 262 | private void prepareToDraw() { |
Filip Gruszczynski | 4544b92 | 2015-04-16 13:18:58 -0700 | [diff] [blame] | 263 | if (mDisplayState == Display.STATE_DOZE |
| 264 | || mDisplayState == Display.STATE_DOZE_SUSPEND) { |
| 265 | try { |
| 266 | mSession.pokeDrawLock(mWindow); |
| 267 | } catch (RemoteException e) { |
| 268 | // System server died, can be ignored. |
| 269 | } |
| 270 | } |
John Reck | 6bc7014 | 2016-10-26 16:49:17 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public Canvas lockCanvas() { |
| 275 | prepareToDraw(); |
Filip Gruszczynski | 4544b92 | 2015-04-16 13:18:58 -0700 | [diff] [blame] | 276 | return super.lockCanvas(); |
| 277 | } |
John Reck | 6bc7014 | 2016-10-26 16:49:17 -0700 | [diff] [blame] | 278 | |
| 279 | @Override |
| 280 | public Canvas lockCanvas(Rect dirty) { |
| 281 | prepareToDraw(); |
| 282 | return super.lockCanvas(dirty); |
| 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public Canvas lockHardwareCanvas() { |
| 287 | prepareToDraw(); |
| 288 | return super.lockHardwareCanvas(); |
| 289 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 290 | }; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 291 | |
| 292 | final class WallpaperInputEventReceiver extends InputEventReceiver { |
| 293 | public WallpaperInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 294 | super(inputChannel, looper); |
| 295 | } |
| 296 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 297 | @Override |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 298 | public void onInputEvent(InputEvent event) { |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 299 | boolean handled = false; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 300 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 301 | if (event instanceof MotionEvent |
| 302 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 303 | MotionEvent dup = MotionEvent.obtainNoHistory((MotionEvent)event); |
| 304 | dispatchPointer(dup); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 305 | handled = true; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 306 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 307 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 308 | finishInputEvent(event, handled); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 311 | } |
| 312 | WallpaperInputEventReceiver mInputEventReceiver; |
| 313 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 314 | final BaseIWindow mWindow = new BaseIWindow() { |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 315 | @Override |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame^] | 316 | public void resized(Rect frame, Rect contentInsets, |
| 317 | Rect visibleInsets, Rect stableInsets, boolean reportDraw, |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 318 | MergedConfiguration mergedConfiguration, Rect backDropRect, boolean forceLayout, |
Brad Stenning | e057369 | 2019-03-11 13:52:46 -0700 | [diff] [blame] | 319 | boolean alwaysConsumeSystemBars, int displayId, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 320 | DisplayCutout.ParcelableWrapper displayCutout) { |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame^] | 321 | Message msg = mCaller.obtainMessageI(MSG_WINDOW_RESIZED, |
| 322 | reportDraw ? 1 : 0); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 323 | mCaller.sendMessage(msg); |
| 324 | } |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 325 | |
| 326 | @Override |
| 327 | public void moved(int newX, int newY) { |
| 328 | Message msg = mCaller.obtainMessageII(MSG_WINDOW_MOVED, newX, newY); |
| 329 | mCaller.sendMessage(msg); |
| 330 | } |
| 331 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 332 | @Override |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 333 | public void dispatchAppVisibility(boolean visible) { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 334 | // We don't do this in preview mode; we'll let the preview |
| 335 | // activity tell us when to run. |
| 336 | if (!mIWallpaperEngine.mIsPreview) { |
| 337 | Message msg = mCaller.obtainMessageI(MSG_VISIBILITY_CHANGED, |
| 338 | visible ? 1 : 0); |
| 339 | mCaller.sendMessage(msg); |
| 340 | } |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 341 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 342 | |
| 343 | @Override |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 344 | public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, |
| 345 | boolean sync) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 346 | synchronized (mLock) { |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 347 | if (DEBUG) Log.v(TAG, "Dispatch wallpaper offsets: " + x + ", " + y); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 348 | mPendingXOffset = x; |
| 349 | mPendingYOffset = y; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 350 | mPendingXOffsetStep = xStep; |
| 351 | mPendingYOffsetStep = yStep; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 352 | if (sync) { |
| 353 | mPendingSync = true; |
| 354 | } |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 355 | if (!mOffsetMessageEnqueued) { |
| 356 | mOffsetMessageEnqueued = true; |
| 357 | Message msg = mCaller.obtainMessage(MSG_WALLPAPER_OFFSETS); |
| 358 | mCaller.sendMessage(msg); |
| 359 | } |
| 360 | } |
| 361 | } |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 362 | |
| 363 | @Override |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 364 | public void dispatchWallpaperCommand(String action, int x, int y, |
| 365 | int z, Bundle extras, boolean sync) { |
| 366 | synchronized (mLock) { |
| 367 | if (DEBUG) Log.v(TAG, "Dispatch wallpaper command: " + x + ", " + y); |
| 368 | WallpaperCommand cmd = new WallpaperCommand(); |
| 369 | cmd.action = action; |
| 370 | cmd.x = x; |
| 371 | cmd.y = y; |
| 372 | cmd.z = z; |
| 373 | cmd.extras = extras; |
| 374 | cmd.sync = sync; |
| 375 | Message msg = mCaller.obtainMessage(MSG_WALLPAPER_COMMAND); |
| 376 | msg.obj = cmd; |
| 377 | mCaller.sendMessage(msg); |
| 378 | } |
| 379 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 380 | }; |
Lucas Dupin | 416fe95 | 2017-08-14 10:58:40 -0700 | [diff] [blame] | 381 | |
| 382 | /** |
| 383 | * Default constructor |
| 384 | */ |
| 385 | public Engine() { |
| 386 | this(SystemClock::elapsedRealtime, Handler.getMain()); |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Constructor used for test purposes. |
| 391 | * |
| 392 | * @param clockFunction Supplies current times in millis. |
| 393 | * @param handler Used for posting/deferring asynchronous calls. |
| 394 | * @hide |
| 395 | */ |
| 396 | @VisibleForTesting |
| 397 | public Engine(Supplier<Long> clockFunction, Handler handler) { |
| 398 | mClockFunction = clockFunction; |
| 399 | mHandler = handler; |
| 400 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 401 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 402 | /** |
| 403 | * Provides access to the surface in which this wallpaper is drawn. |
| 404 | */ |
| 405 | public SurfaceHolder getSurfaceHolder() { |
| 406 | return mSurfaceHolder; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 407 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 408 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 409 | /** |
| 410 | * Convenience for {@link WallpaperManager#getDesiredMinimumWidth() |
| 411 | * WallpaperManager.getDesiredMinimumWidth()}, returning the width |
| 412 | * that the system would like this wallpaper to run in. |
| 413 | */ |
| 414 | public int getDesiredMinimumWidth() { |
| 415 | return mIWallpaperEngine.mReqWidth; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 416 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 417 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 418 | /** |
| 419 | * Convenience for {@link WallpaperManager#getDesiredMinimumHeight() |
| 420 | * WallpaperManager.getDesiredMinimumHeight()}, returning the height |
| 421 | * that the system would like this wallpaper to run in. |
| 422 | */ |
| 423 | public int getDesiredMinimumHeight() { |
| 424 | return mIWallpaperEngine.mReqHeight; |
| 425 | } |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 426 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 427 | /** |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 428 | * Return whether the wallpaper is currently visible to the user, |
| 429 | * this is the last value supplied to |
| 430 | * {@link #onVisibilityChanged(boolean)}. |
| 431 | */ |
| 432 | public boolean isVisible() { |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 433 | return mReportedVisible; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 434 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 435 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 436 | /** |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 437 | * Returns true if this engine is running in preview mode -- that is, |
| 438 | * it is being shown to the user before they select it as the actual |
| 439 | * wallpaper. |
| 440 | */ |
| 441 | public boolean isPreview() { |
| 442 | return mIWallpaperEngine.mIsPreview; |
| 443 | } |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 444 | |
| 445 | /** |
| 446 | * Returns true if this engine is running in ambient mode -- that is, |
Lucas Dupin | 8f09a50 | 2018-07-27 16:47:45 +0800 | [diff] [blame] | 447 | * it is being shown in low power mode, on always on display. |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 448 | * @hide |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 449 | */ |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 450 | @SystemApi |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 451 | public boolean isInAmbientMode() { |
| 452 | return mIsInAmbientMode; |
| 453 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 454 | |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 455 | /** |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 456 | * Control whether this wallpaper will receive raw touch events |
| 457 | * from the window manager as the user interacts with the window |
| 458 | * that is currently displaying the wallpaper. By default they |
| 459 | * are turned off. If enabled, the events will be received in |
| 460 | * {@link #onTouchEvent(MotionEvent)}. |
| 461 | */ |
| 462 | public void setTouchEventsEnabled(boolean enabled) { |
| 463 | mWindowFlags = enabled |
| 464 | ? (mWindowFlags&~WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE) |
| 465 | : (mWindowFlags|WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); |
| 466 | if (mCreated) { |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 467 | updateSurface(false, false, false); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 468 | } |
| 469 | } |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * Control whether this wallpaper will receive notifications when the wallpaper |
| 473 | * has been scrolled. By default, wallpapers will receive notifications, although |
| 474 | * the default static image wallpapers do not. It is a performance optimization to |
| 475 | * set this to false. |
| 476 | * |
| 477 | * @param enabled whether the wallpaper wants to receive offset notifications |
| 478 | */ |
| 479 | public void setOffsetNotificationsEnabled(boolean enabled) { |
| 480 | mWindowPrivateFlags = enabled |
| 481 | ? (mWindowPrivateFlags | |
| 482 | WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS) |
| 483 | : (mWindowPrivateFlags & |
| 484 | ~WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS); |
| 485 | if (mCreated) { |
| 486 | updateSurface(false, false, false); |
| 487 | } |
| 488 | } |
Jeff Sharkey | 35be756 | 2012-04-18 19:16:15 -0700 | [diff] [blame] | 489 | |
| 490 | /** {@hide} */ |
Mathew Inwood | e380737 | 2018-08-10 09:51:03 +0100 | [diff] [blame] | 491 | @UnsupportedAppUsage |
Jeff Sharkey | 35be756 | 2012-04-18 19:16:15 -0700 | [diff] [blame] | 492 | public void setFixedSizeAllowed(boolean allowed) { |
| 493 | mFixedSizeAllowed = allowed; |
| 494 | } |
| 495 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 496 | /** |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 497 | * Called once to initialize the engine. After returning, the |
| 498 | * engine's surface will be created by the framework. |
| 499 | */ |
| 500 | public void onCreate(SurfaceHolder surfaceHolder) { |
| 501 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 502 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 503 | /** |
| 504 | * Called right before the engine is going away. After this the |
| 505 | * surface will be destroyed and this Engine object is no longer |
| 506 | * valid. |
| 507 | */ |
| 508 | public void onDestroy() { |
| 509 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 510 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 511 | /** |
| 512 | * Called to inform you of the wallpaper becoming visible or |
| 513 | * hidden. <em>It is very important that a wallpaper only use |
| 514 | * CPU while it is visible.</em>. |
| 515 | */ |
| 516 | public void onVisibilityChanged(boolean visible) { |
| 517 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 518 | |
| 519 | /** |
| 520 | * Called with the current insets that are in effect for the wallpaper. |
| 521 | * This gives you the part of the overall wallpaper surface that will |
| 522 | * generally be visible to the user (ignoring position offsets applied to it). |
| 523 | * |
| 524 | * @param insets Insets to apply. |
| 525 | */ |
| 526 | public void onApplyWindowInsets(WindowInsets insets) { |
| 527 | } |
| 528 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 529 | /** |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 530 | * Called as the user performs touch-screen interaction with the |
| 531 | * window that is currently showing this wallpaper. Note that the |
| 532 | * events you receive here are driven by the actual application the |
Marco Nelissen | ae87bd0 | 2009-09-17 09:44:43 -0700 | [diff] [blame] | 533 | * user is interacting with, so if it is slow you will get fewer |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 534 | * move events. |
| 535 | */ |
| 536 | public void onTouchEvent(MotionEvent event) { |
| 537 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 538 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 539 | /** |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 540 | * Called to inform you of the wallpaper's offsets changing |
| 541 | * within its contain, corresponding to the container's |
| 542 | * call to {@link WallpaperManager#setWallpaperOffsets(IBinder, float, float) |
| 543 | * WallpaperManager.setWallpaperOffsets()}. |
| 544 | */ |
| 545 | public void onOffsetsChanged(float xOffset, float yOffset, |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 546 | float xOffsetStep, float yOffsetStep, |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 547 | int xPixelOffset, int yPixelOffset) { |
| 548 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 549 | |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 550 | /** |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 551 | * Process a command that was sent to the wallpaper with |
Dianne Hackborn | 13bf8260 | 2009-11-05 21:45:51 -0800 | [diff] [blame] | 552 | * {@link WallpaperManager#sendWallpaperCommand}. |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 553 | * The default implementation does nothing, and always returns null |
| 554 | * as the result. |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 555 | * |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 556 | * @param action The name of the command to perform. This tells you |
| 557 | * what to do and how to interpret the rest of the arguments. |
| 558 | * @param x Generic integer parameter. |
| 559 | * @param y Generic integer parameter. |
| 560 | * @param z Generic integer parameter. |
| 561 | * @param extras Any additional parameters. |
| 562 | * @param resultRequested If true, the caller is requesting that |
| 563 | * a result, appropriate for the command, be returned back. |
| 564 | * @return If returning a result, create a Bundle and place the |
| 565 | * result data in to it. Otherwise return null. |
| 566 | */ |
| 567 | public Bundle onCommand(String action, int x, int y, int z, |
| 568 | Bundle extras, boolean resultRequested) { |
| 569 | return null; |
| 570 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 571 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 572 | /** |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 573 | * Called when the device enters or exits ambient mode. |
| 574 | * |
| 575 | * @param inAmbientMode {@code true} if in ambient mode. |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 576 | * @param animationDuration How long the transition animation to change the ambient state |
| 577 | * should run, in milliseconds. If 0 is passed as the argument |
| 578 | * here, the state should be switched immediately. |
Lucas Dupin | 8f09a50 | 2018-07-27 16:47:45 +0800 | [diff] [blame] | 579 | * |
| 580 | * @see #isInAmbientMode() |
| 581 | * @see WallpaperInfo#supportsAmbientMode() |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 582 | * @hide |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 583 | */ |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 584 | @SystemApi |
| 585 | public void onAmbientModeChanged(boolean inAmbientMode, long animationDuration) { |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /** |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 589 | * Called when an application has changed the desired virtual size of |
| 590 | * the wallpaper. |
| 591 | */ |
| 592 | public void onDesiredSizeChanged(int desiredWidth, int desiredHeight) { |
| 593 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 594 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 595 | /** |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 596 | * Convenience for {@link SurfaceHolder.Callback#surfaceChanged |
| 597 | * SurfaceHolder.Callback.surfaceChanged()}. |
| 598 | */ |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 599 | public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| 600 | } |
| 601 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 602 | /** |
Dianne Hackborn | 1d28f9c | 2010-07-13 20:38:06 -0700 | [diff] [blame] | 603 | * Convenience for {@link SurfaceHolder.Callback2#surfaceRedrawNeeded |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 604 | * SurfaceHolder.Callback.surfaceRedrawNeeded()}. |
| 605 | */ |
| 606 | public void onSurfaceRedrawNeeded(SurfaceHolder holder) { |
| 607 | } |
| 608 | |
| 609 | /** |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 610 | * Convenience for {@link SurfaceHolder.Callback#surfaceCreated |
| 611 | * SurfaceHolder.Callback.surfaceCreated()}. |
| 612 | */ |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 613 | public void onSurfaceCreated(SurfaceHolder holder) { |
| 614 | } |
| 615 | |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 616 | /** |
| 617 | * Convenience for {@link SurfaceHolder.Callback#surfaceDestroyed |
| 618 | * SurfaceHolder.Callback.surfaceDestroyed()}. |
| 619 | */ |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 620 | public void onSurfaceDestroyed(SurfaceHolder holder) { |
| 621 | } |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 622 | |
| 623 | /** |
| 624 | * Notifies the engine that wallpaper colors changed significantly. |
Lucas Dupin | 98eabbd | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 625 | * This will trigger a {@link #onComputeColors()} call. |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 626 | */ |
Lucas Dupin | 98eabbd | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 627 | public void notifyColorsChanged() { |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 628 | final long now = mClockFunction.get(); |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 629 | if (now - mLastColorInvalidation < NOTIFY_COLORS_RATE_LIMIT_MS) { |
| 630 | Log.w(TAG, "This call has been deferred. You should only call " |
| 631 | + "notifyColorsChanged() once every " |
| 632 | + (NOTIFY_COLORS_RATE_LIMIT_MS / 1000f) + " seconds."); |
Lucas Dupin | 416fe95 | 2017-08-14 10:58:40 -0700 | [diff] [blame] | 633 | if (!mHandler.hasCallbacks(mNotifyColorsChanged)) { |
| 634 | mHandler.postDelayed(mNotifyColorsChanged, NOTIFY_COLORS_RATE_LIMIT_MS); |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 635 | } |
| 636 | return; |
| 637 | } |
| 638 | mLastColorInvalidation = now; |
Lucas Dupin | 416fe95 | 2017-08-14 10:58:40 -0700 | [diff] [blame] | 639 | mHandler.removeCallbacks(mNotifyColorsChanged); |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 640 | |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 641 | try { |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 642 | final WallpaperColors newColors = onComputeColors(); |
| 643 | if (mConnection != null) { |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 644 | mConnection.onWallpaperColorsChanged(newColors, mDisplay.getDisplayId()); |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 645 | } else { |
| 646 | Log.w(TAG, "Can't notify system because wallpaper connection " |
| 647 | + "was not established."); |
| 648 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 649 | } catch (RemoteException e) { |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 650 | Log.w(TAG, "Can't notify system because wallpaper connection was lost.", e); |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 651 | } |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /** |
Lucas Dupin | 98eabbd | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 655 | * Called by the system when it needs to know what colors the wallpaper is using. |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 656 | * You might return null if no color information is available at the moment. |
| 657 | * In that case you might want to call {@link #notifyColorsChanged()} when |
| 658 | * color information becomes available. |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 659 | * <p> |
Lucas Dupin | 98eabbd | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 660 | * The simplest way of creating a {@link android.app.WallpaperColors} object is by using |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 661 | * {@link android.app.WallpaperColors#fromBitmap(Bitmap)} or |
| 662 | * {@link android.app.WallpaperColors#fromDrawable(Drawable)}, but you can also specify |
Lucas Dupin | 98eabbd | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 663 | * your main colors by constructing a {@link android.app.WallpaperColors} object manually. |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 664 | * |
Lucas Dupin | 84b89d9 | 2017-05-09 12:16:19 -0700 | [diff] [blame] | 665 | * @return Wallpaper colors. |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 666 | */ |
Lucas Dupin | 98eabbd | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 667 | public @Nullable WallpaperColors onComputeColors() { |
Lucas Dupin | c40608c | 2017-04-14 18:33:08 -0700 | [diff] [blame] | 668 | return null; |
| 669 | } |
Lucas Dupin | ea1fb1e | 2017-04-05 17:39:44 -0700 | [diff] [blame] | 670 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 671 | /** |
| 672 | * Sets internal engine state. Only for testing. |
| 673 | * @param created {@code true} or {@code false}. |
| 674 | * @hide |
| 675 | */ |
| 676 | @VisibleForTesting |
| 677 | public void setCreated(boolean created) { |
| 678 | mCreated = created; |
| 679 | } |
| 680 | |
Dianne Hackborn | 527de8e | 2011-08-22 16:10:36 -0700 | [diff] [blame] | 681 | protected void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) { |
| 682 | out.print(prefix); out.print("mInitializing="); out.print(mInitializing); |
| 683 | out.print(" mDestroyed="); out.println(mDestroyed); |
| 684 | out.print(prefix); out.print("mVisible="); out.print(mVisible); |
Dianne Hackborn | 527de8e | 2011-08-22 16:10:36 -0700 | [diff] [blame] | 685 | out.print(" mReportedVisible="); out.println(mReportedVisible); |
Jeff Brown | 3d110b2 | 2014-11-21 19:01:13 -0800 | [diff] [blame] | 686 | out.print(prefix); out.print("mDisplay="); out.println(mDisplay); |
Dianne Hackborn | 527de8e | 2011-08-22 16:10:36 -0700 | [diff] [blame] | 687 | out.print(prefix); out.print("mCreated="); out.print(mCreated); |
| 688 | out.print(" mSurfaceCreated="); out.print(mSurfaceCreated); |
| 689 | out.print(" mIsCreating="); out.print(mIsCreating); |
| 690 | out.print(" mDrawingAllowed="); out.println(mDrawingAllowed); |
| 691 | out.print(prefix); out.print("mWidth="); out.print(mWidth); |
| 692 | out.print(" mCurWidth="); out.print(mCurWidth); |
| 693 | out.print(" mHeight="); out.print(mHeight); |
| 694 | out.print(" mCurHeight="); out.println(mCurHeight); |
| 695 | out.print(prefix); out.print("mType="); out.print(mType); |
| 696 | out.print(" mWindowFlags="); out.print(mWindowFlags); |
| 697 | out.print(" mCurWindowFlags="); out.println(mCurWindowFlags); |
Dianne Hackborn | d052a94 | 2014-11-21 15:23:13 -0800 | [diff] [blame] | 698 | out.print(prefix); out.print("mWindowPrivateFlags="); out.print(mWindowPrivateFlags); |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 699 | out.print(" mCurWindowPrivateFlags="); out.println(mCurWindowPrivateFlags); |
Dianne Hackborn | 527de8e | 2011-08-22 16:10:36 -0700 | [diff] [blame] | 700 | out.print(prefix); out.print("mVisibleInsets="); |
| 701 | out.print(mVisibleInsets.toShortString()); |
| 702 | out.print(" mWinFrame="); out.print(mWinFrame.toShortString()); |
| 703 | out.print(" mContentInsets="); out.println(mContentInsets.toShortString()); |
Andrii Kulian | 4460796 | 2017-03-16 11:06:24 -0700 | [diff] [blame] | 704 | out.print(prefix); out.print("mConfiguration="); |
| 705 | out.println(mMergedConfiguration.getMergedConfiguration()); |
Dianne Hackborn | 527de8e | 2011-08-22 16:10:36 -0700 | [diff] [blame] | 706 | out.print(prefix); out.print("mLayout="); out.println(mLayout); |
| 707 | synchronized (mLock) { |
| 708 | out.print(prefix); out.print("mPendingXOffset="); out.print(mPendingXOffset); |
| 709 | out.print(" mPendingXOffset="); out.println(mPendingXOffset); |
| 710 | out.print(prefix); out.print("mPendingXOffsetStep="); |
| 711 | out.print(mPendingXOffsetStep); |
| 712 | out.print(" mPendingXOffsetStep="); out.println(mPendingXOffsetStep); |
| 713 | out.print(prefix); out.print("mOffsetMessageEnqueued="); |
| 714 | out.print(mOffsetMessageEnqueued); |
| 715 | out.print(" mPendingSync="); out.println(mPendingSync); |
| 716 | if (mPendingMove != null) { |
| 717 | out.print(prefix); out.print("mPendingMove="); out.println(mPendingMove); |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 722 | private void dispatchPointer(MotionEvent event) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 723 | if (event.isTouchEvent()) { |
| 724 | synchronized (mLock) { |
| 725 | if (event.getAction() == MotionEvent.ACTION_MOVE) { |
| 726 | mPendingMove = event; |
| 727 | } else { |
| 728 | mPendingMove = null; |
| 729 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 730 | } |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 731 | Message msg = mCaller.obtainMessageO(MSG_TOUCH_EVENT, event); |
| 732 | mCaller.sendMessage(msg); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 733 | } else { |
| 734 | event.recycle(); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 737 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 738 | void updateSurface(boolean forceRelayout, boolean forceReport, boolean redrawNeeded) { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 739 | if (mDestroyed) { |
| 740 | Log.w(TAG, "Ignoring updateSurface: destroyed"); |
| 741 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 742 | |
| 743 | boolean fixedSize = false; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 744 | int myWidth = mSurfaceHolder.getRequestedWidth(); |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 745 | if (myWidth <= 0) myWidth = ViewGroup.LayoutParams.MATCH_PARENT; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 746 | else fixedSize = true; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 747 | int myHeight = mSurfaceHolder.getRequestedHeight(); |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 748 | if (myHeight <= 0) myHeight = ViewGroup.LayoutParams.MATCH_PARENT; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 749 | else fixedSize = true; |
| 750 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 751 | final boolean creating = !mCreated; |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 752 | final boolean surfaceCreating = !mSurfaceCreated; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 753 | final boolean formatChanged = mFormat != mSurfaceHolder.getRequestedFormat(); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 754 | boolean sizeChanged = mWidth != myWidth || mHeight != myHeight; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 755 | boolean insetsChanged = !mCreated; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 756 | final boolean typeChanged = mType != mSurfaceHolder.getRequestedType(); |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 757 | final boolean flagsChanged = mCurWindowFlags != mWindowFlags || |
| 758 | mCurWindowPrivateFlags != mWindowPrivateFlags; |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 759 | if (forceRelayout || creating || surfaceCreating || formatChanged || sizeChanged |
Dianne Hackborn | bce0cbb | 2012-10-05 11:06:53 -0700 | [diff] [blame] | 760 | || typeChanged || flagsChanged || redrawNeeded |
| 761 | || !mIWallpaperEngine.mShownReported) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 762 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 763 | if (DEBUG) Log.v(TAG, "Changes: creating=" + creating |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 764 | + " format=" + formatChanged + " size=" + sizeChanged); |
| 765 | |
| 766 | try { |
| 767 | mWidth = myWidth; |
| 768 | mHeight = myHeight; |
| 769 | mFormat = mSurfaceHolder.getRequestedFormat(); |
| 770 | mType = mSurfaceHolder.getRequestedType(); |
| 771 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 772 | mLayout.x = 0; |
| 773 | mLayout.y = 0; |
Valentin Iftime | 6239e53 | 2018-08-24 17:17:26 +0200 | [diff] [blame] | 774 | |
| 775 | if (!fixedSize) { |
| 776 | mLayout.width = myWidth; |
| 777 | mLayout.height = myHeight; |
| 778 | } else { |
| 779 | // Force the wallpaper to cover the screen in both dimensions |
| 780 | // only internal implementations like ImageWallpaper |
| 781 | DisplayInfo displayInfo = new DisplayInfo(); |
| 782 | mDisplay.getDisplayInfo(displayInfo); |
wilsonshih | 3b2683a | 2019-01-19 17:01:19 +0800 | [diff] [blame] | 783 | final float layoutScale = Math.max( |
| 784 | (float) displayInfo.logicalHeight / (float) myHeight, |
| 785 | (float) displayInfo.logicalWidth / (float) myWidth); |
| 786 | mLayout.height = (int) (myHeight * layoutScale); |
| 787 | mLayout.width = (int) (myWidth * layoutScale); |
Lucas Dupin | 6155aa4 | 2018-09-05 11:15:52 -0700 | [diff] [blame] | 788 | mWindowFlags |= WindowManager.LayoutParams.FLAG_SCALED; |
Valentin Iftime | 6239e53 | 2018-08-24 17:17:26 +0200 | [diff] [blame] | 789 | } |
| 790 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 791 | mLayout.format = mFormat; |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 792 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 793 | mCurWindowFlags = mWindowFlags; |
| 794 | mLayout.flags = mWindowFlags |
| 795 | | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 796 | | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 797 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
Lucas Dupin | 6155aa4 | 2018-09-05 11:15:52 -0700 | [diff] [blame] | 798 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; |
Chet Haase | a8e5a2b | 2011-10-28 13:18:16 -0700 | [diff] [blame] | 799 | mCurWindowPrivateFlags = mWindowPrivateFlags; |
| 800 | mLayout.privateFlags = mWindowPrivateFlags; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 801 | |
| 802 | mLayout.memoryType = mType; |
| 803 | mLayout.token = mWindowToken; |
| 804 | |
| 805 | if (!mCreated) { |
Filip Gruszczynski | d66ba06 | 2015-03-23 12:59:02 -0700 | [diff] [blame] | 806 | // Retrieve watch round info |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 807 | TypedArray windowStyle = obtainStyledAttributes( |
| 808 | com.android.internal.R.styleable.Window); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 809 | windowStyle.recycle(); |
| 810 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 811 | // Add window |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 812 | mLayout.type = mIWallpaperEngine.mWindowType; |
Fabrice Di Meglio | aac0d4e | 2012-07-19 19:21:26 -0700 | [diff] [blame] | 813 | mLayout.gravity = Gravity.START|Gravity.TOP; |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 814 | mLayout.setTitle(WallpaperService.this.getClass().getName()); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 815 | mLayout.windowAnimations = |
| 816 | com.android.internal.R.style.Animation_Wallpaper; |
Arthur Hung | 12a06ce | 2019-07-22 15:35:17 +0800 | [diff] [blame] | 817 | InputChannel inputChannel = new InputChannel(); |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 818 | |
Craig Mautner | 6881a10 | 2012-07-27 13:04:51 -0700 | [diff] [blame] | 819 | if (mSession.addToDisplay(mWindow, mWindow.mSeq, mLayout, View.VISIBLE, |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 820 | mDisplay.getDisplayId(), mWinFrame, mContentInsets, mStableInsets, |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame^] | 821 | mDisplayCutout, inputChannel, |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 822 | mInsetsState) < 0) { |
Mattias Petersson | d9463f5 | 2011-01-12 15:38:55 +0100 | [diff] [blame] | 823 | Log.w(TAG, "Failed to add window while updating wallpaper surface."); |
| 824 | return; |
| 825 | } |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 826 | mCreated = true; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 827 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 828 | mInputEventReceiver = new WallpaperInputEventReceiver( |
Arthur Hung | 12a06ce | 2019-07-22 15:35:17 +0800 | [diff] [blame] | 829 | inputChannel, Looper.myLooper()); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 830 | } |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 831 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 832 | mSurfaceHolder.mSurfaceLock.lock(); |
| 833 | mDrawingAllowed = true; |
| 834 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 835 | if (!fixedSize) { |
| 836 | mLayout.surfaceInsets.set(mIWallpaperEngine.mDisplayPadding); |
| 837 | } else { |
| 838 | mLayout.surfaceInsets.set(0, 0, 0, 0); |
| 839 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 840 | final int relayoutResult = mSession.relayout( |
Dianne Hackborn | 9a230e0 | 2011-10-06 11:51:27 -0700 | [diff] [blame] | 841 | mWindow, mWindow.mSeq, mLayout, mWidth, mHeight, |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame^] | 842 | View.VISIBLE, 0, -1, mWinFrame, mContentInsets, |
| 843 | mVisibleInsets, mStableInsets, mBackdropFrame, |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 844 | mDisplayCutout, mMergedConfiguration, mSurfaceControl, |
Jorim Jaggi | f96c90a | 2018-09-26 16:55:15 +0200 | [diff] [blame] | 845 | mInsetsState); |
Robert Carr | 5fea55b | 2018-12-10 13:05:52 -0800 | [diff] [blame] | 846 | if (mSurfaceControl.isValid()) { |
| 847 | mSurfaceHolder.mSurface.copyFrom(mSurfaceControl); |
| 848 | mSurfaceControl.release(); |
| 849 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 850 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 851 | if (DEBUG) Log.v(TAG, "New surface: " + mSurfaceHolder.mSurface |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 852 | + ", frame=" + mWinFrame); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 853 | |
Adrian Roos | 2ae3805 | 2014-12-09 17:03:01 +0000 | [diff] [blame] | 854 | int w = mWinFrame.width(); |
| 855 | int h = mWinFrame.height(); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 856 | |
| 857 | if (!fixedSize) { |
| 858 | final Rect padding = mIWallpaperEngine.mDisplayPadding; |
Jorim Jaggi | f081f06 | 2019-10-24 16:24:54 +0200 | [diff] [blame^] | 859 | w += padding.left + padding.right; |
| 860 | h += padding.top + padding.bottom; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 861 | mContentInsets.left += padding.left; |
| 862 | mContentInsets.top += padding.top; |
| 863 | mContentInsets.right += padding.right; |
| 864 | mContentInsets.bottom += padding.bottom; |
| 865 | mStableInsets.left += padding.left; |
| 866 | mStableInsets.top += padding.top; |
| 867 | mStableInsets.right += padding.right; |
| 868 | mStableInsets.bottom += padding.bottom; |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 869 | mDisplayCutout.set(mDisplayCutout.get().inset(-padding.left, -padding.top, |
| 870 | -padding.right, -padding.bottom)); |
Valentin Iftime | 6239e53 | 2018-08-24 17:17:26 +0200 | [diff] [blame] | 871 | } else { |
| 872 | w = myWidth; |
| 873 | h = myHeight; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 876 | if (mCurWidth != w) { |
| 877 | sizeChanged = true; |
| 878 | mCurWidth = w; |
| 879 | } |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 880 | if (mCurHeight != h) { |
| 881 | sizeChanged = true; |
| 882 | mCurHeight = h; |
| 883 | } |
Jeff Brown | 30bc34f | 2011-01-25 12:56:56 -0800 | [diff] [blame] | 884 | |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 885 | if (DEBUG) { |
| 886 | Log.v(TAG, "Wallpaper size has changed: (" + mCurWidth + ", " + mCurHeight); |
| 887 | } |
| 888 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 889 | insetsChanged |= !mDispatchedContentInsets.equals(mContentInsets); |
| 890 | insetsChanged |= !mDispatchedStableInsets.equals(mStableInsets); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 891 | insetsChanged |= !mDispatchedDisplayCutout.equals(mDisplayCutout.get()); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 892 | |
Jeff Brown | 30bc34f | 2011-01-25 12:56:56 -0800 | [diff] [blame] | 893 | mSurfaceHolder.setSurfaceFrameSize(w, h); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 894 | mSurfaceHolder.mSurfaceLock.unlock(); |
| 895 | |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 896 | if (!mSurfaceHolder.mSurface.isValid()) { |
| 897 | reportSurfaceDestroyed(); |
| 898 | if (DEBUG) Log.v(TAG, "Layout: Surface destroyed"); |
| 899 | return; |
| 900 | } |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 901 | |
| 902 | boolean didSurface = false; |
| 903 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 904 | try { |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 905 | mSurfaceHolder.ungetCallbacks(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 906 | |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 907 | if (surfaceCreating) { |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 908 | mIsCreating = true; |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 909 | didSurface = true; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 910 | if (DEBUG) Log.v(TAG, "onSurfaceCreated(" |
| 911 | + mSurfaceHolder + "): " + this); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 912 | onSurfaceCreated(mSurfaceHolder); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 913 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 914 | if (callbacks != null) { |
| 915 | for (SurfaceHolder.Callback c : callbacks) { |
| 916 | c.surfaceCreated(mSurfaceHolder); |
| 917 | } |
| 918 | } |
| 919 | } |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 920 | |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 921 | redrawNeeded |= creating || (relayoutResult |
| 922 | & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0; |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 923 | |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 924 | if (forceReport || creating || surfaceCreating |
| 925 | || formatChanged || sizeChanged) { |
Dianne Hackborn | cbf1504 | 2009-08-18 18:29:09 -0700 | [diff] [blame] | 926 | if (DEBUG) { |
| 927 | RuntimeException e = new RuntimeException(); |
| 928 | e.fillInStackTrace(); |
| 929 | Log.w(TAG, "forceReport=" + forceReport + " creating=" + creating |
| 930 | + " formatChanged=" + formatChanged |
| 931 | + " sizeChanged=" + sizeChanged, e); |
| 932 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 933 | if (DEBUG) Log.v(TAG, "onSurfaceChanged(" |
| 934 | + mSurfaceHolder + ", " + mFormat |
| 935 | + ", " + mCurWidth + ", " + mCurHeight |
| 936 | + "): " + this); |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 937 | didSurface = true; |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 938 | onSurfaceChanged(mSurfaceHolder, mFormat, |
| 939 | mCurWidth, mCurHeight); |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 940 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 941 | if (callbacks != null) { |
| 942 | for (SurfaceHolder.Callback c : callbacks) { |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 943 | c.surfaceChanged(mSurfaceHolder, mFormat, |
| 944 | mCurWidth, mCurHeight); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | } |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 948 | |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 949 | if (insetsChanged) { |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 950 | mDispatchedContentInsets.set(mContentInsets); |
| 951 | mDispatchedStableInsets.set(mStableInsets); |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 952 | mDispatchedDisplayCutout = mDisplayCutout.get(); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 953 | mFinalStableInsets.set(mDispatchedStableInsets); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 954 | WindowInsets insets = new WindowInsets(mFinalSystemInsets, |
Jorim Jaggi | 297985a | 2018-11-30 17:24:58 +0100 | [diff] [blame] | 955 | mFinalStableInsets, |
Adrian Roos | d4970af | 2017-11-10 15:48:01 +0100 | [diff] [blame] | 956 | getResources().getConfiguration().isScreenRound(), false, |
Adrian Roos | 5c6b622 | 2017-11-07 17:36:10 +0100 | [diff] [blame] | 957 | mDispatchedDisplayCutout); |
Filip Gruszczynski | 2217f61 | 2015-05-26 11:32:08 -0700 | [diff] [blame] | 958 | if (DEBUG) { |
| 959 | Log.v(TAG, "dispatching insets=" + insets); |
| 960 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 961 | onApplyWindowInsets(insets); |
| 962 | } |
| 963 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 964 | if (redrawNeeded) { |
| 965 | onSurfaceRedrawNeeded(mSurfaceHolder); |
| 966 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 967 | if (callbacks != null) { |
| 968 | for (SurfaceHolder.Callback c : callbacks) { |
| 969 | if (c instanceof SurfaceHolder.Callback2) { |
| 970 | ((SurfaceHolder.Callback2)c).surfaceRedrawNeeded( |
| 971 | mSurfaceHolder); |
| 972 | } |
| 973 | } |
| 974 | } |
| 975 | } |
| 976 | |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 977 | if (didSurface && !mReportedVisible) { |
| 978 | // This wallpaper is currently invisible, but its |
| 979 | // surface has changed. At this point let's tell it |
| 980 | // again that it is invisible in case the report about |
| 981 | // the surface caused it to start running. We really |
| 982 | // don't want wallpapers running when not visible. |
| 983 | if (mIsCreating) { |
| 984 | // Some wallpapers will ignore this call if they |
| 985 | // had previously been told they were invisble, |
| 986 | // so if we are creating a new surface then toggle |
| 987 | // the state to get them to notice. |
| 988 | if (DEBUG) Log.v(TAG, "onVisibilityChanged(true) at surface: " |
| 989 | + this); |
| 990 | onVisibilityChanged(true); |
| 991 | } |
| 992 | if (DEBUG) Log.v(TAG, "onVisibilityChanged(false) at surface: " |
| 993 | + this); |
| 994 | onVisibilityChanged(false); |
| 995 | } |
| 996 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 997 | } finally { |
| 998 | mIsCreating = false; |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 999 | mSurfaceCreated = true; |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 1000 | if (redrawNeeded) { |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1001 | mSession.finishDrawing(mWindow, null /* postDrawTransaction */); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1002 | } |
Dianne Hackborn | bce0cbb | 2012-10-05 11:06:53 -0700 | [diff] [blame] | 1003 | mIWallpaperEngine.reportShown(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1004 | } |
| 1005 | } catch (RemoteException ex) { |
| 1006 | } |
| 1007 | if (DEBUG) Log.v( |
| 1008 | TAG, "Layout: x=" + mLayout.x + " y=" + mLayout.y + |
| 1009 | " w=" + mLayout.width + " h=" + mLayout.height); |
| 1010 | } |
| 1011 | } |
Lucas Dupin | 65b4765 | 2017-07-19 17:32:26 -0700 | [diff] [blame] | 1012 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1013 | void attach(IWallpaperEngineWrapper wrapper) { |
Dianne Hackborn | cbf1504 | 2009-08-18 18:29:09 -0700 | [diff] [blame] | 1014 | if (DEBUG) Log.v(TAG, "attach: " + this + " wrapper=" + wrapper); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1015 | if (mDestroyed) { |
| 1016 | return; |
| 1017 | } |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1018 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1019 | mIWallpaperEngine = wrapper; |
| 1020 | mCaller = wrapper.mCaller; |
| 1021 | mConnection = wrapper.mConnection; |
| 1022 | mWindowToken = wrapper.mWindowToken; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1023 | mSurfaceHolder.setSizeFromLayout(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1024 | mInitializing = true; |
Jeff Brown | f9e989d | 2013-04-04 23:04:03 -0700 | [diff] [blame] | 1025 | mSession = WindowManagerGlobal.getWindowSession(); |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1026 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1027 | mWindow.setSession(mSession); |
Dianne Hackborn | 9fe6cb5 | 2011-09-09 13:02:43 -0700 | [diff] [blame] | 1028 | |
Filip Gruszczynski | 4544b92 | 2015-04-16 13:18:58 -0700 | [diff] [blame] | 1029 | mLayout.packageName = getPackageName(); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1030 | mIWallpaperEngine.mDisplayManager.registerDisplayListener(mDisplayListener, |
| 1031 | mCaller.getHandler()); |
| 1032 | mDisplay = mIWallpaperEngine.mDisplay; |
wilsonshih | 8ccb9ce | 2018-12-04 11:44:31 +0800 | [diff] [blame] | 1033 | mDisplayContext = createDisplayContext(mDisplay); |
Filip Gruszczynski | 4544b92 | 2015-04-16 13:18:58 -0700 | [diff] [blame] | 1034 | mDisplayState = mDisplay.getState(); |
Dianne Hackborn | 9fe6cb5 | 2011-09-09 13:02:43 -0700 | [diff] [blame] | 1035 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1036 | if (DEBUG) Log.v(TAG, "onCreate(): " + this); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1037 | onCreate(mSurfaceHolder); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1038 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1039 | mInitializing = false; |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1040 | |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 1041 | mReportedVisible = false; |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 1042 | updateSurface(false, false, false); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1043 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1044 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1045 | /** |
wilsonshih | 8ccb9ce | 2018-12-04 11:44:31 +0800 | [diff] [blame] | 1046 | * The {@link Context} with resources that match the current display the wallpaper is on. |
| 1047 | * For multiple display environment, multiple engines can be created to render on each |
| 1048 | * display, but these displays may have different densities. Use this context to get the |
| 1049 | * corresponding resources for currently display, avoiding the context of the service. |
wilsonshih | fd058f6 | 2019-02-13 15:57:06 +0800 | [diff] [blame] | 1050 | * <p> |
| 1051 | * The display context will never be {@code null} after |
| 1052 | * {@link Engine#onCreate(SurfaceHolder)} has been called. |
wilsonshih | 8ccb9ce | 2018-12-04 11:44:31 +0800 | [diff] [blame] | 1053 | * |
| 1054 | * @return A {@link Context} for current display. |
| 1055 | */ |
wilsonshih | fd058f6 | 2019-02-13 15:57:06 +0800 | [diff] [blame] | 1056 | @Nullable |
wilsonshih | 8ccb9ce | 2018-12-04 11:44:31 +0800 | [diff] [blame] | 1057 | public Context getDisplayContext() { |
| 1058 | return mDisplayContext; |
| 1059 | } |
| 1060 | |
| 1061 | /** |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1062 | * Executes life cycle event and updates internal ambient mode state based on |
| 1063 | * message sent from handler. |
| 1064 | * |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 1065 | * @param inAmbientMode {@code true} if in ambient mode. |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 1066 | * @param animationDuration For how long the transition will last, in ms. |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1067 | * @hide |
| 1068 | */ |
| 1069 | @VisibleForTesting |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 1070 | public void doAmbientModeChanged(boolean inAmbientMode, long animationDuration) { |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1071 | if (!mDestroyed) { |
| 1072 | if (DEBUG) { |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 1073 | Log.v(TAG, "onAmbientModeChanged(" + inAmbientMode + ", " |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 1074 | + animationDuration + "): " + this); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1075 | } |
| 1076 | mIsInAmbientMode = inAmbientMode; |
| 1077 | if (mCreated) { |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 1078 | onAmbientModeChanged(inAmbientMode, animationDuration); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1083 | void doDesiredSizeChanged(int desiredWidth, int desiredHeight) { |
| 1084 | if (!mDestroyed) { |
| 1085 | if (DEBUG) Log.v(TAG, "onDesiredSizeChanged(" |
| 1086 | + desiredWidth + "," + desiredHeight + "): " + this); |
Joe Onorato | dcfae5c | 2010-10-28 18:03:23 -0700 | [diff] [blame] | 1087 | mIWallpaperEngine.mReqWidth = desiredWidth; |
| 1088 | mIWallpaperEngine.mReqHeight = desiredHeight; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1089 | onDesiredSizeChanged(desiredWidth, desiredHeight); |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 1090 | doOffsetsChanged(true); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1091 | } |
| 1092 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1093 | |
| 1094 | void doDisplayPaddingChanged(Rect padding) { |
| 1095 | if (!mDestroyed) { |
| 1096 | if (DEBUG) Log.v(TAG, "onDisplayPaddingChanged(" + padding + "): " + this); |
| 1097 | if (!mIWallpaperEngine.mDisplayPadding.equals(padding)) { |
| 1098 | mIWallpaperEngine.mDisplayPadding.set(padding); |
| 1099 | updateSurface(true, false, false); |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1104 | void doVisibilityChanged(boolean visible) { |
Dianne Hackborn | af1f42b | 2009-11-20 16:27:27 -0800 | [diff] [blame] | 1105 | if (!mDestroyed) { |
| 1106 | mVisible = visible; |
| 1107 | reportVisibility(); |
| 1108 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 1109 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1110 | |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 1111 | void reportVisibility() { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1112 | if (!mDestroyed) { |
Filip Gruszczynski | 4544b92 | 2015-04-16 13:18:58 -0700 | [diff] [blame] | 1113 | mDisplayState = mDisplay == null ? Display.STATE_UNKNOWN : mDisplay.getState(); |
| 1114 | boolean visible = mVisible && mDisplayState != Display.STATE_OFF; |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 1115 | if (mReportedVisible != visible) { |
| 1116 | mReportedVisible = visible; |
| 1117 | if (DEBUG) Log.v(TAG, "onVisibilityChanged(" + visible |
| 1118 | + "): " + this); |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1119 | if (visible) { |
| 1120 | // If becoming visible, in preview mode the surface |
| 1121 | // may have been destroyed so now we need to make |
| 1122 | // sure it is re-created. |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 1123 | doOffsetsChanged(false); |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 1124 | updateSurface(false, false, false); |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1125 | } |
Dianne Hackborn | bcbcaa7 | 2009-09-10 10:54:46 -0700 | [diff] [blame] | 1126 | onVisibilityChanged(visible); |
| 1127 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1128 | } |
| 1129 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1130 | |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 1131 | void doOffsetsChanged(boolean always) { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1132 | if (mDestroyed) { |
| 1133 | return; |
| 1134 | } |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 1135 | |
| 1136 | if (!always && !mOffsetsChanged) { |
| 1137 | return; |
| 1138 | } |
| 1139 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1140 | float xOffset; |
| 1141 | float yOffset; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1142 | float xOffsetStep; |
| 1143 | float yOffsetStep; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1144 | boolean sync; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1145 | synchronized (mLock) { |
| 1146 | xOffset = mPendingXOffset; |
| 1147 | yOffset = mPendingYOffset; |
Marco Nelissen | bf6956b | 2009-11-09 15:21:13 -0800 | [diff] [blame] | 1148 | xOffsetStep = mPendingXOffsetStep; |
| 1149 | yOffsetStep = mPendingYOffsetStep; |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1150 | sync = mPendingSync; |
| 1151 | mPendingSync = false; |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1152 | mOffsetMessageEnqueued = false; |
| 1153 | } |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 1154 | |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1155 | if (mSurfaceCreated) { |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 1156 | if (mReportedVisible) { |
| 1157 | if (DEBUG) Log.v(TAG, "Offsets change in " + this |
| 1158 | + ": " + xOffset + "," + yOffset); |
| 1159 | final int availw = mIWallpaperEngine.mReqWidth-mCurWidth; |
| 1160 | final int xPixels = availw > 0 ? -(int)(availw*xOffset+.5f) : 0; |
| 1161 | final int availh = mIWallpaperEngine.mReqHeight-mCurHeight; |
| 1162 | final int yPixels = availh > 0 ? -(int)(availh*yOffset+.5f) : 0; |
| 1163 | onOffsetsChanged(xOffset, yOffset, xOffsetStep, yOffsetStep, xPixels, yPixels); |
| 1164 | } else { |
| 1165 | mOffsetsChanged = true; |
| 1166 | } |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1167 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1168 | |
Dianne Hackborn | 19382ac | 2009-09-11 21:13:37 -0700 | [diff] [blame] | 1169 | if (sync) { |
| 1170 | try { |
| 1171 | if (DEBUG) Log.v(TAG, "Reporting offsets change complete"); |
| 1172 | mSession.wallpaperOffsetsComplete(mWindow.asBinder()); |
| 1173 | } catch (RemoteException e) { |
| 1174 | } |
| 1175 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1176 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1177 | |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1178 | void doCommand(WallpaperCommand cmd) { |
| 1179 | Bundle result; |
| 1180 | if (!mDestroyed) { |
| 1181 | result = onCommand(cmd.action, cmd.x, cmd.y, cmd.z, |
| 1182 | cmd.extras, cmd.sync); |
| 1183 | } else { |
| 1184 | result = null; |
| 1185 | } |
| 1186 | if (cmd.sync) { |
| 1187 | try { |
| 1188 | if (DEBUG) Log.v(TAG, "Reporting command complete"); |
| 1189 | mSession.wallpaperCommandComplete(mWindow.asBinder(), result); |
| 1190 | } catch (RemoteException e) { |
| 1191 | } |
| 1192 | } |
| 1193 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1194 | |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1195 | void reportSurfaceDestroyed() { |
| 1196 | if (mSurfaceCreated) { |
| 1197 | mSurfaceCreated = false; |
Dianne Hackborn | dc8a7f6 | 2010-05-10 11:29:34 -0700 | [diff] [blame] | 1198 | mSurfaceHolder.ungetCallbacks(); |
| 1199 | SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks(); |
| 1200 | if (callbacks != null) { |
| 1201 | for (SurfaceHolder.Callback c : callbacks) { |
| 1202 | c.surfaceDestroyed(mSurfaceHolder); |
| 1203 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1204 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1205 | if (DEBUG) Log.v(TAG, "onSurfaceDestroyed(" |
| 1206 | + mSurfaceHolder + "): " + this); |
| 1207 | onSurfaceDestroyed(mSurfaceHolder); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1208 | } |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1209 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1210 | |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1211 | void detach() { |
| 1212 | if (mDestroyed) { |
| 1213 | return; |
| 1214 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1215 | |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1216 | mDestroyed = true; |
Jeff Brown | 3d110b2 | 2014-11-21 19:01:13 -0800 | [diff] [blame] | 1217 | |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1218 | if (mIWallpaperEngine.mDisplayManager != null) { |
| 1219 | mIWallpaperEngine.mDisplayManager.unregisterDisplayListener(mDisplayListener); |
Jeff Brown | 3d110b2 | 2014-11-21 19:01:13 -0800 | [diff] [blame] | 1220 | } |
| 1221 | |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1222 | if (mVisible) { |
| 1223 | mVisible = false; |
| 1224 | if (DEBUG) Log.v(TAG, "onVisibilityChanged(false): " + this); |
| 1225 | onVisibilityChanged(false); |
| 1226 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1227 | |
Dianne Hackborn | 18ee31e | 2010-04-27 15:54:02 -0700 | [diff] [blame] | 1228 | reportSurfaceDestroyed(); |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1229 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1230 | if (DEBUG) Log.v(TAG, "onDestroy(): " + this); |
| 1231 | onDestroy(); |
Jeff Brown | 3d110b2 | 2014-11-21 19:01:13 -0800 | [diff] [blame] | 1232 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1233 | if (mCreated) { |
| 1234 | try { |
Dianne Hackborn | ba3e31d | 2010-04-22 18:59:03 -0700 | [diff] [blame] | 1235 | if (DEBUG) Log.v(TAG, "Removing window and destroying surface " |
| 1236 | + mSurfaceHolder.getSurface() + " of: " + this); |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1237 | |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 1238 | if (mInputEventReceiver != null) { |
| 1239 | mInputEventReceiver.dispose(); |
| 1240 | mInputEventReceiver = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1241 | } |
Vishnu Nair | f7645aa | 2019-06-18 11:14:01 -0700 | [diff] [blame] | 1242 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1243 | mSession.remove(mWindow); |
| 1244 | } catch (RemoteException e) { |
| 1245 | } |
Dianne Hackborn | 0586a1b | 2009-09-06 21:08:27 -0700 | [diff] [blame] | 1246 | mSurfaceHolder.mSurface.release(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1247 | mCreated = false; |
| 1248 | } |
| 1249 | } |
Jeff Brown | 3d110b2 | 2014-11-21 19:01:13 -0800 | [diff] [blame] | 1250 | |
| 1251 | private final DisplayListener mDisplayListener = new DisplayListener() { |
| 1252 | @Override |
| 1253 | public void onDisplayChanged(int displayId) { |
| 1254 | if (mDisplay.getDisplayId() == displayId) { |
| 1255 | reportVisibility(); |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | @Override |
| 1260 | public void onDisplayRemoved(int displayId) { |
| 1261 | } |
| 1262 | |
| 1263 | @Override |
| 1264 | public void onDisplayAdded(int displayId) { |
| 1265 | } |
| 1266 | }; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1267 | } |
Jeff Brown | 3d110b2 | 2014-11-21 19:01:13 -0800 | [diff] [blame] | 1268 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1269 | class IWallpaperEngineWrapper extends IWallpaperEngine.Stub |
| 1270 | implements HandlerCaller.Callback { |
| 1271 | private final HandlerCaller mCaller; |
| 1272 | |
| 1273 | final IWallpaperConnection mConnection; |
| 1274 | final IBinder mWindowToken; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1275 | final int mWindowType; |
| 1276 | final boolean mIsPreview; |
Dianne Hackborn | bce0cbb | 2012-10-05 11:06:53 -0700 | [diff] [blame] | 1277 | boolean mShownReported; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1278 | int mReqWidth; |
| 1279 | int mReqHeight; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1280 | final Rect mDisplayPadding = new Rect(); |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1281 | final int mDisplayId; |
| 1282 | final DisplayManager mDisplayManager; |
| 1283 | final Display mDisplay; |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 1284 | private final AtomicBoolean mDetached = new AtomicBoolean(); |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1285 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1286 | Engine mEngine; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1287 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1288 | IWallpaperEngineWrapper(WallpaperService context, |
| 1289 | IWallpaperConnection conn, IBinder windowToken, |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1290 | int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding, |
| 1291 | int displayId) { |
Mita Yun | aa8dc2e | 2012-12-10 18:32:03 -0800 | [diff] [blame] | 1292 | mCaller = new HandlerCaller(context, context.getMainLooper(), this, true); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1293 | mConnection = conn; |
| 1294 | mWindowToken = windowToken; |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1295 | mWindowType = windowType; |
| 1296 | mIsPreview = isPreview; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1297 | mReqWidth = reqWidth; |
| 1298 | mReqHeight = reqHeight; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1299 | mDisplayPadding.set(padding); |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1300 | mDisplayId = displayId; |
wilsonshih | 81e10a7 | 2018-11-15 10:54:21 +0800 | [diff] [blame] | 1301 | |
| 1302 | // Create a display context before onCreateEngine. |
| 1303 | mDisplayManager = getSystemService(DisplayManager.class); |
| 1304 | mDisplay = mDisplayManager.getDisplay(mDisplayId); |
| 1305 | |
| 1306 | if (mDisplay == null) { |
| 1307 | // Ignore this engine. |
| 1308 | throw new IllegalArgumentException("Cannot find display with id" + mDisplayId); |
| 1309 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1310 | Message msg = mCaller.obtainMessage(DO_ATTACH); |
| 1311 | mCaller.sendMessage(msg); |
| 1312 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1313 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1314 | public void setDesiredSize(int width, int height) { |
| 1315 | Message msg = mCaller.obtainMessageII(DO_SET_DESIRED_SIZE, width, height); |
| 1316 | mCaller.sendMessage(msg); |
| 1317 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1318 | |
| 1319 | public void setDisplayPadding(Rect padding) { |
| 1320 | Message msg = mCaller.obtainMessageO(DO_SET_DISPLAY_PADDING, padding); |
| 1321 | mCaller.sendMessage(msg); |
| 1322 | } |
| 1323 | |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1324 | public void setVisibility(boolean visible) { |
| 1325 | Message msg = mCaller.obtainMessageI(MSG_VISIBILITY_CHANGED, |
| 1326 | visible ? 1 : 0); |
| 1327 | mCaller.sendMessage(msg); |
| 1328 | } |
| 1329 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1330 | @Override |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 1331 | public void setInAmbientMode(boolean inAmbientDisplay, long animationDuration) |
Lucas Dupin | 660d573 | 2017-12-19 10:05:19 -0800 | [diff] [blame] | 1332 | throws RemoteException { |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 1333 | Message msg = mCaller.obtainMessageIO(DO_IN_AMBIENT_MODE, inAmbientDisplay ? 1 : 0, |
| 1334 | animationDuration); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1335 | mCaller.sendMessage(msg); |
| 1336 | } |
| 1337 | |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 1338 | public void dispatchPointer(MotionEvent event) { |
| 1339 | if (mEngine != null) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1340 | mEngine.dispatchPointer(event); |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 1341 | } else { |
| 1342 | event.recycle(); |
Dianne Hackborn | 6adba24 | 2009-11-10 11:10:09 -0800 | [diff] [blame] | 1343 | } |
| 1344 | } |
Jeff Brown | 9f3bdfe | 2010-10-13 06:01:27 -0700 | [diff] [blame] | 1345 | |
| 1346 | public void dispatchWallpaperCommand(String action, int x, int y, |
| 1347 | int z, Bundle extras) { |
| 1348 | if (mEngine != null) { |
| 1349 | mEngine.mWindow.dispatchWallpaperCommand(action, x, y, z, extras, false); |
| 1350 | } |
| 1351 | } |
| 1352 | |
Dianne Hackborn | bce0cbb | 2012-10-05 11:06:53 -0700 | [diff] [blame] | 1353 | public void reportShown() { |
| 1354 | if (!mShownReported) { |
| 1355 | mShownReported = true; |
| 1356 | try { |
| 1357 | mConnection.engineShown(this); |
| 1358 | } catch (RemoteException e) { |
| 1359 | Log.w(TAG, "Wallpaper host disappeared", e); |
| 1360 | return; |
| 1361 | } |
| 1362 | } |
| 1363 | } |
| 1364 | |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 1365 | public void requestWallpaperColors() { |
| 1366 | Message msg = mCaller.obtainMessage(MSG_REQUEST_WALLPAPER_COLORS); |
| 1367 | mCaller.sendMessage(msg); |
| 1368 | } |
| 1369 | |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1370 | public void destroy() { |
| 1371 | Message msg = mCaller.obtainMessage(DO_DETACH); |
| 1372 | mCaller.sendMessage(msg); |
| 1373 | } |
| 1374 | |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 1375 | public void detach() { |
| 1376 | mDetached.set(true); |
| 1377 | } |
| 1378 | |
| 1379 | private void doDetachEngine() { |
| 1380 | mActiveEngines.remove(mEngine); |
| 1381 | mEngine.detach(); |
| 1382 | } |
| 1383 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1384 | @Override |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1385 | public void executeMessage(Message message) { |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 1386 | if (mDetached.get()) { |
| 1387 | if (mActiveEngines.contains(mEngine)) { |
| 1388 | doDetachEngine(); |
| 1389 | } |
| 1390 | return; |
| 1391 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1392 | switch (message.what) { |
| 1393 | case DO_ATTACH: { |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1394 | try { |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1395 | mConnection.attachEngine(this, mDisplayId); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1396 | } catch (RemoteException e) { |
| 1397 | Log.w(TAG, "Wallpaper host disappeared", e); |
| 1398 | return; |
| 1399 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1400 | Engine engine = onCreateEngine(); |
| 1401 | mEngine = engine; |
Dianne Hackborn | af1f42b | 2009-11-20 16:27:27 -0800 | [diff] [blame] | 1402 | mActiveEngines.add(engine); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1403 | engine.attach(this); |
| 1404 | return; |
| 1405 | } |
| 1406 | case DO_DETACH: { |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 1407 | doDetachEngine(); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1408 | return; |
| 1409 | } |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1410 | case DO_SET_DESIRED_SIZE: { |
| 1411 | mEngine.doDesiredSizeChanged(message.arg1, message.arg2); |
| 1412 | return; |
| 1413 | } |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1414 | case DO_SET_DISPLAY_PADDING: { |
| 1415 | mEngine.doDisplayPaddingChanged((Rect) message.obj); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1416 | return; |
| 1417 | } |
| 1418 | case DO_IN_AMBIENT_MODE: { |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 1419 | mEngine.doAmbientModeChanged(message.arg1 != 0, (Long) message.obj); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 1420 | return; |
Dianne Hackborn | 067e5f6 | 2014-09-07 23:14:30 -0700 | [diff] [blame] | 1421 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1422 | case MSG_UPDATE_SURFACE: |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 1423 | mEngine.updateSurface(true, false, false); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1424 | break; |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1425 | case MSG_VISIBILITY_CHANGED: |
| 1426 | if (DEBUG) Log.v(TAG, "Visibility change in " + mEngine |
| 1427 | + ": " + message.arg1); |
Dianne Hackborn | 284ac93 | 2009-08-28 10:34:25 -0700 | [diff] [blame] | 1428 | mEngine.doVisibilityChanged(message.arg1 != 0); |
Dianne Hackborn | 759a39e | 2009-08-09 17:20:27 -0700 | [diff] [blame] | 1429 | break; |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1430 | case MSG_WALLPAPER_OFFSETS: { |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 1431 | mEngine.doOffsetsChanged(true); |
Dianne Hackborn | 72c82ab | 2009-08-11 21:13:54 -0700 | [diff] [blame] | 1432 | } break; |
Dianne Hackborn | 7580493 | 2009-10-20 20:15:20 -0700 | [diff] [blame] | 1433 | case MSG_WALLPAPER_COMMAND: { |
| 1434 | WallpaperCommand cmd = (WallpaperCommand)message.obj; |
| 1435 | mEngine.doCommand(cmd); |
| 1436 | } break; |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1437 | case MSG_WINDOW_RESIZED: { |
| 1438 | final boolean reportDraw = message.arg1 != 0; |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 1439 | mEngine.updateSurface(true, false, reportDraw); |
Dianne Hackborn | 9e4e727 | 2011-08-30 14:06:51 -0700 | [diff] [blame] | 1440 | mEngine.doOffsetsChanged(true); |
Dianne Hackborn | 7341d7a | 2009-08-14 11:37:52 -0700 | [diff] [blame] | 1441 | } break; |
Craig Mautner | 5702d4d | 2012-06-30 14:10:16 -0700 | [diff] [blame] | 1442 | case MSG_WINDOW_MOVED: { |
| 1443 | // Do nothing. What does it mean for a Wallpaper to move? |
| 1444 | } break; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1445 | case MSG_TOUCH_EVENT: { |
Jeff Brown | 840db1f | 2010-10-21 17:36:54 -0700 | [diff] [blame] | 1446 | boolean skip = false; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1447 | MotionEvent ev = (MotionEvent)message.obj; |
Jeff Brown | 840db1f | 2010-10-21 17:36:54 -0700 | [diff] [blame] | 1448 | if (ev.getAction() == MotionEvent.ACTION_MOVE) { |
| 1449 | synchronized (mEngine.mLock) { |
| 1450 | if (mEngine.mPendingMove == ev) { |
| 1451 | mEngine.mPendingMove = null; |
| 1452 | } else { |
| 1453 | // this is not the motion event we are looking for.... |
| 1454 | skip = true; |
| 1455 | } |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1456 | } |
| 1457 | } |
Jeff Brown | 840db1f | 2010-10-21 17:36:54 -0700 | [diff] [blame] | 1458 | if (!skip) { |
| 1459 | if (DEBUG) Log.v(TAG, "Delivering touch event: " + ev); |
| 1460 | mEngine.onTouchEvent(ev); |
| 1461 | } |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1462 | ev.recycle(); |
| 1463 | } break; |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 1464 | case MSG_REQUEST_WALLPAPER_COLORS: { |
| 1465 | if (mConnection == null) { |
| 1466 | break; |
| 1467 | } |
| 1468 | try { |
wilsonshih | 36597d4 | 2018-12-05 18:56:39 +0800 | [diff] [blame] | 1469 | mConnection.onWallpaperColorsChanged(mEngine.onComputeColors(), mDisplayId); |
Lucas Dupin | 50ba991 | 2017-07-14 11:55:05 -0700 | [diff] [blame] | 1470 | } catch (RemoteException e) { |
| 1471 | // Connection went away, nothing to do in here. |
| 1472 | } |
| 1473 | } break; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1474 | default : |
| 1475 | Log.w(TAG, "Unknown message type " + message.what); |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | /** |
| 1481 | * Implements the internal {@link IWallpaperService} interface to convert |
| 1482 | * incoming calls to it back to calls on an {@link WallpaperService}. |
| 1483 | */ |
| 1484 | class IWallpaperServiceWrapper extends IWallpaperService.Stub { |
| 1485 | private final WallpaperService mTarget; |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 1486 | private IWallpaperEngineWrapper mEngineWrapper; |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1487 | |
| 1488 | public IWallpaperServiceWrapper(WallpaperService context) { |
| 1489 | mTarget = context; |
| 1490 | } |
| 1491 | |
Craig Mautner | b1ef369 | 2012-11-16 17:31:04 -0800 | [diff] [blame] | 1492 | @Override |
Dianne Hackborn | 3be63c0 | 2009-08-20 19:31:38 -0700 | [diff] [blame] | 1493 | public void attach(IWallpaperConnection conn, IBinder windowToken, |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1494 | int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding, |
| 1495 | int displayId) { |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 1496 | mEngineWrapper = new IWallpaperEngineWrapper(mTarget, conn, windowToken, |
wilsonshih | de93f49 | 2018-11-01 21:23:40 +0800 | [diff] [blame] | 1497 | windowType, isPreview, reqWidth, reqHeight, padding, displayId); |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1498 | } |
wilsonshih | b72ff9c | 2019-03-21 17:27:02 +0800 | [diff] [blame] | 1499 | |
| 1500 | @Override |
| 1501 | public void detach() { |
| 1502 | mEngineWrapper.detach(); |
| 1503 | } |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1504 | } |
Craig Mautner | b1ef369 | 2012-11-16 17:31:04 -0800 | [diff] [blame] | 1505 | |
Dianne Hackborn | af1f42b | 2009-11-20 16:27:27 -0800 | [diff] [blame] | 1506 | @Override |
| 1507 | public void onCreate() { |
| 1508 | super.onCreate(); |
| 1509 | } |
| 1510 | |
| 1511 | @Override |
| 1512 | public void onDestroy() { |
| 1513 | super.onDestroy(); |
| 1514 | for (int i=0; i<mActiveEngines.size(); i++) { |
| 1515 | mActiveEngines.get(i).detach(); |
| 1516 | } |
| 1517 | mActiveEngines.clear(); |
| 1518 | } |
| 1519 | |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1520 | /** |
| 1521 | * Implement to return the implementation of the internal accessibility |
| 1522 | * service interface. Subclasses should not override. |
| 1523 | */ |
| 1524 | @Override |
| 1525 | public final IBinder onBind(Intent intent) { |
| 1526 | return new IWallpaperServiceWrapper(this); |
| 1527 | } |
Craig Mautner | b1ef369 | 2012-11-16 17:31:04 -0800 | [diff] [blame] | 1528 | |
Dianne Hackborn | 23ef7b4 | 2009-11-18 18:20:39 -0800 | [diff] [blame] | 1529 | /** |
| 1530 | * Must be implemented to return a new instance of the wallpaper's engine. |
| 1531 | * Note that multiple instances may be active at the same time, such as |
| 1532 | * when the wallpaper is currently set as the active wallpaper and the user |
| 1533 | * is in the wallpaper picker viewing a preview of it as well. |
| 1534 | */ |
Dianne Hackborn | 4c62fc0 | 2009-08-08 20:40:27 -0700 | [diff] [blame] | 1535 | public abstract Engine onCreateEngine(); |
Dianne Hackborn | 527de8e | 2011-08-22 16:10:36 -0700 | [diff] [blame] | 1536 | |
| 1537 | @Override |
| 1538 | protected void dump(FileDescriptor fd, PrintWriter out, String[] args) { |
| 1539 | out.print("State of wallpaper "); out.print(this); out.println(":"); |
| 1540 | for (int i=0; i<mActiveEngines.size(); i++) { |
| 1541 | Engine engine = mActiveEngines.get(i); |
| 1542 | out.print(" Engine "); out.print(engine); out.println(":"); |
| 1543 | engine.dump(" ", fd, out, args); |
| 1544 | } |
| 1545 | } |
Dianne Hackborn | 8cc6a50 | 2009-08-05 21:29:42 -0700 | [diff] [blame] | 1546 | } |