Skip to content

Conversation

@TranceLove
Copy link
Collaborator

@TranceLove TranceLove commented Jul 25, 2020

PR Info

Issue tracker

Fixes will automatically close the related issue

Fixes #1918
-or-
Addresses #

Release

Addresses release/3.5 or release/3.6

Test cases

  • Covered

Manual testing

  • Done

If yes,

  • Device:
  • OS:

Build tasks success

Successfully running following tasks on local

  • ./gradlew assembledebug
  • ./gradlew spotlessCheck

Related PR

Related to PR #

Additional Info

Summary on changes:

  • Upgrade Gradle plugin to 3.6.4, last version to work with SDK 28 while fixing classloading issues when running tests
  • Upgrade Robolectric to 4.3.1
  • Test code refactoring as recommended by doc, enable coverage to API 28. Robolectric requires Java 9 to run tests against API 29, it's still disabled until we found an agreed and convenient way to enable it
  • Little build.gradle cleanup, removed duplicate dependency and moved some library version to variables

- Update gradle plugin to 3.6.4, the minimal version without updating to SDK 29. This is necessary for fixing some classloader issues with BouncyCastle when running tests
- Update to Robolectric 4.3; also added AndroidX test packages as required
- As first step to Robolectric adaptation, removed no longer valid `constants = BuildConfig.class` in tests
- decoupled some library versions to variables
- add support for tests against API 28. API 29 requires Java 9, so it's disabled (although stub had been added)
- change test runner to AndroidJUnit4 per docs recommended
- RuntimeEnvironment.application -> ApplicationProvider.getApplicationContext() (where applicable - GenericCopyUtilTest relies on Theories to run test, can still use old method)
@TranceLove TranceLove added Issue-Task (low) This isn't a bug, but should be dealt with. Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Area-Test Related to tests (Robolectric, Espresso, JUnit) labels Jul 25, 2020
@TranceLove TranceLove force-pushed the TranceLove/feature/1918 branch from 30963f2 to 1b43654 Compare July 26, 2020 13:54
- moved jcifs.Config.registerSmbURLHandler() from SmbConnectDialog to AppConfig.runInBackground()
- encrypt paths in UtilsHandler.renameSMB() as it was stored encrypted in database

Tested on Oneplus 2 running AOSPExtended (7.1.2) and LG Nexus 5x running AOSPExtended (9.0).
@TranceLove TranceLove force-pushed the TranceLove/feature/1918 branch from be93d46 to 3132aa4 Compare August 1, 2020 15:43
- ColorUtils: Add back missing break statement to prevent unknown icons being colored to default color
- NotificationConstants: Fix constant to use per reported by Android Studio
- Return of MainActivity test
- Remove deprecated API usage in TextEditorActivityTest
- Add test cases for CloudSheetFragment, NotificationConstants, SmbUtil, TinyDB, along with some more little util classes
@TranceLove TranceLove force-pushed the TranceLove/feature/1918 branch from 3132aa4 to 97db16f Compare August 1, 2020 15:50
- Added test cases for DbViewerTask, WriteFileAbstraction and EditableFileAbstraction
- EditableFileAbstraction, schema changed from integer to enum constant
@TranceLove
Copy link
Collaborator Author

TranceLove commented Aug 6, 2020

Sidenote: if you got java.lang.VerifyError while runing all the tests from within Android Studio for test coverage, read this: robolectric/robolectric#5428

In short, add -noverify in VM options and change test runner to JaCoCo

@EmmanuelMess
Copy link
Member

I am getting this when running the tests:

Exception in thread "main" java.lang.NoClassDefFoundError: com/afollestad/materialdialogs/folderselector/FolderChooserDialog$FolderCallback
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at org.junit.internal.builders.SuiteMethodBuilder.hasSuiteMethod(SuiteMethodBuilder.java:18)
	at com.intellij.junit4.JUnit46ClassesRequestBuilder.collectWrappedRunners(JUnit46ClassesRequestBuilder.java:75)
	at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:47)
	at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:90)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:46)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.lang.ClassNotFoundException: com.afollestad.materialdialogs.folderselector.FolderChooserDialog$FolderCallback
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	... 25 more

@TranceLove
Copy link
Collaborator Author

Try clean the gradle project first and run again. Otherwise may I know the environment (OS, JDK versions) you're running tests?

I am getting this when running the tests:

Exception in thread "main" java.lang.NoClassDefFoundError: com/afollestad/materialdialogs/folderselector/FolderChooserDialog$FolderCallback
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at org.junit.internal.builders.SuiteMethodBuilder.hasSuiteMethod(SuiteMethodBuilder.java:18)
	at com.intellij.junit4.JUnit46ClassesRequestBuilder.collectWrappedRunners(JUnit46ClassesRequestBuilder.java:75)
	at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:47)
	at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:90)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:46)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.lang.ClassNotFoundException: com.afollestad.materialdialogs.folderselector.FolderChooserDialog$FolderCallback
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
	... 25 more

With the current logic, if there is a broken symlink the block will exit at all, causing incomplete file listings. Adding a try/catch here can keep the loop to stay.
@EmmanuelMess
Copy link
Member

Ok, today it works, no idea what happened.

- moved jcifs.Config.registerSmbURLHandler() from SmbConnectDialog to AppConfig.runInBackground()
- encrypt paths in UtilsHandler.renameSMB() as it was stored encrypted in database

Tested on Oneplus 2 running AOSPExtended (7.1.2) and LG Nexus 5x running AOSPExtended (9.0).
@TranceLove TranceLove force-pushed the TranceLove/feature/1918 branch from f034741 to 0b6a61c Compare August 8, 2020 14:57
TranceLove and others added 7 commits August 9, 2020 11:29
- Log broken symbolic link
- Refactor ListFilesOnSshdTest for better codacy compliance. Also changed performVerify() to use awaitility's await() to better match the situation that file listings should not be broken because of broken symlinks
1946: Add translucent theme at amaze startup
With Robolectric 4's support for SDK >= 29 in place, they require the tests must run on JDK 9 or above. Therefore some adaptations must be done to allow this.

- add back APIs removed in JDK 9 which are required by Android builds
- all Robolectric test cases will have their maxSdk @config settings centralized in robolectric.properties

Due to robolectric/robolectric#5456 and developer adaptation to JDK > 8 is still not yet in place, running the test suite within Android Studio is still not possible out-of-the-box, this commit will not enable running with SDK 29 yet; but once everyone's ready it will be just a switch at robolectric.properties above

Tested building from command line with JDK 11 (Latest LTS version) and Android Studio, both on Ubuntu Focal x86_64.

Reference: https://medium.com/@jack_martynov/adopt-android-build-on-the-jdk11-macos-cc8f05995341
In #1947 there was a `android:screenOrientation="sensor"` declared in the manifest, causing UI to rotate as the device changes its orientation, which is quite annoying. Remove it.

Tested on Fairphone 3 running LineageOS 16.0 (9.0), still no white screen at startup even when Amaze uses dark themes.
Fix broken symlinks on SSH server causing incomplete file listings
…d text file creation method within FileUtil and check for intent type = text, basis which a text file will be created on the path the user is currently present.
…d text file creation method within FileUtil and check for intent type = text, basis which a text file will be created on the path the user is currently present.
Fix screen rotation problem after PR #1947 applied
@VishalNehra
Copy link
Member

This PR still WIP?

@TranceLove
Copy link
Collaborator Author

This PR still WIP?

Should have done the parts needed for this PR. Only need you to loosen the grip on codacy, that it cannot detect assertions inside callbacks.

@VishalNehra
Copy link
Member

Got it, will do (:

TranceLove and others added 11 commits August 19, 2020 13:16
Addresses #1961.

Previously due to preventing conflict with stock BouncyCastle on Android devices some tweaks were added to CustomSshJConfig. But with full adaptation of BouncyCastle over the stock one it should be safe to remove the tweaks and use stock features as much as possible.

Tested on Fairphone 3 running LineageOS 16.0 (9.0), using ED25519 private key to authenticate against OpenSSH server 8.2p1 on Ubuntu 20.04.
Lifting tweaks in CustomSshJConfig to enable advanced crypto features
- use HybridFileParcelable(SmbFile) for jcifs SmbFile in HybridFile.listFiles() and HybridFile.forEachChildrenFile()
- use HybridFileParcelable(RemoteResourceInfo) for sshj RemoteResourceInfo in HybridFile.listFiles() and HybridFile.forEachChildrenFile()
- Add javadoc for the 2 new HybridFileParcelable constructors
- remove duplicated parseSmbPath() and parseSftpPath() from MainActivityHelper
In #1947 there was a `android:screenOrientation="sensor"` declared in the manifest, causing UI to rotate as the device changes its orientation, which is quite annoying. Remove it.

Tested on Fairphone 3 running LineageOS 16.0 (9.0), still no white screen at startup even when Amaze uses dark themes.
- moved jcifs.Config.registerSmbURLHandler() from SmbConnectDialog to AppConfig.runInBackground()
- encrypt paths in UtilsHandler.renameSMB() as it was stored encrypted in database

Tested on Oneplus 2 running AOSPExtended (7.1.2) and LG Nexus 5x running AOSPExtended (9.0).
Addresses #1961.

Previously due to preventing conflict with stock BouncyCastle on Android devices some tweaks were added to CustomSshJConfig. But with full adaptation of BouncyCastle over the stock one it should be safe to remove the tweaks and use stock features as much as possible.

Tested on Fairphone 3 running LineageOS 16.0 (9.0), using ED25519 private key to authenticate against OpenSSH server 8.2p1 on Ubuntu 20.04.
…d text file creation method within FileUtil and check for intent type = text, basis which a text file will be created on the path the user is currently present.
…d text file creation method within FileUtil and check for intent type = text, basis which a text file will be created on the path the user is currently present.
…d text file creation method within FileUtil and check for intent type = text, basis which a text file will be created on the path the user is currently present.
#1856 Fix for app crashing when using save as option from browser
Fix OTG not loading file lists on Android >= N + refactoring
VishalNehra
VishalNehra previously approved these changes Aug 20, 2020
- Update gradle plugin to 3.6.4, the minimal version without updating to SDK 29. This is necessary for fixing some classloader issues with BouncyCastle when running tests
- Update to Robolectric 4.3; also added AndroidX test packages as required
- As first step to Robolectric adaptation, removed no longer valid `constants = BuildConfig.class` in tests
- decoupled some library versions to variables
- add support for tests against API 28. API 29 requires Java 9, so it's disabled (although stub had been added)
- change test runner to AndroidJUnit4 per docs recommended
- RuntimeEnvironment.application -> ApplicationProvider.getApplicationContext() (where applicable - GenericCopyUtilTest relies on Theories to run test, can still use old method)
- ColorUtils: Add back missing break statement to prevent unknown icons being colored to default color
- NotificationConstants: Fix constant to use per reported by Android Studio
- Return of MainActivity test
- Remove deprecated API usage in TextEditorActivityTest
- Add test cases for CloudSheetFragment, NotificationConstants, SmbUtil, TinyDB, along with some more little util classes
- Added test cases for DbViewerTask, WriteFileAbstraction and EditableFileAbstraction
- EditableFileAbstraction, schema changed from integer to enum constant
With Robolectric 4's support for SDK >= 29 in place, they require the tests must run on JDK 9 or above. Therefore some adaptations must be done to allow this.

- add back APIs removed in JDK 9 which are required by Android builds
- all Robolectric test cases will have their maxSdk @config settings centralized in robolectric.properties

Due to robolectric/robolectric#5456 and developer adaptation to JDK > 8 is still not yet in place, running the test suite within Android Studio is still not possible out-of-the-box, this commit will not enable running with SDK 29 yet; but once everyone's ready it will be just a switch at robolectric.properties above

Tested building from command line with JDK 11 (Latest LTS version) and Android Studio, both on Ubuntu Focal x86_64.

Reference: https://medium.com/@jack_martynov/adopt-android-build-on-the-jdk11-macos-cc8f05995341
@VishalNehra VishalNehra merged commit 6bc3f98 into release/3.5 Aug 20, 2020
@TranceLove TranceLove deleted the TranceLove/feature/1918 branch August 20, 2020 23:26
@TranceLove TranceLove mentioned this pull request Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. Area-Test Related to tests (Robolectric, Espresso, JUnit) Issue-Task (low) This isn't a bug, but should be dealt with.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade to Robolectric 4

4 participants