diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2017-12-12 17:26:23 -0700 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2017-12-13 13:59:04 -0700 |
| commit | 8439ac08b1b8ef362cd649dbefdea4ac140051e2 (patch) | |
| tree | f7dfbb91bb60ff3c2e8768aa9975ca45b4563e59 /core/java/android/content/ContextWrapper.java | |
| parent | ff38f236b55b51a9f8e03b909f4791ccca329c48 (diff) | |
Start accepting Executors instead of Handlers.
After discussion in API council, our new best-practices are to have
developers provide an Executor to dispatch callbacks/listeners on,
instead of the previous guidance of using a Handler.
Define Context.getMainExecutor() to easily obtain an Executor
associated with the main thread of application. This allows new
APIs to require a @NonNull Executor. Also define a new
@CallbackExecutor auto-doc annotation that explains background and
points developers at new Context method above.
Test: cts-tradefed run commandAndExit cts-dev -m CtsContentTestCases -t android.content.cts.ContextTest#testMainLooper
Test: cts-tradefed run commandAndExit cts-dev -m CtsContentTestCases -t android.content.cts.ContextTest#testMainExecutor
Bug: 70348426
Change-Id: I536892bcd80fcfba1bb1ddf67648c08a26d7ddd2
Diffstat (limited to 'core/java/android/content/ContextWrapper.java')
| -rw-r--r-- | core/java/android/content/ContextWrapper.java | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java index 85acdc6b8101..67de4fe6bc4b 100644 --- a/core/java/android/content/ContextWrapper.java +++ b/core/java/android/content/ContextWrapper.java @@ -45,6 +45,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.concurrent.Executor; /** * Proxying implementation of Context that simply delegates all of its calls to @@ -103,7 +104,12 @@ public class ContextWrapper extends Context { public Looper getMainLooper() { return mBase.getMainLooper(); } - + + @Override + public Executor getMainExecutor() { + return mBase.getMainExecutor(); + } + @Override public Context getApplicationContext() { return mBase.getApplicationContext(); |
