Skip to content

Commit 43c741b

Browse files
[url_launcher] Fix Android Java warnings (#3690)
[url_launcher] Fix Android Java warnings
1 parent 491102b commit 43c741b

File tree

8 files changed

+31
-172
lines changed

8 files changed

+31
-172
lines changed

packages/url_launcher/url_launcher_android/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 6.0.27
22

3+
* Fixes Java warnings.
34
* Updates minimum Flutter version to 3.3.
45

56
## 6.0.26

packages/url_launcher/url_launcher_android/android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ android {
3232
checkAllWarnings true
3333
warningsAsErrors true
3434
disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency'
35-
baseline file("lint-baseline.xml")
3635
}
3736

3837

packages/url_launcher/url_launcher_android/android/lint-baseline.xml

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

packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/MethodCallHandlerImpl.java

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

77
import android.os.Bundle;
88
import android.util.Log;
9+
import androidx.annotation.NonNull;
910
import androidx.annotation.Nullable;
1011
import io.flutter.plugin.common.BinaryMessenger;
1112
import io.flutter.plugin.common.MethodCall;
@@ -30,7 +31,7 @@ final class MethodCallHandlerImpl implements MethodCallHandler {
3031
}
3132

3233
@Override
33-
public void onMethodCall(MethodCall call, Result result) {
34+
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
3435
final String url = call.argument("url");
3536
switch (call.method) {
3637
case "canLaunch":
@@ -80,11 +81,11 @@ void stopListening() {
8081
channel = null;
8182
}
8283

83-
private void onCanLaunch(Result result, String url) {
84+
private void onCanLaunch(@NonNull Result result, @NonNull String url) {
8485
result.success(urlLauncher.canLaunch(url));
8586
}
8687

87-
private void onLaunch(MethodCall call, Result result, String url) {
88+
private void onLaunch(@NonNull MethodCall call, @NonNull Result result, @NonNull String url) {
8889
final boolean useWebView = call.argument("useWebView");
8990
final boolean enableJavaScript = call.argument("enableJavaScript");
9091
final boolean enableDomStorage = call.argument("enableDomStorage");
@@ -111,7 +112,7 @@ private void onCloseWebView(Result result) {
111112
result.success(null);
112113
}
113114

114-
private static Bundle extractBundle(Map<String, String> headersMap) {
115+
private static @NonNull Bundle extractBundle(Map<String, String> headersMap) {
115116
final Bundle headersBundle = new Bundle();
116117
for (String key : headersMap.keySet()) {
117118
final String value = headersMap.get(key);

packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncher.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.os.Bundle;
1414
import android.provider.Browser;
1515
import android.util.Log;
16+
import androidx.annotation.NonNull;
1617
import androidx.annotation.Nullable;
1718

1819
/** Launches components for URLs. */
@@ -37,7 +38,7 @@ void setActivity(@Nullable Activity activity) {
3738
}
3839

3940
/** Returns whether the given {@code url} resolves into an existing component. */
40-
boolean canLaunch(String url) {
41+
boolean canLaunch(@NonNull String url) {
4142
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
4243
launchIntent.setData(Uri.parse(url));
4344
ComponentName componentName =
@@ -65,8 +66,8 @@ boolean canLaunch(String url) {
6566
* launchIntent}. {@link LaunchStatus#OK} otherwise.
6667
*/
6768
LaunchStatus launch(
68-
String url,
69-
Bundle headersBundle,
69+
@NonNull String url,
70+
@NonNull Bundle headersBundle,
7071
boolean useWebView,
7172
boolean enableJavaScript,
7273
boolean enableDomStorage) {

packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/UrlLauncherPlugin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public final class UrlLauncherPlugin implements FlutterPlugin, ActivityAware {
2929
* won't react to changes in activity or context, unlike {@link UrlLauncherPlugin}.
3030
*/
3131
@SuppressWarnings("deprecation")
32-
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
32+
public static void registerWith(
33+
@NonNull io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
3334
MethodCallHandlerImpl handler =
3435
new MethodCallHandlerImpl(new UrlLauncher(registrar.context(), registrar.activity()));
3536
handler.startListening(registrar.messenger());
@@ -61,6 +62,7 @@ public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
6162
return;
6263
}
6364

65+
assert urlLauncher != null;
6466
urlLauncher.setActivity(binding.getActivity());
6567
}
6668

@@ -71,6 +73,7 @@ public void onDetachedFromActivity() {
7173
return;
7274
}
7375

76+
assert urlLauncher != null;
7477
urlLauncher.setActivity(null);
7578
}
7679

packages/url_launcher/url_launcher_android/android/src/main/java/io/flutter/plugins/urllauncher/WebViewActivity.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class WebViewActivity extends Activity {
3434
* Use this to trigger a BroadcastReceiver inside WebViewActivity
3535
* that will request the current instance to finish.
3636
* */
37-
public static String ACTION_CLOSE = "close action";
37+
public static final String ACTION_CLOSE = "close action";
3838

3939
private final BroadcastReceiver broadcastReceiver =
4040
new BroadcastReceiver() {
@@ -74,12 +74,13 @@ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request
7474
}
7575
};
7676

77-
private WebView webview;
77+
// Uses default (package-private) access since it's used by inner class implementations.
78+
WebView webview;
7879

79-
private IntentFilter closeIntentFilter = new IntentFilter(ACTION_CLOSE);
80+
private final IntentFilter closeIntentFilter = new IntentFilter(ACTION_CLOSE);
8081

8182
// Verifies that a url opened by `Window.open` has a secure url.
82-
private class FlutterWebChromeClient extends WebChromeClient {
83+
class FlutterWebChromeClient extends WebChromeClient {
8384
@Override
8485
public boolean onCreateWindow(
8586
final WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
@@ -117,7 +118,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
117118
}
118119

119120
@Override
120-
public void onCreate(Bundle savedInstanceState) {
121+
public void onCreate(@Nullable Bundle savedInstanceState) {
121122
super.onCreate(savedInstanceState);
122123
webview = new WebView(this);
123124
setContentView(webview);
@@ -146,7 +147,7 @@ public void onCreate(Bundle savedInstanceState) {
146147
}
147148

148149
@VisibleForTesting
149-
public static Map<String, String> extractHeaders(@Nullable Bundle headersBundle) {
150+
public static @NonNull Map<String, String> extractHeaders(@Nullable Bundle headersBundle) {
150151
if (headersBundle == null) {
151152
return Collections.emptyMap();
152153
}
@@ -165,25 +166,25 @@ protected void onDestroy() {
165166
}
166167

167168
@Override
168-
public boolean onKeyDown(int keyCode, KeyEvent event) {
169+
public boolean onKeyDown(int keyCode, @Nullable KeyEvent event) {
169170
if (keyCode == KeyEvent.KEYCODE_BACK && webview.canGoBack()) {
170171
webview.goBack();
171172
return true;
172173
}
173174
return super.onKeyDown(keyCode, event);
174175
}
175176

176-
private static String URL_EXTRA = "url";
177-
private static String ENABLE_JS_EXTRA = "enableJavaScript";
178-
private static String ENABLE_DOM_EXTRA = "enableDomStorage";
177+
private static final String URL_EXTRA = "url";
178+
private static final String ENABLE_JS_EXTRA = "enableJavaScript";
179+
private static final String ENABLE_DOM_EXTRA = "enableDomStorage";
179180

180181
/* Hides the constants used to forward data to the Activity instance. */
181-
public static Intent createIntent(
182-
Context context,
183-
String url,
182+
public static @NonNull Intent createIntent(
183+
@NonNull Context context,
184+
@NonNull String url,
184185
boolean enableJavaScript,
185186
boolean enableDomStorage,
186-
Bundle headersBundle) {
187+
@NonNull Bundle headersBundle) {
187188
return new Intent(context, WebViewActivity.class)
188189
.putExtra(URL_EXTRA, url)
189190
.putExtra(ENABLE_JS_EXTRA, enableJavaScript)

packages/url_launcher/url_launcher_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: url_launcher_android
22
description: Android implementation of the url_launcher plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
5-
version: 6.0.26
5+
version: 6.0.27
66

77
environment:
88
sdk: ">=2.18.0 <4.0.0"

0 commit comments

Comments
 (0)