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

Commit dc48e70

Browse files
authored
[path_provider] Add v2 embedding support for (#2284)
1 parent cba3932 commit dc48e70

File tree

13 files changed

+114
-28
lines changed

13 files changed

+114
-28
lines changed

packages/path_provider/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.4.5
2+
3+
* Add support for v2 plugins APIs.
4+
15
## 1.4.4
26

37
* Update driver tests in the example app to e2e tests.

packages/path_provider/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ afterEvaluate {
6262
}
6363
}
6464
}
65-
}
65+
}

packages/path_provider/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
package io.flutter.plugins.pathprovider;
66

7+
import android.content.Context;
78
import android.os.Build.VERSION;
89
import android.os.Build.VERSION_CODES;
910
import androidx.annotation.NonNull;
11+
import io.flutter.embedding.engine.plugins.FlutterPlugin;
1012
import io.flutter.plugin.common.MethodCall;
1113
import io.flutter.plugin.common.MethodChannel;
1214
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
@@ -17,19 +19,33 @@
1719
import java.util.ArrayList;
1820
import java.util.List;
1921

20-
public class PathProviderPlugin implements MethodCallHandler {
22+
public class PathProviderPlugin implements FlutterPlugin, MethodCallHandler {
2123

22-
private final Registrar mRegistrar;
24+
private Context context;
25+
private MethodChannel channel;
26+
27+
public PathProviderPlugin() {}
2328

2429
public static void registerWith(Registrar registrar) {
25-
MethodChannel channel =
26-
new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider");
27-
PathProviderPlugin instance = new PathProviderPlugin(registrar);
28-
channel.setMethodCallHandler(instance);
30+
PathProviderPlugin instance = new PathProviderPlugin();
31+
instance.channel = new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider");
32+
instance.context = registrar.context();
33+
instance.channel.setMethodCallHandler(instance);
2934
}
3035

31-
private PathProviderPlugin(Registrar registrar) {
32-
this.mRegistrar = registrar;
36+
@Override
37+
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
38+
channel =
39+
new MethodChannel(
40+
binding.getFlutterEngine().getDartExecutor(), "plugins.flutter.io/path_provider");
41+
context = binding.getApplicationContext();
42+
channel.setMethodCallHandler(this);
43+
}
44+
45+
@Override
46+
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
47+
channel.setMethodCallHandler(null);
48+
channel = null;
3349
}
3450

3551
@Override
@@ -61,19 +77,19 @@ public void onMethodCall(MethodCall call, @NonNull Result result) {
6177
}
6278

6379
private String getPathProviderTemporaryDirectory() {
64-
return mRegistrar.context().getCacheDir().getPath();
80+
return context.getCacheDir().getPath();
6581
}
6682

6783
private String getApplicationSupportDirectory() {
68-
return PathUtils.getFilesDir(mRegistrar.context());
84+
return PathUtils.getFilesDir(context);
6985
}
7086

7187
private String getPathProviderApplicationDocumentsDirectory() {
72-
return PathUtils.getDataDirectory(mRegistrar.context());
88+
return PathUtils.getDataDirectory(context);
7389
}
7490

7591
private String getPathProviderStorageDirectory() {
76-
final File dir = mRegistrar.context().getExternalFilesDir(null);
92+
final File dir = context.getExternalFilesDir(null);
7793
if (dir == null) {
7894
return null;
7995
}
@@ -84,13 +100,13 @@ private List<String> getPathProviderExternalCacheDirectories() {
84100
final List<String> paths = new ArrayList<>();
85101

86102
if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
87-
for (File dir : mRegistrar.context().getExternalCacheDirs()) {
103+
for (File dir : context.getExternalCacheDirs()) {
88104
if (dir != null) {
89105
paths.add(dir.getAbsolutePath());
90106
}
91107
}
92108
} else {
93-
File dir = mRegistrar.context().getExternalCacheDir();
109+
File dir = context.getExternalCacheDir();
94110
if (dir != null) {
95111
paths.add(dir.getAbsolutePath());
96112
}
@@ -103,13 +119,13 @@ private List<String> getPathProviderExternalStorageDirectories(String type) {
103119
final List<String> paths = new ArrayList<>();
104120

105121
if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
106-
for (File dir : mRegistrar.context().getExternalFilesDirs(type)) {
122+
for (File dir : context.getExternalFilesDirs(type)) {
107123
if (dir != null) {
108124
paths.add(dir.getAbsolutePath());
109125
}
110126
}
111127
} else {
112-
File dir = mRegistrar.context().getExternalFilesDir(type);
128+
File dir = context.getExternalFilesDir(type);
113129
if (dir != null) {
114130
paths.add(dir.getAbsolutePath());
115131
}

packages/path_provider/example/android/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ flutter {
5454
}
5555

5656
dependencies {
57+
androidTestImplementation 'androidx.test:runner:1.2.0'
58+
androidTestImplementation 'androidx.test:rules:1.2.0'
59+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
60+
5761
testImplementation 'junit:junit:4.12'
5862
androidTestImplementation 'androidx.test:runner:1.1.1'
5963
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
package io.flutter.plugins.pathprovider;
3+
4+
import androidx.test.rule.ActivityTestRule;
5+
import dev.flutter.plugins.e2e.FlutterRunner;
6+
import io.flutter.plugins.pathproviderexample.EmbeddingV1Activity;
7+
import org.junit.Rule;
8+
import org.junit.runner.RunWith;
9+
10+
@RunWith(FlutterRunner.class)
11+
public class EmbeddingV1ActivityTest {
12+
@Rule
13+
public ActivityTestRule<EmbeddingV1Activity> rule =
14+
new ActivityTestRule<>(EmbeddingV1Activity.class);
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
package io.flutter.plugins.pathprovider;
3+
4+
import androidx.test.rule.ActivityTestRule;
5+
import dev.flutter.plugins.e2e.FlutterRunner;
6+
import io.flutter.plugins.pathproviderexample.MainActivity;
7+
import org.junit.Rule;
8+
import org.junit.runner.RunWith;
9+
10+
@RunWith(FlutterRunner.class)
11+
public class MainActivityTest {
12+
@Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class);
13+
}

packages/path_provider/example/android/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
<uses-permission android:name="android.permission.INTERNET"/>
55

66
<application android:name="io.flutter.app.FlutterApplication" android:label="path_provider_example" android:icon="@mipmap/ic_launcher">
7+
<activity
8+
android:name=".EmbeddingV1Activity"
9+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
10+
android:hardwareAccelerated="true"
11+
android:windowSoftInputMode="adjustResize">
12+
</activity>
713
<activity android:name=".MainActivity"
814
android:launchMode="singleTop"
915
android:theme="@android:style/Theme.Black.NoTitleBar"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
package io.flutter.plugins.pathproviderexample;
3+
4+
import android.os.Bundle;
5+
import io.flutter.app.FlutterActivity;
6+
import io.flutter.plugins.GeneratedPluginRegistrant;
7+
8+
public class EmbeddingV1Activity extends FlutterActivity {
9+
@Override
10+
protected void onCreate(Bundle savedInstanceState) {
11+
super.onCreate(savedInstanceState);
12+
GeneratedPluginRegistrant.registerWith(this);
13+
}
14+
}

packages/path_provider/example/android/app/src/main/java/io/flutter/plugins/pathproviderexample/MainActivity.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
package io.flutter.plugins.pathproviderexample;
66

7-
import android.os.Bundle;
8-
import io.flutter.app.FlutterActivity;
9-
import io.flutter.plugins.GeneratedPluginRegistrant;
7+
import dev.flutter.plugins.e2e.E2EPlugin;
8+
import io.flutter.embedding.android.FlutterActivity;
9+
import io.flutter.embedding.engine.FlutterEngine;
10+
import io.flutter.plugins.pathprovider.PathProviderPlugin;
1011

1112
public class MainActivity extends FlutterActivity {
12-
13+
// TODO(xster): Remove this once v2 of GeneratedPluginRegistrant rolls to stable. https://github.com/flutter/flutter/issues/42694
1314
@Override
14-
protected void onCreate(Bundle savedInstanceState) {
15-
super.onCreate(savedInstanceState);
16-
GeneratedPluginRegistrant.registerWith(this);
15+
public void configureFlutterEngine(FlutterEngine flutterEngine) {
16+
flutterEngine.getPlugins().add(new PathProviderPlugin());
17+
flutterEngine.getPlugins().add(new E2EPlugin());
1718
}
1819
}

packages/path_provider/example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

packages/path_provider/example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ dependencies:
88
path: ../
99

1010
dev_dependencies:
11+
e2e: ^0.2.1
1112
flutter_driver:
1213
sdk: flutter
1314
test: any
14-
e2e: ^0.2.1
1515

1616
flutter:
1717
uses-material-design: true

packages/path_provider/pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for getting commonly used locations on the Android &
33
iOS file systems, such as the temp and app data directories.
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider
6-
version: 1.4.4
6+
version: 1.4.5
77

88
flutter:
99
plugin:
@@ -18,6 +18,7 @@ dependencies:
1818
meta: ^1.0.5
1919

2020
dev_dependencies:
21+
e2e: ^0.2.1
2122
flutter_test:
2223
sdk: flutter
2324
flutter_driver:
@@ -27,4 +28,4 @@ dev_dependencies:
2728

2829
environment:
2930
sdk: ">=2.0.0-dev.28.0 <3.0.0"
30-
flutter: ">=0.1.4 <2.0.0"
31+
flutter: ">=1.9.1+hotfix.5 <2.0.0"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:path_provider/path_provider.dart';
3+
import 'package:e2e/e2e.dart';
4+
5+
void main() {
6+
E2EWidgetsFlutterBinding.ensureInitialized();
7+
8+
testWidgets('Can get temporary directory', (WidgetTester tester) async {
9+
final String tempPath = (await getTemporaryDirectory()).path;
10+
expect(tempPath, isNotEmpty);
11+
});
12+
}

0 commit comments

Comments
 (0)