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

Fix race condition and android bugs resulting in an incomplete/corrupted installation #44

Merged
merged 1 commit into from
Nov 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/android/src/com/nordnetab/chcp/main/HotCodePushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.nordnetab.chcp.main.utils.Paths;
import com.nordnetab.chcp.main.utils.VersionHelper;

import com.nordnetab.chcp.main.model.ChcpError;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.ConfigXmlParser;
import org.apache.cordova.CordovaArgs;
Expand Down Expand Up @@ -368,7 +370,12 @@ private void installUpdate(CallbackContext jsCallback) {
installJsCallback = jsCallback;
}

UpdatesInstaller.install(fileStructure);
if (UpdatesInstaller.install(fileStructure)) {
// ensure that we set the www folder as invalid, temporarily,
// so that if the app crashes or is killed we don't run from a corrupted www folder
pluginInternalPrefs.setWwwFolderInstalled(false);
pluginInternalPrefsStorage.storeInPreference(pluginInternalPrefs);
}
}

// endregion
Expand Down Expand Up @@ -436,6 +443,7 @@ private void redirectToLocalStorage() {
currentUrl = currentUrl.replace(LOCAL_ASSETS_FOLDER, "");
String external = Paths.get(fileStructure.wwwFolder(), currentUrl);
if (!new File(external).exists()) {
Log.d("CHCP", "External starting page not found. Aborting page change.");
return;
}

Expand Down Expand Up @@ -617,6 +625,10 @@ public void onEvent(NothingToUpdateEvent event) {
@SuppressWarnings("unused")
public void onEvent(UpdateDownloadErrorEvent event) {
Log.d("CHCP", "Failed to update");
if (event.error() == ChcpError.LOCAL_VERSION_OF_APPLICATION_CONFIG_NOT_FOUND || event.error() == ChcpError.LOCAL_VERSION_OF_MANIFEST_NOT_FOUND) {
Log.d("CHCP", "Can't load application config from installation folder. Reinstalling external folder");
installWwwFolder();
}

PluginResult jsResult = PluginResultHelper.pluginResultFromEvent(event);

Expand Down Expand Up @@ -645,6 +657,10 @@ public void onEvent(UpdateDownloadErrorEvent event) {
public void onEvent(UpdateInstalledEvent event) {
Log.d("CHCP", "Update is installed");

// reconfirm that our www folder is now valid
pluginInternalPrefs.setWwwFolderInstalled(true);
pluginInternalPrefsStorage.storeInPreference(pluginInternalPrefs);

final PluginResult jsResult = PluginResultHelper.pluginResultFromEvent(event);

if (installJsCallback != null) {
Expand All @@ -666,8 +682,12 @@ private void resetApplicationToStartingPage() {
public void run() {
webView.clearHistory();
webView.clearCache();
final String startingPage = getStartingPage() + "?" + System.currentTimeMillis();
final String externalStartingPage = FILE_PREFIX + Paths.get(fileStructure.wwwFolder(), startingPage);
final String external = Paths.get(fileStructure.wwwFolder(), getStartingPage());
if (!new File(external).exists()) {
Log.d("CHCP", "External starting page not found. Aborting page change.");
return;
}
final String externalStartingPage = FILE_PREFIX + external + "?" + System.currentTimeMillis();
webView.loadUrlIntoView(externalStartingPage, false);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public static boolean isInstalling() {
}

private static void execute(final InstallationWorker task) {
isInstalling = true;
new Thread(new Runnable() {
@Override
public void run() {
isInstalling = true;
task.run();
isInstalling = false;
}
Expand Down