Skip to content

Commit 1adccf1

Browse files
author
Emmanuel Garcia
authored
Fix first batch of warnings in the Android embedding (flutter#30807)
1 parent bbe4e97 commit 1adccf1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+329
-206
lines changed

shell/platform/android/io/flutter/embedding/android/FlutterView.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ public InputConnection onCreateInputConnection(@NonNull EditorInfo outAttrs) {
876876
* methods.
877877
*/
878878
@Override
879-
public boolean checkInputConnectionProxy(View view) {
879+
public boolean checkInputConnectionProxy(@NonNull View view) {
880880
return flutterEngine != null
881881
? flutterEngine.getPlatformViewsController().checkInputConnectionProxy(view)
882882
: super.checkInputConnectionProxy(view);
@@ -894,7 +894,7 @@ public boolean checkInputConnectionProxy(View view) {
894894
* previous {@code keyCode} to generate a unicode combined character.
895895
*/
896896
@Override
897-
public boolean dispatchKeyEvent(KeyEvent event) {
897+
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
898898
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
899899
// Tell Android to start tracking this event.
900900
getKeyDispatcherState().startTracking(event, this);
@@ -1003,6 +1003,7 @@ public AccessibilityNodeProvider getAccessibilityNodeProvider() {
10031003
* @return The view matching the accessibility id if any.
10041004
*/
10051005
@SuppressLint("SoonBlockedPrivateApi")
1006+
@Nullable
10061007
public View findViewByAccessibilityIdTraversal(int accessibilityId) {
10071008
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
10081009
return findViewByAccessibilityIdRootedAtCurrentView(accessibilityId, this);
@@ -1349,7 +1350,7 @@ public void onFlutterUiNoLongerDisplayed() {
13491350
});
13501351
}
13511352

1352-
public void attachOverlaySurfaceToRender(FlutterImageView view) {
1353+
public void attachOverlaySurfaceToRender(@NonNull FlutterImageView view) {
13531354
if (flutterEngine != null) {
13541355
view.attachToRenderer(flutterEngine.getRenderer());
13551356
}
@@ -1450,13 +1451,13 @@ private void sendViewportMetricsToFlutter() {
14501451
}
14511452

14521453
@Override
1453-
public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
1454+
public void onProvideAutofillVirtualStructure(@NonNull ViewStructure structure, int flags) {
14541455
super.onProvideAutofillVirtualStructure(structure, flags);
14551456
textInputPlugin.onProvideAutofillVirtualStructure(structure, flags);
14561457
}
14571458

14581459
@Override
1459-
public void autofill(SparseArray<AutofillValue> values) {
1460+
public void autofill(@NonNull SparseArray<AutofillValue> values) {
14601461
textInputPlugin.autofill(values);
14611462
}
14621463

shell/platform/android/io/flutter/embedding/android/KeyboardManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public class KeyboardManager {
7979
* dispatched to.
8080
*/
8181
public KeyboardManager(
82-
View view, @NonNull TextInputPlugin textInputPlugin, Responder[] responders) {
82+
@NonNull View view,
83+
@NonNull TextInputPlugin textInputPlugin,
84+
@NonNull Responder[] responders) {
8385
this.view = view;
8486
this.textInputPlugin = textInputPlugin;
8587
this.responders = responders;
@@ -103,7 +105,7 @@ public KeyboardManager(
103105
*/
104106
interface Responder {
105107
interface OnKeyEventHandledCallback {
106-
void onKeyEventHandled(Boolean canHandleEvent);
108+
void onKeyEventHandled(boolean canHandleEvent);
107109
}
108110

109111
/**
@@ -122,7 +124,7 @@ private class Callback implements OnKeyEventHandledCallback {
122124
boolean isCalled = false;
123125

124126
@Override
125-
public void onKeyEventHandled(Boolean canHandleEvent) {
127+
public void onKeyEventHandled(boolean canHandleEvent) {
126128
if (isCalled) {
127129
throw new IllegalStateException(
128130
"The onKeyEventHandledCallback should be called exactly once.");
@@ -140,7 +142,7 @@ public void onKeyEventHandled(Boolean canHandleEvent) {
140142
this.keyEvent = keyEvent;
141143
}
142144

143-
@NonNull final KeyEvent keyEvent;
145+
final KeyEvent keyEvent;
144146
int unrepliedCount = responders.length;
145147
boolean isEventHandled = false;
146148

@@ -149,9 +151,9 @@ public OnKeyEventHandledCallback buildCallback() {
149151
}
150152
}
151153

152-
@NonNull protected final Responder[] responders;
153-
@NonNull private final HashSet<KeyEvent> redispatchedEvents = new HashSet<>();
154-
@NonNull private final TextInputPlugin textInputPlugin;
154+
protected final Responder[] responders;
155+
private final HashSet<KeyEvent> redispatchedEvents = new HashSet<>();
156+
private final TextInputPlugin textInputPlugin;
155157
private final View view;
156158

157159
public boolean handleEvent(@NonNull KeyEvent keyEvent) {

shell/platform/android/io/flutter/embedding/android/MotionEventTracker.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.util.LongSparseArray;
44
import android.view.MotionEvent;
5+
import androidx.annotation.NonNull;
56
import androidx.annotation.Nullable;
67
import java.util.PriorityQueue;
78
import java.util.concurrent.atomic.AtomicLong;
@@ -18,10 +19,12 @@ private MotionEventId(long id) {
1819
this.id = id;
1920
}
2021

22+
@NonNull
2123
public static MotionEventId from(long id) {
2224
return new MotionEventId(id);
2325
}
2426

27+
@NonNull
2528
public static MotionEventId createUnique() {
2629
return MotionEventId.from(ID_COUNTER.incrementAndGet());
2730
}
@@ -35,6 +38,7 @@ public long getId() {
3538
private final PriorityQueue<Long> unusedEvents;
3639
private static MotionEventTracker INSTANCE;
3740

41+
@NonNull
3842
public static MotionEventTracker getInstance() {
3943
if (INSTANCE == null) {
4044
INSTANCE = new MotionEventTracker();
@@ -48,7 +52,8 @@ private MotionEventTracker() {
4852
}
4953

5054
/** Tracks the event and returns a unique MotionEventId identifying the event. */
51-
public MotionEventId track(MotionEvent event) {
55+
@NonNull
56+
public MotionEventId track(@NonNull MotionEvent event) {
5257
MotionEventId eventId = MotionEventId.createUnique();
5358
eventById.put(eventId.id, MotionEvent.obtain(event));
5459
unusedEvents.add(eventId.id);
@@ -61,7 +66,7 @@ public MotionEventId track(MotionEvent event) {
6166
* popped or discarded.
6267
*/
6368
@Nullable
64-
public MotionEvent pop(MotionEventId eventId) {
69+
public MotionEvent pop(@NonNull MotionEventId eventId) {
6570
// remove all the older events.
6671
while (!unusedEvents.isEmpty() && unusedEvents.peek() < eventId.id) {
6772
eventById.remove(unusedEvents.poll());

shell/platform/android/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class PlayStoreDeferredComponentManager implements DeferredComponentManag
6666

6767
private class FeatureInstallStateUpdatedListener implements SplitInstallStateUpdatedListener {
6868
@SuppressLint("DefaultLocale")
69-
public void onStateUpdate(SplitInstallSessionState state) {
69+
public void onStateUpdate(@NonNull SplitInstallSessionState state) {
7070
int sessionId = state.sessionId();
7171
if (sessionIdToName.get(sessionId) != null) {
7272
switch (state.status()) {
@@ -231,7 +231,7 @@ private boolean verifyJNI() {
231231
return true;
232232
}
233233

234-
public void setDeferredComponentChannel(DeferredComponentChannel channel) {
234+
public void setDeferredComponentChannel(@NonNull DeferredComponentChannel channel) {
235235
this.channel = channel;
236236
}
237237

@@ -288,7 +288,7 @@ private void initLoadingUnitMappingToComponentNames() {
288288
}
289289
}
290290

291-
public void installDeferredComponent(int loadingUnitId, String componentName) {
291+
public void installDeferredComponent(int loadingUnitId, @Nullable String componentName) {
292292
String resolvedComponentName =
293293
componentName != null ? componentName : loadingUnitIdToComponentNames.get(loadingUnitId);
294294
if (resolvedComponentName == null) {
@@ -357,7 +357,9 @@ public void installDeferredComponent(int loadingUnitId, String componentName) {
357357
});
358358
}
359359

360-
public String getDeferredComponentInstallState(int loadingUnitId, String componentName) {
360+
@NonNull
361+
public String getDeferredComponentInstallState(
362+
int loadingUnitId, @Nullable String componentName) {
361363
String resolvedComponentName =
362364
componentName != null ? componentName : loadingUnitIdToComponentNames.get(loadingUnitId);
363365
if (resolvedComponentName == null) {
@@ -375,7 +377,7 @@ public String getDeferredComponentInstallState(int loadingUnitId, String compone
375377
return sessionIdToState.get(sessionId);
376378
}
377379

378-
public void loadAssets(int loadingUnitId, String componentName) {
380+
public void loadAssets(int loadingUnitId, @NonNull String componentName) {
379381
if (!verifyJNI()) {
380382
return;
381383
}
@@ -393,7 +395,7 @@ public void loadAssets(int loadingUnitId, String componentName) {
393395
}
394396
}
395397

396-
public void loadDartLibrary(int loadingUnitId, String componentName) {
398+
public void loadDartLibrary(int loadingUnitId, @NonNull String componentName) {
397399
if (!verifyJNI()) {
398400
return;
399401
}
@@ -478,7 +480,7 @@ public void loadDartLibrary(int loadingUnitId, String componentName) {
478480
loadingUnitId, searchPaths.toArray(new String[searchPaths.size()]));
479481
}
480482

481-
public boolean uninstallDeferredComponent(int loadingUnitId, String componentName) {
483+
public boolean uninstallDeferredComponent(int loadingUnitId, @Nullable String componentName) {
482484
String resolvedComponentName =
483485
componentName != null ? componentName : loadingUnitIdToComponentNames.get(loadingUnitId);
484486
if (resolvedComponentName == null) {

shell/platform/android/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistry.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public ShimPluginRegistry(@NonNull FlutterEngine flutterEngine) {
4848
}
4949

5050
@Override
51-
public Registrar registrarFor(String pluginKey) {
51+
@NonNull
52+
public Registrar registrarFor(@NonNull String pluginKey) {
5253
Log.v(TAG, "Creating plugin Registrar for '" + pluginKey + "'");
5354
if (pluginMap.containsKey(pluginKey)) {
5455
throw new IllegalStateException("Plugin key " + pluginKey + " is already in use");
@@ -60,13 +61,13 @@ public Registrar registrarFor(String pluginKey) {
6061
}
6162

6263
@Override
63-
public boolean hasPlugin(String pluginKey) {
64+
public boolean hasPlugin(@NonNull String pluginKey) {
6465
return pluginMap.containsKey(pluginKey);
6566
}
6667

6768
@Override
6869
@SuppressWarnings("unchecked")
69-
public <T> T valuePublishedByPlugin(String pluginKey) {
70+
public <T> T valuePublishedByPlugin(@NonNull String pluginKey) {
7071
return (T) pluginMap.get(pluginKey);
7172
}
7273

shell/platform/android/io/flutter/embedding/engine/renderer/SurfaceTextureWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void detachFromGLContext() {
6767

6868
// Called by native.
6969
@SuppressWarnings("unused")
70-
public void getTransformMatrix(float[] mtx) {
70+
public void getTransformMatrix(@NonNull float[] mtx) {
7171
surfaceTexture.getTransformMatrix(mtx);
7272
}
7373
}

shell/platform/android/io/flutter/embedding/engine/systemchannels/LocalizationChannel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public interface LocalizationMessageHandler {
110110
* The Flutter application would like to obtain the string resource of given {@code key} in
111111
* {@code locale}.
112112
*/
113-
String getStringResource(@NonNull String key, String locale);
113+
@NonNull
114+
String getStringResource(@NonNull String key, @NonNull String locale);
114115
}
115116
}

shell/platform/android/io/flutter/embedding/engine/systemchannels/RestorationChannel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package io.flutter.embedding.engine.systemchannels;
66

77
import androidx.annotation.NonNull;
8+
import androidx.annotation.Nullable;
89
import io.flutter.Log;
910
import io.flutter.embedding.engine.dart.DartExecutor;
1011
import io.flutter.plugin.common.MethodCall;
@@ -72,12 +73,13 @@ public RestorationChannel(
7273
private boolean frameworkHasRequestedData = false;
7374

7475
/** Obtain the most current restoration data that the framework has provided. */
76+
@Nullable
7577
public byte[] getRestorationData() {
7678
return restorationData;
7779
}
7880

7981
/** Set the restoration data from which the framework will restore its state. */
80-
public void setRestorationData(byte[] data) {
82+
public void setRestorationData(@NonNull byte[] data) {
8183
engineHasProvidedData = true;
8284
if (pendingFrameworkRestorationChannelRequest != null) {
8385
// If their is a pending request from the framework, answer it.

shell/platform/android/io/flutter/embedding/engine/systemchannels/TextInputChannel.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private static HashMap<Object, Object> createEditingDeltaJSON(
205205
*/
206206
public void updateEditingState(
207207
int inputClientId,
208-
String text,
208+
@NonNull String text,
209209
int selectionStart,
210210
int selectionEnd,
211211
int composingStart,
@@ -235,7 +235,7 @@ public void updateEditingState(
235235
}
236236

237237
public void updateEditingStateWithDeltas(
238-
int inputClientId, ArrayList<TextEditingDelta> batchDeltas) {
238+
int inputClientId, @NonNull ArrayList<TextEditingDelta> batchDeltas) {
239239

240240
Log.v(
241241
TAG,
@@ -250,7 +250,7 @@ public void updateEditingStateWithDeltas(
250250
}
251251

252252
public void updateEditingStateWithTag(
253-
int inputClientId, HashMap<String, TextEditState> editStates) {
253+
int inputClientId, @NonNull HashMap<String, TextEditState> editStates) {
254254
Log.v(
255255
TAG,
256256
"Sending message to update editing state for "
@@ -325,7 +325,8 @@ public void unspecifiedAction(int inputClientId) {
325325
Arrays.asList(inputClientId, "TextInputAction.unspecified"));
326326
}
327327

328-
public void performPrivateCommand(int inputClientId, String action, Bundle data) {
328+
public void performPrivateCommand(
329+
int inputClientId, @NonNull String action, @NonNull Bundle data) {
329330
HashMap<Object, Object> json = new HashMap<>();
330331
json.put("action", action);
331332
if (data != null) {
@@ -415,7 +416,7 @@ public interface TextInputMethodHandler {
415416
* @param transform a 4x4 matrix that maps the local paint coordinate system to coordinate
416417
* system of the FlutterView that owns the current client.
417418
*/
418-
void setEditableSizeAndTransform(double width, double height, double[] transform);
419+
void setEditableSizeAndTransform(double width, double height, @NonNull double[] transform);
419420

420421
// TODO(mattcarroll): javadoc
421422
void setEditingState(@NonNull TextEditState editingState);
@@ -432,11 +433,12 @@ public interface TextInputMethodHandler {
432433
* commands.
433434
* @param data Any data to include with the command.
434435
*/
435-
void sendAppPrivateCommand(String action, Bundle data);
436+
void sendAppPrivateCommand(@NonNull String action, @NonNull Bundle data);
436437
}
437438

438439
/** A text editing configuration. */
439440
public static class Configuration {
441+
@NonNull
440442
public static Configuration fromJson(@NonNull JSONObject json)
441443
throws JSONException, NoSuchFieldException {
442444
final String inputActionName = json.getString("inputAction");
@@ -494,6 +496,7 @@ private static Integer inputActionFromTextInputAction(@NonNull String inputActio
494496
}
495497

496498
public static class Autofill {
499+
@NonNull
497500
public static Autofill fromJson(@NonNull JSONObject json)
498501
throws JSONException, NoSuchFieldException {
499502
final String uniqueIdentifier = json.getString("uniqueIdentifier");
@@ -729,6 +732,7 @@ static TextCapitalization fromValue(@NonNull String encodedName) throws NoSuchFi
729732

730733
/** State of an on-going text editing session. */
731734
public static class TextEditState {
735+
@NonNull
732736
public static TextEditState fromJson(@NonNull JSONObject textEditState) throws JSONException {
733737
return new TextEditState(
734738
textEditState.getString("text"),

shell/platform/android/io/flutter/plugin/common/JSONMessageCodec.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package io.flutter.plugin.common;
66

7+
import androidx.annotation.Nullable;
78
import java.nio.ByteBuffer;
89
import org.json.JSONException;
910
import org.json.JSONObject;
@@ -28,7 +29,8 @@ public final class JSONMessageCodec implements MessageCodec<Object> {
2829
private JSONMessageCodec() {}
2930

3031
@Override
31-
public ByteBuffer encodeMessage(Object message) {
32+
@Nullable
33+
public ByteBuffer encodeMessage(@Nullable Object message) {
3234
if (message == null) {
3335
return null;
3436
}
@@ -41,7 +43,8 @@ public ByteBuffer encodeMessage(Object message) {
4143
}
4244

4345
@Override
44-
public Object decodeMessage(ByteBuffer message) {
46+
@Nullable
47+
public Object decodeMessage(@Nullable ByteBuffer message) {
4548
if (message == null) {
4649
return null;
4750
}

0 commit comments

Comments
 (0)