Skip to content

Commit 5c53cee

Browse files
committed
Merge branch 'master' into gmain
* master: [in_app_purchase] Android Code Inspection and Clean up (flutter#3120) Android Code Inspection and Clean up (flutter#3117) [in_app_purchase] Fix finishing purchases upon payment cancellation (flutter#3106) [google_maps_flutter_web] Fix convert.dart issues (flutter#3093) [multiple] Opt-out tests of null-safety (flutter#3113) [webview_flutter] add public documentation. (flutter#3114) in_app_purchase: started supported null as a parameter for the sandbox arguement (flutter#3110) [connectivity] Android Code Inspection and Clean up (flutter#3051) [android_intent] Android Code Inspection and Clean up (flutter#3043) Remove `io.flutter.embedded_views_preview` from README [google_maps_flutter] Fix headline in the readme (flutter#3100) [webview_flutter] Add new entrypoint that uses hybrid composition on Android (flutter#3067) [google_maps_flutter] Out of developers preview, bump to 1.0.0 (flutter#3091) [url_launcher_web] Move third_party under src. (flutter#3080) [plugin_platform_interface] Fix homepage in pubspec.yaml (flutter#3088) [connectivity_for_web] Fix homepage in pubspec.yaml (flutter#3089) [in_app_purchase] Update typo in example main.dart (flutter#3073)
2 parents 49d258c + c8e3aa1 commit 5c53cee

File tree

56 files changed

+656
-144
lines changed

Some content is hidden

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

56 files changed

+656
-144
lines changed

packages/android_intent/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.7+5
2+
3+
* Android Code Inspection and Clean up.
4+
15
## 0.3.7+4
26

37
* Keep handling deprecated Android v1 classes for backward compatibility.

packages/android_intent/android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
group 'io.flutter.plugins.androidintent'
22
version '1.0-SNAPSHOT'
3+
def args = ["-Xlint:deprecation","-Xlint:unchecked","-Werror"]
34

45
buildscript {
56
repositories {
@@ -19,6 +20,10 @@ rootProject.allprojects {
1920
}
2021
}
2122

23+
project.getTasks().withType(JavaCompile){
24+
options.compilerArgs.addAll(args)
25+
}
26+
2227
apply plugin: 'com.android.library'
2328

2429
android {

packages/android_intent/android/src/main/java/io/flutter/plugins/androidintent/MethodCallHandlerImpl.java

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
1616
import io.flutter.plugin.common.MethodChannel.Result;
1717
import java.util.ArrayList;
18+
import java.util.HashMap;
1819
import java.util.Map;
1920

2021
/** Forwards incoming {@link MethodCall}s to {@link IntentSender#send}. */
@@ -75,14 +76,19 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
7576
String action = convertAction((String) call.argument("action"));
7677
Integer flags = call.argument("flags");
7778
String category = call.argument("category");
78-
Uri data = call.argument("data") != null ? Uri.parse((String) call.argument("data")) : null;
79-
Bundle arguments = convertArguments((Map<String, ?>) call.argument("arguments"));
79+
String stringData = call.argument("data");
80+
Uri data = call.argument("data") != null ? Uri.parse(stringData) : null;
81+
Map<String, ?> stringMap = call.argument("arguments");
82+
Bundle arguments = convertArguments(stringMap);
8083
String packageName = call.argument("package");
81-
ComponentName componentName =
82-
(!TextUtils.isEmpty(packageName)
83-
&& !TextUtils.isEmpty((String) call.argument("componentName")))
84-
? new ComponentName(packageName, (String) call.argument("componentName"))
85-
: null;
84+
String component = call.argument("componentName");
85+
ComponentName componentName = null;
86+
if (packageName != null
87+
&& component != null
88+
&& !TextUtils.isEmpty(packageName)
89+
&& !TextUtils.isEmpty(component)) {
90+
componentName = new ComponentName(packageName, component);
91+
}
8692
String type = call.argument("type");
8793

8894
Intent intent =
@@ -128,6 +134,9 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
128134
}
129135
for (String key : arguments.keySet()) {
130136
Object value = arguments.get(key);
137+
ArrayList<String> stringArrayList = isStringArrayList(value);
138+
ArrayList<Integer> integerArrayList = isIntegerArrayList(value);
139+
Map<String, ?> stringMap = isStringKeyedMap(value);
131140
if (value instanceof Integer) {
132141
bundle.putInt(key, (Integer) value);
133142
} else if (value instanceof String) {
@@ -146,42 +155,67 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
146155
bundle.putLongArray(key, (long[]) value);
147156
} else if (value instanceof double[]) {
148157
bundle.putDoubleArray(key, (double[]) value);
149-
} else if (isTypedArrayList(value, Integer.class)) {
150-
bundle.putIntegerArrayList(key, (ArrayList<Integer>) value);
151-
} else if (isTypedArrayList(value, String.class)) {
152-
bundle.putStringArrayList(key, (ArrayList<String>) value);
153-
} else if (isStringKeyedMap(value)) {
154-
bundle.putBundle(key, convertArguments((Map<String, ?>) value));
158+
} else if (integerArrayList != null) {
159+
bundle.putIntegerArrayList(key, integerArrayList);
160+
} else if (stringArrayList != null) {
161+
bundle.putStringArrayList(key, stringArrayList);
162+
} else if (stringMap != null) {
163+
bundle.putBundle(key, convertArguments(stringMap));
155164
} else {
156165
throw new UnsupportedOperationException("Unsupported type " + value);
157166
}
158167
}
159168
return bundle;
160169
}
161170

162-
private static boolean isTypedArrayList(Object value, Class<?> type) {
171+
private static ArrayList<Integer> isIntegerArrayList(Object value) {
172+
ArrayList<Integer> integerArrayList = new ArrayList<>();
163173
if (!(value instanceof ArrayList)) {
164-
return false;
174+
return null;
165175
}
166-
ArrayList list = (ArrayList) value;
167-
for (Object o : list) {
168-
if (!(o == null || type.isInstance(o))) {
169-
return false;
176+
ArrayList<?> intList = (ArrayList<?>) value;
177+
for (Object o : intList) {
178+
if (!(o instanceof Integer)) {
179+
return null;
180+
} else {
181+
integerArrayList.add((Integer) o);
170182
}
171183
}
172-
return true;
184+
return integerArrayList;
173185
}
174186

175-
private static boolean isStringKeyedMap(Object value) {
187+
private static ArrayList<String> isStringArrayList(Object value) {
188+
ArrayList<String> stringArrayList = new ArrayList<>();
189+
if (!(value instanceof ArrayList)) {
190+
return null;
191+
}
192+
ArrayList<?> stringList = (ArrayList<?>) value;
193+
for (Object o : stringList) {
194+
if (!(o instanceof String)) {
195+
return null;
196+
} else {
197+
stringArrayList.add((String) o);
198+
}
199+
}
200+
return stringArrayList;
201+
}
202+
203+
private static Map<String, ?> isStringKeyedMap(Object value) {
204+
Map<String, Object> stringMap = new HashMap<>();
176205
if (!(value instanceof Map)) {
177-
return false;
206+
return null;
178207
}
179-
Map map = (Map) value;
180-
for (Object key : map.keySet()) {
181-
if (!(key == null || key instanceof String)) {
182-
return false;
208+
Map<?, ?> mapValue = (Map<?, ?>) value;
209+
for (Object key : mapValue.keySet()) {
210+
if (!(key instanceof String)) {
211+
return null;
212+
} else {
213+
Object o = mapValue.get(key);
214+
if (o != null) {
215+
stringMap.put((String) key, o);
216+
}
183217
}
184218
}
185-
return true;
219+
return stringMap;
186220
}
187221
}

packages/android_intent/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/android_intent
44
# 0.3.y+z is compatible with 1.0.0, if you land a breaking change bump
55
# the version to 2.0.0.
66
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
7-
version: 0.3.7+4
7+
version: 0.3.7+5
88

99
flutter:
1010
plugin:

packages/connectivity/connectivity/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.4.9+4
2+
3+
* Update README with the updated information about WifiInfo on Android O or higher.
4+
* Android: Avoiding uses or overrides a deprecated API
5+
16
## 0.4.9+3
27

38
* Keep handling deprecated Android v1 classes for backward compatibility.

packages/connectivity/connectivity/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ dispose() {
5959

6060
Note that connectivity changes are no longer communicated to Android apps in the background starting with Android O. *You should always check for connectivity status when your app is resumed.* The broadcast is only useful when your application is in the foreground.
6161

62+
To successfully get WiFi Name or Wi-Fi BSSID starting with Android O, ensure all of the following conditions are met:
63+
64+
* If your app is targeting Android 10 (API level 29) SDK or higher, your app has the ACCESS_FINE_LOCATION permission.
65+
66+
* If your app is targeting SDK lower than Android 10 (API level 29), your app has the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
67+
68+
* Location services are enabled on the device (under Settings > Location).
69+
6270
You can get wi-fi related information using:
6371

6472
```dart

packages/connectivity/connectivity/android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
group 'io.flutter.plugins.connectivity'
22
version '1.0-SNAPSHOT'
3+
def args = ["-Xlint:deprecation","-Xlint:unchecked","-Werror"]
34

45
buildscript {
56
repositories {
@@ -19,6 +20,10 @@ rootProject.allprojects {
1920
}
2021
}
2122

23+
project.getTasks().withType(JavaCompile){
24+
options.compilerArgs.addAll(args)
25+
}
26+
2227
apply plugin: 'com.android.library'
2328

2429
android {

packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/Connectivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,8 @@ private String getNetworkTypeLegacy() {
100100
return "none";
101101
}
102102
}
103+
104+
public ConnectivityManager getConnectivityManager() {
105+
return connectivityManager;
106+
}
103107
}

packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityBroadcastReceiver.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import android.content.Intent;
1010
import android.content.IntentFilter;
1111
import android.net.ConnectivityManager;
12+
import android.net.Network;
13+
import android.os.Build;
14+
import android.os.Handler;
15+
import android.os.Looper;
16+
import androidx.annotation.RequiresApi;
1217
import io.flutter.plugin.common.EventChannel;
1318

1419
/**
@@ -24,6 +29,8 @@ class ConnectivityBroadcastReceiver extends BroadcastReceiver
2429
private Context context;
2530
private Connectivity connectivity;
2631
private EventChannel.EventSink events;
32+
private Handler mainHandler = new Handler(Looper.getMainLooper());
33+
public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
2734

2835
ConnectivityBroadcastReceiver(Context context, Connectivity connectivity) {
2936
this.context = context;
@@ -33,12 +40,20 @@ class ConnectivityBroadcastReceiver extends BroadcastReceiver
3340
@Override
3441
public void onListen(Object arguments, EventChannel.EventSink events) {
3542
this.events = events;
36-
context.registerReceiver(this, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
43+
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
44+
connectivity.getConnectivityManager().registerDefaultNetworkCallback(getNetworkCallback());
45+
} else {
46+
context.registerReceiver(this, new IntentFilter(CONNECTIVITY_ACTION));
47+
}
3748
}
3849

3950
@Override
4051
public void onCancel(Object arguments) {
41-
context.unregisterReceiver(this);
52+
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
53+
connectivity.getConnectivityManager().unregisterNetworkCallback(getNetworkCallback());
54+
} else {
55+
context.unregisterReceiver(this);
56+
}
4257
}
4358

4459
@Override
@@ -47,4 +62,30 @@ public void onReceive(Context context, Intent intent) {
4762
events.success(connectivity.getNetworkType());
4863
}
4964
}
65+
66+
@RequiresApi(api = Build.VERSION_CODES.N)
67+
ConnectivityManager.NetworkCallback getNetworkCallback() {
68+
return new ConnectivityManager.NetworkCallback() {
69+
@Override
70+
public void onAvailable(Network network) {
71+
sendEvent();
72+
}
73+
74+
@Override
75+
public void onLost(Network network) {
76+
sendEvent();
77+
}
78+
};
79+
}
80+
81+
private void sendEvent() {
82+
Runnable runnable =
83+
new Runnable() {
84+
@Override
85+
public void run() {
86+
events.success(connectivity.getNetworkType());
87+
}
88+
};
89+
mainHandler.post(runnable);
90+
}
5091
}

packages/connectivity/connectivity/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ private void setupChannels(BinaryMessenger messenger, Context context) {
4141
eventChannel = new EventChannel(messenger, "plugins.flutter.io/connectivity_status");
4242
ConnectivityManager connectivityManager =
4343
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
44-
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
44+
WifiManager wifiManager =
45+
(WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
4546

4647
Connectivity connectivity = new Connectivity(connectivityManager, wifiManager);
4748

0 commit comments

Comments
 (0)