Skip to content

Commit

Permalink
[google_sign_in] Fix Android Java warnings (#3762)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stuartmorgan authored Apr 21, 2023
1 parent 47f3d0a commit 500c8ad
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 889 deletions.
4 changes: 4 additions & 0 deletions packages/google_sign_in/google_sign_in_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.1.11

* Fixes Java warnings.

## 6.1.10

* Sets an explicit Java compatibility version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ android {
checkAllWarnings true
warningsAsErrors true
disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency'
baseline file("lint-baseline.xml")
}


Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.flutter.plugins.googlesignin;

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

private final ThreadPoolExecutor executor;
Expand All @@ -53,16 +54,9 @@ public BackgroundTaskRunner(int threads) {
*
* <p>The callback will be notified on the UI thread.
*/
public <T> void runInBackground(Callable<T> task, final Callback<T> callback) {
public <T> void runInBackground(@NonNull Callable<T> task, final @NonNull Callback<T> callback) {
final ListenableFuture<T> future = runInBackground(task);
future.addListener(
new Runnable() {
@Override
public void run() {
callback.run(future);
}
},
Executors.uiThreadExecutor());
future.addListener(() -> callback.run(future), Executors.uiThreadExecutor());
}

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

executor.execute(
new Runnable() {
@Override
public void run() {
if (!future.isCancelled()) {
try {
future.set(task.call());
} catch (Throwable t) {
future.setException(t);
}
() -> {
if (!future.isCancelled()) {
try {
future.set(task.call());
} catch (Throwable t) {
future.setException(t);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import java.util.concurrent.Executor;

/**
Expand All @@ -16,7 +17,7 @@
*/
public final class Executors {

private static final class UiThreadExecutor implements Executor {
static final class UiThreadExecutor implements Executor {
private static final Handler UI_THREAD = new Handler(Looper.getMainLooper());

@Override
Expand All @@ -26,7 +27,7 @@ public void execute(Runnable command) {
}

/** Returns an {@code Executor} that will post commands to the UI thread. */
public static Executor uiThreadExecutor() {
public static @NonNull Executor uiThreadExecutor() {
return new UiThreadExecutor();
}

Expand Down
Loading

0 comments on commit 500c8ad

Please sign in to comment.