diff --git a/android/jdonkey/AndroidManifest.xml b/android/jdonkey/AndroidManifest.xml index a2cf823c..a787c984 100644 --- a/android/jdonkey/AndroidManifest.xml +++ b/android/jdonkey/AndroidManifest.xml @@ -3,8 +3,8 @@ xmlns:tools="http://schemas.android.com/tools" package="org.dkf.jmule" android:installLocation="auto" - android:versionCode="34" - android:versionName="34"> + android:versionCode="35" + android:versionName="35"> @@ -27,7 +27,8 @@ + android:theme="@style/SplashTheme" + android:exported="true"> @@ -36,7 +37,8 @@ + android:label="@string/app_name" + android:exported="true"> @@ -96,7 +98,7 @@ android:resource="@xml/provider_paths" /> - + diff --git a/android/jdonkey/build.gradle b/android/jdonkey/build.gradle index 7908e5cf..4282a56f 100644 --- a/android/jdonkey/build.gradle +++ b/android/jdonkey/build.gradle @@ -10,7 +10,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:7.0.4' + classpath 'com.android.tools.build:gradle:7.2.1' } } @@ -66,13 +66,13 @@ def changeApkOutput(variant) { boolean isAssembleRelease = gradle.startParameter.taskNames.contains("assembleRelease") || gradle.startParameter.taskNames.contains("assembleBasicRelease") android { - compileSdkVersion 31 + compileSdkVersion 32 defaultConfig { applicationId 'org.dkf.jmule' versionName project.ext.versionName minSdkVersion 16 - targetSdkVersion 30 + targetSdkVersion 32 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -100,9 +100,6 @@ android { } } - lintOptions { - abortOnError false - } signingConfigs { release { @@ -154,6 +151,9 @@ android { resValue "string", "application_label", "Mule" } } + lint { + abortOnError false + } applicationVariants.all { variant -> changeApkOutput(variant) @@ -170,9 +170,9 @@ dependencies { implementation 'androidx.documentfile:documentfile:1.0.1' implementation 'com.google.android.material:material:1.4.0' implementation 'androidx.preference:preference:1.1.1' - debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5' - releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5' - testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1' + //releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:2.9.1' + //testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:2.9.1' testImplementation 'org.robolectric:robolectric:4.6' androidTestImplementation 'androidx.test:core:' + project.ext.coreVersion androidTestImplementation 'androidx.test.ext:junit:' + project.ext.extJUnitVersion diff --git a/android/jdonkey/src/main/java/org/dkf/jmule/AndroidPaths.java b/android/jdonkey/src/main/java/org/dkf/jmule/AndroidPaths.java index 82de4a6a..bdc422dc 100644 --- a/android/jdonkey/src/main/java/org/dkf/jmule/AndroidPaths.java +++ b/android/jdonkey/src/main/java/org/dkf/jmule/AndroidPaths.java @@ -40,27 +40,34 @@ */ public final class AndroidPaths { private static final boolean USE_EXTERNAL_STORAGE_DIR_ON_OR_AFTER_ANDROID_10 = true; - private final Context context; + private final Application app; private static final Map fileTypeFolders = new HashMap<>(); private static final Object fileTypeFoldersLock = new Object(); - public AndroidPaths(Context app) { - this.context = app; + public AndroidPaths(Application app) { + this.app = app; } public File data() { if (SystemUtils.hasAndroid10OrNewer()) { - File externalDir = context.getExternalFilesDir(null); - return USE_EXTERNAL_STORAGE_DIR_ON_OR_AFTER_ANDROID_10 ? externalDir : context.getFilesDir(); + if (SystemUtils.hasAndroid10()) { + return app.getExternalFilesDir(null); + } + + // On Android 11 and up, they finally let us use File objects in the public download directory as long as we have permission from the user + return android11AndUpStorage(); + } + if (SystemUtils.hasAndroid10OrNewer()) { + File externalDir = app.getExternalFilesDir(null); + return USE_EXTERNAL_STORAGE_DIR_ON_OR_AFTER_ANDROID_10 ? externalDir : app.getFilesDir(); } /* For Older versions of Android where we used to have access to write to external storage - * + * /Download/FrostWire/ */ - String path = ConfigurationManager.instance().getStoragePath(); - return new File(ConfigurationManager.instance().getStoragePath()); + return new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath()); } public static byte getFileType(String filePath, boolean returnTorrentsAsDocument) { @@ -79,6 +86,10 @@ public static byte getFileType(String filePath, boolean returnTorrentsAsDocument return result; } + public static File android11AndUpStorage() { + return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); + } + /** * FILE_TYPE_AUDIO -> "Music" diff --git a/android/jdonkey/src/main/java/org/dkf/jmule/AndroidPlatform.java b/android/jdonkey/src/main/java/org/dkf/jmule/AndroidPlatform.java index 7825f399..0ed7c2b7 100644 --- a/android/jdonkey/src/main/java/org/dkf/jmule/AndroidPlatform.java +++ b/android/jdonkey/src/main/java/org/dkf/jmule/AndroidPlatform.java @@ -18,6 +18,7 @@ package org.dkf.jmule; +import android.app.Application; import android.content.Context; import android.os.Build; import android.os.Looper; @@ -88,7 +89,7 @@ enum NetworkType { private final int sdk; - public AndroidPlatform(Context app) { + public AndroidPlatform(Application app) { fileSystem = buildFileSystem(app); systemPaths = new AndroidPaths(app); appSettings = new AndroidSettings(); diff --git a/android/jdonkey/src/main/java/org/dkf/jmule/MainApplication.java b/android/jdonkey/src/main/java/org/dkf/jmule/MainApplication.java index d00bd512..c32561e1 100644 --- a/android/jdonkey/src/main/java/org/dkf/jmule/MainApplication.java +++ b/android/jdonkey/src/main/java/org/dkf/jmule/MainApplication.java @@ -19,7 +19,6 @@ package org.dkf.jmule; import android.app.Application; -import com.squareup.leakcanary.LeakCanary; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,14 +39,6 @@ public void onTerminate() { public void onCreate() { super.onCreate(); - if (LeakCanary.isInAnalyzerProcess(this)) { - // This process is dedicated to LeakCanary for heap analysis. - // You should not init your app in this process. - return; - } - - LeakCanary.install(this); - try { Platforms.set(new AndroidPlatform(this)); diff --git a/android/jdonkey/src/main/java/org/dkf/jmule/Platforms.java b/android/jdonkey/src/main/java/org/dkf/jmule/Platforms.java index 9efaf21b..1ea712c1 100644 --- a/android/jdonkey/src/main/java/org/dkf/jmule/Platforms.java +++ b/android/jdonkey/src/main/java/org/dkf/jmule/Platforms.java @@ -19,12 +19,15 @@ package org.dkf.jmule; import java.io.File; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author gubatron * @author aldenml */ public final class Platforms { + private static final Logger LOG = LoggerFactory.getLogger(Platforms.class); private static AndroidPlatform platform; @@ -64,6 +67,8 @@ public static AndroidSettings appSettings() { } public static File data() { - return get().systemPaths().data(); + File f = get().systemPaths().data(); + LOG.warn("PLATFORM FILE " + f.getAbsolutePath()); + return f; } } diff --git a/android/jdonkey/src/main/java/org/dkf/jmule/adapters/TransferListAdapter.java b/android/jdonkey/src/main/java/org/dkf/jmule/adapters/TransferListAdapter.java index 0f490564..cfe96291 100644 --- a/android/jdonkey/src/main/java/org/dkf/jmule/adapters/TransferListAdapter.java +++ b/android/jdonkey/src/main/java/org/dkf/jmule/adapters/TransferListAdapter.java @@ -257,6 +257,7 @@ private String populateTransferDownloadMenuAction(Transfer download, List dialogPtr; + + OkButtonOnClickListener(Dialog newNoWifiInformationDialog) { + this.dialogPtr = Ref.weak(newNoWifiInformationDialog); + } + + @Override + public void onClick(View view) { + if (Ref.alive(dialogPtr)) { + dialogPtr.get().dismiss(); + } + } + } + + public ShowThePathMenuAction(Context context + , Transfer transfer) { + super(context, R.drawable.ic_search_black_24dp, R.string.transfers_context_menu_show_path_title); + this.transfer = transfer; + } + + @Override + protected void onClick(Context context) { + if (transfer != null) { + ShowThePathDialog dialog = ShowThePathDialog.newInstance(context, transfer.getFilePath()); + dialog.show(((Activity)context).getFragmentManager()); + } + } +} + diff --git a/android/jdonkey/src/main/java/org/dkf/jmule/util/SystemUtils.java b/android/jdonkey/src/main/java/org/dkf/jmule/util/SystemUtils.java index 8dd01741..f3514370 100644 --- a/android/jdonkey/src/main/java/org/dkf/jmule/util/SystemUtils.java +++ b/android/jdonkey/src/main/java/org/dkf/jmule/util/SystemUtils.java @@ -50,6 +50,10 @@ public final class SystemUtils { private static final int VERSION_CODE_KITKAT = 19; private static final int VERSION_SDK_NOUGAT_7_0 = 24; + private static final int VERSION_SDK_NOUGAT_7_0_N = 24; + private static final int VERSION_SDK_ANDROID_10_Q = 29; + private static final int VERSION_SDK_ANDROID_11_R = 30; + private static final int VERSION_SDK_ANDROID_12_S = 31; private SystemUtils() { } @@ -195,6 +199,23 @@ private static boolean hasSdkOrNewer(int versionCode) { return Build.VERSION.SDK_INT >= versionCode; } + @SuppressWarnings("SameParameterValue") + private static boolean hasSdk(int versionCode) { + return Build.VERSION.SDK_INT == versionCode; + } + + + public static boolean hasAndroid10() { + return hasSdk(VERSION_SDK_ANDROID_10_Q); + } + + /** + * Used to determine if the device is running Android11 or greater + */ + public static boolean hasAndroid11OrNewer() { + return hasSdkOrNewer(VERSION_SDK_ANDROID_11_R); + } + /** * Used to determine if the device is running * KitKat (Android 4.4) or greater @@ -226,12 +247,6 @@ public static boolean hasNougatOrNewer() { return hasSdkOrNewer(VERSION_SDK_NOUGAT_7_0); } - /** - * Used to determine if the device is running Android11 or greater - */ - public static boolean hasAndroid11OrNewer() { - return hasSdkOrNewer(30); //Build.VERSION_CODES.R - } /** * We call it "safe" because if any exceptions are thrown, diff --git a/android/jdonkey/src/main/res/layout/dialog_default_info.xml b/android/jdonkey/src/main/res/layout/dialog_default_info.xml new file mode 100644 index 00000000..bfcd644a --- /dev/null +++ b/android/jdonkey/src/main/res/layout/dialog_default_info.xml @@ -0,0 +1,54 @@ + + + + + + + + +