Skip to content

Commit cec30d4

Browse files
hamdikahlounEgor
authored and
Egor
committed
[android_intent] Android Code Inspection and Clean up (flutter#3043)
1 parent da73fdf commit cec30d4

File tree

4 files changed

+71
-28
lines changed

4 files changed

+71
-28
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:

0 commit comments

Comments
 (0)