dpa99c / cordova-plugin-cloud-settings

A Cordova plugin for Android & iOS to persist user settings in cloud storage across devices and installs.
27 stars 17 forks source link

Android backup test failing #8

Closed pliablepixels closed 6 years ago

pliablepixels commented 6 years ago

Hi, based on #7 I retried my backup attempts and I do believe the problem is not a case of delayed backup. I am doing something wrong that is resulting in backup failure (I incorrectly wrote it worked earlier)

Android OS version: 7.0

Here are my backup settings: screen

Here is how I am trying to do a manual backup:

adb shell bmgr backupnow com.pliablepixels.zmninja_pro

My apk Sdk versions:

sdkVersion:'16'
targetSdkVersion:'26'

The error I see on logcat:

Gist:

09-04 15:45:29.473  2408  2434 I Backup  : [GmsBackupTransport] Backup finished for com.pliablepixels.zmninja_pro
09-04 15:45:29.475  1563  3332 E PFTBT   : Error -1002 backing up com.pliablepixels.zmninja_pro
09-04 15:45:29.477  1563  3332 I PFTBT   : Transport suggested backoff=3241206
09-04 15:45:29.477  1563  3332 I PFTBT   : Transport rejected backup of com.pliablepixels.zmninja_pro, skipping
09-04 15:45:29.477  1563  3332 I PFTBT   : Full backup completed with status: 0

Full Log:

09-04 15:45:23.990  3322  3322 D AndroidRuntime: CheckJNI is OFF
09-04 15:45:24.050  3322  3322 E libmdmdetect: Failed to open /sys/bus/msm_subsys/devices/subsys0/name: Permission denied
09-04 15:45:24.046  3322  3322 W main    : type=1400 audit(0.0:40): avc: denied { read } for uid=2000 name="name" dev="sysfs" ino=22300 scontext=u:r:shell:s0 tcontext=u:object_r:sysfs:s0 tclass=file permissive=0
09-04 15:45:24.066  3322  3322 D ICU     : No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
09-04 15:45:24.092  3322  3322 I Radio-JNI: register_android_hardware_Radio DONE
09-04 15:45:24.106  3322  3322 D AndroidRuntime: Calling main entry com.android.commands.bmgr.Bmgr
09-04 15:45:24.110  1563  2387 V PerformBackupTask: Beginning backup of 0 targets
09-04 15:45:24.129  1563  2387 D PerformBackupTask: invokeAgentForBackup on @pm@
09-04 15:45:24.138  1563  2387 I BackupRestoreController: Getting widget state for user: 0
09-04 15:45:24.138  1563  2387 D PerformBackupTask: Starting full backups for: [com.pliablepixels.zmninja_pro]
09-04 15:45:24.139  1563  2387 I BackupManagerService: K/V backup pass finished.
09-04 15:45:24.139  1563  3332 I PFTBT   : Initiating full-data transport backup of com.pliablepixels.zmninja_pro
09-04 15:45:24.141  2408  2436 I Backup  : [GmsBackupTransport] Attempt to do full backup on com.pliablepixels.zmninja_pro
09-04 15:45:24.144  2408  2436 I Backup  : [FullBackupSession] Using unencrypted processor for com.pliablepixels.zmninja_pro
09-04 15:45:24.170  2408  2408 W ChimeraUtils: Non Chimera context
09-04 15:45:24.192  2408  2436 I Backup  : [FullBackupWrapper] create full backup for : com.pliablepixels.zmninja_pro
09-04 15:45:24.195  2408  3335 I Backup  : [FullBackupWrapper] Start scotty uploading.
09-04 15:45:24.206  1563  3336 I ActivityManager: Start proc 3339:com.pliablepixels.zmninja_pro/u0a220 for backup android/FullBackupAgent
09-04 15:45:24.207  1563  3336 D BackupManagerService: awaiting agent for ApplicationInfo{cdbb6e3 com.pliablepixels.zmninja_pro}
09-04 15:45:24.210  3339  3339 I art     : Late-enabling -Xcheck:jni
09-04 15:45:24.257  1563  2553 D BackupManagerService: agentConnected pkg=com.pliablepixels.zmninja_pro agent=android.os.BinderProxy@6ec7ab3
09-04 15:45:24.257  1563  3336 I BackupManagerService: got agent android.app.IBackupAgent$Stub$Proxy@984f870
09-04 15:45:24.263  3339  3353 V BackupXmlParserLogging: android:fullBackupContent - found xml resource
09-04 15:45:24.265  3339  3353 V BackupXmlParserLogging: 
09-04 15:45:24.265  3339  3353 V BackupXmlParserLogging: ====================================================
09-04 15:45:24.265  3339  3353 V BackupXmlParserLogging: Found valid fullBackupContent; parsing xml resource.
09-04 15:45:24.265  3339  3353 V BackupXmlParserLogging: ====================================================
09-04 15:45:24.265  3339  3353 V BackupXmlParserLogging: 
09-04 15:45:24.270  3339  3353 V BackupXmlParserLogging: ...parsed /data/data/com.pliablepixels.zmninja_pro/shared_prefs for domain "sharedpref"
09-04 15:45:24.271  3339  3353 V BackupXmlParserLogging: ...parsed /data/data/com.pliablepixels.zmninja_pro/databases for domain "database"
09-04 15:45:24.272  3339  3353 V BackupXmlParserLogging: ...parsed /storage/emulated/0/Android/data/com.pliablepixels.zmninja_pro/files for domain "external"
09-04 15:45:24.272  3339  3353 V BackupXmlParserLogging: ...parsed /data/data/com.pliablepixels.zmninja_pro/files/cloudsettings.json for domain "file"
09-04 15:45:24.273  3339  3353 V BackupXmlParserLogging: 
09-04 15:45:24.273  3339  3353 V BackupXmlParserLogging: Xml resource parsing complete.
09-04 15:45:24.273  3339  3353 V BackupXmlParserLogging: Final tally.
09-04 15:45:24.273  3339  3353 V BackupXmlParserLogging: Includes:
09-04 15:45:24.274  3339  3353 V BackupXmlParserLogging:   domain=f
09-04 15:45:24.274  3339  3353 V BackupXmlParserLogging:   /data/data/com.pliablepixels.zmninja_pro/files/cloudsettings.json
09-04 15:45:24.274  3339  3353 V BackupXmlParserLogging: Excludes:
09-04 15:45:24.274  3339  3353 V BackupXmlParserLogging:   /data/data/com.pliablepixels.zmninja_pro/databases
09-04 15:45:24.274  3339  3353 V BackupXmlParserLogging:   /storage/emulated/0/Android/data/com.pliablepixels.zmninja_pro/files
09-04 15:45:24.274  3339  3353 V BackupXmlParserLogging:   /data/data/com.pliablepixels.zmninja_pro/shared_prefs
09-04 15:45:24.274  3339  3353 V BackupXmlParserLogging:   
09-04 15:45:24.274  3339  3353 V BackupXmlParserLogging: ====================================================
09-04 15:45:24.274  3339  3353 V BackupXmlParserLogging: 
09-04 15:45:24.280  1563  3336 I BackupRestoreController: Getting widget state for user: 0
09-04 15:45:24.282  1563  3357 I file_backup_helper:    Name: apps/com.pliablepixels.zmninja_pro/_manifest
09-04 15:45:24.282  1563  3357 D BackupManagerService: Calling doFullBackup() on com.pliablepixels.zmninja_pro
09-04 15:45:24.286  3339  3352 I file_backup_helper:    Name: apps/com.pliablepixels.zmninja_pro/f/cloudsettings.json
09-04 15:45:24.291  3339  3339 I Process : Sending signal. PID: 3339 SIG: 9
09-04 15:45:24.302  1563  1807 I ActivityManager: Process com.pliablepixels.zmninja_pro (pid 3339) has died
09-04 15:45:24.302  1563  1807 D ActivityManager: cleanUpApplicationRecord -- 3339
09-04 15:45:25.185   910   910 I MSM-irqbalance: Decided to move IRQ18 from CPU0 [P:0] to CPU6 [P:1] (banned)
09-04 15:45:25.186   910   910 I MSM-irqbalance: Decided to move IRQ18 from CPU1 [P:0] to CPU4 [P:1] (banned)
09-04 15:45:25.186   910   910 I MSM-irqbalance: Decided to move IRQ18 from CPU2 [P:0] to CPU5 [P:1] (banned)
09-04 15:45:25.187   910   910 I MSM-irqbalance: Decided to move IRQ18 from CPU3 [P:0] to CPU7 [P:1] (banned)
09-04 15:45:28.092  2298  2426 D ClClient: Not sending keepalive.  Current connection state=STOPPED
09-04 15:45:29.206   783  3338 D libc    : dns request timeout: netid(100), id(0xa05d), server(10.6.1.1)
09-04 15:45:29.209   785   785 I cnss-daemon: RTM_NEWNEIGH message received: 28
09-04 15:45:29.209   785   785 E cnss-daemon: Stale or unreachable neighbors, ndm state: 16
09-04 15:45:29.215   785   785 I cnss-daemon: RTM_NEWNEIGH message received: 28
09-04 15:45:29.215   785   785 I cnss-daemon: NDA_DST received: 10.6.1.1 ul: 16844298
09-04 15:45:29.215   785   785 I cnss-daemon: NDA_LLADDR received
09-04 15:45:29.465  2408  3335 I Backup  : [FullBackupWrapper] Scotty response: res=470 raw=11264 up=11264
09-04 15:45:29.473  2408  2434 I Backup  : [GmsBackupTransport] Backup finished for com.pliablepixels.zmninja_pro
09-04 15:45:29.475  1563  3332 E PFTBT   : Error -1002 backing up com.pliablepixels.zmninja_pro
09-04 15:45:29.477  1563  3332 I PFTBT   : Transport suggested backoff=3241206
09-04 15:45:29.477  1563  3332 I PFTBT   : Transport rejected backup of com.pliablepixels.zmninja_pro, skipping
09-04 15:45:29.477  1563  3332 I PFTBT   : Full backup completed with status: 0
09-04 15:45:29.477  1563  3332 I BackupManagerService: Full data backup pass finished.
pliablepixels commented 6 years ago

Based on this, quota seems to be a potential issue. The backed up data is tiny, but I'm checking for that now.

pliablepixels commented 6 years ago

Closing. My backup is still not working. After switching backup accounts and rebooting, doing a manual backup does work (I see a backup file on google drive). However, if I delete the app and reinstall it (via adb install), the cloud settings are not restored because the load() function only returns a timestamp: field not the rest, which is odd. I'll be debugging further.

dpa99c commented 6 years ago

OK. Also see the example project for comparison.

pliablepixels commented 6 years ago

Everything seems to be working with my project today 🤷‍♂️ So far my testing has involved manually invoking the backup of my app data after I invoke the save() function and it works.

I only wish there was a way to make the backup instant! I've tested by manually invoking backup now from adb shell so far - I suppose that validates backup itself is working and this plugin is correctly saving the data locally for remote backup. Still waiting for auto backup to kick in.

Thanks for the plugin!

SnehalJ1509 commented 3 years ago

Hi @dpa99c, I am also using this plugin and facing the same issue as @pliablepixels. In iOS it is working properly as expected but for Android the auto backup is not happening. I've also tried through command line and the backup happens but I want to try the backup in real scenario.

Currently I've Android 10, so as per docs auto backup should happen instead of key/value backup but it is not happening. I also build the example project that you have mentioned in the above comment and tried it out but auto backup is not happening for that also. The Backup settings is enabled for my phone and is set to Wi-Fi.

I have few questions:-

  1. In AndroidManifest.xml the allowBackup is set to true and it must be required to be true for the backup to happen. But fullBackupOnly should be set to true or false for the plugin to work properly?
  2. If fullBackupOnly is set to true then it will take full backup of the app but does it include our json data also that we have saved through plugin? Or to backup only json data we have to set it to false?
  3. The docs says auto backup happens if Wi-Fi is connected, phone is idle and at least 24 hrs have passed. I've tried this but still auto backup is not happening. Is there anything else that I am missing?

Thanks in advance!

pslyman commented 3 years ago

I thought I would contribute here. I have a few apps that utilize cloud settings backup. One of them open source if it helps to poke around: https://github.com/pslyman/OpenTrackFit

Android backups happen once every 24 hours, or when you manually run them (Settings > System > Backup > Back up now). If you uninstall the app, it will remove the backup too, IIRC (don't quote me on that one, it may have changed). The app cannot be installed via ADB to restore the cloud backup. It must be installed through the Play Store, or by automatic restore on a new device.

@SnehalJ1509

  1. Yes, allowBackup, and fullBackupOnly are set to true in my project. However, AndroidManifest.xml is volatile and shouldn't be edited manually. The plugin should handle that part.
  2. Good question. On my apps it's set to true, and it also saves the JSON saved through the plugin.
  3. Refer to above. You can run it manually through the settings. That's the fastest way when testing it.

When I tested this plugin, I had another phone (emulator works too) that I would use. I'd make the backup on phone 1 (including saved JSON through the plugin) then set up phone 2 (or emulator) as a new device, restoring from my most recent backup along the way. It may work to just install the app from the PlayStore instead of restoring from backup, but I had to be sure when testing. I don't think ADB will work.

It's finicky and ridiculous, but I don't think it's the plugin's fault. It's just the way Google handles things.

SnehalJ1509 commented 3 years ago

Thank you @pslyman for the answers.

As mentioned above, first I tried with adb commands and the backup works. I checked it in Google Drive -> Backups -> {phone_name} backup -> App data -> {my_app_bundle_id}. It shows proper date/time. After that I've also tried with allowBackup and fullBackupOnly set to true, updated the JSON, saved it from app and then manually took the backup through settings. Then when I checked in Google Drive, I can only see the backup I took through adb earlier. I don't see the updated date/time for my app.

If I check in the app, the load() still returns the updated JSON saved through app. But if I uninstall the app and install it again in the same phone, the exist() gives me true but when I run load(), it gives me JSON saved through adb and not the updated one saved through manual backup. So it seems confusing if I am missing some configuration or I am doing it all wrong.

Thanks for your repo link. I'll surely check it out how its implemented there.

pslyman commented 3 years ago

@SnehalJ1509 Thanks for clarifying, I had misunderstood. I may not have a solution, but I find it curious that ADB vs Google Drive cloud settings don't seem to match. I do know that Google is very particular about how they do things, so there may be an inconsistency between ADB and a key-signed version through the Play Store. If you find what you're doing matches up with my repo, consider making a signed closed beta release that just you can access, and do a bit of testing that way. It's cumbersome, but maybe it'll unveil something you hadn't noticed before.

I'm under the impression that your configuration is correct. Hard to say beyond that though, assuming your API key is functional.

SnehalJ1509 commented 3 years ago

@pslyman Currently I am just doing POC so not doing it through a key-signed version. Just testing with dev build, creating an apk and installing it in my phone. I am not sure if this is the reason for not working but ideally that should not be the case.

I checked you repo and everything seems same as what I have done except the save part where 1st you are saving blank json and then the json data. Why is that? If that is to replace the existing the data then may be you could have passed true as another parameter to it.

I've generated an API key from Google console and probably that should also not be a problem.

pslyman commented 3 years ago

@SnehalJ1509 You're correct that I don't need to be saving blank json, good catch. It clears the cloudSave before loading new data, but it isn't necessary with that second parameter. I'll have to update that.

A couple of observations:

  1. Although you can do a cloudSave (saving JSON to the app data), and then test that it exists, I've never been successful in getting Google to back it up unless I have a key-signed version I've downloaded privately through the Google Play Store. Maybe that doesn't matter? I've been under the impression that it does.

  2. Uninstalling the app has always deleted my cloudSave for some reason. If I install the app on another phone or do a Google restore on another phone, then it works. Unfortunately it's always been very finicky and difficult to test for me without a secondary (or emulated) device. The cloudSave system may be more flexible than that, but it's been the biggest headache for me to test.

If your code is the same as mine, it may be worth doing a key-signing, dropping the APK onto an internal testing channel of Google Play Store, then installing it that way. Manually back up in Google's settings, then do a restore through your Google account on an emulator or second device. That was the only way (months ago) that I was able to get it to work. Unless Google has changed things since July, I'm not sure what to suggest.

I totally get just doing POC though, may not be worth the effort. Best of luck. I'm happy to help out how I can, but I think I'm out of idea.

SnehalJ1509 commented 3 years ago

@pslyman I tried with key-signing and published the APK in Google Beta testing and installed it from there. I manually took backup but still the backup is not appearing in Google Drive. And after uninstalling the app and reinstalling it in same device, I still always get data in cloud as false.

So now it feels like a dead end. I am not sure what I am doing wrong.