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