Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
62e74ea
Fix README.md for url_launcher_web (#2136)
hterkelsen Oct 7, 2019
a5a1b36
[video_player] Basic test for VideoPlayerController initialization (#…
amirh Oct 7, 2019
a9153ef
BugFix: `formatHint` was meant for network streams. (#2141)
jtmcdole Oct 7, 2019
bf17b0a
Rename instrumentation_adapter plugin to e2e plugin (#2161)
collinjackson Oct 8, 2019
9f9e5f7
[local_auth] Define clang module for iOS (#2146)
jmagman Oct 8, 2019
2fcff58
[url_launcher] Enable androidx and jetifier in android gradle propert…
bparrishMines Oct 10, 2019
1dae5b7
[url_launcher] Define clang module for iOS (#2177)
jmagman Oct 11, 2019
3900700
[shared_preferences] Define clang module for iOS
jmagman Oct 11, 2019
369a879
[sensors] Define clang module for iOS (#2175)
jmagman Oct 11, 2019
b182da8
[package_info] Define clang module for iOS (#2148)
jmagman Oct 11, 2019
178263d
[quick_actions] Define clang module for iOS (#2149)
jmagman Oct 11, 2019
ff8a4d7
[path_provider] Define clang module for iOS (#2147)
jmagman Oct 11, 2019
decb6b6
[e2e] update README (#2178)
collinjackson Oct 11, 2019
0359295
[android_intent] Migrate to the new embedding (#2143)
Oct 14, 2019
026043e
[video_player] Define clang module for iOS (#2183)
jmagman Oct 14, 2019
878daa9
[google_sign_in] Define clang module for iOS (#2184)
jmagman Oct 14, 2019
3f8502e
[webview_flutter] Define clang module for iOS (#2185)
jmagman Oct 14, 2019
37cb413
[battery] Define clang module for iOS (#2179)
jmagman Oct 14, 2019
f54320b
[share] Define clang module for iOS (#2180)
jmagman Oct 14, 2019
63d0571
[android_intent] Bump the Flutter SDK min version (#2188)
Oct 14, 2019
8697a03
Run clang analyzer on iOS and macOS code in CI test when packages cha…
jmagman Oct 14, 2019
326b21b
[battery] Support the v2 Android embedder (#2152)
amirh Oct 14, 2019
3a77d38
[battery] relax the example app minimal required Flutter version (#2…
amirh Oct 14, 2019
0992077
[image_picker] fix crash when aar from 'flutter build aar' (#2120)
liujingtech Oct 14, 2019
573c9ff
[flutter_webview] Migrate to the new embedding (#2169)
Oct 15, 2019
f7297f5
[e2e] Update to support new embedder (#2190)
collinjackson Oct 15, 2019
fb37cfc
[image_picker] Fix iOS build and analyzer warnings (#2191)
jmagman Oct 15, 2019
ba5c774
[camera] Migrate to the new embedding (#2165)
Oct 15, 2019
67697ab
[Connectivity] migrate to the new android embedding (#2142)
Oct 15, 2019
93fe8f7
[in_app_purchase] Fix iOS build warning (#2192)
jmagman Oct 15, 2019
c794ac1
[in_app_purchase] migrate to the v2 android embedding (#2155)
Oct 15, 2019
8150245
[url_launcher] Migrate to the new embedding (#2157)
Oct 15, 2019
3305e37
[webview_flutter] (Trivial) Add V2 warnings (#2196)
Oct 15, 2019
ac1052e
[battery] add e2e dependency to the example app (#2194)
amirh Oct 15, 2019
c155379
Enable testing on both master and stable (#2197)
collinjackson Oct 16, 2019
575f3e7
Revert "Enable testing on both master and stable (#2197)" (#2199)
collinjackson Oct 16, 2019
3e047f9
[url_launcher] Revert embedding support (#2201)
Oct 16, 2019
2ca7b52
[flutter_webview] Revert v2 embedder support (#2200)
Oct 16, 2019
8251326
Add plugin for Android lifecycle in embedding (#2168)
amirh Oct 16, 2019
ec57790
s/flutter_android_lifecycle/flutter_plugin_android_lifecycle/ (#2205)
amirh Oct 17, 2019
c3a9764
update readme (#2206)
amirh Oct 17, 2019
2c161ec
[flutter_plugin_android_lifecycle] bump e2e depenency to 0.2.1 (#2207)
amirh Oct 17, 2019
8099875
[android_intent] Cleanup the V2 migration (#2195)
Oct 17, 2019
dce7169
[package_info] Support the v2 Android embedder (with e2e tests) (#2160)
collinjackson Oct 17, 2019
3e271bc
Re-land testing of plugins on stable (#2203)
collinjackson Oct 17, 2019
2951f84
[url_launcher] Re-land v2 embedding support (#2204)
Oct 17, 2019
b1488e6
Ensure that when testing on stable Cirrus is upgraded to latest on iO…
collinjackson Oct 17, 2019
37936b5
[google_maps_flutter] Add NonNull macro to reduce warnings in iOS (#2…
ened Oct 18, 2019
4cb29b5
[android_intent] componentName must be provided before resolveActivit…
Oct 18, 2019
7310033
[battery]remove AndroidX constraint (#2216)
Oct 18, 2019
a3b00b0
[in_app_purchase] remove AndroidX constraint (#2215)
Oct 18, 2019
53e2151
remove android x in magic script (#2218)
Oct 18, 2019
e4b0cc4
remove android x constraint (#2219)
Oct 18, 2019
a79b89c
[connectivity]remove AndroidX constraint (#2212)
Oct 18, 2019
84dec1a
[url_launcher]remove AndroidX constraint (#2220)
Oct 19, 2019
dadb913
remove android x constraint (#2221)
Oct 19, 2019
017a57e
[path_provider] Android: Support multiple external storage options (#…
ened Oct 21, 2019
08fd95c
[Share] Support v2 android embedder. (#2156)
Oct 21, 2019
3ad2d83
[sensor] Support v2 android embedder. (#2164)
Oct 21, 2019
e61ba6e
[device_info] Support v2 android embedding. (#2163)
Oct 21, 2019
655dd19
[flutter_plugin_android_lifecycle] register the e2e plugin in the exa…
amirh Oct 21, 2019
28107c1
delete all example/android/app/gradle.properties files (#2208)
amirh Oct 21, 2019
fe9b559
[shared_preferences] Support v2 android embedding. (#2162)
Oct 22, 2019
f04b3c8
[url_launcher] Add `url_launcher_platform_interface` package (#2217)
hterkelsen Oct 22, 2019
a68932e
Forbid `... implements UrlLauncherPlatform` (#2230)
amirh Oct 23, 2019
63b4e6b
[url_launcher] Use `url_launcher_platform_interface` to handle calls …
hterkelsen Oct 23, 2019
a1fffa6
[multiple] V2 embedding plugins use compileOnly (#2232)
Oct 25, 2019
a5b7ba8
Use package import to import files inside lib/ directory. (#2236)
chingjun Oct 25, 2019
8160f31
[cleanup] Remove AndroidX warning (#2231)
Oct 28, 2019
bdd41e9
[Shared_preferences]suppress warnings (#2241)
Oct 28, 2019
fe49a79
[e2e] update README (#2233)
collinjackson Oct 28, 2019
7a6c105
[image_picker] swap width and height when source image when orientati…
owops Oct 29, 2019
421b241
[google_maps_flutter] Cast error.code to unsigned long to avoid using…
tommyzed Oct 29, 2019
dff23ca
[url_launcher] Migrate url_launcher_web to the platform interface (#2…
hterkelsen Oct 29, 2019
5b179e3
Adapt the FlutterLifecycleAdapter to the new embedding API (#2243)
amirh Oct 29, 2019
89c4816
[camera] Android: Improve image streaming by creating a request suita…
PerLycke Oct 29, 2019
4c793a3
[google_sign_in] Fix deprecated API usage issue by upgrading CocoaPod…
collinjackson Oct 29, 2019
ffb7903
[local_auth] Api to stop authentication (#2111)
karan-rawal Oct 30, 2019
451a689
run the publish with the pub version from flutter stable (#2250)
amirh Nov 1, 2019
f31d16a
[webview_flutter] Re-land support v2 embedding support (#2209)
Nov 1, 2019
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
Prev Previous commit
Next Next commit
[android_intent] Migrate to the new embedding (flutter#2143)
Migrate android intent to the new embedding.

- Refactors the existing plugin logic into two new classes.
- Adds an implementation of the plugin for the new embedding.
- Adds a unit test.
  • Loading branch information
Michael Klimushyn authored Oct 14, 2019
commit 03592956c73f0de601c19f5cc6f813374d348c50
11 changes: 9 additions & 2 deletions packages/android_intent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.3.4

* Migrate the plugin to use the V2 Android engine embedding. This shouldn't
affect existing functionality. Plugin authors who use the V2 embedding can now
instantiate the plugin and expect that it correctly responds to app lifecycle
changes.

## 0.3.3+3

* Define clang module for iOS.
Expand All @@ -8,11 +15,11 @@

## 0.3.3+1

* Added "action_application_details_settings" action to open application info settings .
* Added "action_application_details_settings" action to open application info settings .

## 0.3.3

* Added "flags" option to call intent.addFlags(int) in native.
* Added "flags" option to call intent.addFlags(int) in native.

## 0.3.2

Expand Down
36 changes: 36 additions & 0 deletions packages/android_intent/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,40 @@ android {
lintOptions {
disable 'InvalidPackage'
}
testOptions {
unitTests.includeAndroidResources = true
}
}

dependencies {
compileOnly 'androidx.annotation:annotation:1.0.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
testImplementation 'androidx.test:core:1.0.0'
testImplementation 'org.robolectric:robolectric:4.3'
}

// TODO(mklim): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
afterEvaluate {
def containsEmbeddingDependencies = false
for (def configuration : configurations.all) {
for (def dependency : configuration.dependencies) {
if (dependency.group == 'io.flutter' &&
dependency.name.startsWith('flutter_embedding') &&
dependency.isTransitive())
{
containsEmbeddingDependencies = true
break
}
}
}
if (!containsEmbeddingDependencies) {
android {
dependencies {
def lifecycle_version = "2.1.0"
api "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
api "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,161 +1,74 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.androidintent;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import java.util.ArrayList;
import java.util.Map;

/** AndroidIntentPlugin */
@SuppressWarnings("unchecked")
public class AndroidIntentPlugin implements MethodCallHandler {
private static final String TAG = AndroidIntentPlugin.class.getCanonicalName();
private final Registrar mRegistrar;
/**
* Plugin implementation that uses the new {@code io.flutter.embedding} package.
*
* <p>Instantiate this in an add to app scenario to gracefully handle activity and context changes.
*/
public final class AndroidIntentPlugin implements FlutterPlugin, ActivityAware {
private final IntentSender sender;
private final MethodCallHandlerImpl impl;

/** Plugin registration. */
public static void registerWith(Registrar registrar) {
final MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/android_intent");
channel.setMethodCallHandler(new AndroidIntentPlugin(registrar));
/**
* Initialize this within the {@code #configureFlutterEngine} of a Flutter activity or fragment.
*
* <p>See {@code io.flutter.plugins.androidintentexample.MainActivity} for an example.
*/
public AndroidIntentPlugin() {
sender = new IntentSender(/*activity=*/ null, /*context=*/ null);
impl = new MethodCallHandlerImpl(sender);
}

private AndroidIntentPlugin(Registrar registrar) {
this.mRegistrar = registrar;
/**
* Registers a plugin implementation that uses the stable {@code io.flutter.plugin.common}
* package.
*
* <p>Calling this automatically initializes the plugin. However plugins initialized this way
* won't react to changes in activity or context, unlike {@link AndroidIntentPlugin}.
*/
public static void registerWith(Registrar registrar) {
IntentSender sender = new IntentSender(registrar.activity(), registrar.context());
MethodCallHandlerImpl impl = new MethodCallHandlerImpl(sender);
impl.startListening(registrar.messenger());
}

private String convertAction(String action) {
switch (action) {
case "action_view":
return Intent.ACTION_VIEW;
case "action_voice":
return Intent.ACTION_VOICE_COMMAND;
case "settings":
return Settings.ACTION_SETTINGS;
case "action_location_source_settings":
return Settings.ACTION_LOCATION_SOURCE_SETTINGS;
case "action_application_details_settings":
return Settings.ACTION_APPLICATION_DETAILS_SETTINGS;
default:
return action;
}
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
sender.setApplicationContext(binding.getApplicationContext());
sender.setActivity(null);
impl.startListening(binding.getFlutterEngine().getDartExecutor());
}

private Bundle convertArguments(Map<String, ?> arguments) {
Bundle bundle = new Bundle();
for (String key : arguments.keySet()) {
Object value = arguments.get(key);
if (value instanceof Integer) {
bundle.putInt(key, (Integer) value);
} else if (value instanceof String) {
bundle.putString(key, (String) value);
} else if (value instanceof Boolean) {
bundle.putBoolean(key, (Boolean) value);
} else if (value instanceof Double) {
bundle.putDouble(key, (Double) value);
} else if (value instanceof Long) {
bundle.putLong(key, (Long) value);
} else if (value instanceof byte[]) {
bundle.putByteArray(key, (byte[]) value);
} else if (value instanceof int[]) {
bundle.putIntArray(key, (int[]) value);
} else if (value instanceof long[]) {
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 {
throw new UnsupportedOperationException("Unsupported type " + value);
}
}
return bundle;
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
sender.setApplicationContext(null);
sender.setActivity(null);
impl.stopListening();
}

private boolean isTypedArrayList(Object value, Class<?> type) {
if (!(value instanceof ArrayList)) {
return false;
}
ArrayList list = (ArrayList) value;
for (Object o : list) {
if (!(o == null || type.isInstance(o))) {
return false;
}
}
return true;
@Override
public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) {
sender.setActivity(binding.getActivity());
}

private boolean isStringKeyedMap(Object value) {
if (!(value instanceof Map)) {
return false;
}
Map map = (Map) value;
for (Object key : map.keySet()) {
if (!(key == null || key instanceof String)) {
return false;
}
}
return true;
@Override
public void onDetachedFromActivity() {
sender.setActivity(null);
}

private Context getActiveContext() {
return (mRegistrar.activity() != null) ? mRegistrar.activity() : mRegistrar.context();
@Override
public void onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity();
}

@Override
public void onMethodCall(MethodCall call, Result result) {
Context context = getActiveContext();
String action = convertAction((String) call.argument("action"));

// Build intent
Intent intent = new Intent(action);
if (mRegistrar.activity() == null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
if (call.argument("flag") != null) {
intent.addFlags((Integer) call.argument("flags"));
}
if (call.argument("category") != null) {
intent.addCategory((String) call.argument("category"));
}
if (call.argument("data") != null) {
intent.setData(Uri.parse((String) call.argument("data")));
}
if (call.argument("arguments") != null) {
intent.putExtras(convertArguments((Map) call.argument("arguments")));
}
if (call.argument("package") != null) {
String packageName = (String) call.argument("package");
intent.setPackage(packageName);
if (call.argument("componentName") != null) {
intent.setComponent(
new ComponentName(packageName, (String) call.argument("componentName")));
}
if (intent.resolveActivity(context.getPackageManager()) == null) {
Log.i(TAG, "Cannot resolve explicit intent - ignoring package");
intent.setPackage(null);
}
}

Log.i(TAG, "Sending intent " + intent);
context.startActivity(intent);

result.success(null);
public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) {
onAttachedToActivity(binding);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package io.flutter.plugins.androidintent;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.Nullable;

/** Forms and launches intents. */
public final class IntentSender {
private static final String TAG = "IntentSender";

private @Nullable Activity activity;
private @Nullable Context applicationContext;

/**
* Caches the given {@code activity} and {@code applicationContext} to use for sending intents
* later.
*
* <p>Either may be null initially, but at least {@code applicationContext} should be set before
* calling {@link #send}.
*
* <p>See also {@link #setActivity}, {@link #setApplicationContext}, and {@link #send}.
*/
public IntentSender(@Nullable Activity activity, @Nullable Context applicationContext) {
this.activity = activity;
this.applicationContext = applicationContext;
}

/**
* Creates and launches an intent with the given params using the cached {@link Activity} and
* {@link Context}.
*
* <p>This will fail to create and send the intent if {@code applicationContext} hasn't been set
* at the time of calling.
*
* <p>This uses {@code activity} to start the intent whenever it's not null. Otherwise it falls
* back to {@code applicationContext} and adds {@link Intent#FLAG_ACTIVITY_NEW_TASK} to the intent
* before launching it.
*
* @param action the Intent action, such as {@code ACTION_VIEW}.
* @param flags forwarded to {@link Intent#addFlags(int)} if non-null.
* @param category forwarded to {@link Intent#addCategory(String)} if non-null.
* @param data forwarded to {@link Intent#setData(Uri)} if non-null.
* @param arguments forwarded to {@link Intent#putExtras(Bundle)} if non-null.
* @param packageName forwarded to {@link Intent#setPackage(String)} if non-null. This is forced
* to null if it can't be resolved.
* @param componentName forwarded to {@link Intent#setComponent(ComponentName)} if non-null.
*/
void send(
String action,
@Nullable Integer flags,
@Nullable String category,
@Nullable Uri data,
@Nullable Bundle arguments,
@Nullable String packageName,
@Nullable ComponentName componentName) {
if (applicationContext == null) {
Log.wtf(TAG, "Trying to send an intent before the applicationContext was initialized.");
return;
}

Intent intent = new Intent(action);

if (flags != null) {
intent.addFlags(flags);
}
if (!TextUtils.isEmpty(category)) {
intent.addCategory(category);
}
if (data != null) {
intent.setData(data);
}
if (arguments != null) {
intent.putExtras(arguments);
}
if (!TextUtils.isEmpty(packageName)) {
intent.setPackage(packageName);
if (intent.resolveActivity(applicationContext.getPackageManager()) == null) {
Log.i(TAG, "Cannot resolve explicit intent - ignoring package");
intent.setPackage(null);
}
}
if (componentName != null) {
intent.setComponent(componentName);
}

Log.v(TAG, "Sending intent " + intent);
if (activity != null) {
activity.startActivity(intent);
} else {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
applicationContext.startActivity(intent);
}
}

/** Caches the given {@code activity} to use for {@link #send}. */
void setActivity(@Nullable Activity activity) {
this.activity = activity;
}

/** Caches the given {@code applicationContext} to use for {@link #send}. */
void setApplicationContext(@Nullable Context applicationContext) {
this.applicationContext = applicationContext;
}
}
Loading