Reland: Fix first batch of warnings in the Android embedding (flutter/engine#31530)

This commit is contained in:
Emmanuel Garcia
2022-02-18 11:39:07 -08:00
committed by GitHub
parent d7f869cc93
commit 0eb5a3774a
40 changed files with 291 additions and 147 deletions

View File

@@ -878,7 +878,7 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC
* previous {@code keyCode} to generate a unicode combined character.
*/
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
// Tell Android to start tracking this event.
getKeyDispatcherState().startTracking(event, this);
@@ -987,6 +987,7 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC
* @return The view matching the accessibility id if any.
*/
@SuppressLint("SoonBlockedPrivateApi")
@Nullable
public View findViewByAccessibilityIdTraversal(int accessibilityId) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
return findViewByAccessibilityIdRootedAtCurrentView(accessibilityId, this);
@@ -1333,7 +1334,7 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC
});
}
public void attachOverlaySurfaceToRender(FlutterImageView view) {
public void attachOverlaySurfaceToRender(@NonNull FlutterImageView view) {
if (flutterEngine != null) {
view.attachToRenderer(flutterEngine.getRenderer());
}
@@ -1434,13 +1435,13 @@ public class FlutterView extends FrameLayout implements MouseCursorPlugin.MouseC
}
@Override
public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
public void onProvideAutofillVirtualStructure(@NonNull ViewStructure structure, int flags) {
super.onProvideAutofillVirtualStructure(structure, flags);
textInputPlugin.onProvideAutofillVirtualStructure(structure, flags);
}
@Override
public void autofill(SparseArray<AutofillValue> values) {
public void autofill(@NonNull SparseArray<AutofillValue> values) {
textInputPlugin.autofill(values);
}

View File

@@ -79,7 +79,9 @@ public class KeyboardManager {
* dispatched to.
*/
public KeyboardManager(
View view, @NonNull TextInputPlugin textInputPlugin, Responder[] responders) {
@NonNull View view,
@NonNull TextInputPlugin textInputPlugin,
@NonNull Responder[] responders) {
this.view = view;
this.textInputPlugin = textInputPlugin;
this.responders = responders;
@@ -103,7 +105,7 @@ public class KeyboardManager {
*/
interface Responder {
interface OnKeyEventHandledCallback {
void onKeyEventHandled(Boolean canHandleEvent);
void onKeyEventHandled(boolean canHandleEvent);
}
/**
@@ -122,7 +124,7 @@ public class KeyboardManager {
boolean isCalled = false;
@Override
public void onKeyEventHandled(Boolean canHandleEvent) {
public void onKeyEventHandled(boolean canHandleEvent) {
if (isCalled) {
throw new IllegalStateException(
"The onKeyEventHandledCallback should be called exactly once.");
@@ -140,7 +142,7 @@ public class KeyboardManager {
this.keyEvent = keyEvent;
}
@NonNull final KeyEvent keyEvent;
final KeyEvent keyEvent;
int unrepliedCount = responders.length;
boolean isEventHandled = false;
@@ -149,9 +151,9 @@ public class KeyboardManager {
}
}
@NonNull protected final Responder[] responders;
@NonNull private final HashSet<KeyEvent> redispatchedEvents = new HashSet<>();
@NonNull private final TextInputPlugin textInputPlugin;
protected final Responder[] responders;
private final HashSet<KeyEvent> redispatchedEvents = new HashSet<>();
private final TextInputPlugin textInputPlugin;
private final View view;
public boolean handleEvent(@NonNull KeyEvent keyEvent) {

View File

@@ -2,6 +2,7 @@ package io.flutter.embedding.android;
import android.util.LongSparseArray;
import android.view.MotionEvent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.PriorityQueue;
import java.util.concurrent.atomic.AtomicLong;
@@ -18,10 +19,12 @@ public final class MotionEventTracker {
this.id = id;
}
@NonNull
public static MotionEventId from(long id) {
return new MotionEventId(id);
}
@NonNull
public static MotionEventId createUnique() {
return MotionEventId.from(ID_COUNTER.incrementAndGet());
}
@@ -35,6 +38,7 @@ public final class MotionEventTracker {
private final PriorityQueue<Long> unusedEvents;
private static MotionEventTracker INSTANCE;
@NonNull
public static MotionEventTracker getInstance() {
if (INSTANCE == null) {
INSTANCE = new MotionEventTracker();
@@ -48,7 +52,8 @@ public final class MotionEventTracker {
}
/** Tracks the event and returns a unique MotionEventId identifying the event. */
public MotionEventId track(MotionEvent event) {
@NonNull
public MotionEventId track(@NonNull MotionEvent event) {
MotionEventId eventId = MotionEventId.createUnique();
eventById.put(eventId.id, MotionEvent.obtain(event));
unusedEvents.add(eventId.id);
@@ -61,7 +66,7 @@ public final class MotionEventTracker {
* popped or discarded.
*/
@Nullable
public MotionEvent pop(MotionEventId eventId) {
public MotionEvent pop(@NonNull MotionEventId eventId) {
// remove all the older events.
while (!unusedEvents.isEmpty() && unusedEvents.peek() < eventId.id) {
eventById.remove(unusedEvents.poll());

View File

@@ -66,7 +66,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
private class FeatureInstallStateUpdatedListener implements SplitInstallStateUpdatedListener {
@SuppressLint("DefaultLocale")
public void onStateUpdate(SplitInstallSessionState state) {
public void onStateUpdate(@NonNull SplitInstallSessionState state) {
int sessionId = state.sessionId();
if (sessionIdToName.get(sessionId) != null) {
switch (state.status()) {
@@ -231,7 +231,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
return true;
}
public void setDeferredComponentChannel(DeferredComponentChannel channel) {
public void setDeferredComponentChannel(@NonNull DeferredComponentChannel channel) {
this.channel = channel;
}
@@ -288,7 +288,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
}
}
public void installDeferredComponent(int loadingUnitId, String componentName) {
public void installDeferredComponent(int loadingUnitId, @Nullable String componentName) {
String resolvedComponentName =
componentName != null ? componentName : loadingUnitIdToComponentNames.get(loadingUnitId);
if (resolvedComponentName == null) {
@@ -357,7 +357,9 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
});
}
public String getDeferredComponentInstallState(int loadingUnitId, String componentName) {
@NonNull
public String getDeferredComponentInstallState(
int loadingUnitId, @Nullable String componentName) {
String resolvedComponentName =
componentName != null ? componentName : loadingUnitIdToComponentNames.get(loadingUnitId);
if (resolvedComponentName == null) {
@@ -375,7 +377,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
return sessionIdToState.get(sessionId);
}
public void loadAssets(int loadingUnitId, String componentName) {
public void loadAssets(int loadingUnitId, @NonNull String componentName) {
if (!verifyJNI()) {
return;
}
@@ -393,7 +395,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
}
}
public void loadDartLibrary(int loadingUnitId, String componentName) {
public void loadDartLibrary(int loadingUnitId, @NonNull String componentName) {
if (!verifyJNI()) {
return;
}
@@ -478,7 +480,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
loadingUnitId, searchPaths.toArray(new String[searchPaths.size()]));
}
public boolean uninstallDeferredComponent(int loadingUnitId, String componentName) {
public boolean uninstallDeferredComponent(int loadingUnitId, @Nullable String componentName) {
String resolvedComponentName =
componentName != null ? componentName : loadingUnitIdToComponentNames.get(loadingUnitId);
if (resolvedComponentName == null) {

View File

@@ -48,7 +48,8 @@ public class ShimPluginRegistry implements PluginRegistry {
}
@Override
public Registrar registrarFor(String pluginKey) {
@NonNull
public Registrar registrarFor(@NonNull String pluginKey) {
Log.v(TAG, "Creating plugin Registrar for '" + pluginKey + "'");
if (pluginMap.containsKey(pluginKey)) {
throw new IllegalStateException("Plugin key " + pluginKey + " is already in use");
@@ -60,13 +61,13 @@ public class ShimPluginRegistry implements PluginRegistry {
}
@Override
public boolean hasPlugin(String pluginKey) {
public boolean hasPlugin(@NonNull String pluginKey) {
return pluginMap.containsKey(pluginKey);
}
@Override
@SuppressWarnings("unchecked")
public <T> T valuePublishedByPlugin(String pluginKey) {
public <T> T valuePublishedByPlugin(@NonNull String pluginKey) {
return (T) pluginMap.get(pluginKey);
}

View File

@@ -86,7 +86,7 @@ public class SurfaceTextureWrapper {
// Called by native.
@SuppressWarnings("unused")
public void getTransformMatrix(float[] mtx) {
public void getTransformMatrix(@NonNull float[] mtx) {
surfaceTexture.getTransformMatrix(mtx);
}
}

View File

@@ -110,6 +110,7 @@ public class LocalizationChannel {
* The Flutter application would like to obtain the string resource of given {@code key} in
* {@code locale}.
*/
String getStringResource(@NonNull String key, String locale);
@NonNull
String getStringResource(@NonNull String key, @NonNull String locale);
}
}

View File

@@ -5,6 +5,7 @@
package io.flutter.embedding.engine.systemchannels;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.Log;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugin.common.MethodCall;
@@ -72,12 +73,13 @@ public class RestorationChannel {
private boolean frameworkHasRequestedData = false;
/** Obtain the most current restoration data that the framework has provided. */
@Nullable
public byte[] getRestorationData() {
return restorationData;
}
/** Set the restoration data from which the framework will restore its state. */
public void setRestorationData(byte[] data) {
public void setRestorationData(@NonNull byte[] data) {
engineHasProvidedData = true;
if (pendingFrameworkRestorationChannelRequest != null) {
// If their is a pending request from the framework, answer it.

View File

@@ -203,7 +203,7 @@ public class TextInputChannel {
*/
public void updateEditingState(
int inputClientId,
String text,
@NonNull String text,
int selectionStart,
int selectionEnd,
int composingStart,
@@ -233,7 +233,7 @@ public class TextInputChannel {
}
public void updateEditingStateWithDeltas(
int inputClientId, ArrayList<TextEditingDelta> batchDeltas) {
int inputClientId, @NonNull ArrayList<TextEditingDelta> batchDeltas) {
Log.v(
TAG,
@@ -248,7 +248,7 @@ public class TextInputChannel {
}
public void updateEditingStateWithTag(
int inputClientId, HashMap<String, TextEditState> editStates) {
int inputClientId, @NonNull HashMap<String, TextEditState> editStates) {
Log.v(
TAG,
"Sending message to update editing state for "
@@ -323,7 +323,8 @@ public class TextInputChannel {
Arrays.asList(inputClientId, "TextInputAction.unspecified"));
}
public void performPrivateCommand(int inputClientId, String action, Bundle data) {
public void performPrivateCommand(
int inputClientId, @NonNull String action, @NonNull Bundle data) {
HashMap<Object, Object> json = new HashMap<>();
json.put("action", action);
if (data != null) {
@@ -411,7 +412,7 @@ public class TextInputChannel {
* @param transform a 4x4 matrix that maps the local paint coordinate system to coordinate
* system of the FlutterView that owns the current client.
*/
void setEditableSizeAndTransform(double width, double height, double[] transform);
void setEditableSizeAndTransform(double width, double height, @NonNull double[] transform);
// TODO(mattcarroll): javadoc
void setEditingState(@NonNull TextEditState editingState);
@@ -428,11 +429,12 @@ public class TextInputChannel {
* commands.
* @param data Any data to include with the command.
*/
void sendAppPrivateCommand(String action, Bundle data);
void sendAppPrivateCommand(@NonNull String action, @NonNull Bundle data);
}
/** A text editing configuration. */
public static class Configuration {
@NonNull
public static Configuration fromJson(@NonNull JSONObject json)
throws JSONException, NoSuchFieldException {
final String inputActionName = json.getString("inputAction");
@@ -490,6 +492,7 @@ public class TextInputChannel {
}
public static class Autofill {
@NonNull
public static Autofill fromJson(@NonNull JSONObject json)
throws JSONException, NoSuchFieldException {
final String uniqueIdentifier = json.getString("uniqueIdentifier");
@@ -725,6 +728,7 @@ public class TextInputChannel {
/** State of an on-going text editing session. */
public static class TextEditState {
@NonNull
public static TextEditState fromJson(@NonNull JSONObject textEditState) throws JSONException {
return new TextEditState(
textEditState.getString("text"),

View File

@@ -4,6 +4,7 @@
package io.flutter.plugin.common;
import androidx.annotation.Nullable;
import java.nio.ByteBuffer;
import org.json.JSONException;
import org.json.JSONObject;
@@ -28,7 +29,8 @@ public final class JSONMessageCodec implements MessageCodec<Object> {
private JSONMessageCodec() {}
@Override
public ByteBuffer encodeMessage(Object message) {
@Nullable
public ByteBuffer encodeMessage(@Nullable Object message) {
if (message == null) {
return null;
}
@@ -41,7 +43,8 @@ public final class JSONMessageCodec implements MessageCodec<Object> {
}
@Override
public Object decodeMessage(ByteBuffer message) {
@Nullable
public Object decodeMessage(@Nullable ByteBuffer message) {
if (message == null) {
return null;
}

View File

@@ -4,6 +4,8 @@
package io.flutter.plugin.common;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.nio.ByteBuffer;
import org.json.JSONArray;
import org.json.JSONException;
@@ -26,7 +28,8 @@ public final class JSONMethodCodec implements MethodCodec {
private JSONMethodCodec() {}
@Override
public ByteBuffer encodeMethodCall(MethodCall methodCall) {
@NonNull
public ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall) {
try {
final JSONObject map = new JSONObject();
map.put("method", methodCall.method);
@@ -38,7 +41,8 @@ public final class JSONMethodCodec implements MethodCodec {
}
@Override
public MethodCall decodeMethodCall(ByteBuffer message) {
@NonNull
public MethodCall decodeMethodCall(@NonNull ByteBuffer message) {
try {
final Object json = JSONMessageCodec.INSTANCE.decodeMessage(message);
if (json instanceof JSONObject) {
@@ -56,13 +60,15 @@ public final class JSONMethodCodec implements MethodCodec {
}
@Override
public ByteBuffer encodeSuccessEnvelope(Object result) {
@NonNull
public ByteBuffer encodeSuccessEnvelope(@Nullable Object result) {
return JSONMessageCodec.INSTANCE.encodeMessage(new JSONArray().put(JSONUtil.wrap(result)));
}
@Override
@NonNull
public ByteBuffer encodeErrorEnvelope(
String errorCode, String errorMessage, Object errorDetails) {
@NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) {
return JSONMessageCodec.INSTANCE.encodeMessage(
new JSONArray()
.put(errorCode)
@@ -71,8 +77,12 @@ public final class JSONMethodCodec implements MethodCodec {
}
@Override
@NonNull
public ByteBuffer encodeErrorEnvelopeWithStacktrace(
String errorCode, String errorMessage, Object errorDetails, String errorStacktrace) {
@NonNull String errorCode,
@Nullable String errorMessage,
@Nullable Object errorDetails,
@Nullable String errorStacktrace) {
return JSONMessageCodec.INSTANCE.encodeMessage(
new JSONArray()
.put(errorCode)
@@ -82,7 +92,8 @@ public final class JSONMethodCodec implements MethodCodec {
}
@Override
public Object decodeEnvelope(ByteBuffer envelope) {
@NonNull
public Object decodeEnvelope(@NonNull ByteBuffer envelope) {
try {
final Object json = JSONMessageCodec.INSTANCE.decodeMessage(envelope);
if (json instanceof JSONArray) {

View File

@@ -1,5 +1,6 @@
package io.flutter.plugin.common;
import androidx.annotation.Nullable;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
@@ -17,7 +18,8 @@ public class JSONUtil {
* Convert the Json java representation to Java objects. Particularly used for converting
* JSONArray and JSONObject to Lists and Maps.
*/
public static Object unwrap(Object o) {
@Nullable
public static Object unwrap(@Nullable Object o) {
if (JSONObject.NULL.equals(o) || o == null) {
return null;
}
@@ -57,7 +59,8 @@ public class JSONUtil {
}
/** Backport of {@link JSONObject#wrap(Object)} for use on pre-KitKat systems. */
public static Object wrap(Object o) {
@Nullable
public static Object wrap(@Nullable Object o) {
if (o == null) {
return JSONObject.NULL;
}

View File

@@ -4,6 +4,7 @@
package io.flutter.plugin.common;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.BuildConfig;
import java.util.Map;
@@ -27,9 +28,10 @@ public final class MethodCall {
* Creates a {@link MethodCall} with the specified method name and arguments.
*
* @param method the method name String, not null.
* @param arguments the arguments, a value supported by the channel's message codec.
* @param arguments the arguments, a value supported by the channel's message codec. Possibly,
* null.
*/
public MethodCall(String method, Object arguments) {
public MethodCall(@NonNull String method, @Nullable Object arguments) {
if (BuildConfig.DEBUG && method == null) {
throw new AssertionError("Parameter method must not be null.");
}
@@ -44,6 +46,7 @@ public final class MethodCall {
* @return the arguments with static type T
*/
@SuppressWarnings("unchecked")
@Nullable
public <T> T arguments() {
return (T) arguments;
}
@@ -62,7 +65,7 @@ public final class MethodCall {
*/
@SuppressWarnings("unchecked")
@Nullable
public <T> T argument(String key) {
public <T> T argument(@NonNull String key) {
if (arguments == null) {
return null;
} else if (arguments instanceof Map) {
@@ -85,7 +88,7 @@ public final class MethodCall {
* @throws ClassCastException if {@link #arguments} can be cast to neither {@link Map} nor {@link
* JSONObject}.
*/
public boolean hasArgument(String key) {
public boolean hasArgument(@NonNull String key) {
if (arguments == null) {
return false;
} else if (arguments instanceof Map) {

View File

@@ -44,7 +44,7 @@ public class MethodChannel {
* @param messenger a {@link BinaryMessenger}.
* @param name a channel name String.
*/
public MethodChannel(BinaryMessenger messenger, String name) {
public MethodChannel(@NonNull BinaryMessenger messenger, @NonNull String name) {
this(messenger, name, StandardMethodCodec.INSTANCE);
}
@@ -56,7 +56,8 @@ public class MethodChannel {
* @param name a channel name String.
* @param codec a {@link MessageCodec}.
*/
public MethodChannel(BinaryMessenger messenger, String name, MethodCodec codec) {
public MethodChannel(
@NonNull BinaryMessenger messenger, @NonNull String name, @NonNull MethodCodec codec) {
this(messenger, name, codec, null);
}
@@ -72,9 +73,9 @@ public class MethodChannel {
* BinaryMessenger#makeBackgroundTaskQueue()}.
*/
public MethodChannel(
BinaryMessenger messenger,
String name,
MethodCodec codec,
@NonNull BinaryMessenger messenger,
@NonNull String name,
@NonNull MethodCodec codec,
@Nullable BinaryMessenger.TaskQueue taskQueue) {
if (BuildConfig.DEBUG) {
if (messenger == null) {
@@ -114,7 +115,8 @@ public class MethodChannel {
* @param callback a {@link Result} callback for the invocation result, or null.
*/
@UiThread
public void invokeMethod(String method, @Nullable Object arguments, @Nullable Result callback) {
public void invokeMethod(
@NonNull String method, @Nullable Object arguments, @Nullable Result callback) {
messenger.send(
name,
codec.encodeMethodCall(new MethodCall(method, arguments)),
@@ -212,7 +214,8 @@ public class MethodChannel {
* supported by the codec. For instance, if you are using {@link StandardMessageCodec}
* (default), please see its documentation on what types are supported.
*/
void error(String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails);
void error(
@NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails);
/** Handles a call to an unimplemented method. */
void notImplemented();

View File

@@ -4,6 +4,8 @@
package io.flutter.plugin.common;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.nio.ByteBuffer;
/**
@@ -23,7 +25,8 @@ public interface MethodCodec {
* @return a {@link ByteBuffer} containing the encoding between position 0 and the current
* position.
*/
ByteBuffer encodeMethodCall(MethodCall methodCall);
@NonNull
ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall);
/**
* Decodes a message call from binary.
@@ -32,7 +35,8 @@ public interface MethodCodec {
* @return a {@link MethodCall} representation of the bytes between the given buffer's current
* position and its limit.
*/
MethodCall decodeMethodCall(ByteBuffer methodCall);
@NonNull
MethodCall decodeMethodCall(@NonNull ByteBuffer methodCall);
/**
* Encodes a successful result into a binary envelope message.
@@ -41,7 +45,8 @@ public interface MethodCodec {
* @return a {@link ByteBuffer} containing the encoding between position 0 and the current
* position.
*/
ByteBuffer encodeSuccessEnvelope(Object result);
@NonNull
ByteBuffer encodeSuccessEnvelope(@Nullable Object result);
/**
* Encodes an error result into a binary envelope message.
@@ -53,7 +58,9 @@ public interface MethodCodec {
* @return a {@link ByteBuffer} containing the encoding between position 0 and the current
* position.
*/
ByteBuffer encodeErrorEnvelope(String errorCode, String errorMessage, Object errorDetails);
@NonNull
ByteBuffer encodeErrorEnvelope(
@NonNull String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails);
/**
* Encodes an error result into a binary envelope message with the native stacktrace.
@@ -66,8 +73,12 @@ public interface MethodCodec {
* @return a {@link ByteBuffer} containing the encoding between position 0 and the current
* position.
*/
@NonNull
ByteBuffer encodeErrorEnvelopeWithStacktrace(
String errorCode, String errorMessage, Object errorDetails, String errorStacktrace);
@NonNull String errorCode,
@Nullable String errorMessage,
@Nullable Object errorDetails,
@Nullable String errorStacktrace);
/**
* Decodes a result envelope from binary.
@@ -76,5 +87,6 @@ public interface MethodCodec {
* @return the enveloped result Object.
* @throws FlutterException if the envelope was an error envelope.
*/
Object decodeEnvelope(ByteBuffer envelope);
@NonNull
Object decodeEnvelope(@NonNull ByteBuffer envelope);
}

View File

@@ -7,6 +7,8 @@ package io.flutter.plugin.common;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
@@ -36,7 +38,8 @@ public interface PluginRegistry {
* @deprecated See https://flutter.dev/go/android-project-migration for migration details.
*/
@Deprecated
Registrar registrarFor(String pluginKey);
@NonNull
Registrar registrarFor(@NonNull String pluginKey);
/**
* Returns whether the specified plugin is known to this registry.
@@ -47,7 +50,7 @@ public interface PluginRegistry {
* @deprecated See https://flutter.dev/go/android-project-migration for migration details.
*/
@Deprecated
boolean hasPlugin(String pluginKey);
boolean hasPlugin(@NonNull String pluginKey);
/**
* Returns the value published by the specified plugin, if any.
@@ -63,7 +66,8 @@ public interface PluginRegistry {
* @deprecated See https://flutter.dev/go/android-project-migration for migration details.
*/
@Deprecated
<T> T valuePublishedByPlugin(String pluginKey);
@Nullable
<T> T valuePublishedByPlugin(@NonNull String pluginKey);
/**
* Receiver of registrations from a single plugin.
@@ -95,6 +99,7 @@ public interface PluginRegistry {
* <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
* http://flutter.dev/go/android-plugin-migration
*/
@Nullable
Activity activity();
/**
@@ -107,6 +112,7 @@ public interface PluginRegistry {
* <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
* http://flutter.dev/go/android-plugin-migration
*/
@NonNull
Context context();
/**
@@ -122,6 +128,7 @@ public interface PluginRegistry {
* @return the current {@link #activity() Activity}, if not null, otherwise the {@link
* #context() Application}.
*/
@NonNull
Context activeContext();
/**
@@ -135,6 +142,7 @@ public interface PluginRegistry {
* <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
* http://flutter.dev/go/android-plugin-migration
*/
@NonNull
BinaryMessenger messenger();
/**
@@ -147,6 +155,7 @@ public interface PluginRegistry {
* <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
* http://flutter.dev/go/android-plugin-migration
*/
@NonNull
TextureRegistry textures();
/**
@@ -161,6 +170,7 @@ public interface PluginRegistry {
* <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
* http://flutter.dev/go/android-plugin-migration
*/
@NonNull
PlatformViewRegistry platformViewRegistry();
/**
@@ -176,6 +186,7 @@ public interface PluginRegistry {
* <p>For instructions on migrating a plugin from Flutter's v1 Android embedding to v2, visit
* http://flutter.dev/go/android-plugin-migration
*/
@NonNull
FlutterView view();
/**
@@ -187,7 +198,8 @@ public interface PluginRegistry {
* @param asset the name of the asset. The name can be hierarchical
* @return the filename to be used with {@link android.content.res.AssetManager}
*/
String lookupKeyForAsset(String asset);
@NonNull
String lookupKeyForAsset(@NonNull String asset);
/**
* Returns the file name for the given asset which originates from the specified packageName.
@@ -200,7 +212,8 @@ public interface PluginRegistry {
* @param packageName the name of the package from which the asset originates
* @return the file name to be used with {@link android.content.res.AssetManager}
*/
String lookupKeyForAsset(String asset, String packageName);
@NonNull
String lookupKeyForAsset(@NonNull String asset, @NonNull String packageName);
/**
* Publishes a value associated with the plugin being registered.
@@ -222,7 +235,8 @@ public interface PluginRegistry {
* @param value the value, possibly null.
* @return this {@link Registrar}.
*/
Registrar publish(Object value);
@NonNull
Registrar publish(@Nullable Object value);
/**
* Adds a callback allowing the plugin to take part in handling incoming calls to {@code
@@ -240,7 +254,9 @@ public interface PluginRegistry {
* @param listener a {@link RequestPermissionsResultListener} callback.
* @return this {@link Registrar}.
*/
Registrar addRequestPermissionsResultListener(RequestPermissionsResultListener listener);
@NonNull
Registrar addRequestPermissionsResultListener(
@NonNull RequestPermissionsResultListener listener);
/**
* Adds a callback allowing the plugin to take part in handling incoming calls to {@link
@@ -256,7 +272,8 @@ public interface PluginRegistry {
* @param listener an {@link ActivityResultListener} callback.
* @return this {@link Registrar}.
*/
Registrar addActivityResultListener(ActivityResultListener listener);
@NonNull
Registrar addActivityResultListener(@NonNull ActivityResultListener listener);
/**
* Adds a callback allowing the plugin to take part in handling incoming calls to {@link
@@ -272,7 +289,8 @@ public interface PluginRegistry {
* @param listener a {@link NewIntentListener} callback.
* @return this {@link Registrar}.
*/
Registrar addNewIntentListener(NewIntentListener listener);
@NonNull
Registrar addNewIntentListener(@NonNull NewIntentListener listener);
/**
* Adds a callback allowing the plugin to take part in handling incoming calls to {@link
@@ -288,7 +306,8 @@ public interface PluginRegistry {
* @param listener a {@link UserLeaveHintListener} callback.
* @return this {@link Registrar}.
*/
Registrar addUserLeaveHintListener(UserLeaveHintListener listener);
@NonNull
Registrar addUserLeaveHintListener(@NonNull UserLeaveHintListener listener);
/**
* Adds a callback allowing the plugin to take part in handling incoming calls to {@link
@@ -312,7 +331,8 @@ public interface PluginRegistry {
*/
// TODO(amirh): Add a line in the javadoc above that points to a Platform Views website guide
// when one is available (but not a website API doc)
Registrar addViewDestroyListener(ViewDestroyListener listener);
@NonNull
Registrar addViewDestroyListener(@NonNull ViewDestroyListener listener);
}
/**
@@ -328,7 +348,8 @@ public interface PluginRegistry {
* {@code PackageManager.PERMISSION_GRANTED} or {@code PackageManager.PERMISSION_DENIED}.
* @return true if the result has been handled.
*/
boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults);
boolean onRequestPermissionsResult(
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults);
}
/**
@@ -345,7 +366,7 @@ public interface PluginRegistry {
* attached to Intent "extras").
* @return true if the result has been handled.
*/
boolean onActivityResult(int requestCode, int resultCode, Intent data);
boolean onActivityResult(int requestCode, int resultCode, @NonNull Intent data);
}
/**
@@ -356,7 +377,7 @@ public interface PluginRegistry {
* @param intent The new intent that was started for the activity.
* @return true if the new intent has been handled.
*/
boolean onNewIntent(Intent intent);
boolean onNewIntent(@NonNull Intent intent);
}
/**
@@ -376,7 +397,7 @@ public interface PluginRegistry {
*/
@Deprecated
interface ViewDestroyListener {
boolean onViewDestroy(FlutterNativeView view);
boolean onViewDestroy(@NonNull FlutterNativeView view);
}
/**
@@ -389,6 +410,6 @@ public interface PluginRegistry {
*/
@Deprecated
interface PluginRegistrantCallback {
void registerWith(PluginRegistry registry);
void registerWith(@NonNull PluginRegistry registry);
}
}

View File

@@ -4,6 +4,8 @@
package io.flutter.plugin.common;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.BuildConfig;
import io.flutter.Log;
import java.io.ByteArrayOutputStream;
@@ -65,7 +67,8 @@ public class StandardMessageCodec implements MessageCodec<Object> {
public static final StandardMessageCodec INSTANCE = new StandardMessageCodec();
@Override
public ByteBuffer encodeMessage(Object message) {
@Nullable
public ByteBuffer encodeMessage(@Nullable Object message) {
if (message == null) {
return null;
}
@@ -77,7 +80,8 @@ public class StandardMessageCodec implements MessageCodec<Object> {
}
@Override
public Object decodeMessage(ByteBuffer message) {
@Nullable
public Object decodeMessage(@Nullable ByteBuffer message) {
if (message == null) {
return null;
}
@@ -111,7 +115,7 @@ public class StandardMessageCodec implements MessageCodec<Object> {
* Writes an int representing a size to the specified stream. Uses an expanding code of 1 to 5
* bytes to optimize for small values.
*/
protected static final void writeSize(ByteArrayOutputStream stream, int value) {
protected static final void writeSize(@NonNull ByteArrayOutputStream stream, int value) {
if (BuildConfig.DEBUG && 0 > value) {
Log.e(TAG, "Attempted to write a negative size.");
}
@@ -127,7 +131,7 @@ public class StandardMessageCodec implements MessageCodec<Object> {
}
/** Writes the least significant two bytes of the specified int to the specified stream. */
protected static final void writeChar(ByteArrayOutputStream stream, int value) {
protected static final void writeChar(@NonNull ByteArrayOutputStream stream, int value) {
if (LITTLE_ENDIAN) {
stream.write(value);
stream.write(value >>> 8);
@@ -138,7 +142,7 @@ public class StandardMessageCodec implements MessageCodec<Object> {
}
/** Writes the specified int as 4 bytes to the specified stream. */
protected static final void writeInt(ByteArrayOutputStream stream, int value) {
protected static final void writeInt(@NonNull ByteArrayOutputStream stream, int value) {
if (LITTLE_ENDIAN) {
stream.write(value);
stream.write(value >>> 8);
@@ -153,7 +157,7 @@ public class StandardMessageCodec implements MessageCodec<Object> {
}
/** Writes the specified long as 8 bytes to the specified stream. */
protected static final void writeLong(ByteArrayOutputStream stream, long value) {
protected static final void writeLong(@NonNull ByteArrayOutputStream stream, long value) {
if (LITTLE_ENDIAN) {
stream.write((byte) value);
stream.write((byte) (value >>> 8));
@@ -176,17 +180,18 @@ public class StandardMessageCodec implements MessageCodec<Object> {
}
/** Writes the specified double as 4 bytes to the specified stream */
protected static final void writeFloat(ByteArrayOutputStream stream, float value) {
protected static final void writeFloat(@NonNull ByteArrayOutputStream stream, float value) {
writeInt(stream, Float.floatToIntBits(value));
}
/** Writes the specified double as 8 bytes to the specified stream. */
protected static final void writeDouble(ByteArrayOutputStream stream, double value) {
protected static final void writeDouble(@NonNull ByteArrayOutputStream stream, double value) {
writeLong(stream, Double.doubleToLongBits(value));
}
/** Writes the length and then the actual bytes of the specified array to the specified stream. */
protected static final void writeBytes(ByteArrayOutputStream stream, byte[] bytes) {
protected static final void writeBytes(
@NonNull ByteArrayOutputStream stream, @NonNull byte[] bytes) {
writeSize(stream, bytes.length);
stream.write(bytes, 0, bytes.length);
}
@@ -196,7 +201,7 @@ public class StandardMessageCodec implements MessageCodec<Object> {
* aligned to a whole multiple of the specified alignment. An example usage with alignment = 8 is
* to ensure doubles are word-aligned in the stream.
*/
protected static final void writeAlignment(ByteArrayOutputStream stream, int alignment) {
protected static final void writeAlignment(@NonNull ByteArrayOutputStream stream, int alignment) {
final int mod = stream.size() % alignment;
if (mod != 0) {
for (int i = 0; i < alignment - mod; i++) {
@@ -212,7 +217,7 @@ public class StandardMessageCodec implements MessageCodec<Object> {
* <p>Subclasses can extend the codec by overriding this method, calling super for values that the
* extension does not handle.
*/
protected void writeValue(ByteArrayOutputStream stream, Object value) {
protected void writeValue(@NonNull ByteArrayOutputStream stream, @NonNull Object value) {
if (value == null || value.equals(null)) {
stream.write(NULL);
} else if (value instanceof Boolean) {
@@ -294,7 +299,7 @@ public class StandardMessageCodec implements MessageCodec<Object> {
}
/** Reads an int representing a size as written by writeSize. */
protected static final int readSize(ByteBuffer buffer) {
protected static final int readSize(@NonNull ByteBuffer buffer) {
if (!buffer.hasRemaining()) {
throw new IllegalArgumentException("Message corrupted");
}
@@ -309,7 +314,8 @@ public class StandardMessageCodec implements MessageCodec<Object> {
}
/** Reads a byte array as written by writeBytes. */
protected static final byte[] readBytes(ByteBuffer buffer) {
@NonNull
protected static final byte[] readBytes(@NonNull ByteBuffer buffer) {
final int length = readSize(buffer);
final byte[] bytes = new byte[length];
buffer.get(bytes);
@@ -317,7 +323,7 @@ public class StandardMessageCodec implements MessageCodec<Object> {
}
/** Reads alignment padding bytes as written by writeAlignment. */
protected static final void readAlignment(ByteBuffer buffer, int alignment) {
protected static final void readAlignment(@NonNull ByteBuffer buffer, int alignment) {
final int mod = buffer.position() % alignment;
if (mod != 0) {
buffer.position(buffer.position() + alignment - mod);
@@ -325,7 +331,8 @@ public class StandardMessageCodec implements MessageCodec<Object> {
}
/** Reads a value as written by writeValue. */
protected final Object readValue(ByteBuffer buffer) {
@NonNull
protected final Object readValue(@NonNull ByteBuffer buffer) {
if (!buffer.hasRemaining()) {
throw new IllegalArgumentException("Message corrupted");
}
@@ -339,7 +346,8 @@ public class StandardMessageCodec implements MessageCodec<Object> {
* <p>Subclasses may extend the codec by overriding this method, calling super for types that the
* extension does not handle.
*/
protected Object readValueOfType(byte type, ByteBuffer buffer) {
@Nullable
protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
final Object result;
switch (type) {
case NULL:

View File

@@ -4,6 +4,7 @@
package io.flutter.plugin.common;
import androidx.annotation.NonNull;
import io.flutter.plugin.common.StandardMessageCodec.ExposedByteArrayOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -27,12 +28,13 @@ public final class StandardMethodCodec implements MethodCodec {
private final StandardMessageCodec messageCodec;
/** Creates a new method codec based on the specified message codec. */
public StandardMethodCodec(StandardMessageCodec messageCodec) {
public StandardMethodCodec(@NonNull StandardMessageCodec messageCodec) {
this.messageCodec = messageCodec;
}
@Override
public ByteBuffer encodeMethodCall(MethodCall methodCall) {
@NonNull
public ByteBuffer encodeMethodCall(@NonNull MethodCall methodCall) {
final ExposedByteArrayOutputStream stream = new ExposedByteArrayOutputStream();
messageCodec.writeValue(stream, methodCall.method);
messageCodec.writeValue(stream, methodCall.arguments);
@@ -42,7 +44,8 @@ public final class StandardMethodCodec implements MethodCodec {
}
@Override
public MethodCall decodeMethodCall(ByteBuffer methodCall) {
@NonNull
public MethodCall decodeMethodCall(@NonNull ByteBuffer methodCall) {
methodCall.order(ByteOrder.nativeOrder());
final Object method = messageCodec.readValue(methodCall);
final Object arguments = messageCodec.readValue(methodCall);
@@ -53,7 +56,8 @@ public final class StandardMethodCodec implements MethodCodec {
}
@Override
public ByteBuffer encodeSuccessEnvelope(Object result) {
@NonNull
public ByteBuffer encodeSuccessEnvelope(@NonNull Object result) {
final ExposedByteArrayOutputStream stream = new ExposedByteArrayOutputStream();
stream.write(0);
messageCodec.writeValue(stream, result);
@@ -63,8 +67,9 @@ public final class StandardMethodCodec implements MethodCodec {
}
@Override
@NonNull
public ByteBuffer encodeErrorEnvelope(
String errorCode, String errorMessage, Object errorDetails) {
@NonNull String errorCode, @NonNull String errorMessage, @NonNull Object errorDetails) {
final ExposedByteArrayOutputStream stream = new ExposedByteArrayOutputStream();
stream.write(1);
messageCodec.writeValue(stream, errorCode);
@@ -80,8 +85,12 @@ public final class StandardMethodCodec implements MethodCodec {
}
@Override
@NonNull
public ByteBuffer encodeErrorEnvelopeWithStacktrace(
String errorCode, String errorMessage, Object errorDetails, String errorStacktrace) {
@NonNull String errorCode,
@NonNull String errorMessage,
@NonNull Object errorDetails,
@NonNull String errorStacktrace) {
final ExposedByteArrayOutputStream stream = new ExposedByteArrayOutputStream();
stream.write(1);
messageCodec.writeValue(stream, errorCode);
@@ -98,7 +107,8 @@ public final class StandardMethodCodec implements MethodCodec {
}
@Override
public Object decodeEnvelope(ByteBuffer envelope) {
@NonNull
public Object decodeEnvelope(@NonNull ByteBuffer envelope) {
envelope.order(ByteOrder.nativeOrder());
final byte flag = envelope.get();
switch (flag) {
@@ -125,7 +135,8 @@ public final class StandardMethodCodec implements MethodCodec {
throw new IllegalArgumentException("Envelope corrupted");
}
private static String getStackTrace(Throwable t) {
@NonNull
private static String getStackTrace(@NonNull Throwable t) {
Writer result = new StringWriter();
t.printStackTrace(new PrintWriter(result));
return result.toString();

View File

@@ -4,6 +4,7 @@
package io.flutter.plugin.common;
import androidx.annotation.Nullable;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
@@ -21,7 +22,8 @@ public final class StringCodec implements MessageCodec<String> {
private StringCodec() {}
@Override
public ByteBuffer encodeMessage(String message) {
@Nullable
public ByteBuffer encodeMessage(@Nullable String message) {
if (message == null) {
return null;
}
@@ -33,7 +35,8 @@ public final class StringCodec implements MessageCodec<String> {
}
@Override
public String decodeMessage(ByteBuffer message) {
@Nullable
public String decodeMessage(@Nullable ByteBuffer message) {
if (message == null) {
return null;
}

View File

@@ -4,6 +4,7 @@
package io.flutter.plugin.editing;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import io.flutter.Log;
import org.json.JSONException;
@@ -12,8 +13,8 @@ import org.json.JSONObject;
/// A representation of the change that occured to an editing state, along with the resulting
/// composing and selection regions.
public final class TextEditingDelta {
private CharSequence oldText;
private CharSequence deltaText;
private @NonNull CharSequence oldText;
private @NonNull CharSequence deltaText;
private int deltaStart;
private int deltaEnd;
private int newSelectionStart;
@@ -24,10 +25,10 @@ public final class TextEditingDelta {
private static final String TAG = "TextEditingDelta";
public TextEditingDelta(
CharSequence oldEditable,
@NonNull CharSequence oldEditable,
int replacementDestinationStart,
int replacementDestinationEnd,
CharSequence replacementSource,
@NonNull CharSequence replacementSource,
int selectionStart,
int selectionEnd,
int composingStart,
@@ -46,7 +47,7 @@ public final class TextEditingDelta {
// Non text update delta constructor.
public TextEditingDelta(
CharSequence oldText,
@NonNull CharSequence oldText,
int selectionStart,
int selectionEnd,
int composingStart,
@@ -60,11 +61,13 @@ public final class TextEditingDelta {
}
@VisibleForTesting
@NonNull
public CharSequence getOldText() {
return oldText;
}
@VisibleForTesting
@NonNull
public CharSequence getDeltaText() {
return deltaText;
}
@@ -99,13 +102,15 @@ public final class TextEditingDelta {
return newComposingEnd;
}
private void setDeltas(CharSequence oldText, CharSequence newText, int newStart, int newExtent) {
private void setDeltas(
@NonNull CharSequence oldText, @NonNull CharSequence newText, int newStart, int newExtent) {
this.oldText = oldText;
deltaText = newText;
deltaStart = newStart;
deltaEnd = newExtent;
}
@NonNull
public JSONObject toJSON() {
JSONObject delta = new JSONObject();

View File

@@ -56,7 +56,7 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
@SuppressLint("NewApi")
public TextInputPlugin(
View view,
@NonNull View view,
@NonNull TextInputChannel textInputChannel,
@NonNull PlatformViewsController platformViewsController) {
mView = view;
@@ -251,8 +251,9 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
return textType;
}
@Nullable
public InputConnection createInputConnection(
View view, KeyboardManager keyboardManager, EditorInfo outAttrs) {
@NonNull View view, @NonNull KeyboardManager keyboardManager, @NonNull EditorInfo outAttrs) {
if (inputTarget.type == InputTarget.Type.NO_TARGET) {
lastInputConnection = null;
return null;
@@ -325,7 +326,7 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
}
}
public void sendTextInputAppPrivateCommand(String action, Bundle data) {
public void sendTextInputAppPrivateCommand(@NonNull String action, @NonNull Bundle data) {
mImm.sendAppPrivateCommand(mView, action, data);
}
@@ -506,7 +507,7 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
}
// -------- Start: KeyboardManager Synchronous Responder -------
public boolean handleKeyEvent(KeyEvent keyEvent) {
public boolean handleKeyEvent(@NonNull KeyEvent keyEvent) {
if (!getInputMethodManager().isAcceptingText() || lastInputConnection == null) {
return false;
}
@@ -664,7 +665,7 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
}
}
public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
public void onProvideAutofillVirtualStructure(@NonNull ViewStructure structure, int flags) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || !needsAutofill()) {
return;
}
@@ -708,7 +709,7 @@ public class TextInputPlugin implements ListenableEditingState.EditingStateWatch
}
}
public void autofill(SparseArray<AutofillValue> values) {
public void autofill(@NonNull SparseArray<AutofillValue> values) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}

View File

@@ -82,7 +82,8 @@ public class LocalizationPlugin {
* <p>FlutterEngine must be non-null when this method is invoked.
*/
@SuppressWarnings("deprecation")
public Locale resolveNativeLocale(List<Locale> supportedLocales) {
@Nullable
public Locale resolveNativeLocale(@Nullable List<Locale> supportedLocales) {
if (supportedLocales == null || supportedLocales.isEmpty()) {
return null;
}
@@ -188,7 +189,8 @@ public class LocalizationPlugin {
}
@VisibleForTesting
public static Locale localeFromString(String localeString) {
@NonNull
public static Locale localeFromString(@NonNull String localeString) {
// Use Locale.forLanguageTag if available (API 21+).
if (false && Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
return Locale.forLanguageTag(localeString);

View File

@@ -121,6 +121,7 @@ public class MouseCursorPlugin {
* <p>This is typically implemented by calling {@link android.view.PointerIcon#getSystemIcon}
* with the context associated with this view.
*/
@NonNull
public PointerIcon getSystemPointerIcon(int type);
/**

View File

@@ -131,12 +131,14 @@ public class PlatformPlugin {
}
};
public PlatformPlugin(Activity activity, PlatformChannel platformChannel) {
public PlatformPlugin(@NonNull Activity activity, @NonNull PlatformChannel platformChannel) {
this(activity, platformChannel, null);
}
public PlatformPlugin(
Activity activity, PlatformChannel platformChannel, PlatformPluginDelegate delegate) {
@NonNull Activity activity,
@NonNull PlatformChannel platformChannel,
@NonNull PlatformPluginDelegate delegate) {
this.activity = activity;
this.platformChannel = platformChannel;
this.platformChannel.setPlatformMessageHandler(mPlatformMessageHandler);
@@ -152,7 +154,7 @@ public class PlatformPlugin {
this.platformChannel.setPlatformMessageHandler(null);
}
private void playSystemSound(PlatformChannel.SoundType soundType) {
private void playSystemSound(@NonNull PlatformChannel.SoundType soundType) {
if (soundType == PlatformChannel.SoundType.CLICK) {
View view = activity.getWindow().getDecorView();
view.playSoundEffect(SoundEffectConstants.CLICK);
@@ -160,7 +162,8 @@ public class PlatformPlugin {
}
@VisibleForTesting
/* package */ void vibrateHapticFeedback(PlatformChannel.HapticFeedbackType feedbackType) {
/* package */ void vibrateHapticFeedback(
@NonNull PlatformChannel.HapticFeedbackType feedbackType) {
View view = activity.getWindow().getDecorView();
switch (feedbackType) {
case STANDARD:

View File

@@ -7,10 +7,12 @@ package io.flutter.plugin.platform;
import android.annotation.SuppressLint;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/** A handle to an Android view to be embedded in the Flutter hierarchy. */
public interface PlatformView {
/** Returns the Android view to be embedded in the Flutter hierarchy. */
@Nullable
View getView();
/**

View File

@@ -5,13 +5,15 @@
package io.flutter.plugin.platform;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.plugin.common.MessageCodec;
public abstract class PlatformViewFactory {
private final MessageCodec<Object> createArgsCodec;
/** @param createArgsCodec the codec used to decode the args parameter of {@link #create}. */
public PlatformViewFactory(MessageCodec<Object> createArgsCodec) {
public PlatformViewFactory(@Nullable MessageCodec<Object> createArgsCodec) {
this.createArgsCodec = createArgsCodec;
}
@@ -25,9 +27,11 @@ public abstract class PlatformViewFactory {
* createArgsCodec argument passed to the constructor. This is null if createArgsCodec was
* null, or no arguments were sent from the Flutter app.
*/
public abstract PlatformView create(Context context, int viewId, Object args);
@NonNull
public abstract PlatformView create(@Nullable Context context, int viewId, @Nullable Object args);
/** Returns the codec to be used for decoding the args parameter of {@link #create}. */
@Nullable
public final MessageCodec<Object> getCreateArgsCodec() {
return createArgsCodec;
}

View File

@@ -4,6 +4,8 @@
package io.flutter.plugin.platform;
import androidx.annotation.NonNull;
/**
* Registry for platform view factories.
*
@@ -18,5 +20,5 @@ public interface PlatformViewRegistry {
* @param factory factory for creating platform views of the specified type.
* @return true if succeeded, false if a factory is already registered for viewTypeId.
*/
boolean registerViewFactory(String viewTypeId, PlatformViewFactory factory);
boolean registerViewFactory(@NonNull String viewTypeId, @NonNull PlatformViewFactory factory);
}

View File

@@ -5,6 +5,7 @@
package io.flutter.plugin.platform;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.view.AccessibilityBridge;
@@ -23,7 +24,7 @@ public interface PlatformViewsAccessibilityDelegate {
* <p>Accessibility events originating in platform views belonging to this delegate will be
* delegated to this accessibility bridge.
*/
void attachAccessibilityBridge(AccessibilityBridge accessibilityBridge);
void attachAccessibilityBridge(@NonNull AccessibilityBridge accessibilityBridge);
/**
* Detaches the current accessibility bridge.

View File

@@ -449,7 +449,9 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
* @param dartExecutor The dart execution context, which is used to set up a system channel.
*/
public void attach(
Context context, TextureRegistry textureRegistry, @NonNull DartExecutor dartExecutor) {
@Nullable Context context,
@NonNull TextureRegistry textureRegistry,
@NonNull DartExecutor dartExecutor) {
if (this.context != null) {
throw new AssertionError(
"A PlatformViewsController can only be attached to a single output target.\n"
@@ -516,7 +518,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
}
@Override
public void attachAccessibilityBridge(AccessibilityBridge accessibilityBridge) {
public void attachAccessibilityBridge(@NonNull AccessibilityBridge accessibilityBridge) {
accessibilityEventsDelegate.setAccessibilityBridge(accessibilityBridge);
}
@@ -534,7 +536,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
* <p>A platform views controller should be attached to a text input plugin whenever it is
* possible for the Flutter framework to receive text input.
*/
public void attachTextInputPlugin(TextInputPlugin textInputPlugin) {
public void attachTextInputPlugin(@NonNull TextInputPlugin textInputPlugin) {
this.textInputPlugin = textInputPlugin;
}
@@ -568,6 +570,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
}
@Override
@Nullable
public View getPlatformViewById(int viewId) {
final PlatformView platformView = platformViews.get(viewId);
if (platformView == null) {
@@ -692,7 +695,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
flutterView.addView(parentView);
}
public void attachToFlutterRenderer(FlutterRenderer flutterRenderer) {
public void attachToFlutterRenderer(@NonNull FlutterRenderer flutterRenderer) {
androidTouchProcessor = new AndroidTouchProcessor(flutterRenderer, /*trackMotionEvents=*/ true);
}
@@ -717,7 +720,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
int height,
int viewWidth,
int viewHeight,
FlutterMutatorsStack mutatorsStack) {
@NonNull FlutterMutatorsStack mutatorsStack) {
initializeRootImageViewIfNeeded();
initializePlatformViewIfNeeded(viewId);
@@ -856,6 +859,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
*/
@VisibleForTesting
@TargetApi(19)
@NonNull
public FlutterOverlaySurface createOverlaySurface(@NonNull FlutterImageView imageView) {
final int id = nextOverlayLayerId++;
overlayLayerViews.put(id, imageView);
@@ -870,6 +874,7 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
* <p>This member is not intended for public use, and is only visible for testing.
*/
@TargetApi(19)
@NonNull
public FlutterOverlaySurface createOverlaySurface() {
// Overlay surfaces have the same size as the background surface.
//

View File

@@ -6,10 +6,12 @@ package io.flutter.util;
import android.content.Context;
import android.os.Build;
import androidx.annotation.NonNull;
import java.io.File;
public final class PathUtils {
public static String getFilesDir(Context applicationContext) {
@NonNull
public static String getFilesDir(@NonNull Context applicationContext) {
File filesDir = applicationContext.getFilesDir();
if (filesDir == null) {
filesDir = new File(getDataDirPath(applicationContext), "files");
@@ -17,7 +19,8 @@ public final class PathUtils {
return filesDir.getPath();
}
public static String getDataDirectory(Context applicationContext) {
@NonNull
public static String getDataDirectory(@NonNull Context applicationContext) {
final String name = "flutter";
File flutterDir = applicationContext.getDir(name, Context.MODE_PRIVATE);
if (flutterDir == null) {
@@ -26,7 +29,8 @@ public final class PathUtils {
return flutterDir.getPath();
}
public static String getCacheDirectory(Context applicationContext) {
@NonNull
public static String getCacheDirectory(@NonNull Context applicationContext) {
File cacheDir;
if (Build.VERSION.SDK_INT >= 21) {
cacheDir = applicationContext.getCodeCacheDir();

View File

@@ -19,7 +19,8 @@ public final class ViewUtils {
* <p>This method will recursively traverse up the context chain if it is a {@link ContextWrapper}
* until it finds the first instance of the base context that is an {@link Activity}.
*/
public static Activity getActivity(Context context) {
@Nullable
public static Activity getActivity(@Nullable Context context) {
if (context == null) {
return null;
}

View File

@@ -846,13 +846,16 @@ public class FlutterView extends SurfaceView
@Override
@UiThread
public void setMessageHandler(String channel, BinaryMessageHandler handler) {
public void setMessageHandler(@NonNull String channel, @NonNull BinaryMessageHandler handler) {
mNativeView.setMessageHandler(channel, handler);
}
@Override
@UiThread
public void setMessageHandler(String channel, BinaryMessageHandler handler, TaskQueue taskQueue) {
public void setMessageHandler(
@NonNull String channel,
@NonNull BinaryMessageHandler handler,
@NonNull TaskQueue taskQueue) {
mNativeView.setMessageHandler(channel, handler, taskQueue);
}
@@ -862,12 +865,14 @@ public class FlutterView extends SurfaceView
}
@Override
@NonNull
public TextureRegistry.SurfaceTextureEntry createSurfaceTexture() {
final SurfaceTexture surfaceTexture = new SurfaceTexture(0);
return registerSurfaceTexture(surfaceTexture);
}
@Override
@NonNull
public TextureRegistry.SurfaceTextureEntry registerSurfaceTexture(
@NonNull SurfaceTexture surfaceTexture) {
surfaceTexture.detachFromGLContext();

View File

@@ -19,6 +19,7 @@ public interface TextureRegistry {
*
* @return A SurfaceTextureEntry.
*/
@NonNull
SurfaceTextureEntry createSurfaceTexture();
/**
@@ -26,11 +27,13 @@ public interface TextureRegistry {
*
* @return A SurfaceTextureEntry.
*/
@NonNull
SurfaceTextureEntry registerSurfaceTexture(@NonNull SurfaceTexture surfaceTexture);
/** A registry entry for a managed SurfaceTexture. */
interface SurfaceTextureEntry {
/** @return The managed SurfaceTexture. */
@NonNull
SurfaceTexture surfaceTexture();
/** @return The identity of this SurfaceTexture. */

View File

@@ -49,7 +49,7 @@ public class VsyncWaiter {
private FlutterJNI flutterJNI;
@NonNull
public static VsyncWaiter getInstance(float fps, FlutterJNI flutterJNI) {
public static VsyncWaiter getInstance(float fps, @NonNull FlutterJNI flutterJNI) {
if (instance == null) {
instance = new VsyncWaiter(flutterJNI);
}
@@ -60,7 +60,8 @@ public class VsyncWaiter {
@TargetApi(17)
@NonNull
public static VsyncWaiter getInstance(DisplayManager displayManager, FlutterJNI flutterJNI) {
public static VsyncWaiter getInstance(
@NonNull DisplayManager displayManager, @NonNull FlutterJNI flutterJNI) {
if (instance == null) {
instance = new VsyncWaiter(flutterJNI);
}
@@ -103,7 +104,7 @@ public class VsyncWaiter {
}
};
private VsyncWaiter(FlutterJNI flutterJNI) {
private VsyncWaiter(@NonNull FlutterJNI flutterJNI) {
this.flutterJNI = flutterJNI;
}

View File

@@ -8,6 +8,7 @@ import static org.junit.Assert.assertTrue;
import android.content.res.Configuration;
import android.os.Build;
import androidx.annotation.NonNull;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Locale;
@@ -29,7 +30,7 @@ public class TestUtils {
}
}
public static void setLegacyLocale(Configuration config, Locale locale) {
public static void setLegacyLocale(@NonNull Configuration config, @NonNull Locale locale) {
try {
Field field = config.getClass().getField("locale");
field.setAccessible(true);

View File

@@ -1,6 +1,7 @@
package io.flutter.embedding.android;
import android.content.Intent;
import androidx.annotation.NonNull;
import org.robolectric.Robolectric;
import org.robolectric.android.controller.ActivityController;
@@ -14,7 +15,8 @@ public class RobolectricFlutterActivity {
* Creates a {@code FlutterActivity} that is controlled by Robolectric, which otherwise can not be
* done in a test outside of the io.flutter.embedding.android package.
*/
public static FlutterActivity createFlutterActivity(Intent intent) {
@NonNull
public static FlutterActivity createFlutterActivity(@NonNull Intent intent) {
ActivityController<FlutterActivity> activityController =
Robolectric.buildActivity(FlutterActivity.class, intent);
FlutterActivity flutterActivity = activityController.get();
@@ -26,8 +28,9 @@ public class RobolectricFlutterActivity {
* Returns a given {@code FlutterActivity}'s {@code BackgroundMode} for use by tests that do not
* sit in the {@code io.flutter.embedding.android} package.
*/
@NonNull
public static FlutterActivityLaunchConfigs.BackgroundMode getBackgroundMode(
FlutterActivity activity) {
@NonNull FlutterActivity activity) {
return activity.getBackgroundMode();
}
}

View File

@@ -4,6 +4,7 @@ import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.shadow.api.Shadow;
@@ -16,7 +17,8 @@ public class SplashShadowResources {
public static final int THEMED_SPLASH_DRAWABLE_ID = 212121;
// All other getDrawable() calls, call this method internally.
public Drawable getDrawableForDensity(int id, int density, Resources.Theme theme)
@NonNull
public Drawable getDrawableForDensity(int id, int density, @NonNull Resources.Theme theme)
throws Exception {
if (id == SPLASH_DRAWABLE_ID) {
return new ColorDrawable(Color.BLUE);

View File

@@ -1,5 +1,7 @@
package io.flutter.plugins;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import io.flutter.embedding.engine.FlutterEngine;
import java.util.ArrayList;
@@ -13,7 +15,7 @@ import java.util.List;
@VisibleForTesting
public class GeneratedPluginRegistrant {
private static final List<FlutterEngine> registeredEngines = new ArrayList<>();
public static RuntimeException pluginRegistrationException;
public static @Nullable RuntimeException pluginRegistrationException;
/**
* The one and only method currently generated by the tool.
@@ -21,7 +23,7 @@ public class GeneratedPluginRegistrant {
* <p>Normally it registers all plugins in an app with the given {@code engine}. This fake tracks
* all registered engines instead.
*/
public static void registerWith(FlutterEngine engine) {
public static void registerWith(@NonNull FlutterEngine engine) {
if (pluginRegistrationException != null) {
throw pluginRegistrationException;
}
@@ -46,6 +48,7 @@ public class GeneratedPluginRegistrant {
* <p>CAUTION: This list is static and must be manually wiped in between test runs. See {@link
* #clearRegisteredEngines()}.
*/
@NonNull
public static List<FlutterEngine> getRegisteredEngines() {
return new ArrayList<>(registeredEngines);
}

View File

@@ -80,6 +80,9 @@ Future<int> runLint(ArgParser argParser, ArgResults argResults) async {
if (!entity.path.endsWith('.java')) {
continue;
}
if (entity.path.endsWith('Test.java')) {
continue;
}
projectXml.writeln(' <src file="${entity.path}" />');
}

View File

@@ -5,10 +5,6 @@
<module name="FlutterEngine" android="true" library="true" compile-sdk-version="android-S">
<manifest file="../../../flutter/shell/platform/android/AndroidManifest.xml" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/TestUtils.java" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/SmokeTest.java" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/util/PathUtilsTest.java" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/util/ViewUtilsTest.java" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/util/PreconditionsTest.java" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/util/FakeKeyEvent.java" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/plugins/GeneratedPluginRegistrant.java" />
<src file="../../../flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityTest.java" />