Skip to content

Commit

Permalink
fix(android): dont allow redundant downloads of versions that already…
Browse files Browse the repository at this point in the history
… exist
  • Loading branch information
lincolnthree committed May 10, 2022
1 parent 9e5c37c commit e9f81d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,19 @@ public void run() {
if (latestVersionName != null && !"".equals(latestVersionName) && !current.getName().equals(latestVersionName)) {

final VersionInfo latest = CapacitorUpdaterPlugin.this.implementation.getVersionInfoByName(latestVersionName);
if(latest != null && latest.isErrorStatus()) {
Log.e(CapacitorUpdater.TAG, "Latest version already exists, and is in error state. Aborting update.");
return;
if(latest != null) {
if(latest.isErrorStatus()) {
Log.e(CapacitorUpdater.TAG, "Latest version already exists, and is in error state. Aborting update.");
return;
}
if(latest.isDownloaded()){
Log.e(CapacitorUpdater.TAG, "Latest version already exists and download is NOT required. Update will occur next time app moves to background.");
CapacitorUpdaterPlugin.this.implementation.setNextVersion(latest.getVersion());
return;
}
}


new Thread(new Runnable(){
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class VersionInfo {
public static final String VERSION_BUILTIN = "builtin";
public static final String DOWNLOADED_BUILTIN = "1970-01-01T00:00:00.000Z";

private final String downloaded;
private final String name;
Expand All @@ -27,8 +28,12 @@ public Boolean isErrorStatus() {
return VersionStatus.ERROR == this.status;
}

public boolean isDownloaded() {
return !this.isBuiltin() && this.downloaded != null && this.downloaded.trim().length() == DOWNLOADED_BUILTIN.length();
}

public String getDownloaded() {
return this.isBuiltin() ? "1970-01-01T00:00:00.000Z" : this.downloaded;
return this.isBuiltin() ? DOWNLOADED_BUILTIN : this.downloaded;
}

public String getName() {
Expand Down

0 comments on commit e9f81d7

Please sign in to comment.