Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[android_intent] Android Code Inspection and Clean up #3043

Merged
merged 13 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/android_intent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.7+5

* Android Code Inspection and Clean up.

## 0.3.7+4

* Keep handling deprecated Android v1 classes for backward compatibility.
Expand Down
5 changes: 5 additions & 0 deletions packages/android_intent/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
group 'io.flutter.plugins.androidintent'
version '1.0-SNAPSHOT'
def args = ["-Xlint:deprecation","-Xlint:unchecked","-Werror"]

buildscript {
repositories {
Expand All @@ -19,6 +20,10 @@ rootProject.allprojects {
}
}

project.getTasks().withType(JavaCompile){
options.compilerArgs.addAll(args)
}

apply plugin: 'com.android.library'

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/** Forwards incoming {@link MethodCall}s to {@link IntentSender#send}. */
Expand Down Expand Up @@ -75,14 +76,19 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
String action = convertAction((String) call.argument("action"));
Integer flags = call.argument("flags");
String category = call.argument("category");
Uri data = call.argument("data") != null ? Uri.parse((String) call.argument("data")) : null;
Bundle arguments = convertArguments((Map<String, ?>) call.argument("arguments"));
String stringData = call.argument("data");
Uri data = call.argument("data") != null ? Uri.parse(stringData) : null;
Map<String, ?> stringMap = call.argument("arguments");
Bundle arguments = convertArguments(stringMap);
String packageName = call.argument("package");
ComponentName componentName =
(!TextUtils.isEmpty(packageName)
&& !TextUtils.isEmpty((String) call.argument("componentName")))
? new ComponentName(packageName, (String) call.argument("componentName"))
: null;
String component = call.argument("componentName");
ComponentName componentName = null;
if (packageName != null
&& component != null
&& !TextUtils.isEmpty(packageName)
&& !TextUtils.isEmpty(component)) {
componentName = new ComponentName(packageName, component);
}
String type = call.argument("type");

Intent intent =
Expand Down Expand Up @@ -128,6 +134,9 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
}
for (String key : arguments.keySet()) {
Object value = arguments.get(key);
ArrayList<String> stringArrayList = isStringArrayList(value);
ArrayList<Integer> integerArrayList = isIntegerArrayList(value);
Map<String, ?> stringMap = isStringKeyedMap(value);
if (value instanceof Integer) {
bundle.putInt(key, (Integer) value);
} else if (value instanceof String) {
Expand All @@ -146,42 +155,67 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
bundle.putLongArray(key, (long[]) value);
} else if (value instanceof double[]) {
bundle.putDoubleArray(key, (double[]) value);
} else if (isTypedArrayList(value, Integer.class)) {
bundle.putIntegerArrayList(key, (ArrayList<Integer>) value);
} else if (isTypedArrayList(value, String.class)) {
bundle.putStringArrayList(key, (ArrayList<String>) value);
} else if (isStringKeyedMap(value)) {
bundle.putBundle(key, convertArguments((Map<String, ?>) value));
} else if (integerArrayList != null) {
bundle.putIntegerArrayList(key, integerArrayList);
} else if (stringArrayList != null) {
bundle.putStringArrayList(key, stringArrayList);
} else if (stringMap != null) {
bundle.putBundle(key, convertArguments(stringMap));
} else {
throw new UnsupportedOperationException("Unsupported type " + value);
}
}
return bundle;
}

private static boolean isTypedArrayList(Object value, Class<?> type) {
private static ArrayList<Integer> isIntegerArrayList(Object value) {
ArrayList<Integer> integerArrayList = new ArrayList<>();
if (!(value instanceof ArrayList)) {
return false;
return null;
}
ArrayList list = (ArrayList) value;
for (Object o : list) {
if (!(o == null || type.isInstance(o))) {
return false;
ArrayList<?> intList = (ArrayList<?>) value;
for (Object o : intList) {
if (!(o instanceof Integer)) {
return null;
} else {
integerArrayList.add((Integer) o);
}
}
return true;
return integerArrayList;
}

private static boolean isStringKeyedMap(Object value) {
private static ArrayList<String> isStringArrayList(Object value) {
ArrayList<String> stringArrayList = new ArrayList<>();
if (!(value instanceof ArrayList)) {
return null;
}
ArrayList<?> stringList = (ArrayList<?>) value;
for (Object o : stringList) {
if (!(o instanceof String)) {
return null;
} else {
stringArrayList.add((String) o);
}
}
return stringArrayList;
}

private static Map<String, ?> isStringKeyedMap(Object value) {
Map<String, Object> stringMap = new HashMap<>();
if (!(value instanceof Map)) {
return false;
return null;
}
Map map = (Map) value;
for (Object key : map.keySet()) {
if (!(key == null || key instanceof String)) {
return false;
Map<?, ?> mapValue = (Map<?, ?>) value;
for (Object key : mapValue.keySet()) {
if (!(key instanceof String)) {
return null;
} else {
Object o = mapValue.get(key);
if (o != null) {
stringMap.put((String) key, o);
}
}
}
return true;
return stringMap;
}
}
2 changes: 1 addition & 1 deletion packages/android_intent/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/android_intent
# 0.3.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.3.7+4
version: 0.3.7+5

flutter:
plugin:
Expand Down