156 lines
5.4 KiB
Java
156 lines
5.4 KiB
Java
package io.flutter.plugins.custompathprovider;
|
|
|
|
import android.content.Context;
|
|
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
|
import io.flutter.plugin.common.MethodCall;
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
import io.flutter.plugin.common.PluginRegistry;
|
|
import io.flutter.util.PathUtils;
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class CustomPathProviderPlugin implements FlutterPlugin, MethodChannel.MethodCallHandler {
|
|
private MethodChannel channel;
|
|
private Context context;
|
|
|
|
public static void registerWith(PluginRegistry.Registrar registrar) {
|
|
CustomPathProviderPlugin customPathProviderPlugin = new CustomPathProviderPlugin();
|
|
customPathProviderPlugin.channel = new MethodChannel(registrar.messenger(), "plugins.flutter.io/path_provider");
|
|
customPathProviderPlugin.context = registrar.context();
|
|
customPathProviderPlugin.channel.setMethodCallHandler(customPathProviderPlugin);
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.plugins.FlutterPlugin
|
|
public void onAttachedToEngine(FlutterPlugin.FlutterPluginBinding flutterPluginBinding) {
|
|
this.channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "plugins.flutter.io/path_provider");
|
|
this.context = flutterPluginBinding.getApplicationContext();
|
|
this.channel.setMethodCallHandler(this);
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.plugins.FlutterPlugin
|
|
public void onDetachedFromEngine(FlutterPlugin.FlutterPluginBinding flutterPluginBinding) {
|
|
this.channel.setMethodCallHandler(null);
|
|
this.channel = null;
|
|
}
|
|
|
|
/* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
|
|
@Override // io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
|
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
|
|
char c;
|
|
String str = methodCall.method;
|
|
str.hashCode();
|
|
switch (str.hashCode()) {
|
|
case -1832373352:
|
|
if (str.equals("getApplicationSupportDirectory")) {
|
|
c = 0;
|
|
break;
|
|
}
|
|
c = 65535;
|
|
break;
|
|
case -1208689078:
|
|
if (str.equals("getExternalCacheDirectories")) {
|
|
c = 1;
|
|
break;
|
|
}
|
|
c = 65535;
|
|
break;
|
|
case 299667825:
|
|
if (str.equals("getExternalStorageDirectories")) {
|
|
c = 2;
|
|
break;
|
|
}
|
|
c = 65535;
|
|
break;
|
|
case 1200320591:
|
|
if (str.equals("getApplicationDocumentsDirectory")) {
|
|
c = 3;
|
|
break;
|
|
}
|
|
c = 65535;
|
|
break;
|
|
case 1252916648:
|
|
if (str.equals("getStorageDirectory")) {
|
|
c = 4;
|
|
break;
|
|
}
|
|
c = 65535;
|
|
break;
|
|
case 1711844626:
|
|
if (str.equals("getTemporaryDirectory")) {
|
|
c = 5;
|
|
break;
|
|
}
|
|
c = 65535;
|
|
break;
|
|
default:
|
|
c = 65535;
|
|
break;
|
|
}
|
|
if (c == 0) {
|
|
result.success(getApplicationSupportDirectory());
|
|
return;
|
|
}
|
|
if (c == 1) {
|
|
result.success(getPathProviderExternalCacheDirectories());
|
|
return;
|
|
}
|
|
if (c == 2) {
|
|
result.success(getPathProviderExternalStorageDirectories(CustomStorageDirectoryMapper.androidType((Integer) methodCall.argument("type"))));
|
|
return;
|
|
}
|
|
if (c == 3) {
|
|
result.success(getPathProviderApplicationDocumentsDirectory());
|
|
return;
|
|
}
|
|
if (c == 4) {
|
|
result.success(getPathProviderStorageDirectory());
|
|
} else if (c == 5) {
|
|
result.success(getPathProviderTemporaryDirectory());
|
|
} else {
|
|
result.notImplemented();
|
|
}
|
|
}
|
|
|
|
private String getPathProviderTemporaryDirectory() {
|
|
return this.context.getCacheDir().getPath();
|
|
}
|
|
|
|
private String getApplicationSupportDirectory() {
|
|
return PathUtils.getFilesDir(this.context);
|
|
}
|
|
|
|
private String getPathProviderApplicationDocumentsDirectory() {
|
|
return PathUtils.getDataDirectory(this.context);
|
|
}
|
|
|
|
private String getPathProviderStorageDirectory() {
|
|
File externalFilesDir = this.context.getExternalFilesDir(null);
|
|
if (externalFilesDir == null) {
|
|
return null;
|
|
}
|
|
return externalFilesDir.getAbsolutePath();
|
|
}
|
|
|
|
private List<String> getPathProviderExternalCacheDirectories() {
|
|
ArrayList arrayList = new ArrayList();
|
|
for (File file : this.context.getExternalCacheDirs()) {
|
|
if (file != null) {
|
|
arrayList.add(file.getAbsolutePath());
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
private List<String> getPathProviderExternalStorageDirectories(String str) {
|
|
ArrayList arrayList = new ArrayList();
|
|
for (File file : this.context.getExternalFilesDirs(str)) {
|
|
if (file != null) {
|
|
arrayList.add(file.getAbsolutePath());
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
}
|