未验证 提交 3bcd6a8f 编写于 作者: M Matt Carroll 提交者: GitHub

Android Embedding Refactor PR34: Fill in missing nullability annotations. (#9384)

上级 e8e9ba29
......@@ -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;
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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;
......
......@@ -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();
}
......
......@@ -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<Locale> locales = new ArrayList<>();
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
LocaleList localeList = config.getLocales();
......
......@@ -88,7 +88,9 @@ public class FlutterEngine implements LifecycleOwner {
@NonNull
private final TextInputChannel textInputChannel;
@NonNull
private final Set<EngineLifecycleListener> engineLifecycleListeners = new HashSet<>();
@NonNull
private final EngineLifecycleListener engineLifecycleListener = new EngineLifecycleListener() {
@SuppressWarnings("unused")
public void onPreEngineRestart() {
......
......@@ -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) {
......
......@@ -43,31 +43,46 @@ class FlutterEnginePluginRegistry implements PluginRegistry,
private static final String TAG = "EnginePluginRegistry";
// PluginRegistry
@NonNull
private final Map<Class<? extends FlutterPlugin>, FlutterPlugin> plugins = new HashMap<>();
// Standard FlutterPlugin
@NonNull
private final FlutterPlugin.FlutterPluginBinding pluginBinding;
@NonNull
private final FlutterEngineAndroidLifecycle flutterEngineAndroidLifecycle;
// ActivityAware
@NonNull
private final Map<Class<? extends FlutterPlugin>, ActivityAware> activityAwarePlugins = new HashMap<>();
@Nullable
private Activity activity;
@Nullable
private FlutterEngineActivityPluginBinding activityPluginBinding;
private boolean isWaitingForActivityReattachment = false;
// ServiceAware
@NonNull
private final Map<Class<? extends FlutterPlugin>, ServiceAware> serviceAwarePlugins = new HashMap<>();
@Nullable
private Service service;
@Nullable
private FlutterEngineServicePluginBinding servicePluginBinding;
// BroadcastReceiver
@NonNull
private final Map<Class<? extends FlutterPlugin>, BroadcastReceiverAware> broadcastReceiverAwarePlugins = new HashMap<>();
@Nullable
private BroadcastReceiver broadcastReceiver;
@Nullable
private FlutterEngineBroadcastReceiverPluginBinding broadcastReceiverPluginBinding;
// ContentProvider
@NonNull
private final Map<Class<? extends FlutterPlugin>, 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<io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener> onRequestPermissionsResultListeners = new HashSet<>();
@NonNull
private final Set<io.flutter.plugin.common.PluginRegistry.ActivityResultListener> onActivityResultListeners = new HashSet<>();
@NonNull
private final Set<io.flutter.plugin.common.PluginRegistry.NewIntentListener> onNewIntentListeners = new HashSet<>();
@NonNull
private final Set<io.flutter.plugin.common.PluginRegistry.UserLeaveHintListener> 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<ServiceAware.OnModeChangeListener> 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) {
......
......@@ -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<EngineLifecycleListener> engineLifecycleListeners = new HashSet<>();
@NonNull
private final Set<OnFirstFrameRenderedListener> 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);
}
}
......@@ -92,6 +92,7 @@ public class FlutterShellArgs {
return new FlutterShellArgs(args);
}
@NonNull
private Set<String> args;
/**
......
......@@ -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);
......
......@@ -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");
}
......
......@@ -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);
}
......@@ -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 {
* <p>
* 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
......
......@@ -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,
......
......@@ -30,7 +30,7 @@ public class AccessibilityChannel {
private final BasicMessageChannel.MessageHandler<Object> parsingMessageHandler = new BasicMessageChannel.MessageHandler<Object>() {
@Override
public void onMessage(Object message, BasicMessageChannel.Reply<Object> reply) {
public void onMessage(@Nullable Object message, @NonNull BasicMessageChannel.Reply<Object> reply) {
// If there is no handler to respond to this message then we don't need to
// parse it. Return.
if (handler == null) {
......
......@@ -32,7 +32,7 @@ public class LocalizationChannel {
/**
* Send the given {@code locales} to Dart.
*/
public void sendLocales(List<Locale> locales) {
public void sendLocales(@NonNull List<Locale> locales) {
Log.v(TAG, "Sending Locales to Flutter.");
List<String> data = new ArrayList<>();
for (Locale locale : locales) {
......
......@@ -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);
}
......
......@@ -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<SystemUiOverlay> decodeSystemUiOverlays(@NonNull JSONArray encodedSystemUiOverlay) throws JSONException, NoSuchFieldException {
List<SystemUiOverlay> 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;
......
......@@ -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<String, Object> 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);
......
......@@ -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<Object> 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<Object> channel;
@NonNull
private Map<String, Object> message = new HashMap<>();
MessageBuilder(@NonNull BasicMessageChannel<Object> 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) {
......
......@@ -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":
......
......@@ -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<T> {
private static final String TAG = "BasicMessageChannel#";
@NonNull
private final BinaryMessenger messenger;
@NonNull
private final String name;
@NonNull
private final MessageCodec<T> codec;
/**
......@@ -40,7 +45,7 @@ public final class BasicMessageChannel<T> {
* @param name a channel name String.
* @param codec a {@link MessageCodec}.
*/
public BasicMessageChannel(BinaryMessenger messenger, String name, MessageCodec<T> codec) {
public BasicMessageChannel(@NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MessageCodec<T> codec) {
if (BuildConfig.DEBUG) {
if (messenger == null) {
Log.e(TAG, "Parameter messenger must not be null.");
......@@ -62,7 +67,7 @@ public final class BasicMessageChannel<T> {
*
* @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<T> {
* @param callback a {@link Reply} callback, possibly null.
*/
@UiThread
public void send(T message, final Reply<T> callback) {
public void send(@Nullable T message, @Nullable final Reply<T> callback) {
messenger.send(name, codec.encodeMessage(message),
callback == null ? null : new IncomingReplyHandler(callback));
}
......@@ -92,7 +97,7 @@ public final class BasicMessageChannel<T> {
* @param handler a {@link MessageHandler}, or null to deregister.
*/
@UiThread
public void setMessageHandler(final MessageHandler<T> handler) {
public void setMessageHandler(@Nullable final MessageHandler<T> handler) {
messenger.setMessageHandler(name,
handler == null ? null : new IncomingMessageHandler(handler));
}
......@@ -119,7 +124,7 @@ public final class BasicMessageChannel<T> {
* @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<T> reply);
void onMessage(@Nullable T message, @NonNull Reply<T> reply);
}
/**
......@@ -133,18 +138,18 @@ public final class BasicMessageChannel<T> {
*
* @param reply the reply, possibly null.
*/
void reply(T reply);
void reply(@Nullable T reply);
}
private final class IncomingReplyHandler implements BinaryReply {
private final Reply<T> callback;
private IncomingReplyHandler(Reply<T> callback) {
private IncomingReplyHandler(@NonNull Reply<T> 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<T> {
private final class IncomingMessageHandler implements BinaryMessageHandler {
private final MessageHandler<T> handler;
private IncomingMessageHandler(MessageHandler<T> handler) {
private IncomingMessageHandler(@NonNull MessageHandler<T> 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<T>() {
@Override
......
......@@ -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);
}
}
......@@ -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<T> {
* @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<T> {
* @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);
}
......@@ -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);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册