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