Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
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
5 changes: 5 additions & 0 deletions packages/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.3.2

* Support the v2 Android embedder.
* Migrate to using the new e2e test binding.

## 1.3.1

* Define clang module for iOS.
Expand Down
25 changes: 25 additions & 0 deletions packages/path_provider/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,28 @@ android {
disable 'InvalidPackage'
}
}

// TODO(amirh): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
afterEvaluate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this temporary tweak, the error you were pointing at should be gone on stable. Would you like to sync your PR up to master and try the tests again?

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"
}
}
}
}
2 changes: 2 additions & 0 deletions packages/path_provider/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.enableJetifier=true
android.useAndroidX=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2019 The Flutter 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 dev.flutter.plugins.pathprovider;

import androidx.annotation.NonNull;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.pathprovider.PathProviderMethodCallHandler;

public class PathProviderPlugin implements FlutterPlugin {
@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
MethodChannel channel =
new MethodChannel(
binding.getFlutterEngine().getDartExecutor(), "plugins.flutter.io/path_provider");
PathProviderMethodCallHandler handler =
new PathProviderMethodCallHandler(binding.getApplicationContext());
channel.setMethodCallHandler(handler);
}

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2019 The Flutter 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.pathprovider;

import android.content.Context;
import androidx.annotation.NonNull;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.util.PathUtils;
import java.io.File;

public class PathProviderMethodCallHandler implements MethodCallHandler {

private final Context context;

public PathProviderMethodCallHandler(Context context) {
this.context = context;
}

@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
switch (call.method) {
case "getTemporaryDirectory":
result.success(getPathProviderTemporaryDirectory());
break;
case "getApplicationDocumentsDirectory":
result.success(getPathProviderApplicationDocumentsDirectory());
break;
case "getStorageDirectory":
result.success(getPathProviderStorageDirectory());
break;
case "getApplicationSupportDirectory":
result.success(getApplicationSupportDirectory());
break;
default:
result.notImplemented();
}
}

private String getPathProviderTemporaryDirectory() {
return context.getCacheDir().getPath();
}

private String getApplicationSupportDirectory() {
return PathUtils.getFilesDir(context);
}

private String getPathProviderApplicationDocumentsDirectory() {
return PathUtils.getDataDirectory(context);
}

private String getPathProviderStorageDirectory() {
final File dir = context.getExternalFilesDir(null);
if (dir == null) {
return null;
}
return dir.getAbsolutePath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,15 @@

package io.flutter.plugins.pathprovider;

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 io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.util.PathUtils;
import java.io.File;

public class PathProviderPlugin implements MethodCallHandler {
private final Registrar mRegistrar;
public class PathProviderPlugin {

public static void registerWith(Registrar registrar) {
MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider");
PathProviderPlugin instance = new PathProviderPlugin(registrar);
PathProviderMethodCallHandler instance = new PathProviderMethodCallHandler(registrar.context());
channel.setMethodCallHandler(instance);
}

private PathProviderPlugin(Registrar registrar) {
this.mRegistrar = registrar;
}

@Override
public void onMethodCall(MethodCall call, Result result) {
switch (call.method) {
case "getTemporaryDirectory":
result.success(getPathProviderTemporaryDirectory());
break;
case "getApplicationDocumentsDirectory":
result.success(getPathProviderApplicationDocumentsDirectory());
break;
case "getStorageDirectory":
result.success(getPathProviderStorageDirectory());
break;
case "getApplicationSupportDirectory":
result.success(getApplicationSupportDirectory());
break;
default:
result.notImplemented();
}
}

private String getPathProviderTemporaryDirectory() {
return mRegistrar.context().getCacheDir().getPath();
}

private String getApplicationSupportDirectory() {
return PathUtils.getFilesDir(mRegistrar.context());
}

private String getPathProviderApplicationDocumentsDirectory() {
return PathUtils.getDataDirectory(mRegistrar.context());
}

private String getPathProviderStorageDirectory() {
final File dir = mRegistrar.context().getExternalFilesDir(null);
if (dir == null) {
return null;
}
return dir.getAbsolutePath();
}
}
4 changes: 2 additions & 2 deletions packages/path_provider/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ flutter {

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
// for details. 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.pathproviderexample;

import static org.junit.Assert.*;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class EmbeddingV1ActivityTest {
@Rule
public ActivityTestRule<EmbeddingV1Activity> rule =
new ActivityTestRule<>(EmbeddingV1Activity.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
// for details. 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.pathproviderexample;

import androidx.test.rule.ActivityTestRule;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class MainActivityTest {
@Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="io.flutter.plugins.pathproviderexample">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<application android:name="io.flutter.app.FlutterApplication" android:label="path_provider_example" android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<application
android:name="io.flutter.app.FlutterApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="path_provider_example"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".EmbeddingV1Activity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:exported="true"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.pathproviderexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class EmbeddingV1Activity extends FlutterActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

package io.flutter.plugins.pathproviderexample;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import dev.flutter.plugins.pathprovider.PathProviderPlugin;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;

public class MainActivity extends FlutterActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
public void configureFlutterEngine(FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
// TODO(jackson): Remove this once v2 of GeneratedPluginRegistrant rolls to stable.
// https://github.com/flutter/flutter/issues/42694
flutterEngine.getPlugins().add(new PathProviderPlugin());
}
}
3 changes: 3 additions & 0 deletions packages/path_provider/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableJetifier=false
android.useAndroidX=true
android.enableR8=true
1 change: 1 addition & 0 deletions packages/path_provider/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
path_provider:
path: ../
uuid: "^1.0.0"
e2e: "^0.2.1"

dev_dependencies:
flutter_driver:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import 'dart:async';

import 'dart:io';
import 'package:flutter_driver/driver_extension.dart';
import 'package:e2e/e2e.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider/path_provider.dart';
import 'package:uuid/uuid.dart';

void main() {
final Completer<String> allTestsCompleter = Completer<String>();
enableFlutterDriverExtension(handler: (_) => allTestsCompleter.future);
tearDownAll(() => allTestsCompleter.complete(null));
E2EWidgetsFlutterBinding.ensureInitialized();

test('getTemporaryDirectory', () async {
final Directory result = await getTemporaryDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';

import 'package:flutter_driver/flutter_driver.dart';

Future<void> main() async {
final FlutterDriver driver = await FlutterDriver.connect();
await driver.requestData(null, timeout: const Duration(minutes: 1));
final String result =
await driver.requestData(null, timeout: const Duration(minutes: 1));
driver.close();
exit(result == 'pass' ? 0 : 1);
}