diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/AndroidKeyProcessor.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/AndroidKeyProcessor.java index b6ed765ab1..356a6b3379 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/AndroidKeyProcessor.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/AndroidKeyProcessor.java @@ -13,7 +13,9 @@ import io.flutter.embedding.engine.systemchannels.KeyEventChannel; import io.flutter.plugin.editing.TextInputPlugin; public class AndroidKeyProcessor { + @NonNull private final KeyEventChannel keyEventChannel; + @NonNull private final TextInputPlugin textInputPlugin; private int combiningCharacter; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java index 611b1003d2..7870f9e9ab 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/AndroidTouchProcessor.java @@ -89,7 +89,7 @@ public class AndroidTouchProcessor { * Sends the given {@link MotionEvent} data to Flutter in a format that * Flutter understands. */ - public boolean onTouchEvent(MotionEvent event) { + public boolean onTouchEvent(@NonNull MotionEvent event) { int pointerCount = event.getPointerCount(); // Prepare a data packet of the appropriate size and order. @@ -145,7 +145,7 @@ public class AndroidTouchProcessor { * Generic motion events include joystick movement, mouse hover, track pad touches, scroll wheel * movements, etc. */ - public boolean onGenericMotionEvent(MotionEvent event) { + public boolean onGenericMotionEvent(@NonNull MotionEvent event) { // Method isFromSource is only available in API 18+ (Jelly Bean MR2) // Mouse hover support is not implemented for API < 18. boolean isPointerEvent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java index 5d9ccb6a2b..3341db91c7 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivity.java @@ -87,16 +87,19 @@ public class FlutterActivity extends FragmentActivity implements OnFirstFrameRen private static final String TAG_FLUTTER_FRAGMENT = "flutter_fragment"; // TODO(mattcarroll): replace ID with R.id when build system supports R.java private static final int FRAGMENT_CONTAINER_ID = 609893468; // random number + @Nullable private FlutterFragment flutterFragment; // Used to cover the Activity until the 1st frame is rendered so as to // avoid a brief black flicker from a SurfaceView version of FlutterView. + @Nullable private View coverView; /** * Creates an {@link Intent} that launches a {@code FlutterActivity}, which executes * a {@code main()} Dart entrypoint, and displays the "/" route as Flutter's initial route. */ + @NonNull public static Intent createDefaultIntent(@NonNull Context launchContext) { return createBuilder().build(launchContext); } @@ -105,6 +108,7 @@ public class FlutterActivity extends FragmentActivity implements OnFirstFrameRen * Creates an {@link IntentBuilder}, which can be used to configure an {@link Intent} to * launch a {@code FlutterActivity}. */ + @NonNull public static IntentBuilder createBuilder() { return new IntentBuilder(FlutterActivity.class); } @@ -178,7 +182,7 @@ public class FlutterActivity extends FragmentActivity implements OnFirstFrameRen } @Override - protected void onCreate(Bundle savedInstanceState) { + protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); configureWindowForTransparency(); setContentView(createFragmentContainer()); @@ -368,7 +372,7 @@ public class FlutterActivity extends FragmentActivity implements OnFirstFrameRen } @Override - protected void onNewIntent(Intent intent) { + protected void onNewIntent(@NonNull Intent intent) { // Forward Intents to our FlutterFragment in case it cares. flutterFragment.onNewIntent(intent); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java index ffee3b0ef7..d8908fc7a4 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterFragment.java @@ -331,7 +331,7 @@ public class FlutterFragment extends Fragment { } @Override - public void onAttach(Context context) { + public void onAttach(@NonNull Context context) { super.onAttach(context); initializeFlutter(getContextCompat()); @@ -438,7 +438,7 @@ public class FlutterFragment extends Fragment { @Nullable @Override - public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { Log.v(TAG, "Creating FlutterView."); flutterView = new FlutterView(getContext(), getRenderMode(), getTransparencyMode()); flutterView.addOnFirstFrameRenderedListener(onFirstFrameRenderedListener); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterSurfaceView.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterSurfaceView.java index b01eab5d86..dd9826e002 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterSurfaceView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterSurfaceView.java @@ -50,7 +50,7 @@ public class FlutterSurfaceView extends SurfaceView implements FlutterRenderer.R // FlutterRenderer, and then on to the JNI bridge over to native Flutter code. private final SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() { @Override - public void surfaceCreated(SurfaceHolder holder) { + public void surfaceCreated(@NonNull SurfaceHolder holder) { Log.v(TAG, "SurfaceHolder.Callback.surfaceCreated()"); isSurfaceAvailableForRendering = true; @@ -60,7 +60,7 @@ public class FlutterSurfaceView extends SurfaceView implements FlutterRenderer.R } @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) { Log.v(TAG, "SurfaceHolder.Callback.surfaceChanged()"); if (isAttachedToFlutterRenderer) { changeSurfaceSize(width, height); @@ -68,7 +68,7 @@ public class FlutterSurfaceView extends SurfaceView implements FlutterRenderer.R } @Override - public void surfaceDestroyed(SurfaceHolder holder) { + public void surfaceDestroyed(@NonNull SurfaceHolder holder) { Log.v(TAG, "SurfaceHolder.Callback.surfaceDestroyed()"); isSurfaceAvailableForRendering = false; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterTextureView.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterTextureView.java index 8fe15ba694..14758eb815 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterTextureView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterTextureView.java @@ -61,7 +61,7 @@ public class FlutterTextureView extends TextureView implements FlutterRenderer.R } @Override - public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { + public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height) { Log.v(TAG, "SurfaceTextureListener.onSurfaceTextureSizeChanged()"); if (isAttachedToFlutterRenderer) { changeSurfaceSize(width, height); @@ -69,12 +69,12 @@ public class FlutterTextureView extends TextureView implements FlutterRenderer.R } @Override - public void onSurfaceTextureUpdated(SurfaceTexture surface) { + public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) { // Invoked every time a new frame is available. We don't care. } @Override - public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { + public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) { Log.v(TAG, "SurfaceTextureListener.onSurfaceTextureDestroyed()"); isSurfaceAvailableForRendering = false; @@ -93,14 +93,14 @@ public class FlutterTextureView extends TextureView implements FlutterRenderer.R /** * Constructs a {@code FlutterTextureView} programmatically, without any XML attributes. */ - public FlutterTextureView(Context context) { + public FlutterTextureView(@NonNull Context context) { this(context, null); } /** * Constructs a {@code FlutterTextureView} in an XML-inflation-compliant manner. */ - public FlutterTextureView(Context context, AttributeSet attrs) { + public FlutterTextureView(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java index 8cd9e6b184..d356d79d89 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterView.java @@ -238,7 +238,7 @@ public class FlutterView extends FrameLayout { * change, device language change, device text scale factor change, etc. */ @Override - protected void onConfigurationChanged(Configuration newConfig) { + protected void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); Log.v(TAG, "Configuration changed. Sending locales and user settings to Flutter."); sendLocalesToFlutter(newConfig); @@ -280,7 +280,8 @@ public class FlutterView extends FrameLayout { @Override @TargetApi(20) @RequiresApi(20) - public final WindowInsets onApplyWindowInsets(WindowInsets insets) { + @NonNull + public final WindowInsets onApplyWindowInsets(@NonNull WindowInsets insets) { WindowInsets newInsets = super.onApplyWindowInsets(insets); // Status bar (top) and left/right system insets should partially obscure the content (padding). @@ -315,7 +316,7 @@ public class FlutterView extends FrameLayout { */ @Override @SuppressWarnings("deprecation") - protected boolean fitSystemWindows(Rect insets) { + protected boolean fitSystemWindows(@NonNull Rect insets) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { // Status bar, left/right system insets partially obscure content (padding). viewportMetrics.paddingTop = insets.top; @@ -358,7 +359,8 @@ public class FlutterView extends FrameLayout { * rather than spread that logic throughout this {@code FlutterView}. */ @Override - public InputConnection onCreateInputConnection(EditorInfo outAttrs) { + @Nullable + public InputConnection onCreateInputConnection(@NonNull EditorInfo outAttrs) { if (!isAttachedToFlutterEngine()) { return super.onCreateInputConnection(outAttrs); } @@ -380,7 +382,7 @@ public class FlutterView extends FrameLayout { * character. */ @Override - public boolean onKeyUp(int keyCode, KeyEvent event) { + public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) { if (!isAttachedToFlutterEngine()) { return super.onKeyUp(keyCode, event); } @@ -403,7 +405,7 @@ public class FlutterView extends FrameLayout { * character. */ @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { + public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) { if (!isAttachedToFlutterEngine()) { return super.onKeyDown(keyCode, event); } @@ -419,7 +421,7 @@ public class FlutterView extends FrameLayout { * method forwards all {@link MotionEvent} data from Android to Flutter. */ @Override - public boolean onTouchEvent(MotionEvent event) { + public boolean onTouchEvent(@NonNull MotionEvent event) { if (!isAttachedToFlutterEngine()) { return super.onTouchEvent(event); } @@ -444,7 +446,7 @@ public class FlutterView extends FrameLayout { * method forwards all {@link MotionEvent} data from Android to Flutter. */ @Override - public boolean onGenericMotionEvent(MotionEvent event) { + public boolean onGenericMotionEvent(@NonNull MotionEvent event) { boolean handled = isAttachedToFlutterEngine() && androidTouchProcessor.onGenericMotionEvent(event); return handled ? true : super.onGenericMotionEvent(event); } @@ -461,7 +463,7 @@ public class FlutterView extends FrameLayout { * processed here for accessibility purposes. */ @Override - public boolean onHoverEvent(MotionEvent event) { + public boolean onHoverEvent(@NonNull MotionEvent event) { if (!isAttachedToFlutterEngine()) { return super.onHoverEvent(event); } @@ -477,6 +479,7 @@ public class FlutterView extends FrameLayout { //-------- Start: Accessibility ------- @Override + @Nullable public AccessibilityNodeProvider getAccessibilityNodeProvider() { if (accessibilityBridge != null && accessibilityBridge.isAccessibilityEnabled()) { return accessibilityBridge; @@ -661,7 +664,7 @@ public class FlutterView extends FrameLayout { * FlutterEngine must be non-null when this method is invoked. */ @SuppressWarnings("deprecation") - private void sendLocalesToFlutter(Configuration config) { + private void sendLocalesToFlutter(@NonNull Configuration config) { List locales = new ArrayList<>(); if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { LocaleList localeList = config.getLocales(); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java index 08be1530c8..08ed9f7500 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngine.java @@ -88,7 +88,9 @@ public class FlutterEngine implements LifecycleOwner { @NonNull private final TextInputChannel textInputChannel; + @NonNull private final Set engineLifecycleListeners = new HashSet<>(); + @NonNull private final EngineLifecycleListener engineLifecycleListener = new EngineLifecycleListener() { @SuppressWarnings("unused") public void onPreEngineRestart() { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngineAndroidLifecycle.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngineAndroidLifecycle.java index 671a6ecbbb..600d952cd4 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngineAndroidLifecycle.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEngineAndroidLifecycle.java @@ -40,6 +40,7 @@ final class FlutterEngineAndroidLifecycle extends LifecycleRegistry { private Lifecycle backingLifecycle; private boolean isDestroyed = false; + @NonNull private final LifecycleObserver forwardingObserver = new DefaultLifecycleObserver() { @Override public void onCreate(@NonNull LifecycleOwner owner) { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEnginePluginRegistry.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEnginePluginRegistry.java index 4713c7df1d..370ac44605 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEnginePluginRegistry.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterEnginePluginRegistry.java @@ -43,31 +43,46 @@ class FlutterEnginePluginRegistry implements PluginRegistry, private static final String TAG = "EnginePluginRegistry"; // PluginRegistry + @NonNull private final Map, FlutterPlugin> plugins = new HashMap<>(); // Standard FlutterPlugin + @NonNull private final FlutterPlugin.FlutterPluginBinding pluginBinding; + @NonNull private final FlutterEngineAndroidLifecycle flutterEngineAndroidLifecycle; // ActivityAware + @NonNull private final Map, ActivityAware> activityAwarePlugins = new HashMap<>(); + @Nullable private Activity activity; + @Nullable private FlutterEngineActivityPluginBinding activityPluginBinding; private boolean isWaitingForActivityReattachment = false; // ServiceAware + @NonNull private final Map, ServiceAware> serviceAwarePlugins = new HashMap<>(); + @Nullable private Service service; + @Nullable private FlutterEngineServicePluginBinding servicePluginBinding; // BroadcastReceiver + @NonNull private final Map, BroadcastReceiverAware> broadcastReceiverAwarePlugins = new HashMap<>(); + @Nullable private BroadcastReceiver broadcastReceiver; + @Nullable private FlutterEngineBroadcastReceiverPluginBinding broadcastReceiverPluginBinding; // ContentProvider + @NonNull private final Map, ContentProviderAware> contentProviderAwarePlugins = new HashMap<>(); + @Nullable private ContentProvider contentProvider; + @Nullable private FlutterEngineContentProviderPluginBinding contentProviderPluginBinding; FlutterEnginePluginRegistry( @@ -329,7 +344,7 @@ class FlutterEnginePluginRegistry implements PluginRegistry, } @Override - public boolean onActivityResult(int requestCode, int resultCode, @NonNull Intent data) { + public boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { Log.v(TAG, "Forwarding onActivityResult() to plugins."); if (isAttachedToActivity()) { return activityPluginBinding.onActivityResult(requestCode, resultCode, data); @@ -486,10 +501,15 @@ class FlutterEnginePluginRegistry implements PluginRegistry, //----- End ContentProviderControlSurface ----- private static class FlutterEngineActivityPluginBinding implements ActivityPluginBinding { + @NonNull private final Activity activity; + @NonNull private final Set onRequestPermissionsResultListeners = new HashSet<>(); + @NonNull private final Set onActivityResultListeners = new HashSet<>(); + @NonNull private final Set onNewIntentListeners = new HashSet<>(); + @NonNull private final Set onUserLeaveHintListeners = new HashSet<>(); public FlutterEngineActivityPluginBinding(@NonNull Activity activity) { @@ -556,7 +576,7 @@ class FlutterEnginePluginRegistry implements PluginRegistry, * Invoked by the {@link FlutterEngine} that owns this {@code ActivityPluginBinding} when its * associated {@link Activity} has its {@code onActivityResult(...)} method invoked. */ - boolean onActivityResult(int requestCode, int resultCode, @NonNull Intent data) { + boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { boolean didConsumeResult = false; for (io.flutter.plugin.common.PluginRegistry.ActivityResultListener listener : onActivityResultListeners) { didConsumeResult = listener.onActivityResult(requestCode, resultCode, data) || didConsumeResult; @@ -620,15 +640,17 @@ class FlutterEnginePluginRegistry implements PluginRegistry, } private static class FlutterEngineServicePluginBinding implements ServicePluginBinding { + @NonNull private final Service service; + @NonNull private final Set onModeChangeListeners = new HashSet<>(); FlutterEngineServicePluginBinding(@NonNull Service service) { this.service = service; } - @NonNull @Override + @NonNull public Service getService() { return service; } @@ -657,6 +679,7 @@ class FlutterEnginePluginRegistry implements PluginRegistry, } private static class FlutterEngineBroadcastReceiverPluginBinding implements BroadcastReceiverPluginBinding { + @NonNull private final BroadcastReceiver broadcastReceiver; FlutterEngineBroadcastReceiverPluginBinding(@NonNull BroadcastReceiver broadcastReceiver) { @@ -671,6 +694,7 @@ class FlutterEnginePluginRegistry implements PluginRegistry, } private static class FlutterEngineContentProviderPluginBinding implements ContentProviderPluginBinding { + @NonNull private final ContentProvider contentProvider; FlutterEngineContentProviderPluginBinding(@NonNull ContentProvider contentProvider) { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java index 8fec17cc9f..d65b458734 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterJNI.java @@ -94,21 +94,30 @@ public class FlutterJNI { private static final String TAG = "FlutterJNI"; // This is set from native code via JNI. + @Nullable private static String observatoryUri; @UiThread public static native boolean nativeGetIsSoftwareRenderingEnabled(); + @Nullable public static String getObservatoryUri() { return observatoryUri; } + @Nullable private Long nativePlatformViewId; + @Nullable private FlutterRenderer.RenderSurface renderSurface; + @Nullable private AccessibilityDelegate accessibilityDelegate; + @Nullable private PlatformMessageHandler platformMessageHandler; + @NonNull private final Set engineLifecycleListeners = new HashSet<>(); + @NonNull private final Set firstFrameListeners = new HashSet<>(); + @NonNull private final Looper mainLooper; // cached to avoid synchronization on repeat access. public FlutterJNI() { @@ -139,7 +148,7 @@ public class FlutterJNI { nativePlatformViewId = nativeAttach(this, isBackgroundView); } - private native long nativeAttach(FlutterJNI flutterJNI, boolean isBackgroundView); + private native long nativeAttach(@NonNull FlutterJNI flutterJNI, boolean isBackgroundView); /** * Detaches this {@code FlutterJNI} instance from Flutter's native engine, which precludes @@ -246,7 +255,7 @@ public class FlutterJNI { nativeSurfaceCreated(nativePlatformViewId, surface); } - private native void nativeSurfaceCreated(long nativePlatformViewId, Surface surface); + private native void nativeSurfaceCreated(long nativePlatformViewId, @NonNull Surface surface); /** * Call this method when the {@link Surface} changes that was previously registered with @@ -341,14 +350,14 @@ public class FlutterJNI { * Sends a packet of pointer data to Flutter's engine. */ @UiThread - public void dispatchPointerDataPacket(ByteBuffer buffer, int position) { + public void dispatchPointerDataPacket(@NonNull ByteBuffer buffer, int position) { ensureRunningOnMainThread(); ensureAttachedToNative(); nativeDispatchPointerDataPacket(nativePlatformViewId, buffer, position); } private native void nativeDispatchPointerDataPacket(long nativePlatformViewId, - ByteBuffer buffer, + @NonNull ByteBuffer buffer, int position); //------ End Touch Interaction Support --- @@ -377,7 +386,7 @@ public class FlutterJNI { */ @SuppressWarnings("unused") @UiThread - private void updateSemantics(ByteBuffer buffer, String[] strings) { + private void updateSemantics(@NonNull ByteBuffer buffer, @NonNull String[] strings) { ensureRunningOnMainThread(); if (accessibilityDelegate != null) { accessibilityDelegate.updateSemantics(buffer, strings); @@ -395,7 +404,7 @@ public class FlutterJNI { */ @SuppressWarnings("unused") @UiThread - private void updateCustomAccessibilityActions(ByteBuffer buffer, String[] strings) { + private void updateCustomAccessibilityActions(@NonNull ByteBuffer buffer, @NonNull String[] strings) { ensureRunningOnMainThread(); if (accessibilityDelegate != null) { accessibilityDelegate.updateCustomAccessibilityActions(buffer, strings); @@ -434,7 +443,7 @@ public class FlutterJNI { * {@link #dispatchSemanticsAction(int, AccessibilityBridge.Action, Object)}. */ @UiThread - public void dispatchSemanticsAction(int id, int action, ByteBuffer args, int argsPosition) { + public void dispatchSemanticsAction(int id, int action, @Nullable ByteBuffer args, int argsPosition) { ensureRunningOnMainThread(); ensureAttachedToNative(); nativeDispatchSemanticsAction(nativePlatformViewId, id, action, args, argsPosition); @@ -444,7 +453,7 @@ public class FlutterJNI { long nativePlatformViewId, int id, int action, - ByteBuffer args, + @Nullable ByteBuffer args, int argsPosition ); @@ -478,13 +487,13 @@ public class FlutterJNI { * texture within Flutter's UI. */ @UiThread - public void registerTexture(long textureId, SurfaceTexture surfaceTexture) { + public void registerTexture(long textureId, @NonNull SurfaceTexture surfaceTexture) { ensureRunningOnMainThread(); ensureAttachedToNative(); nativeRegisterTexture(nativePlatformViewId, textureId, surfaceTexture); } - private native void nativeRegisterTexture(long nativePlatformViewId, long textureId, SurfaceTexture surfaceTexture); + private native void nativeRegisterTexture(long nativePlatformViewId, long textureId, @NonNull SurfaceTexture surfaceTexture); /** * Call this method to inform Flutter that a texture previously registered with @@ -580,8 +589,9 @@ public class FlutterJNI { } // Called by native. + // TODO(mattcarroll): determine if message is nonull or nullable @SuppressWarnings("unused") - private void handlePlatformMessage(final String channel, byte[] message, final int replyId) { + private void handlePlatformMessage(@NonNull final String channel, byte[] message, final int replyId) { if (platformMessageHandler != null) { platformMessageHandler.handleMessageFromDart(channel, message, replyId); } @@ -589,6 +599,7 @@ public class FlutterJNI { } // Called by native to respond to a platform message that we sent. + // TODO(mattcarroll): determine if reply is nonull or nullable @SuppressWarnings("unused") private void handlePlatformMessageResponse(int replyId, byte[] reply) { if (platformMessageHandler != null) { @@ -602,7 +613,7 @@ public class FlutterJNI { * {@code channel}. */ @UiThread - public void dispatchEmptyPlatformMessage(String channel, int responseId) { + public void dispatchEmptyPlatformMessage(@NonNull String channel, int responseId) { ensureRunningOnMainThread(); if (isAttached()) { nativeDispatchEmptyPlatformMessage(nativePlatformViewId, channel, responseId); @@ -614,7 +625,7 @@ public class FlutterJNI { // Send an empty platform message to Dart. private native void nativeDispatchEmptyPlatformMessage( long nativePlatformViewId, - String channel, + @NonNull String channel, int responseId ); @@ -622,7 +633,7 @@ public class FlutterJNI { * Sends a reply {@code message} from Android to Flutter over the given {@code channel}. */ @UiThread - public void dispatchPlatformMessage(String channel, ByteBuffer message, int position, int responseId) { + public void dispatchPlatformMessage(@NonNull String channel, @Nullable ByteBuffer message, int position, int responseId) { ensureRunningOnMainThread(); if (isAttached()) { nativeDispatchPlatformMessage( @@ -640,8 +651,8 @@ public class FlutterJNI { // Send a data-carrying platform message to Dart. private native void nativeDispatchPlatformMessage( long nativePlatformViewId, - String channel, - ByteBuffer message, + @NonNull String channel, + @Nullable ByteBuffer message, int position, int responseId ); @@ -665,7 +676,7 @@ public class FlutterJNI { // TODO(mattcarroll): differentiate between channel responses and platform responses. @UiThread - public void invokePlatformMessageResponseCallback(int responseId, ByteBuffer message, int position) { + public void invokePlatformMessageResponseCallback(int responseId, @Nullable ByteBuffer message, int position) { ensureRunningOnMainThread(); if (isAttached()) { nativeInvokePlatformMessageResponseCallback( @@ -683,7 +694,7 @@ public class FlutterJNI { private native void nativeInvokePlatformMessageResponseCallback( long nativePlatformViewId, int responseId, - ByteBuffer message, + @Nullable ByteBuffer message, int position ); //------- End Platform Message Support ---- @@ -718,6 +729,7 @@ public class FlutterJNI { } //----- End Engine Lifecycle Support ---- + // TODO(mattcarroll): determine if this is nonull or nullable @UiThread public Bitmap getBitmap() { ensureRunningOnMainThread(); @@ -725,6 +737,7 @@ public class FlutterJNI { return nativeGetBitmap(nativePlatformViewId); } + // TODO(mattcarroll): determine if this is nonull or nullable private native Bitmap nativeGetBitmap(long nativePlatformViewId); private void ensureRunningOnMainThread() { @@ -749,7 +762,7 @@ public class FlutterJNI { * Implementers are expected to maintain an Android-side cache of custom accessibility actions. * This method provides new actions to add to that cache. */ - void updateCustomAccessibilityActions(ByteBuffer buffer, String[] strings); + void updateCustomAccessibilityActions(@NonNull ByteBuffer buffer, @NonNull String[] strings); /** * Sends new {@code SemanticsNode} information from Flutter to Android. @@ -757,6 +770,6 @@ public class FlutterJNI { * Implementers are expected to maintain an Android-side cache of Flutter's semantics tree. * This method provides updates from Flutter for the Android-side semantics tree cache. */ - void updateSemantics(ByteBuffer buffer, String[] strings); + void updateSemantics(@NonNull ByteBuffer buffer, @NonNull String[] strings); } } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java index 45605cd287..ca37866906 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java @@ -92,6 +92,7 @@ public class FlutterShellArgs { return new FlutterShellArgs(args); } + @NonNull private Set args; /** diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java index 06ebb381a8..4a09d8fb7d 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartExecutor.java @@ -45,7 +45,9 @@ public class DartExecutor implements BinaryMessenger { @NonNull private final DartMessenger messenger; private boolean isApplicationRunning = false; + @Nullable private String isolateServiceId; + @Nullable private IsolateServiceIdListener isolateServiceIdListener; private final BinaryMessenger.BinaryMessageHandler isolateChannelMessageHandler = @@ -206,6 +208,7 @@ public class DartExecutor implements BinaryMessenger { * Returns an identifier for this executor's primary isolate. This identifier can be used * in queries to the Dart service protocol. */ + @Nullable public String getIsolateServiceId() { return isolateServiceId; } @@ -214,14 +217,14 @@ public class DartExecutor implements BinaryMessenger { * Callback interface invoked when the isolate identifier becomes available. */ interface IsolateServiceIdListener { - void onIsolateServiceIdAvailable(String isolateServiceId); + void onIsolateServiceIdAvailable(@NonNull String isolateServiceId); } /** * Set a listener that will be notified when an isolate identifier is available for this * executor's primary isolate. */ - public void setIsolateServiceIdListener(IsolateServiceIdListener listener) { + public void setIsolateServiceIdListener(@Nullable IsolateServiceIdListener listener) { isolateServiceIdListener = listener; if (isolateServiceIdListener != null && isolateServiceId != null) { isolateServiceIdListener.onIsolateServiceIdAvailable(isolateServiceId); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java index 26aa498a86..3c0dac121b 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/DartMessenger.java @@ -130,7 +130,7 @@ class DartMessenger implements BinaryMessenger, PlatformMessageHandler { } @Override - public void reply(ByteBuffer reply) { + public void reply(@Nullable ByteBuffer reply) { if (done.getAndSet(true)) { throw new IllegalStateException("Reply already submitted"); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformMessageHandler.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformMessageHandler.java index ea1011c09a..15600e1c3f 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformMessageHandler.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/dart/PlatformMessageHandler.java @@ -4,12 +4,15 @@ package io.flutter.embedding.engine.dart; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + /** * WARNING: THIS CLASS IS EXPERIMENTAL. DO NOT SHIP A DEPENDENCY ON THIS CODE. * IF YOU USE IT, WE WILL BREAK YOU. */ public interface PlatformMessageHandler { - void handleMessageFromDart(final String channel, byte[] message, final int replyId); + void handleMessageFromDart(@NonNull final String channel, @Nullable byte[] message, final int replyId); - void handlePlatformMessageResponse(int replyId, byte[] reply); + void handlePlatformMessageResponse(int replyId, @Nullable byte[] reply); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/plugins/activity/ActivityControlSurface.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/plugins/activity/ActivityControlSurface.java index a25bd08269..c5833eca7c 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/plugins/activity/ActivityControlSurface.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/plugins/activity/ActivityControlSurface.java @@ -8,6 +8,7 @@ import android.app.Activity; import android.arch.lifecycle.Lifecycle; import android.content.Intent; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; /** * Control surface through which an {@link Activity} attaches to a {@link FlutterEngine}. @@ -82,7 +83,7 @@ public interface ActivityControlSurface { *

* Returns true if one or more plugins utilized this {@link Activity} result. */ - boolean onActivityResult(int requestCode, int resultCode, Intent data); + boolean onActivityResult(int requestCode, int resultCode, @Nullable Intent data); /** * Call this method from the {@link Activity} that is attached to this {@code ActivityControlSurface}'s diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java index d48d3b0111..592acc4588 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/renderer/FlutterRenderer.java @@ -105,10 +105,11 @@ public class FlutterRenderer implements TextureRegistry { final class SurfaceTextureRegistryEntry implements TextureRegistry.SurfaceTextureEntry { private final long id; + @NonNull private final SurfaceTexture surfaceTexture; private boolean released; - SurfaceTextureRegistryEntry(long id, SurfaceTexture surfaceTexture) { + SurfaceTextureRegistryEntry(long id, @NonNull SurfaceTexture surfaceTexture) { this.id = id; this.surfaceTexture = surfaceTexture; @@ -127,7 +128,7 @@ public class FlutterRenderer implements TextureRegistry { private SurfaceTexture.OnFrameAvailableListener onFrameListener = new SurfaceTexture.OnFrameAvailableListener() { @Override - public void onFrameAvailable(SurfaceTexture texture) { + public void onFrameAvailable(@NonNull SurfaceTexture texture) { if (released) { // Even though we make sure to unregister the callback before releasing, as of Android O // SurfaceTexture has a data race when accessing the callback, so the callback may @@ -139,6 +140,7 @@ public class FlutterRenderer implements TextureRegistry { }; @Override + @NonNull public SurfaceTexture surfaceTexture() { return surfaceTexture; } @@ -162,7 +164,7 @@ public class FlutterRenderer implements TextureRegistry { //------ END TextureRegistry IMPLEMENTATION ---- // TODO(mattcarroll): describe the native behavior that this invokes - public void surfaceCreated(Surface surface) { + public void surfaceCreated(@NonNull Surface surface) { flutterJNI.onSurfaceCreated(surface); } @@ -201,17 +203,18 @@ public class FlutterRenderer implements TextureRegistry { } // TODO(mattcarroll): describe the native behavior that this invokes + // TODO(mattcarroll): determine if this is nullable or nonnull public Bitmap getBitmap() { return flutterJNI.getBitmap(); } // TODO(mattcarroll): describe the native behavior that this invokes - public void dispatchPointerDataPacket(ByteBuffer buffer, int position) { + public void dispatchPointerDataPacket(@NonNull ByteBuffer buffer, int position) { flutterJNI.dispatchPointerDataPacket(buffer, position); } // TODO(mattcarroll): describe the native behavior that this invokes - private void registerTexture(long textureId, SurfaceTexture surfaceTexture) { + private void registerTexture(long textureId, @NonNull SurfaceTexture surfaceTexture) { flutterJNI.registerTexture(textureId, surfaceTexture); } @@ -243,7 +246,7 @@ public class FlutterRenderer implements TextureRegistry { // TODO(mattcarroll): describe the native behavior that this invokes public void dispatchSemanticsAction(int id, int action, - ByteBuffer args, + @Nullable ByteBuffer args, int argsPosition) { flutterJNI.dispatchSemanticsAction( id, diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/AccessibilityChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/AccessibilityChannel.java index 47c5a9985a..4e3a7f6707 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/AccessibilityChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/AccessibilityChannel.java @@ -30,7 +30,7 @@ public class AccessibilityChannel { private final BasicMessageChannel.MessageHandler parsingMessageHandler = new BasicMessageChannel.MessageHandler() { @Override - public void onMessage(Object message, BasicMessageChannel.Reply reply) { + public void onMessage(@Nullable Object message, @NonNull BasicMessageChannel.Reply reply) { // If there is no handler to respond to this message then we don't need to // parse it. Return. if (handler == null) { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LocalizationChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LocalizationChannel.java index cfa0a66bf7..a9ba7b96a5 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LocalizationChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/LocalizationChannel.java @@ -32,7 +32,7 @@ public class LocalizationChannel { /** * Send the given {@code locales} to Dart. */ - public void sendLocales(List locales) { + public void sendLocales(@NonNull List locales) { Log.v(TAG, "Sending Locales to Flutter."); List data = new ArrayList<>(); for (Locale locale : locales) { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/NavigationChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/NavigationChannel.java index e544293df3..694ee585c1 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/NavigationChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/NavigationChannel.java @@ -25,12 +25,12 @@ public class NavigationChannel { this.channel = new MethodChannel(dartExecutor, "flutter/navigation", JSONMethodCodec.INSTANCE); } - public void setInitialRoute(String initialRoute) { + public void setInitialRoute(@NonNull String initialRoute) { Log.v(TAG, "Sending message to set initial route to '" + initialRoute + "'"); channel.invokeMethod("setInitialRoute", initialRoute); } - public void pushRoute(String route) { + public void pushRoute(@NonNull String route) { Log.v(TAG, "Sending message to push route '" + route + "'"); channel.invokeMethod("pushRoute", route); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java index 7ec3c2ef6c..68eeb7c750 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java @@ -35,7 +35,7 @@ public class PlatformChannel { private final MethodChannel.MethodCallHandler parsingMethodCallHandler = new MethodChannel.MethodCallHandler() { @Override - public void onMethodCall(MethodCall call, MethodChannel.Result result) { + public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { if (platformMessageHandler == null) { // If no explicit PlatformMessageHandler has been registered then we don't // need to forward this call to an API. Return. @@ -257,6 +257,7 @@ public class PlatformChannel { return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } + @NonNull private AppSwitcherDescription decodeAppSwitcherDescription(@NonNull JSONObject encodedDescription) throws JSONException { int color = encodedDescription.getInt("primaryColor"); if (color != 0) { // 0 means color isn't set, use system default @@ -272,6 +273,7 @@ public class PlatformChannel { * @throws JSONException if {@code encodedSystemUiOverlay} does not contain expected keys and value types. * @throws NoSuchFieldException if any of the given encoded overlay names are invalid. */ + @NonNull private List decodeSystemUiOverlays(@NonNull JSONArray encodedSystemUiOverlay) throws JSONException, NoSuchFieldException { List overlays = new ArrayList<>(); for (int i = 0; i < encodedSystemUiOverlay.length(); ++i) { @@ -295,6 +297,7 @@ public class PlatformChannel { * @throws JSONException if {@code encodedStyle} does not contain expected keys and value types. * @throws NoSuchFieldException if any provided brightness name is invalid. */ + @NonNull private SystemChromeStyle decodeSystemChromeStyle(@NonNull JSONObject encodedStyle) throws JSONException, NoSuchFieldException { Brightness systemNavigationBarIconBrightness = null; // TODO(mattcarroll): add color annotation @@ -425,6 +428,7 @@ public class PlatformChannel { public enum SoundType { CLICK("SystemSoundType.click"); + @NonNull static SoundType fromValue(@NonNull String encodedName) throws NoSuchFieldException { for (SoundType soundType : SoundType.values()) { if (soundType.encodedName.equals(encodedName)) { @@ -453,6 +457,7 @@ public class PlatformChannel { HEAVY_IMPACT("HapticFeedbackType.heavyImpact"), SELECTION_CLICK("HapticFeedbackType.selectionClick"); + @NonNull static HapticFeedbackType fromValue(@Nullable String encodedName) throws NoSuchFieldException { for (HapticFeedbackType feedbackType : HapticFeedbackType.values()) { if ((feedbackType.encodedName == null && encodedName == null) @@ -480,6 +485,7 @@ public class PlatformChannel { LANDSCAPE_LEFT("DeviceOrientation.landscapeLeft"), LANDSCAPE_RIGHT("DeviceOrientation.landscapeRight"); + @NonNull static DeviceOrientation fromValue(@NonNull String encodedName) throws NoSuchFieldException { for (DeviceOrientation orientation : DeviceOrientation.values()) { if (orientation.encodedName.equals(encodedName)) { @@ -508,6 +514,7 @@ public class PlatformChannel { TOP_OVERLAYS("SystemUiOverlay.top"), BOTTOM_OVERLAYS("SystemUiOverlay.bottom"); + @NonNull static SystemUiOverlay fromValue(@NonNull String encodedName) throws NoSuchFieldException { for (SystemUiOverlay overlay : SystemUiOverlay.values()) { if (overlay.encodedName.equals(encodedName)) { @@ -578,6 +585,7 @@ public class PlatformChannel { LIGHT("Brightness.light"), DARK("Brightness.dark"); + @NonNull static Brightness fromValue(@NonNull String encodedName) throws NoSuchFieldException { for (Brightness brightness : Brightness.values()) { if (brightness.encodedName.equals(encodedName)) { @@ -601,7 +609,8 @@ public class PlatformChannel { public enum ClipboardContentFormat { PLAIN_TEXT("text/plain"); - static ClipboardContentFormat fromValue(String encodedName) throws NoSuchFieldException { + @NonNull + static ClipboardContentFormat fromValue(@NonNull String encodedName) throws NoSuchFieldException { for (ClipboardContentFormat format : ClipboardContentFormat.values()) { if (format.encodedName.equals(encodedName)) { return format; diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java index 39702fa739..0e2c3ed0ff 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java @@ -38,7 +38,7 @@ public class PlatformViewsChannel { private final MethodChannel.MethodCallHandler parsingHandler = new MethodChannel.MethodCallHandler() { @Override - public void onMethodCall(MethodCall call, MethodChannel.Result result) { + public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { // If there is no handler to respond to this message then we don't need to // parse it. Return. if (handler == null) { @@ -70,7 +70,7 @@ public class PlatformViewsChannel { } } - private void create(MethodCall call, MethodChannel.Result result) { + private void create(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { Map createArgs = call.arguments(); PlatformViewCreationRequest request = new PlatformViewCreationRequest( (int) createArgs.get("id"), @@ -187,7 +187,7 @@ public class PlatformViewsChannel { } } - private void clearFocus(MethodCall call, MethodChannel.Result result) { + private void clearFocus(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { int viewId = call.arguments(); try { handler.clearFocus(viewId); diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/SettingsChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/SettingsChannel.java index 5eba516610..5fafc343d9 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/SettingsChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/SettingsChannel.java @@ -17,35 +17,42 @@ public class SettingsChannel { private static final String TEXT_SCALE_FACTOR = "textScaleFactor"; private static final String ALWAYS_USE_24_HOUR_FORMAT = "alwaysUse24HourFormat"; private static final String PLATFORM_BRIGHTNESS = "platformBrightness"; - + + @NonNull public final BasicMessageChannel channel; public SettingsChannel(@NonNull DartExecutor dartExecutor) { this.channel = new BasicMessageChannel<>(dartExecutor, CHANNEL_NAME, JSONMessageCodec.INSTANCE); } - + + @NonNull public MessageBuilder startMessage() { return new MessageBuilder(channel); } public static class MessageBuilder { + @NonNull private final BasicMessageChannel channel; + @NonNull private Map message = new HashMap<>(); MessageBuilder(@NonNull BasicMessageChannel channel) { this.channel = channel; } - + + @NonNull public MessageBuilder setTextScaleFactor(float textScaleFactor) { message.put(TEXT_SCALE_FACTOR, textScaleFactor); return this; } - + + @NonNull public MessageBuilder setUse24HourFormat(boolean use24HourFormat) { message.put(ALWAYS_USE_24_HOUR_FORMAT, use24HourFormat); return this; } - + + @NonNull public MessageBuilder setPlatformBrightness(@NonNull PlatformBrightness brightness) { message.put(PLATFORM_BRIGHTNESS, brightness.name); return this; @@ -69,7 +76,8 @@ public class SettingsChannel { public enum PlatformBrightness { light("light"), dark("dark"); - + + @NonNull public String name; PlatformBrightness(@NonNull String name) { diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java index 6196bec2c0..857168dadc 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java @@ -41,7 +41,7 @@ public class TextInputChannel { private final MethodChannel.MethodCallHandler parsingMethodHandler = new MethodChannel.MethodCallHandler() { @Override - public void onMethodCall(MethodCall call, MethodChannel.Result result) { + public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { if (textInputMethodHandler == null) { // If no explicit TextInputMethodHandler has been registered then we don't // need to forward this call to an API. Return. @@ -278,6 +278,7 @@ public class TextInputChannel { ); } + @NonNull private static Integer inputActionFromTextInputAction(@NonNull String inputAction) { switch (inputAction) { case "TextInputAction.newline": diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java index 15cee8bb60..23a45430c6 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BasicMessageChannel.java @@ -4,6 +4,8 @@ package io.flutter.plugin.common; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import android.util.Log; import java.nio.ByteBuffer; @@ -28,8 +30,11 @@ import io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler; public final class BasicMessageChannel { private static final String TAG = "BasicMessageChannel#"; + @NonNull private final BinaryMessenger messenger; + @NonNull private final String name; + @NonNull private final MessageCodec codec; /** @@ -40,7 +45,7 @@ public final class BasicMessageChannel { * @param name a channel name String. * @param codec a {@link MessageCodec}. */ - public BasicMessageChannel(BinaryMessenger messenger, String name, MessageCodec codec) { + public BasicMessageChannel(@NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MessageCodec codec) { if (BuildConfig.DEBUG) { if (messenger == null) { Log.e(TAG, "Parameter messenger must not be null."); @@ -62,7 +67,7 @@ public final class BasicMessageChannel { * * @param message the message, possibly null. */ - public void send(T message) { + public void send(@Nullable T message) { send(message, null); } @@ -75,7 +80,7 @@ public final class BasicMessageChannel { * @param callback a {@link Reply} callback, possibly null. */ @UiThread - public void send(T message, final Reply callback) { + public void send(@Nullable T message, @Nullable final Reply callback) { messenger.send(name, codec.encodeMessage(message), callback == null ? null : new IncomingReplyHandler(callback)); } @@ -92,7 +97,7 @@ public final class BasicMessageChannel { * @param handler a {@link MessageHandler}, or null to deregister. */ @UiThread - public void setMessageHandler(final MessageHandler handler) { + public void setMessageHandler(@Nullable final MessageHandler handler) { messenger.setMessageHandler(name, handler == null ? null : new IncomingMessageHandler(handler)); } @@ -119,7 +124,7 @@ public final class BasicMessageChannel { * @param message the message, possibly null. * @param reply a {@link Reply} for sending a single message reply back to Flutter. */ - void onMessage(T message, Reply reply); + void onMessage(@Nullable T message, @NonNull Reply reply); } /** @@ -133,18 +138,18 @@ public final class BasicMessageChannel { * * @param reply the reply, possibly null. */ - void reply(T reply); + void reply(@Nullable T reply); } private final class IncomingReplyHandler implements BinaryReply { private final Reply callback; - private IncomingReplyHandler(Reply callback) { + private IncomingReplyHandler(@NonNull Reply callback) { this.callback = callback; } @Override - public void reply(ByteBuffer reply) { + public void reply(@Nullable ByteBuffer reply) { try { callback.reply(codec.decodeMessage(reply)); } catch (RuntimeException e) { @@ -156,12 +161,12 @@ public final class BasicMessageChannel { private final class IncomingMessageHandler implements BinaryMessageHandler { private final MessageHandler handler; - private IncomingMessageHandler(MessageHandler handler) { + private IncomingMessageHandler(@NonNull MessageHandler handler) { this.handler = handler; } @Override - public void onMessage(ByteBuffer message, final BinaryReply callback) { + public void onMessage(@Nullable ByteBuffer message, @NonNull final BinaryReply callback) { try { handler.onMessage(codec.decodeMessage(message), new Reply() { @Override diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BinaryMessenger.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BinaryMessenger.java index 8906d12864..d259156b77 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BinaryMessenger.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/BinaryMessenger.java @@ -4,6 +4,8 @@ package io.flutter.plugin.common; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.UiThread; import java.nio.ByteBuffer; @@ -32,7 +34,7 @@ public interface BinaryMessenger { * between position zero and current position, or null. */ @UiThread - void send(String channel, ByteBuffer message); + void send(@NonNull String channel, @Nullable ByteBuffer message); /** * Sends a binary message to the Flutter application, optionally expecting a reply. @@ -46,7 +48,7 @@ public interface BinaryMessenger { * message, possibly null. */ @UiThread - void send(String channel, ByteBuffer message, BinaryReply callback); + void send(@NonNull String channel, @Nullable ByteBuffer message, @Nullable BinaryReply callback); /** * Registers a handler to be invoked when the Flutter application sends a message @@ -62,7 +64,7 @@ public interface BinaryMessenger { * @param handler a {@link BinaryMessageHandler} to be invoked on incoming messages, or null. */ @UiThread - void setMessageHandler(String channel, BinaryMessageHandler handler); + void setMessageHandler(@NonNull String channel, @Nullable BinaryMessageHandler handler); /** * Handler for incoming binary messages from Flutter. @@ -82,7 +84,7 @@ public interface BinaryMessenger { * @param reply A {@link BinaryReply} used for submitting a reply back to Flutter. */ @UiThread - void onMessage(ByteBuffer message, BinaryReply reply); + void onMessage(@Nullable ByteBuffer message, @NonNull BinaryReply reply); } /** @@ -99,6 +101,6 @@ public interface BinaryMessenger { * Reply receivers can read from the buffer directly. */ @UiThread - void reply(ByteBuffer reply); + void reply(@Nullable ByteBuffer reply); } } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MessageCodec.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MessageCodec.java index a1a0590df4..c10c6c4c2d 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MessageCodec.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MessageCodec.java @@ -4,6 +4,8 @@ package io.flutter.plugin.common; +import android.support.annotation.Nullable; + import java.nio.ByteBuffer; /** @@ -19,7 +21,8 @@ public interface MessageCodec { * @return a ByteBuffer containing the encoding between position 0 and * the current position, or null, if message is null. */ - ByteBuffer encodeMessage(T message); + @Nullable + ByteBuffer encodeMessage(@Nullable T message); /** * Decodes the specified message from binary. @@ -28,5 +31,6 @@ public interface MessageCodec { * @return a T value representation of the bytes between the given buffer's current * position and its limit, or null, if message is null. */ - T decodeMessage(ByteBuffer message); + @Nullable + T decodeMessage(@Nullable ByteBuffer message); } diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java index e468b9b277..8bab6098b0 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/common/MethodChannel.java @@ -142,7 +142,7 @@ public final class MethodChannel { * @param result A {@link Result} used for submitting the result of the call. */ @UiThread - void onMethodCall(MethodCall call, Result result); + void onMethodCall(@NonNull MethodCall call, @NonNull Result result); } /**