Skip to content

Commit 500c8ad

Browse files
[google_sign_in] Fix Android Java warnings (#3762)
Removes lint-baseline.xml, and fixes all resulting warnings. Also fixes some warnings that only show up in the AS linter as opportunistic fixes. All anonymous object->lambda conversions were auto-generated by the AS auto-fix for those warnings. Fixed an edge case bug found during warning fixes; the Dart `getTokens` call has an argument that was (I assume accidentally) declared as `bool? shouldRecoverAuth = true` instead of `bool shouldRecoverAuth = true`, which means that while it defaults to `true` if not passed, it can be explicitly passed `null` and will keep that value. This was being passed directly into the method channel, and on the Java side was extracted as a `boolean` which would throw an exception on null. Part of flutter/flutter#88011
1 parent 47f3d0a commit 500c8ad

File tree

10 files changed

+150
-889
lines changed

10 files changed

+150
-889
lines changed

packages/google_sign_in/google_sign_in_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 6.1.11
2+
3+
* Fixes Java warnings.
4+
15
## 6.1.10
26

37
* Sets an explicit Java compatibility version.

packages/google_sign_in/google_sign_in_android/android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ android {
3737
checkAllWarnings true
3838
warningsAsErrors true
3939
disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency'
40-
baseline file("lint-baseline.xml")
4140
}
4241

4342

packages/google_sign_in/google_sign_in_android/android/lint-baseline.xml

Lines changed: 0 additions & 730 deletions
This file was deleted.

packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/BackgroundTaskRunner.java

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

55
package io.flutter.plugins.googlesignin;
66

7+
import androidx.annotation.NonNull;
78
import com.google.common.util.concurrent.ListenableFuture;
89
import com.google.common.util.concurrent.SettableFuture;
910
import java.util.concurrent.BlockingQueue;
@@ -31,7 +32,7 @@ public interface Callback<T> {
3132
* the future is guaranteed not to block). If the future completed with an exception, then
3233
* {@code get()} will throw an {@code ExecutionException}.
3334
*/
34-
void run(Future<T> future);
35+
void run(@NonNull Future<T> future);
3536
}
3637

3738
private final ThreadPoolExecutor executor;
@@ -53,16 +54,9 @@ public BackgroundTaskRunner(int threads) {
5354
*
5455
* <p>The callback will be notified on the UI thread.
5556
*/
56-
public <T> void runInBackground(Callable<T> task, final Callback<T> callback) {
57+
public <T> void runInBackground(@NonNull Callable<T> task, final @NonNull Callback<T> callback) {
5758
final ListenableFuture<T> future = runInBackground(task);
58-
future.addListener(
59-
new Runnable() {
60-
@Override
61-
public void run() {
62-
callback.run(future);
63-
}
64-
},
65-
Executors.uiThreadExecutor());
59+
future.addListener(() -> callback.run(future), Executors.uiThreadExecutor());
6660
}
6761

6862
/**
@@ -72,19 +66,16 @@ public void run() {
7266
* <p>Note: the future will be notified on the background thread. To be notified on the UI thread,
7367
* use {@link #runInBackground(Callable,Callback)}.
7468
*/
75-
public <T> ListenableFuture<T> runInBackground(final Callable<T> task) {
69+
public @NonNull <T> ListenableFuture<T> runInBackground(final @NonNull Callable<T> task) {
7670
final SettableFuture<T> future = SettableFuture.create();
7771

7872
executor.execute(
79-
new Runnable() {
80-
@Override
81-
public void run() {
82-
if (!future.isCancelled()) {
83-
try {
84-
future.set(task.call());
85-
} catch (Throwable t) {
86-
future.setException(t);
87-
}
73+
() -> {
74+
if (!future.isCancelled()) {
75+
try {
76+
future.set(task.call());
77+
} catch (Throwable t) {
78+
future.setException(t);
8879
}
8980
}
9081
});

packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/Executors.java

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

77
import android.os.Handler;
88
import android.os.Looper;
9+
import androidx.annotation.NonNull;
910
import java.util.concurrent.Executor;
1011

1112
/**
@@ -16,7 +17,7 @@
1617
*/
1718
public final class Executors {
1819

19-
private static final class UiThreadExecutor implements Executor {
20+
static final class UiThreadExecutor implements Executor {
2021
private static final Handler UI_THREAD = new Handler(Looper.getMainLooper());
2122

2223
@Override
@@ -26,7 +27,7 @@ public void execute(Runnable command) {
2627
}
2728

2829
/** Returns an {@code Executor} that will post commands to the UI thread. */
29-
public static Executor uiThreadExecutor() {
30+
public static @NonNull Executor uiThreadExecutor() {
3031
return new UiThreadExecutor();
3132
}
3233

0 commit comments

Comments
 (0)