Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto upload does not start automatically #12337

Merged

Conversation

JonasMayerDev
Copy link
Collaborator

@JonasMayerDev JonasMayerDev commented Jan 3, 2024

Screen_recording_20240103_123529.webm
  • Add foreground info (also interesting for user) to prevent android killing the worker. (Only visible if worker is active more than ca. 1s -> Use large folder with many files for testing)

  • Make getFileChecksum a lot faster (previously over 1 h for a folder of 6000 Images now only minutes)
    Screenshot_2024-01-02_13-37-46
    Previously 7.5s
    Screenshot_2024-01-02_13-45-05
    Now 15ms
    |_ Should be tested (maybe too good to be true)

For me, it also helps with #12141

  • Tests written, or not not needed

@JonasMayerDev JonasMayerDev linked an issue Jan 3, 2024 that may be closed by this pull request
4 tasks
@JonasMayerDev
Copy link
Collaborator Author

Just tested my "new" getFileChecksum, and it returns the same result as the old one did for the same file (tested with 1 file), so I guess it should work fine.

@alperozturk96
Copy link
Collaborator

alperozturk96 commented Jan 3, 2024

@JonasMayerDev App is crashing here is the log

E  FATAL EXCEPTION: main
                                                                                                    Process: com.nextcloud.client, PID: 32671
                                                                                                    android.app.InvalidForegroundServiceTypeException: Starting FGS with type none callerApp=ProcessRecord{9752a8e 32671:com.nextcloud.client/u0a217} targetSDK=34 has been prohibited
                                                                                                    	at android.app.InvalidForegroundServiceTypeException$1.createFromParcel(InvalidForegroundServiceTypeException.java:53)
                                                                                                    	at android.app.InvalidForegroundServiceTypeException$1.createFromParcel(InvalidForegroundServiceTypeException.java:49)
                                                                                                    	at android.os.Parcel.readParcelableInternal(Parcel.java:4870)
                                                                                                    	at android.os.Parcel.readParcelable(Parcel.java:4852)
                                                                                                    	at android.os.Parcel.createExceptionOrNull(Parcel.java:3052)
                                                                                                    	at android.os.Parcel.createException(Parcel.java:3041)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:3024)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:2966)
                                                                                                    	at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6761)
                                                                                                    	at android.app.Service.startForeground(Service.java:862)
                                                                                                    	at androidx.work.impl.foreground.SystemForegroundService$Api31Impl.startForeground(SystemForegroundService.java:194)
                                                                                                    	at androidx.work.impl.foreground.SystemForegroundService$1.run(SystemForegroundService.java:130)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                    	at android.os.Looper.loop(Looper.java:294)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

Copy link
Collaborator

@alperozturk96 alperozturk96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must check implementation on Android 14 emulator. ForegroundServiceHelper may solve this problem

@JonasMayerDev
Copy link
Collaborator Author

@alperozturk96 Do you have a better idea for the manifest.xml entry? I think this is not optimal?

@JonasMayerDev JonasMayerDev force-pushed the 11741-auto-upload-does-not-start-automatically-on-3250 branch from 9359dd4 to 6c834f4 Compare January 8, 2024 10:00
Copy link

github-actions bot commented Jan 8, 2024

Codacy

Lint

TypemasterPR
Warnings6969
Errors33

SpotBugs

CategoryBaseNew
Bad practice2626
Correctness6969
Dodgy code353353
Experimental22
Internationalization99
Malicious code vulnerability22
Multithreaded correctness99
Performance5454
Security1818
Total542542

Copy link

github-actions bot commented Jan 8, 2024

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/12337.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

Copy link
Collaborator

@ZetaTom ZetaTom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've given this PR a quick test run and have encountered the following exception:

Logcat

WM-Processor            I  Moving WorkSpec (29319770-c67b-40c5-bf9e-84dc3f2ac140) to the foreground
UploadsStorageManager   D  QUERY: (status== ? OR last_result==9 OR last_result==13 OR last_result==11 OR last_result==14 ) AND last_result!= 16 ROWID: -1
WM-SystemFgDispatcher   I  Started foreground service Intent { act=ACTION_START_FOREGROUND cmp=com.nextcloud.client/androidx.work.impl.foreground.SystemForegroundService (has extras) }
MediaProvider           D  Reading images for DCIM
UploadsStorageManager   V  getUploads() got 0 rows from page 0, 0 rows total so far, last ID -1
UploadsStorageManager   V  getUploads() returning 0 (0) rows after reading 1 pages
UploadsStorageManager   D  QUERY: (status== ? OR last_result==9 OR last_result==13 OR last_result==11 OR last_result==14 ) AND last_result!= 16 ROWID: -1
UploadsStorageManager   V  getUploads() got 0 rows from page 0, 0 rows total so far, last ID -1
UploadsStorageManager   V  getUploads() returning 0 (0) rows after reading 1 pages
WM-Processor            I  Moving WorkSpec (29319770-c67b-40c5-bf9e-84dc3f2ac140) to the foreground
WM-Processor            I  Moving WorkSpec (29319770-c67b-40c5-bf9e-84dc3f2ac140) to the foreground
WM-WorkerWrapper        E  Work [ id=2f00d1e0-c91b-40e6-8524-501dffca5e18, tags={ com.nextcloud.client.jobs.MediaFoldersDetectionWork, *, name:immediate_media_folder_detection, timestamp:1704785714230, class:MediaFoldersDetectionWork } ] failed because it threw an exception/error
                           java.util.concurrent.ExecutionException: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 
                                at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:516)
                                at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:475)
                                at androidx.work.impl.WorkerWrapper$2.run(WorkerWrapper.java:317)
                                at androidx.work.impl.utils.SerialExecutorImpl$Task.run(SerialExecutorImpl.java:96)
                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                at java.lang.Thread.run(Thread.java:1012)
                           Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 
                                at android.database.AbstractCursor.checkPosition(AbstractCursor.java:521)
                                at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:139)
                                at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:77)
                                at android.database.CursorWrapper.getLong(CursorWrapper.java:131)
                                at com.owncloud.android.datamodel.SyncedFolderProvider.createSyncedFolderFromCursor(SyncedFolderProvider.java:346)
                                at com.owncloud.android.datamodel.SyncedFolderProvider.findByLocalPathAndAccount(SyncedFolderProvider.java:208)
                                at com.nextcloud.client.jobs.MediaFoldersDetectionWork.doWork(MediaFoldersDetectionWork.kt:154)
                                at androidx.work.Worker$1.run(Worker.java:82)
                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) 
                                at java.lang.Thread.run(Thread.java:1012)  
WM-WorkerWrapper        I  Worker result FAILURE for Work [ id=2f00d1e0-c91b-40e6-8524-501dffca5e18, tags={ com.nextcloud.client.jobs.MediaFoldersDetectionWork, *, name:immediate_media_folder_detection, timestamp:1704785714230, class:MediaFoldersDetectionWork } ]
WM-Processor            I  Moving WorkSpec (29319770-c67b-40c5-bf9e-84dc3f2ac140) to the foreground
WM-WorkerWrapper        I  Worker result SUCCESS for Work [ id=29319770-c67b-40c5-bf9e-84dc3f2ac140, tags={ com.nextcloud.client.jobs.FilesSyncWork, *, name:immediate_files_sync, timestamp:1704785714229, class:FilesSyncWork } ]
WM-SystemFgDispatcher   I  Stopping foreground service

This occurred after I moved a 1GB test file into the specified auto-upload directory. At first glance this looks to be another issue, that doesn't stem from this change.

Later on, I've tried again, renaming the test file and got the following log entries:

Logcat

WM-WorkerWrapper        I  Work [ id=c9bd3090-e9fe-4f4b-bc37-95dc04b3144c, tags={ com.nextcloud.client.jobs.ContentObserverWork, *, name:content_observer, timestamp:1704785714230, class:ContentObserverWork } ] was cancelled
                           java.util.concurrent.CancellationException: Task was cancelled.
                                at androidx.work.impl.utils.futures.AbstractFuture.cancellationExceptionWithCause(AbstractFuture.java:1184)
                                at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:514)
                                at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:475)
                                at androidx.work.impl.WorkerWrapper$2.run(WorkerWrapper.java:317)
                                at androidx.work.impl.utils.SerialExecutorImpl$Task.run(SerialExecutorImpl.java:96)
                                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                at java.lang.Thread.run(Thread.java:1012)
MediaProvider           D  Reading images for DCIM
WM-WorkerWrapper        I  Worker result SUCCESS for Work [ id=8f23593d-5431-4981-a960-39f82e604679, tags={ com.nextcloud.client.jobs.MediaFoldersDetectionWork, *, name:immediate_media_folder_detection, timestamp:1704786164352, class:MediaFoldersDetectionWork } ]
WM-Processor            I  Moving WorkSpec (381138c2-92f5-44a4-b84d-5eff98203d3a) to the foreground
WM-SystemFgDispatcher   I  Started foreground service Intent { act=ACTION_START_FOREGROUND cmp=com.nextcloud.client/androidx.work.impl.foreground.SystemForegroundService (has extras) }
UploadsStorageManager   D  QUERY: (status== ? OR last_result==9 OR last_result==13 OR last_result==11 OR last_result==14 ) AND last_result!= 16 ROWID: -1
UploadsStorageManager   V  getUploads() got 0 rows from page 0, 0 rows total so far, last ID -1
UploadsStorageManager   V  getUploads() returning 0 (0) rows after reading 1 pages
UploadsStorageManager   D  QUERY: (status== ? OR last_result==9 OR last_result==13 OR last_result==11 OR last_result==14 ) AND last_result!= 16 ROWID: -1
UploadsStorageManager   V  getUploads() got 0 rows from page 0, 0 rows total so far, last ID -1
UploadsStorageManager   V  getUploads() returning 0 (0) rows after reading 1 pages
WM-Processor            I  Moving WorkSpec (381138c2-92f5-44a4-b84d-5eff98203d3a) to the foreground
WM-Processor            I  Moving WorkSpec (381138c2-92f5-44a4-b84d-5eff98203d3a) to the foreground
WM-Processor            I  Moving WorkSpec (381138c2-92f5-44a4-b84d-5eff98203d3a) to the foreground
UploadsStorageManager   V  Inserting 1 uploads
FileContentProvider     D  applying batch in provider com.owncloud.android.providers.FileContentProvider@8486d7d (temporary: false)
FileContentProvider     D  applied batch in provider com.owncloud.android.providers.FileContentProvider@8486d7d
UploadsStorageManager   D  notifyObserversNow
WM-WorkerWrapper        I  Worker result SUCCESS for Work [ id=381138c2-92f5-44a4-b84d-5eff98203d3a, tags={ com.nextcloud.client.jobs.FilesSyncWork, *, name:immediate_files_sync, timestamp:1704786164352, class:FilesSyncWork } ]
WM-SystemFgDispatcher   I  Stopping foreground service
UploadsStorageManager   D  QUERY: status==0 OR last_result==9 OR last_result==13 OR last_result==11 OR last_result==14 AND account_name== ? ROWID: -1
FilesUploadWorker       D  Handling 1 uploads for account [email protected]:8080
UploadsStorageManager   D  Retrieve job com.owncloud.android.db.OCUpload@6b1b26b for id 2
UploadsStorageManager   V  Updating /storage/emulated/0/DCIM/test.png with status=UPLOAD_IN_PROGRESS
UploadsStorageManager   D  updateUpload returns with: 1 for file: /storage/emulated/0/DCIM/test.png
UploadsStorageManager   D  notifyObserversNow
UploadFileOperation     D  normal upload
UploadFileOperation     D  Checking name collision in server
OwnCloudClient #0       D  REQUEST HEAD /remote.php/dav/files/alice/InstantUpload/DCIM/test.png
TrafficStats            D  tagSocket(94) with statsTag=0xffffffff, statsUid=-1
ExistenceC...eOperation D  Existence check for http://10.0.2.2:8080/remote.php/dav/files/alice/InstantUpload/DCIM/test.png targeting for  existence finished with HTTP status 404(FAIL)
UploadsStorageManager   D  Retrieve job com.owncloud.android.db.OCUpload@15301e0 for id 2
UploadsStorageManager   V  Updating /storage/emulated/0/DCIM/test.png with status=UPLOAD_IN_PROGRESS
UploadsStorageManager   D  updateUpload returns with: 1 for file: /storage/emulated/0/DCIM/test.png
UploadsStorageManager   D  notifyObserversNow
OwnCloudClient #0       D  REQUEST MKCOL /remote.php/dav/uploads/alice/8bdafcf274931efebe4bf35bebfc65ab
OwnCloudClient #0       D  REQUEST PROPFIND /remote.php/dav/uploads/alice/8bdafcf274931efebe4bf35bebfc65ab
TrafficStats            D  tagSocket(105) with statsTag=0xffffffff, statsUid=-1
OwnCloudClient #0       D  REQUEST PUT /remote.php/dav/uploads/alice/8bdafcf274931efebe4bf35bebfc65ab/000001
...

This time I was met with a File upload conflict notification. And when clicking on Resolve conflict an error message appeared, stating that the dialogue couldn't be created.

In both cases, the upload was unsuccessful. Again, I'm not sure how much of that has to do with this pull request.

@JonasMayerDev
Copy link
Collaborator Author

@ZetaTom I am not entirely sure but as you said I can not imagine how these fails are caused by this pr... Could you maybe do the exact same thing on master and see if it works there? And if you have time test again in this PR to see if it is a reliably reproducible issue for you?

Copy link
Collaborator

@ZetaTom ZetaTom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some trial and error, I think there's either something wrong with my local instance or it's also happening on master. Either way, this PR doesn't seem to directly affect this behaviour.

@alperozturk96 alperozturk96 merged commit 1757ede into master Jan 11, 2024
20 checks passed
@delete-merged-branch delete-merged-branch bot deleted the 11741-auto-upload-does-not-start-automatically-on-3250 branch January 11, 2024 08:10
@JonasMayerDev
Copy link
Collaborator Author

/backport to stable-3.27

@backportbot-nextcloud
Copy link

The backport to stable-3.27 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable-3.27
git pull origin stable-3.27

# Create the new backport branch
git checkout -b fix/foo-stable-3.27

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts. Resolve them.
git cherry-pick abc123

# Push the cherry pick commit to the remote repository and open a pull request
git push origin fix/foo-stable-3.27

Error: Unknown error

More info at https://docs.nextcloud.com/server/latest/developer_manual/getting_started/development_process.html#manual-backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto Upload does not start automatically on 3.25.0
4 participants