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