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 /test-mock/src | |
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 'test-mock/src')
-rw-r--r-- | test-mock/src/android/test/mock/MockContext.java | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/test-mock/src/android/test/mock/MockContext.java b/test-mock/src/android/test/mock/MockContext.java index 5e5ba462cfca..4dfd0507f351 100644 --- a/test-mock/src/android/test/mock/MockContext.java +++ b/test-mock/src/android/test/mock/MockContext.java @@ -19,13 +19,12 @@ package android.test.mock; import android.annotation.SystemApi; import android.app.IApplicationThread; import android.app.IServiceConnection; -import android.app.Notification; +import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.BroadcastReceiver; import android.content.IntentSender; import android.content.ServiceConnection; import android.content.SharedPreferences; @@ -44,8 +43,8 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.UserHandle; -import android.view.DisplayAdjustments; import android.view.Display; +import android.view.DisplayAdjustments; import java.io.File; import java.io.FileInputStream; @@ -53,6 +52,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.util.concurrent.Executor; /** * A mock {@link android.content.Context} class. All methods are non-functional and throw @@ -87,6 +87,11 @@ public class MockContext extends Context { } @Override + public Executor getMainExecutor() { + throw new UnsupportedOperationException(); + } + + @Override public Context getApplicationContext() { throw new UnsupportedOperationException(); } |