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