diff --git a/packages/path_provider/CHANGELOG.md b/packages/path_provider/CHANGELOG.md index 27dde4284b77..505977e469cf 100644 --- a/packages/path_provider/CHANGELOG.md +++ b/packages/path_provider/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.4.5 + +* Add support for v2 plugins APIs. + ## 1.4.4 * Update driver tests in the example app to e2e tests. diff --git a/packages/path_provider/android/build.gradle b/packages/path_provider/android/build.gradle index 71ea49b2fb39..3bc008e63e0c 100644 --- a/packages/path_provider/android/build.gradle +++ b/packages/path_provider/android/build.gradle @@ -62,4 +62,4 @@ afterEvaluate { } } } -} \ No newline at end of file +} diff --git a/packages/path_provider/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java b/packages/path_provider/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java index 30b00d0e5532..0bf9ee4820a3 100644 --- a/packages/path_provider/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java +++ b/packages/path_provider/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java @@ -4,9 +4,11 @@ package io.flutter.plugins.pathprovider; +import android.content.Context; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import androidx.annotation.NonNull; +import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; @@ -17,19 +19,33 @@ import java.util.ArrayList; import java.util.List; -public class PathProviderPlugin implements MethodCallHandler { +public class PathProviderPlugin implements FlutterPlugin, MethodCallHandler { - private final Registrar mRegistrar; + private Context context; + private MethodChannel channel; + + public PathProviderPlugin() {} public static void registerWith(Registrar registrar) { - MethodChannel channel = - new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider"); - PathProviderPlugin instance = new PathProviderPlugin(registrar); - channel.setMethodCallHandler(instance); + PathProviderPlugin instance = new PathProviderPlugin(); + instance.channel = new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider"); + instance.context = registrar.context(); + instance.channel.setMethodCallHandler(instance); } - private PathProviderPlugin(Registrar registrar) { - this.mRegistrar = registrar; + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { + channel = + new MethodChannel( + binding.getFlutterEngine().getDartExecutor(), "plugins.flutter.io/path_provider"); + context = binding.getApplicationContext(); + channel.setMethodCallHandler(this); + } + + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); + channel = null; } @Override @@ -61,19 +77,19 @@ public void onMethodCall(MethodCall call, @NonNull Result result) { } private String getPathProviderTemporaryDirectory() { - return mRegistrar.context().getCacheDir().getPath(); + return context.getCacheDir().getPath(); } private String getApplicationSupportDirectory() { - return PathUtils.getFilesDir(mRegistrar.context()); + return PathUtils.getFilesDir(context); } private String getPathProviderApplicationDocumentsDirectory() { - return PathUtils.getDataDirectory(mRegistrar.context()); + return PathUtils.getDataDirectory(context); } private String getPathProviderStorageDirectory() { - final File dir = mRegistrar.context().getExternalFilesDir(null); + final File dir = context.getExternalFilesDir(null); if (dir == null) { return null; } @@ -84,13 +100,13 @@ private List getPathProviderExternalCacheDirectories() { final List paths = new ArrayList<>(); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { - for (File dir : mRegistrar.context().getExternalCacheDirs()) { + for (File dir : context.getExternalCacheDirs()) { if (dir != null) { paths.add(dir.getAbsolutePath()); } } } else { - File dir = mRegistrar.context().getExternalCacheDir(); + File dir = context.getExternalCacheDir(); if (dir != null) { paths.add(dir.getAbsolutePath()); } @@ -103,13 +119,13 @@ private List getPathProviderExternalStorageDirectories(String type) { final List paths = new ArrayList<>(); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { - for (File dir : mRegistrar.context().getExternalFilesDirs(type)) { + for (File dir : context.getExternalFilesDirs(type)) { if (dir != null) { paths.add(dir.getAbsolutePath()); } } } else { - File dir = mRegistrar.context().getExternalFilesDir(type); + File dir = context.getExternalFilesDir(type); if (dir != null) { paths.add(dir.getAbsolutePath()); } diff --git a/packages/path_provider/example/android/app/build.gradle b/packages/path_provider/example/android/app/build.gradle index 2ca6a7a4add3..0404c7203903 100644 --- a/packages/path_provider/example/android/app/build.gradle +++ b/packages/path_provider/example/android/app/build.gradle @@ -54,6 +54,10 @@ flutter { } dependencies { + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test:rules:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' diff --git a/packages/path_provider/example/android/app/src/androidTest/java/EmbeddingV1ActivityTest.java b/packages/path_provider/example/android/app/src/androidTest/java/EmbeddingV1ActivityTest.java new file mode 100644 index 000000000000..cce04b79f516 --- /dev/null +++ b/packages/path_provider/example/android/app/src/androidTest/java/EmbeddingV1ActivityTest.java @@ -0,0 +1,15 @@ + +package io.flutter.plugins.pathprovider; + +import androidx.test.rule.ActivityTestRule; +import dev.flutter.plugins.e2e.FlutterRunner; +import io.flutter.plugins.pathproviderexample.EmbeddingV1Activity; +import org.junit.Rule; +import org.junit.runner.RunWith; + +@RunWith(FlutterRunner.class) +public class EmbeddingV1ActivityTest { + @Rule + public ActivityTestRule rule = + new ActivityTestRule<>(EmbeddingV1Activity.class); +} diff --git a/packages/path_provider/example/android/app/src/androidTest/java/MainActivityTest.java b/packages/path_provider/example/android/app/src/androidTest/java/MainActivityTest.java new file mode 100644 index 000000000000..7bdd449981f5 --- /dev/null +++ b/packages/path_provider/example/android/app/src/androidTest/java/MainActivityTest.java @@ -0,0 +1,13 @@ + +package io.flutter.plugins.pathprovider; + +import androidx.test.rule.ActivityTestRule; +import dev.flutter.plugins.e2e.FlutterRunner; +import io.flutter.plugins.pathproviderexample.MainActivity; +import org.junit.Rule; +import org.junit.runner.RunWith; + +@RunWith(FlutterRunner.class) +public class MainActivityTest { + @Rule public ActivityTestRule rule = new ActivityTestRule<>(MainActivity.class); +} diff --git a/packages/path_provider/example/android/app/src/main/AndroidManifest.xml b/packages/path_provider/example/android/app/src/main/AndroidManifest.xml index 793c13b6e612..9e03a9373e33 100644 --- a/packages/path_provider/example/android/app/src/main/AndroidManifest.xml +++ b/packages/path_provider/example/android/app/src/main/AndroidManifest.xml @@ -4,6 +4,12 @@ + + homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider -version: 1.4.4 +version: 1.4.5 flutter: plugin: @@ -18,6 +18,7 @@ dependencies: meta: ^1.0.5 dev_dependencies: + e2e: ^0.2.1 flutter_test: sdk: flutter flutter_driver: @@ -27,4 +28,4 @@ dev_dependencies: environment: sdk: ">=2.0.0-dev.28.0 <3.0.0" - flutter: ">=0.1.4 <2.0.0" + flutter: ">=1.9.1+hotfix.5 <2.0.0" diff --git a/packages/path_provider/test/path_provider_e2e.dart b/packages/path_provider/test/path_provider_e2e.dart new file mode 100644 index 000000000000..545671e32b01 --- /dev/null +++ b/packages/path_provider/test/path_provider_e2e.dart @@ -0,0 +1,12 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:e2e/e2e.dart'; + +void main() { + E2EWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('Can get temporary directory', (WidgetTester tester) async { + final String tempPath = (await getTemporaryDirectory()).path; + expect(tempPath, isNotEmpty); + }); +}