Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Android installation is getting corrupted sometimes #43

Closed
andreialecu opened this issue Nov 21, 2015 · 6 comments
Closed

Android installation is getting corrupted sometimes #43

andreialecu opened this issue Nov 21, 2015 · 6 comments
Labels
Milestone

Comments

@andreialecu
Copy link
Contributor

Sometimes I'm getting an error in the simulator on startup, after chcp tries to install an update. Here's a screenshot:

image

I assume this may happen because the download or installation didn't fully complete before closing the application on a previous run.

Rerunning the application a second time starts it properly again - but it is reverted to the initially installed version (in the apk), all subsequent chcp installed updates are lost.

It also disables any kind of chcp updates from working until the app is uninstalled and reinstalled. I'm seeing an error reported by chcp on every app start:

"{"action":"chcp_updateLoadFailed","error":{"code":-9,"description":"Failed to load current application config"}}"

@andreialecu andreialecu changed the title Android installation is getting corrupt sometimes Android installation is getting corrupted sometimes Nov 21, 2015
@nikDemyankov
Copy link
Member

Understood. Will fix that.

@andreialecu
Copy link
Contributor Author

I'm getting this on real devices as well, not just in the emulator. It might be related to the fact that the app has a lot of small files and the copy is taking a relatively long time (several seconds).

By inspecting the code I'm seeing that files are copied and the 'www' folder is replaced after a new update is installed: https://github.com/nordnet/cordova-hot-code-push/blob/master/src/android/src/com/nordnetab/chcp/main/updater/InstallationWorker.java#L194

I think that ideally the plugin should keep two copies of installations, say www1 and www2 and only swap to www2 if it is fully installed. If it is not, it can keep trying to clear and copy to www2 until everything is verified, and then swap to www2. A second update can then be installed to www1, and by the same logic www1 can then be used as the local folder. Then www2 for the third update and so on.

This would at least ensure that users don't get stuck with a really old version when an update fails to install.

What would be your thoughts regarding this?

@andreialecu
Copy link
Contributor Author

Actually, from what I can see, a variant of this is implemented and there is a backup folder. However, the backup folder is not rolled back to when Failed to load current application config occurs, and it looks like the external www folder remains there, corrupted. So the plugin stops working since it can see that the www folder exists, but it is empty.

I think the following issues need to be fixed.

  1. If Failed to load current application config occurs, check if a verified backup is stored, and rollback to it. If no backup is stored, delete all external plugin data folders and start from scratch.
  2. After external storage www installation, re-verify all files and store a config setting somewhere that it is ready to use, and only then attempt to use it.

For point 1, cordova/app start-up may need to be delayed a bit until the backup is restored, if that is even possible.

@andreialecu
Copy link
Contributor Author

More info. I was able to confirm using

adb shell
run-as package.name ls /data/data/package.name/files/cordova-hot-code-push-plugin/www

That the folder is indeed half-copied. Some files are missing and some are there, the copy didn't go through completely before the app got killed.

@andreialecu
Copy link
Contributor Author

I fixed this and finally got it working correctly. See #44.

@nikDemyankov nikDemyankov added this to the v1.1.2 milestone Nov 24, 2015
@nikDemyankov
Copy link
Member

Closing that issue, since main problem was detected and fixed. Will continue to work on making updates more secure, but it will be another issue - #57.

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

No branches or pull requests

2 participants