blob: 5b8ababb8ca4968d45c823391be4d07bca993a37 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 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
17package android.os;
18
Jeff Brown803c2af2015-03-05 10:52:53 -080019import android.annotation.NonNull;
20import android.annotation.Nullable;
Brad Fitzpatrick1b298252010-11-23 17:16:47 -080021import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.util.Printer;
Makoto Onuki99571512017-03-28 14:12:34 -070023import android.util.Slog;
Netta P958d0a52017-02-07 11:20:55 -080024import android.util.proto.ProtoOutputStream;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26/**
27 * Class used to run a message loop for a thread. Threads by default do
28 * not have a message loop associated with them; to create one, call
29 * {@link #prepare} in the thread that is to run the loop, and then
30 * {@link #loop} to have it process messages until the loop is stopped.
Jeff Brown803c2af2015-03-05 10:52:53 -080031 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032 * <p>Most interaction with a message loop is through the
33 * {@link Handler} class.
Jeff Brown803c2af2015-03-05 10:52:53 -080034 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 * <p>This is a typical example of the implementation of a Looper thread,
36 * using the separation of {@link #prepare} and {@link #loop} to create an
37 * initial Handler to communicate with the Looper.
Brad Fitzpatrick1b298252010-11-23 17:16:47 -080038 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039 * <pre>
40 * class LooperThread extends Thread {
41 * public Handler mHandler;
Brad Fitzpatrick1b298252010-11-23 17:16:47 -080042 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 * public void run() {
44 * Looper.prepare();
Brad Fitzpatrick1b298252010-11-23 17:16:47 -080045 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046 * mHandler = new Handler() {
47 * public void handleMessage(Message msg) {
48 * // process incoming messages here
49 * }
50 * };
Brad Fitzpatrick1b298252010-11-23 17:16:47 -080051 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 * Looper.loop();
53 * }
54 * }</pre>
55 */
Jeff Brown67fc67c2013-04-01 13:00:33 -070056public final class Looper {
Jeff Brown6c7b41a2015-02-26 14:43:53 -080057 /*
58 * API Implementation Note:
59 *
60 * This class contains the code required to set up and manage an event loop
61 * based on MessageQueue. APIs that affect the state of the queue should be
62 * defined on MessageQueue or Handler rather than on Looper itself. For example,
63 * idle handlers and sync barriers are defined on the queue whereas preparing the
Jeff Brown803c2af2015-03-05 10:52:53 -080064 * thread, looping, and quitting are defined on the looper.
Jeff Brown6c7b41a2015-02-26 14:43:53 -080065 */
66
Brad Fitzpatrick1b298252010-11-23 17:16:47 -080067 private static final String TAG = "Looper";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068
69 // sThreadLocal.get() will return null unless you've called prepare().
Xavier Ducrohet7f9f99ea2011-08-11 10:16:17 -070070 static final ThreadLocal<Looper> sThreadLocal = new ThreadLocal<Looper>();
Jeff Brown0f85ce32012-02-16 14:41:10 -080071 private static Looper sMainLooper; // guarded by Looper.class
Marcin Oczeretkod8cc8592018-08-22 16:07:36 +010072 private static Observer sObserver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073
74 final MessageQueue mQueue;
Brad Fitzpatrick1b298252010-11-23 17:16:47 -080075 final Thread mThread;
Brad Fitzpatrick1b298252010-11-23 17:16:47 -080076
Jeff Brown0f85ce32012-02-16 14:41:10 -080077 private Printer mLogging;
Jeff Sharkey74cd3de2016-04-06 17:40:54 -060078 private long mTraceTag;
Brad Fitzpatrick1b298252010-11-23 17:16:47 -080079
Makoto Onuki712886f2018-04-27 15:22:50 -070080 /**
81 * If set, the looper will show a warning log if a message dispatch takes longer than this.
82 */
Makoto Onuki99571512017-03-28 14:12:34 -070083 private long mSlowDispatchThresholdMs;
84
Makoto Onuki712886f2018-04-27 15:22:50 -070085 /**
86 * If set, the looper will show a warning log if a message delivery (actual delivery time -
87 * post time) takes longer than this.
88 */
89 private long mSlowDeliveryThresholdMs;
90
91 /** Initialize the current thread as a looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 * This gives you a chance to create handlers that then reference
93 * this looper, before actually starting the loop. Be sure to call
94 * {@link #loop()} after calling this method, and end it by calling
95 * {@link #quit()}.
96 */
Romain Guyf9284692011-07-13 18:46:21 -070097 public static void prepare() {
Jeff Brown0f85ce32012-02-16 14:41:10 -080098 prepare(true);
99 }
100
101 private static void prepare(boolean quitAllowed) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 if (sThreadLocal.get() != null) {
103 throw new RuntimeException("Only one Looper may be created per thread");
104 }
Jeff Brown0f85ce32012-02-16 14:41:10 -0800105 sThreadLocal.set(new Looper(quitAllowed));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 }
Brad Fitzpatrick1b298252010-11-23 17:16:47 -0800107
108 /**
109 * Initialize the current thread as a looper, marking it as an
110 * application's main looper. The main looper for your application
111 * is created by the Android environment, so you should never need
112 * to call this function yourself. See also: {@link #prepare()}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 */
Romain Guyf9284692011-07-13 18:46:21 -0700114 public static void prepareMainLooper() {
Jeff Brown0f85ce32012-02-16 14:41:10 -0800115 prepare(false);
116 synchronized (Looper.class) {
117 if (sMainLooper != null) {
118 throw new IllegalStateException("The main Looper has already been prepared.");
119 }
120 sMainLooper = myLooper();
121 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 }
Brad Fitzpatrick1b298252010-11-23 17:16:47 -0800123
Jeff Brown803c2af2015-03-05 10:52:53 -0800124 /**
125 * Returns the application's main looper, which lives in the main thread of the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 */
Jeff Brown0f85ce32012-02-16 14:41:10 -0800127 public static Looper getMainLooper() {
128 synchronized (Looper.class) {
129 return sMainLooper;
130 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 }
132
133 /**
Marcin Oczeretkod8cc8592018-08-22 16:07:36 +0100134 * Set the transaction observer for all Loopers in this process.
135 *
136 * @hide
137 */
138 public static void setObserver(@Nullable Observer observer) {
139 sObserver = observer;
140 }
141
142 /**
Brad Fitzpatrick1b298252010-11-23 17:16:47 -0800143 * Run the message queue in this thread. Be sure to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 * {@link #quit()} to end the loop.
145 */
Romain Guyf9284692011-07-13 18:46:21 -0700146 public static void loop() {
Jeff Brown0f85ce32012-02-16 14:41:10 -0800147 final Looper me = myLooper();
Brad Fitzpatrick1b298252010-11-23 17:16:47 -0800148 if (me == null) {
149 throw new RuntimeException("No Looper; Looper.prepare() wasn't called on this thread.");
150 }
Jeff Brown0f85ce32012-02-16 14:41:10 -0800151 final MessageQueue queue = me.mQueue;
152
Dianne Hackborne5dea752011-02-09 14:19:23 -0800153 // Make sure the identity of this thread is that of the local process,
154 // and keep track of what that identity token actually is.
155 Binder.clearCallingIdentity();
156 final long ident = Binder.clearCallingIdentity();
Jeff Brown0f85ce32012-02-16 14:41:10 -0800157
Makoto Onuki712886f2018-04-27 15:22:50 -0700158 // Allow overriding a threshold with a system prop. e.g.
159 // adb shell 'setprop log.looper.1000.main.slow 1 && stop && start'
160 final int thresholdOverride =
161 SystemProperties.getInt("log.looper."
162 + Process.myUid() + "."
163 + Thread.currentThread().getName()
164 + ".slow", 0);
165
166 boolean slowDeliveryDetected = false;
167
Jeff Brown0f85ce32012-02-16 14:41:10 -0800168 for (;;) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 Message msg = queue.next(); // might block
Jeff Brown0f85ce32012-02-16 14:41:10 -0800170 if (msg == null) {
171 // No message indicates that the message queue is quitting.
172 return;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 }
Jeff Brown0f85ce32012-02-16 14:41:10 -0800174
Jeff Brown0f85ce32012-02-16 14:41:10 -0800175 // This must be in a local variable, in case a UI event sets the logger
Jeff Sharkey74cd3de2016-04-06 17:40:54 -0600176 final Printer logging = me.mLogging;
Jeff Brown0f85ce32012-02-16 14:41:10 -0800177 if (logging != null) {
178 logging.println(">>>>> Dispatching to " + msg.target + " " +
179 msg.callback + ": " + msg.what);
Jeff Brown0f85ce32012-02-16 14:41:10 -0800180 }
Marcin Oczeretkod8cc8592018-08-22 16:07:36 +0100181 // Make sure the observer won't change while processing a transaction.
182 final Observer observer = sObserver;
Jeff Brown0f85ce32012-02-16 14:41:10 -0800183
Jeff Sharkey74cd3de2016-04-06 17:40:54 -0600184 final long traceTag = me.mTraceTag;
Makoto Onuki712886f2018-04-27 15:22:50 -0700185 long slowDispatchThresholdMs = me.mSlowDispatchThresholdMs;
186 long slowDeliveryThresholdMs = me.mSlowDeliveryThresholdMs;
187 if (thresholdOverride > 0) {
188 slowDispatchThresholdMs = thresholdOverride;
189 slowDeliveryThresholdMs = thresholdOverride;
190 }
191 final boolean logSlowDelivery = (slowDeliveryThresholdMs > 0) && (msg.when > 0);
192 final boolean logSlowDispatch = (slowDispatchThresholdMs > 0);
193
194 final boolean needStartTime = logSlowDelivery || logSlowDispatch;
195 final boolean needEndTime = logSlowDispatch;
196
Jorim Jaggi407c0be2016-08-01 13:31:55 +0200197 if (traceTag != 0 && Trace.isTagEnabled(traceTag)) {
Jeff Sharkey74cd3de2016-04-06 17:40:54 -0600198 Trace.traceBegin(traceTag, msg.target.getTraceName(msg));
199 }
Makoto Onuki712886f2018-04-27 15:22:50 -0700200
201 final long dispatchStart = needStartTime ? SystemClock.uptimeMillis() : 0;
202 final long dispatchEnd;
Marcin Oczeretkod8cc8592018-08-22 16:07:36 +0100203 Object token = null;
204 if (observer != null) {
205 token = observer.messageDispatchStarting();
206 }
Jeff Sharkey74cd3de2016-04-06 17:40:54 -0600207 try {
Marcin Oczeretkoec758722018-09-12 12:53:47 +0100208 ThreadLocalWorkSourceUid.set(msg.workSourceUid);
Jeff Sharkey74cd3de2016-04-06 17:40:54 -0600209 msg.target.dispatchMessage(msg);
Marcin Oczeretkod8cc8592018-08-22 16:07:36 +0100210 if (observer != null) {
211 observer.messageDispatched(token, msg);
212 }
Makoto Onuki712886f2018-04-27 15:22:50 -0700213 dispatchEnd = needEndTime ? SystemClock.uptimeMillis() : 0;
Marcin Oczeretkod8cc8592018-08-22 16:07:36 +0100214 } catch (Exception exception) {
215 if (observer != null) {
216 observer.dispatchingThrewException(token, msg, exception);
217 }
218 throw exception;
Jeff Sharkey74cd3de2016-04-06 17:40:54 -0600219 } finally {
Marcin Oczeretkoec758722018-09-12 12:53:47 +0100220 ThreadLocalWorkSourceUid.clear();
Jeff Sharkey74cd3de2016-04-06 17:40:54 -0600221 if (traceTag != 0) {
222 Trace.traceEnd(traceTag);
223 }
224 }
Makoto Onuki712886f2018-04-27 15:22:50 -0700225 if (logSlowDelivery) {
226 if (slowDeliveryDetected) {
227 if ((dispatchStart - msg.when) <= 10) {
228 Slog.w(TAG, "Drained");
229 slowDeliveryDetected = false;
230 }
231 } else {
232 if (showSlowLog(slowDeliveryThresholdMs, msg.when, dispatchStart, "delivery",
233 msg)) {
234 // Once we write a slow delivery log, suppress until the queue drains.
235 slowDeliveryDetected = true;
236 }
Makoto Onuki99571512017-03-28 14:12:34 -0700237 }
238 }
Makoto Onuki712886f2018-04-27 15:22:50 -0700239 if (logSlowDispatch) {
240 showSlowLog(slowDispatchThresholdMs, dispatchStart, dispatchEnd, "dispatch", msg);
241 }
Jeff Brown0f85ce32012-02-16 14:41:10 -0800242
243 if (logging != null) {
Jeff Brown0f85ce32012-02-16 14:41:10 -0800244 logging.println("<<<<< Finished to " + msg.target + " " + msg.callback);
Jeff Brown0f85ce32012-02-16 14:41:10 -0800245 }
246
247 // Make sure that during the course of dispatching the
248 // identity of the thread wasn't corrupted.
249 final long newIdent = Binder.clearCallingIdentity();
250 if (ident != newIdent) {
251 Log.wtf(TAG, "Thread identity changed from 0x"
252 + Long.toHexString(ident) + " to 0x"
253 + Long.toHexString(newIdent) + " while dispatching to "
254 + msg.target.getClass().getName() + " "
255 + msg.callback + " what=" + msg.what);
256 }
257
Jeff Brown9867ed72014-02-28 14:00:57 -0800258 msg.recycleUnchecked();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 }
260 }
261
Makoto Onuki712886f2018-04-27 15:22:50 -0700262 private static boolean showSlowLog(long threshold, long measureStart, long measureEnd,
263 String what, Message msg) {
264 final long actualTime = measureEnd - measureStart;
265 if (actualTime < threshold) {
266 return false;
267 }
268 // For slow delivery, the current message isn't really important, but log it anyway.
269 Slog.w(TAG, "Slow " + what + " took " + actualTime + "ms "
270 + Thread.currentThread().getName() + " h="
271 + msg.target.getClass().getName() + " c=" + msg.callback + " m=" + msg.what);
272 return true;
273 }
274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 /**
276 * Return the Looper object associated with the current thread. Returns
277 * null if the calling thread is not associated with a Looper.
278 */
Jeff Brown803c2af2015-03-05 10:52:53 -0800279 public static @Nullable Looper myLooper() {
Brad Fitzpatrick1b298252010-11-23 17:16:47 -0800280 return sThreadLocal.get();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 }
282
283 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 * Return the {@link MessageQueue} object associated with the current
285 * thread. This must be called from a thread running a Looper, or a
286 * NullPointerException will be thrown.
287 */
Jeff Brown803c2af2015-03-05 10:52:53 -0800288 public static @NonNull MessageQueue myQueue() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 return myLooper().mQueue;
290 }
291
Jeff Brown0f85ce32012-02-16 14:41:10 -0800292 private Looper(boolean quitAllowed) {
293 mQueue = new MessageQueue(quitAllowed);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800294 mThread = Thread.currentThread();
295 }
296
Jeff Brown0f85ce32012-02-16 14:41:10 -0800297 /**
Jeff Brownf9e989d2013-04-04 23:04:03 -0700298 * Returns true if the current thread is this looper's thread.
Jeff Brownf9e989d2013-04-04 23:04:03 -0700299 */
300 public boolean isCurrentThread() {
301 return Thread.currentThread() == mThread;
302 }
303
304 /**
Jeff Brown803c2af2015-03-05 10:52:53 -0800305 * Control logging of messages as they are processed by this Looper. If
306 * enabled, a log message will be written to <var>printer</var>
307 * at the beginning and ending of each message dispatch, identifying the
308 * target Handler and message contents.
309 *
310 * @param printer A Printer object that will receive log messages, or
311 * null to disable message logging.
312 */
313 public void setMessageLogging(@Nullable Printer printer) {
314 mLogging = printer;
315 }
316
Jeff Sharkey74cd3de2016-04-06 17:40:54 -0600317 /** {@hide} */
318 public void setTraceTag(long traceTag) {
319 mTraceTag = traceTag;
320 }
321
Makoto Onuki712886f2018-04-27 15:22:50 -0700322 /**
323 * Set a thresholds for slow dispatch/delivery log.
324 * {@hide}
325 */
326 public void setSlowLogThresholdMs(long slowDispatchThresholdMs, long slowDeliveryThresholdMs) {
Makoto Onuki99571512017-03-28 14:12:34 -0700327 mSlowDispatchThresholdMs = slowDispatchThresholdMs;
Makoto Onuki712886f2018-04-27 15:22:50 -0700328 mSlowDeliveryThresholdMs = slowDeliveryThresholdMs;
Makoto Onuki99571512017-03-28 14:12:34 -0700329 }
330
Jeff Brown803c2af2015-03-05 10:52:53 -0800331 /**
Jeff Brown0f85ce32012-02-16 14:41:10 -0800332 * Quits the looper.
Jeff Brown024136f2013-04-11 19:21:32 -0700333 * <p>
Jeff Brown8b60e452013-04-18 15:17:48 -0700334 * Causes the {@link #loop} method to terminate without processing any
335 * more messages in the message queue.
Jeff Brown024136f2013-04-11 19:21:32 -0700336 * </p><p>
Jeff Brown8b60e452013-04-18 15:17:48 -0700337 * Any attempt to post messages to the queue after the looper is asked to quit will fail.
338 * For example, the {@link Handler#sendMessage(Message)} method will return false.
339 * </p><p class="note">
340 * Using this method may be unsafe because some messages may not be delivered
341 * before the looper terminates. Consider using {@link #quitSafely} instead to ensure
342 * that all pending work is completed in an orderly manner.
Jeff Brown024136f2013-04-11 19:21:32 -0700343 * </p>
Jeff Brown8b60e452013-04-18 15:17:48 -0700344 *
345 * @see #quitSafely
Jeff Brown0f85ce32012-02-16 14:41:10 -0800346 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 public void quit() {
Jeff Brown8b60e452013-04-18 15:17:48 -0700348 mQueue.quit(false);
349 }
350
351 /**
352 * Quits the looper safely.
353 * <p>
354 * Causes the {@link #loop} method to terminate as soon as all remaining messages
355 * in the message queue that are already due to be delivered have been handled.
356 * However pending delayed messages with due times in the future will not be
357 * delivered before the loop terminates.
358 * </p><p>
359 * Any attempt to post messages to the queue after the looper is asked to quit will fail.
360 * For example, the {@link Handler#sendMessage(Message)} method will return false.
361 * </p>
362 */
363 public void quitSafely() {
364 mQueue.quit(true);
Jeff Brown0f85ce32012-02-16 14:41:10 -0800365 }
366
367 /**
Jeff Brown803c2af2015-03-05 10:52:53 -0800368 * Gets the Thread associated with this Looper.
369 *
370 * @return The looper's thread.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 */
Jeff Brown803c2af2015-03-05 10:52:53 -0800372 public @NonNull Thread getThread() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 return mThread;
374 }
Brad Fitzpatrick1b298252010-11-23 17:16:47 -0800375
Jeff Brown803c2af2015-03-05 10:52:53 -0800376 /**
377 * Gets this looper's message queue.
378 *
379 * @return The looper's message queue.
380 */
381 public @NonNull MessageQueue getQueue() {
Jeff Browna41ca772010-08-11 14:46:32 -0700382 return mQueue;
383 }
Brad Fitzpatrick1b298252010-11-23 17:16:47 -0800384
Jeff Brown803c2af2015-03-05 10:52:53 -0800385 /**
386 * Dumps the state of the looper for debugging purposes.
387 *
388 * @param pw A printer to receive the contents of the dump.
389 * @param prefix A prefix to prepend to each line which is printed.
390 */
391 public void dump(@NonNull Printer pw, @NonNull String prefix) {
Jeff Brown5182c782013-10-15 20:31:52 -0700392 pw.println(prefix + toString());
Dianne Hackborncb015632017-06-14 17:30:15 -0700393 mQueue.dump(pw, prefix + " ", null);
394 }
395
396 /**
397 * Dumps the state of the looper for debugging purposes.
398 *
399 * @param pw A printer to receive the contents of the dump.
400 * @param prefix A prefix to prepend to each line which is printed.
401 * @param handler Only dump messages for this Handler.
402 * @hide
403 */
404 public void dump(@NonNull Printer pw, @NonNull String prefix, Handler handler) {
405 pw.println(prefix + toString());
406 mQueue.dump(pw, prefix + " ", handler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 }
408
Netta P958d0a52017-02-07 11:20:55 -0800409 /** @hide */
410 public void writeToProto(ProtoOutputStream proto, long fieldId) {
411 final long looperToken = proto.start(fieldId);
412 proto.write(LooperProto.THREAD_NAME, mThread.getName());
413 proto.write(LooperProto.THREAD_ID, mThread.getId());
Kweku Adams15afdeb2018-09-04 11:54:46 -0700414 if (mQueue != null) {
415 mQueue.writeToProto(proto, LooperProto.QUEUE);
416 }
Netta P958d0a52017-02-07 11:20:55 -0800417 proto.end(looperToken);
418 }
419
Jeff Browndc3eb4b2015-03-05 18:21:06 -0800420 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 public String toString() {
Jeff Brown5182c782013-10-15 20:31:52 -0700422 return "Looper (" + mThread.getName() + ", tid " + mThread.getId()
423 + ") {" + Integer.toHexString(System.identityHashCode(this)) + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800424 }
Marcin Oczeretkod8cc8592018-08-22 16:07:36 +0100425
426 /** {@hide} */
427 public interface Observer {
428 /**
429 * Called right before a message is dispatched.
430 *
431 * <p> The token type is not specified to allow the implementation to specify its own type.
432 *
433 * @return a token used for collecting telemetry when dispatching a single message.
434 * The token token must be passed back exactly once to either
435 * {@link Observer#messageDispatched} or {@link Observer#dispatchingThrewException}
436 * and must not be reused again.
437 *
438 */
439 Object messageDispatchStarting();
440
441 /**
442 * Called when a message was processed by a Handler.
443 *
444 * @param token Token obtained by previously calling
445 * {@link Observer#messageDispatchStarting} on the same Observer instance.
446 * @param msg The message that was dispatched.
447 */
448 void messageDispatched(Object token, Message msg);
449
450 /**
451 * Called when an exception was thrown while processing a message.
452 *
453 * @param token Token obtained by previously calling
454 * {@link Observer#messageDispatchStarting} on the same Observer instance.
455 * @param msg The message that was dispatched and caused an exception.
456 * @param exception The exception that was thrown.
457 */
458 void dispatchingThrewException(Object token, Message msg, Exception exception);
459 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460}