Skip to content

Commit

Permalink
V4 to master (#94)
Browse files Browse the repository at this point in the history
* Update NetworkManager, remove some unused code

* Add EngineBroadcastReceiver class, add usage of this class. Upgrade Engine starting behavior. Refactor engine code.

* Add sdome improvements for files storage. Add context menu in transfers to show the absolute file path for a transfer

* Remove obsolete code

* Create empty file before add transfer for non-SAF filesystems to avoid removing transfers when no bytes were received before exit the application

* Set target version to Android 33. Disable lint release builds checking.
  • Loading branch information
a-pavlov authored Aug 21, 2023
1 parent 6c8257b commit b5f7376
Show file tree
Hide file tree
Showing 22 changed files with 661 additions and 136 deletions.
12 changes: 7 additions & 5 deletions android/jdonkey/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Expand All @@ -27,7 +27,8 @@
<activity
android:name="org.dkf.jmule.activities.SplashActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme">
android:theme="@style/SplashTheme"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -36,7 +37,8 @@

<activity
android:name="org.dkf.jmule.activities.MainActivity"
android:label="@string/app_name" >
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="org.dkf.jmule.android.ACTION_SHOW_TRANSFERS" />
<action android:name="org.dkf.jmule.android.ACTION_REQUEST_SHUTDOWN" />
Expand Down Expand Up @@ -96,7 +98,7 @@
android:resource="@xml/provider_paths" />
</provider>

<service android:name="org.dkf.jmule.ED2KService">
<service android:name="org.dkf.jmule.ED2KService" android:exported="false">
<intent-filter>
<action android:name="org.dkf.jmule.INTENT_OPEN"/>
<action android:name="org.dkf.jmule.INTENT_CLOSE"/>
Expand Down
48 changes: 26 additions & 22 deletions android/jdonkey/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import groovy.swing.SwingBuilder
import groovy.xml.Namespace
apply plugin: 'com.android.application'

buildscript {
repositories {
// Gradle 4.1 and higher include support for Google's Maven repo using
// the google() method. And you need to include this repo to download
// Android Gradle plugin 3.0.0 or higher.
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'org.codehaus.groovy:groovy-all:3.0.9'
}
}

Expand All @@ -21,15 +21,15 @@ repositories {

def manifestVersionCode() {
def manifestFile = new File(project.projectDir.absolutePath + '/AndroidManifest.xml')
def ns = new groovy.xml.Namespace("http://schemas.android.com/apk/res/android", "android")
def ns = new Namespace("http://schemas.android.com/apk/res/android", "android")
def xml = new groovy.xml.XmlParser().parse(manifestFile)
//System.out.println("manifestVersionCode: xml.attributes()[ns.versionCode].toString()=" + xml.attributes()[ns.versionCode].toString())
return Integer.parseInt(xml.attributes()[ns.versionCode].toString())
}

def manifestVersionName() {
def manifestFile = file(project.projectDir.absolutePath + '/AndroidManifest.xml')
def ns = new groovy.xml.Namespace("http://schemas.android.com/apk/res/android", "android")
def ns = new Namespace("http://schemas.android.com/apk/res/android", "android")
def xml = new groovy.xml.XmlParser().parse(manifestFile)
//System.out.println("manifestVersionName: " + xml.attributes()[ns.versionName].toString())
return xml.attributes()[ns.versionName].toString()
Expand Down Expand Up @@ -66,13 +66,13 @@ def changeApkOutput(variant) {
boolean isAssembleRelease = gradle.startParameter.taskNames.contains("assembleRelease") || gradle.startParameter.taskNames.contains("assembleBasicRelease")

android {
compileSdkVersion 31
compileSdkVersion 33

defaultConfig {
applicationId 'org.dkf.jmule'
versionName project.ext.versionName
minSdkVersion 16
targetSdkVersion 30
minSdkVersion 21
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -100,9 +100,6 @@ android {
}
}

lintOptions {
abortOnError false
}

signingConfigs {
release {
Expand Down Expand Up @@ -154,6 +151,13 @@ android {
resValue "string", "application_label", "Mule"
}
}
lint {
abortOnError false
}

lintOptions {
checkReleaseBuilds false
}

applicationVariants.all { variant ->
changeApkOutput(variant)
Expand All @@ -162,17 +166,17 @@ android {

dependencies {
implementation project(':core')
implementation 'androidx.appcompat:appcompat:1.4.1'
//api group: 'org.slf4j', name: 'slf4j-android', version: '1.7.+'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.documentfile:documentfile:1.0.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.re2j:re2j:1.6'
implementation 'com.google.code.gson:gson:2.8.8'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
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'
implementation 'com.google.android.material:material:1.7.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
testImplementation 'org.robolectric:robolectric:4.6'
androidTestImplementation 'androidx.test:core:' + project.ext.coreVersion
androidTestImplementation 'androidx.test.ext:junit:' + project.ext.extJUnitVersion
Expand All @@ -187,7 +191,7 @@ class SignatureRequester {
void ask() {
System.setProperty('java.awt.headless', 'false')
if (System.console() == null) { // this is always the case on macOS at least
new groovy.swing.SwingBuilder().edt {
new SwingBuilder().edt {
dialog(modal: true,
title: 'Enter keystore data',
alwaysOnTop: true,
Expand Down
22 changes: 14 additions & 8 deletions android/jdonkey/src/main/java/org/dkf/jmule/AndroidPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,29 @@
*/
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<Byte, String> 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();
}

/* For Older versions of Android where we used to have access to write to external storage
* <externalStoragePath>
* <externalStoragePath>/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) {
Expand All @@ -79,6 +81,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"
Expand Down
19 changes: 2 additions & 17 deletions android/jdonkey/src/main/java/org/dkf/jmule/AndroidPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.dkf.jmule;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.Looper;
Expand Down Expand Up @@ -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();
Expand All @@ -115,22 +116,6 @@ public int androidVersion() {
return sdk;
}

public AndroidPlatform.NetworkType networkType() {
if (NetworkManager.instance().isDataMobileUp()) {
return AndroidPlatform.NetworkType.MOBILE;
}

if (NetworkManager.instance().isDataWIFIUp()) {
return AndroidPlatform.NetworkType.WIFI;
}

if (NetworkManager.instance().isDataWiMAXUp()) {
return AndroidPlatform.NetworkType.WIMAX;
}

return AndroidPlatform.NetworkType.NONE;
}

public static boolean saf() {
AndroidPlatform p = Platforms.get();
return p.fileSystem() instanceof LollipopFileSystem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ private void load() {
defaultValues.put(Constants.PREF_KEY_SEARCH_FULLTEXT_SEARCH_RESULTS_LIMIT, 256);

defaultValues.put(Constants.PREF_KEY_NETWORK_USE_MOBILE_DATA, true);
defaultValues.put(Constants.PREF_KEY_NETWORK_USE_WIFI_ONLY, false);
defaultValues.put(Constants.PREF_KEY_NETWORK_BITTORRENT_ON_VPN_ONLY, false);
defaultValues.put(Constants.PREF_KEY_NETWORK_MAX_CONCURRENT_UPLOADS, 3);


defaultValues.put(Constants.PREF_KEY_STORAGE_PATH, Environment.getExternalStorageDirectory().getAbsolutePath()); // /mnt/sdcard

resetValue(Constants.PREF_KEY_SEARCH_COUNT_DOWNLOAD_FOR_TORRENT_DEEP_SCAN);
Expand Down
3 changes: 3 additions & 0 deletions android/jdonkey/src/main/java/org/dkf/jmule/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ private Constants() {
public static final String PREF_KEY_TRANSFER_MAX_DOWNLOADS = "jmule.prefs.transfer.max_downloads";
public static final String PREF_KEY_TRANSFER_MAX_TOTAL_CONNECTIONS = "jmule.prefs.transfer.max_total_connections";
public static final String PREF_KEY_NETWORK_USE_MOBILE_DATA = "jmule.prefs.network.use_mobile_data";
public static final String PREF_KEY_NETWORK_USE_WIFI_ONLY = "jmule.prefs.network.use_wifi_only";
public static final String PREF_KEY_NETWORK_BITTORRENT_ON_VPN_ONLY = "jmule.prefs.network.bittorrent_on_vpn_only";

// ed2k DHT settings
public static final String PREF_KEY_CONNECT_DHT = "jmule.prefs.connect_dht";
Expand All @@ -115,6 +117,7 @@ private Constants() {
public static final String ACTION_SETTINGS_SELECT_STORAGE = "org.dkf.jmule.ACTION_SETTINGS_SELECT_STORAGE";
public static final String ACTION_SETTINGS_OPEN_TORRENT_SETTINGS = "org.dkf.jmule.ACTION_SETTINGS_OPEN_TORRENT_SETTINGS";
public static final String ACTION_NOTIFY_SDCARD_MOUNTED = "org.dkf.jmule.ACTION_NOTIFY_SDCARD_MOUNTED";
public static final String ACTION_NOTIFY_DATA_INTERNET_CONNECTION = "org.dkf.jmule.NOTIFY_CHECK_INTERNET_CONNECTION";
public static final String EXTRA_DOWNLOAD_COMPLETE_PATH = "org.dkf.jmule.EXTRA_DOWNLOAD_COMPLETE_PATH";
public static final String EXTRA_REFRESH_FILE_TYPE = "org.dkf.jmule.EXTRA_REFRESH_FILE_TYPE";
public static final String EXTRA_FINISH_MAIN_ACTIVITY = "org.dkf.jmule.EXTRA_FINISH_MAIN_ACTIVITY";
Expand Down
29 changes: 26 additions & 3 deletions android/jdonkey/src/main/java/org/dkf/jmule/ED2KService.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.dkf.jed2k.protocol.kad.KadId;
import org.dkf.jed2k.protocol.kad.KadNodesDat;
import org.dkf.jed2k.protocol.server.search.SearchRequest;
import org.dkf.jmule.activities.MainActivity;
import org.slf4j.Logger;

import java.io.BufferedReader;
Expand Down Expand Up @@ -1010,18 +1011,34 @@ private void setupNotification() {

private PendingIntent createShowFrostwireIntent() {
return PendingIntent.getActivity(getApplicationContext(),
0,
new Intent(getApplicationContext(),
MainActivity.class).
setAction(ACTION_SHOW_TRANSFERS).
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK),
PendingIntent.FLAG_IMMUTABLE);

/*return PendingIntent.getActivity(getApplicationContext(),
0,
new Intent(ACTION_SHOW_TRANSFERS)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK),
0);
0);*/
}

private PendingIntent createShutdownIntent() {
return PendingIntent.getActivity(getApplicationContext(),
1,
new Intent(getApplicationContext(),
MainActivity.class).
setAction(ACTION_REQUEST_SHUTDOWN).
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK),
PendingIntent.FLAG_IMMUTABLE);
/*
return PendingIntent.getActivity(getApplicationContext(),
1,
new Intent(ACTION_REQUEST_SHUTDOWN).
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK),
0);
0);*/
}

private void buildNotification(final String title, final String summary, final String extra) {
Expand Down Expand Up @@ -1172,7 +1189,13 @@ public TransferHandle addTransfer(final Hash hash, final long fileSize, final Fi
throw new JED2KException(ErrorCode.IO_EXCEPTION);
}
} else {
return session.addTransfer(hash, fileSize, file);
try {
file.createNewFile();
return session.addTransfer(hash, fileSize, file);
} catch (IOException e) {
log.error("unable to create target file {}", e);
throw new JED2KException(ErrorCode.IO_EXCEPTION);
}
}
}

Expand Down
Loading

0 comments on commit b5f7376

Please sign in to comment.