Razeeman / Android-SimpleTimeTracker

Simple app that tracks time.
GNU General Public License v3.0
536 stars 68 forks source link

[Bug] Google Drive automatic export fails #147

Open rationelis opened 5 months ago

rationelis commented 5 months ago

The automatic export function sometimes fails to upload the .csv file to Google Drive. I get a 'Upload failed: an error occured' notification at midnight. There have been instances where it has worked for me, so there is a happy flow where everything works as expected. Therefore, I don't expect it to be a permission issue.

I have hooked my phone to logcat and tried to re-create the automatic export event. A few times I have managed to re-create the bug and got the same exception every time:

1712 E ContentFileSyncMonitor: Sync failed
01-28 00:00:00.557  2577  1712 E ContentFileSyncMonitor: fmf: Local content not found ContentId[shinyContent=0_30417768-5c11-4546-b463-b32272cb4349]
01-28 00:00:00.557  2577  1712 E ContentFileSyncMonitor:    ...
01-28 00:00:00.557  2577  1712 E ContentFileSyncMonitor:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
01-28 00:00:00.557  2577  1712 E ContentFileSyncMonitor:    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
01-28 00:00:00.557  2577  1712 E ContentFileSyncMonitor:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
01-28 00:00:00.557  2577  1712 E ContentFileSyncMonitor:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
01-28 00:00:00.557  2577  1712 E ContentFileSyncMonitor:    at java.lang.Thread.run(Thread.java:923)
01-28 00:00:00.558  2577  1712 E ContentFileSyncMonitor: Sync failed
01-28 00:00:00.558  2577  1712 E ContentFileSyncMonitor: fmf: Local content not found ContentId[shinyContent=0_30417768-5c11-4546-b463-b32272cb4349]
01-28 00:00:00.558  2577  1712 E ContentFileSyncMonitor:    ...
01-28 00:00:00.558  2577  1712 E ContentFileSyncMonitor:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
01-28 00:00:00.558  2577  1712 E ContentFileSyncMonitor:    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
01-28 00:00:00.558  2577  1712 E ContentFileSyncMonitor:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
01-28 00:00:00.558  2577  1712 E ContentFileSyncMonitor:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
01-28 00:00:00.558  2577  1712 E ContentFileSyncMonitor:    at java.lang.Thread.run(Thread.java:923)
01-28 00:00:00.558  2577  1712 E ContentFileSyncMonitor: Sync failed and cannot be retried.

My hunch: a file is opened on the automaticExportUri location. Then, later on, when it tries to write to that file, it cannot access that newly created file, resulting in an error. Does it have something to do with writing to a virtual storage location?

It is worth noting that I am using a Cat S22 Flip with Android 11. It could have something to do with that as well. It could be that my phone is slow. Or the virtual storage address isn't open/ready at time of exporting? That could explain why it sometimes does work.

rationelis commented 5 months ago

I have cloned the repo and did some more debugging. I got a far nicer error today:

java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.docs.common.storagebackend.StorageBackendContentProvider from ProcessRecord{...} requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs.
   ...
   at android.os.Parcel.readException(Parcel.java:2282)
   at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:5728)
   at android.app.ActivityThread.acquireProvider(ActivityThread.java:6867)
   at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2935)
   at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:2484)
   at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1802)
   at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1633)
   at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1580)
   at com.example.util.simpletimetracker.data_local.resolver.CsvRepoImpl$saveCsvFile$2.invokeSuspend(CsvRepoImpl.kt:52)
   ...

So this permission denial is definitely caused by the openFileDescriptor.

I am a complete novice to mobile development so I shall further investigate the implications of this message.

EDIT: I am running Android 11, API 33.