Skip to content

Commit 4d72c46

Browse files
committed
NetCopyClientConnectionPool refactorings
- Use LruCache - Remove use of CountdownLatch - Made NetCopyClientConnectionPool lifecycle-aware - PasswordUtil remove Context parameter
1 parent 39c2bec commit 4d72c46

File tree

50 files changed

+520
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+520
-456
lines changed

.github/workflows/android-feature.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
with:
2323
distribution: "temurin"
2424
java-version: 17
25+
- name: Set up Gradle
26+
uses: gradle/actions/setup-gradle@v4
2527
- name: Check formatting using spotless
26-
uses: gradle/actions/setup-gradle@v3
27-
with:
28-
arguments: spotlessCheck --stacktrace
28+
run: ./gradlew spotlessCheck --stacktrace
2929

3030
build:
3131
name: Build debug and run Jacoco tests
@@ -37,11 +37,26 @@ jobs:
3737
with:
3838
distribution: "temurin"
3939
java-version: 17
40+
- name: Set up Gradle
41+
uses: gradle/actions/setup-gradle@v4
4042
- name: Build with Gradle
41-
uses: gradle/actions/setup-gradle@v3
42-
with:
43-
arguments: assembledebug --stacktrace
43+
run: ./gradlew assembledebug --stacktrace
4444
- name: Run test cases
45-
uses: gradle/actions/setup-gradle@v3
45+
run: ./gradlew jacocoTestPlayDebugUnitTestReport --stacktrace --info
46+
- name: Upload
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: Event File
50+
path: ${{ github.event_path }}
51+
- name: Upload Unit Test Results
52+
if: (!cancelled())
53+
uses: actions/upload-artifact@v4
4654
with:
47-
arguments: jacocoTestPlayDebugUnitTestReport --stacktrace --info
55+
name: unit-test-results
56+
path: app/build/test-results/test*UnitTest/
57+
# - name: Upload Jacoco Coverage Report
58+
# if: (!cancelled())
59+
# uses: actions/upload-artifact@v4
60+
# with:
61+
# name: jacoco-coverage-report
62+
# path: "app/build/jacoco/jacoco.xml"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Publish Test Results
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Android Build CI", "Android Feature CI"]
6+
types:
7+
- completed
8+
permissions: {}
9+
10+
jobs:
11+
publish_test_results:
12+
runs-on: ubuntu-latest
13+
if: github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure'
14+
15+
permissions:
16+
checks: write
17+
pull-requests: write
18+
actions: read
19+
steps:
20+
- name: Download and Extract Artifacts
21+
uses: dawidd6/action-download-artifact@e7466d1a7587ed14867642c2ca74b5bcc1e19a2d
22+
with:
23+
run_id: ${{ github.event.workflow_run.id }}
24+
path: artifacts
25+
- name: Publish Test Results
26+
uses: EnricoMi/publish-unit-test-result-action@v2
27+
with:
28+
commit: ${{ github.event.workflow_run.head_sha }}
29+
event_file: artifacts/Event File/event.json
30+
event_name: ${{ github.event.workflow_run.event }}
31+
files: "artifacts/**/*.xml"

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ dependencies {
145145
implementation libs.androidX.constraintLayout
146146
implementation libs.androidX.multidex //Multiple dex files
147147
implementation libs.androidX.biometric
148+
implementation libs.androidX.lifecycle
149+
implementation libs.androidX.lifecycle.process
148150
implementation libs.room.runtime
149151
implementation libs.room.rxjava2
150152

app/src/androidTest/java/com/amaze/filemanager/asynchronous/services/ftp/FtpServiceEspressoTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ class FtpServiceEspressoTest {
146146
.putString(
147147
FtpService.KEY_PREFERENCE_PASSWORD,
148148
PasswordUtil.encryptPassword(
149-
ApplicationProvider.getApplicationContext(),
150149
"passw0rD",
151150
),
152151
)

app/src/androidTest/java/com/amaze/filemanager/filesystem/files/CryptUtilTest.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,19 @@
2222

2323
import static org.junit.Assert.assertEquals;
2424

25-
import org.junit.Before;
2625
import org.junit.Test;
2726
import org.junit.runner.RunWith;
2827

2928
import com.amaze.filemanager.BuildConfig;
3029
import com.amaze.filemanager.utils.PasswordUtil;
3130

32-
import android.content.Context;
3331
import android.util.Base64;
3432

3533
import androidx.test.ext.junit.runners.AndroidJUnit4;
36-
import androidx.test.platform.app.InstrumentationRegistry;
3734

3835
@RunWith(AndroidJUnit4.class)
3936
public class CryptUtilTest {
4037

41-
private Context context;
42-
43-
@Before
44-
public void setUp() {
45-
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
46-
}
47-
4838
@Test
4939
public void testIvValueIsCorrect() {
5040
assertEquals("LxbHiJhhUXcj", BuildConfig.CRYPTO_IV);
@@ -53,8 +43,7 @@ public void testIvValueIsCorrect() {
5343
@Test
5444
public void testEncryptDecrypt() throws Exception {
5545
String password = "hackme";
56-
String encrypted = PasswordUtil.INSTANCE.encryptPassword(context, password, Base64.URL_SAFE);
57-
assertEquals(
58-
password, PasswordUtil.INSTANCE.decryptPassword(context, encrypted, Base64.URL_SAFE));
46+
String encrypted = PasswordUtil.INSTANCE.encryptPassword(password, Base64.URL_SAFE);
47+
assertEquals(password, PasswordUtil.INSTANCE.decryptPassword(encrypted, Base64.URL_SAFE));
5948
}
6049
}

app/src/main/java/com/amaze/filemanager/application/AppConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.amaze.filemanager.fileoperations.exceptions.ShellNotRunningException;
4242
import com.amaze.filemanager.fileoperations.filesystem.OpenMode;
4343
import com.amaze.filemanager.filesystem.HybridFile;
44+
import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool;
4445
import com.amaze.filemanager.filesystem.ssh.CustomSshJConfig;
4546
import com.amaze.filemanager.ui.fragments.preferencefragments.PreferencesConstants;
4647
import com.amaze.filemanager.ui.provider.UtilitiesProvider;
@@ -108,6 +109,8 @@ public void onCreate() {
108109
utilsHandler = new UtilsHandler(this, utilitiesDatabase);
109110

110111
runInBackground(Config::registerSmbURLHandler);
112+
// Force Kotlin object NetCopyClientConnectionPool to initialize
113+
NetCopyClientConnectionPool.INSTANCE.toString();
111114

112115
// disabling file exposure method check for api n+
113116
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();

app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/ftp/AbstractGetHostInfoTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class AbstractGetHostInfoTask<V, T : Callable<V>>(
4343
AppConfig.getInstance().run {
4444
progressDialog =
4545
ProgressDialog.show(
46-
this.mainActivityContext,
46+
requireNotNull(this.mainActivityContext),
4747
"",
4848
this.resources.getString(R.string.processing),
4949
)

app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/ftp/auth/FtpAuthenticationTask.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import com.amaze.filemanager.asynchronous.asynctasks.Task
2727
import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool.FTP_URI_PREFIX
2828
import org.apache.commons.net.ftp.FTPClient
2929
import org.json.JSONObject
30-
import java.net.ConnectException
3130
import java.net.SocketException
3231
import java.net.SocketTimeoutException
3332

@@ -62,8 +61,7 @@ class FtpAuthenticationTask(
6261

6362
@MainThread
6463
override fun onError(error: Throwable) {
65-
if (error is SocketException || error is SocketTimeoutException || error is ConnectException
66-
) {
64+
if (error is SocketException || error is SocketTimeoutException) {
6765
AppConfig.toast(
6866
AppConfig.getInstance(),
6967
AppConfig.getInstance()
@@ -79,7 +77,5 @@ class FtpAuthenticationTask(
7977
}
8078

8179
@MainThread
82-
override fun onFinish(value: FTPClient) {
83-
android.util.Log.d("TEST", value.toString())
84-
}
80+
override fun onFinish(value: FTPClient) = Unit
8581
}

app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/ftp/auth/FtpAuthenticationTaskCallable.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package com.amaze.filemanager.asynchronous.asynctasks.ftp.auth
2222

2323
import androidx.annotation.WorkerThread
24-
import com.amaze.filemanager.application.AppConfig
2524
import com.amaze.filemanager.filesystem.ftp.FTPClientImpl
2625
import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool
2726
import com.amaze.filemanager.filesystem.ftp.NetCopyClientConnectionPool.CONNECT_TIMEOUT
@@ -55,7 +54,7 @@ open class FtpAuthenticationTaskCallable(
5554
ftpClient.login(
5655
decode(username, UTF_8.name()),
5756
decode(
58-
PasswordUtil.decryptPassword(AppConfig.getInstance(), password),
57+
PasswordUtil.decryptPassword(password),
5958
UTF_8.name(),
6059
),
6160
)

app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/ftp/auth/FtpsAuthenticationTaskCallable.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
package com.amaze.filemanager.asynchronous.asynctasks.ftp.auth
2222

23-
import com.amaze.filemanager.application.AppConfig
2423
import com.amaze.filemanager.filesystem.ftp.FTPClientImpl
2524
import com.amaze.filemanager.filesystem.ftp.FTPClientImpl.Companion.ARG_TLS
2625
import com.amaze.filemanager.filesystem.ftp.FTPClientImpl.Companion.TLS_EXPLICIT
@@ -57,7 +56,7 @@ class FtpsAuthenticationTaskCallable(
5756
} else {
5857
ftpClient.login(
5958
username,
60-
PasswordUtil.decryptPassword(AppConfig.getInstance(), password),
59+
PasswordUtil.decryptPassword(password),
6160
)
6261
}
6362
return if (loginSuccess) {

0 commit comments

Comments
 (0)