Skip to content

Commit

Permalink
Checksum generator was removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
kolbasa committed Dec 10, 2021
1 parent 1f60b96 commit 63ccd3d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 71 deletions.
1 change: 0 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
<source-file src="src/android/tools/ApkInstaller.java" target-dir="src/de/kolbasa/apkupdater/tools"/>
<source-file src="src/android/tools/AppData.java" target-dir="src/de/kolbasa/apkupdater/tools"/>
<source-file src="src/android/tools/ArchiveManager.java" target-dir="src/de/kolbasa/apkupdater/tools"/>
<source-file src="src/android/tools/ChecksumGenerator.java" target-dir="src/de/kolbasa/apkupdater/tools"/>
<source-file src="src/android/tools/DAReceiver.java" target-dir="src/de/kolbasa/apkupdater/tools"/>
<source-file src="src/android/tools/FileProvider.java" target-dir="src/de/kolbasa/apkupdater/tools"/>
<source-file src="src/android/tools/FileTools.java" target-dir="src/de/kolbasa/apkupdater/tools"/>
Expand Down
20 changes: 9 additions & 11 deletions src/android/ApkUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ private void checkIfRunning() throws DownloadInProgressException {
}
}

private Update getUpdate(boolean calcSum) throws Exception {
private Update getUpdate() throws Exception {
checkIfRunning();
return updateManager.getUpdate(calcSum);
return updateManager.getUpdate();
}

private void pushProgressEvent(CallbackContext callbackContext, Progress progress) {
Expand Down Expand Up @@ -81,9 +81,8 @@ private void download(JSONArray data, CallbackContext callbackContext) {
String url = parseString(data.getString(0));
String basicAuth = parseString(data.getString(1));
String zipPassword = parseString(data.getString(2));
boolean calculateChecksum = data.getBoolean(3);

Update update = updateManager.download(url, basicAuth, zipPassword, calculateChecksum);
Update update = updateManager.download(url, basicAuth, zipPassword);
callbackContext.success(update.toJSON());
} catch (Exception e) {
callbackContext.error(StackExtractor.format(e));
Expand Down Expand Up @@ -118,10 +117,9 @@ private void stop(CallbackContext callbackContext) {
}
}

private void getDownloadedUpdate(JSONArray data, CallbackContext callbackContext) {
private void getDownloadedUpdate(CallbackContext callbackContext) {
try {
boolean calculateChecksum = data.getBoolean(0);
callbackContext.success(getUpdate(calculateChecksum).toJSON());
callbackContext.success(getUpdate().toJSON());
} catch (Exception e) {
callbackContext.error(StackExtractor.format(e));
}
Expand Down Expand Up @@ -169,7 +167,7 @@ private void openInstallSetting(CallbackContext callbackContext) {

private void install(CallbackContext callbackContext) {
try {
Update update = getUpdate(false);
Update update = getUpdate();
updateManager.unzipBundle(update);
ApkInstaller.install(cordova.getContext(), update.getUpdate());
callbackContext.success();
Expand All @@ -196,7 +194,7 @@ private void requestRootAccess(CallbackContext callbackContext) {

private void rootInstall(CallbackContext callbackContext) {
try {
ApkInstaller.rootInstall(cordova.getContext(), getUpdate(false).getUpdate());
ApkInstaller.rootInstall(cordova.getContext(), getUpdate().getUpdate());
callbackContext.success();
} catch (Exception e) {
callbackContext.error(StackExtractor.format(e));
Expand All @@ -213,7 +211,7 @@ private void isDeviceOwner(CallbackContext callbackContext) {

private void ownerInstall(CallbackContext callbackContext) {
try {
ApkInstaller.ownerInstall(cordova.getContext(), getUpdate(false).getUpdate());
ApkInstaller.ownerInstall(cordova.getContext(), getUpdate().getUpdate());
callbackContext.success();
} catch (Exception e) {
callbackContext.error(StackExtractor.format(e));
Expand Down Expand Up @@ -241,7 +239,7 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo
cordova.getThreadPool().execute(() -> stop(callbackContext));
break;
case "getDownloadedUpdate":
cordova.getThreadPool().execute(() -> getDownloadedUpdate(data, callbackContext));
cordova.getThreadPool().execute(() -> getDownloadedUpdate(callbackContext));
break;
case "reset":
cordova.getThreadPool().execute(() -> reset(callbackContext));
Expand Down
36 changes: 0 additions & 36 deletions src/android/tools/ChecksumGenerator.java

This file was deleted.

13 changes: 3 additions & 10 deletions src/android/update/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ public class Update {

private final File update;

private final String checksum;

private final AppInfo appInfo;

private final File bundle;

private final Map<String, File> updateData;

public Update(File update, String checksum, AppInfo appInfo) {
this(update, checksum, appInfo, null, null);
public Update(File update, AppInfo appInfo) {
this(update, appInfo, null, null);
}

public Update(File update, String checksum, AppInfo appInfo, File bundle, Map<String, File> updateData) {
public Update(File update, AppInfo appInfo, File bundle, Map<String, File> updateData) {
this.update = update;
this.checksum = checksum;
this.appInfo = appInfo;
this.bundle = bundle;
this.updateData = updateData;
Expand All @@ -49,10 +46,6 @@ public JSONObject toJSON() throws JSONException {
result.put("path", update.getParent());
result.put("size", update.length());

if (checksum != null) {
result.put("checksum", checksum);
}

if (appInfo != null) {
result.put("app", appInfo.toJSON());
}
Expand Down
22 changes: 9 additions & 13 deletions src/android/update/UpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import de.kolbasa.apkupdater.exceptions.UnzipException;
import de.kolbasa.apkupdater.exceptions.UpdateNotFoundException;
import de.kolbasa.apkupdater.tools.AppData;
import de.kolbasa.apkupdater.tools.ChecksumGenerator;
import de.kolbasa.apkupdater.tools.FileTools;
import de.kolbasa.apkupdater.tools.PermissionManager;
import de.kolbasa.apkupdater.tools.ArchiveManager;
Expand Down Expand Up @@ -193,7 +192,7 @@ private void unzipManifest() throws UnzipException, InvalidPackageException {
}
}

private Update getBundleInfo(File manifest, boolean calcSum) throws JSONException,
private Update getBundleInfo(File manifest) throws JSONException,
IOException, InvalidPackageException {

File bundle = FileTools.findByFileType(downloadDir, BUNDLE).get(0);
Expand All @@ -219,18 +218,16 @@ private Update getBundleInfo(File manifest, boolean calcSum) throws JSONExceptio
File update = new File(downloadDir, updatePath);
data.put(updatePath, update);

String sum = calcSum ? ChecksumGenerator.getFileChecksum(bundle) : null;

String name = obj.getString(MANIFEST_NAME);
String packageName = obj.getString(MANIFEST_PACKAGE_NAME);
String versionName = obj.getString(MANIFEST_VERSION_NAME);
Integer versionCode = obj.getInt(MANIFEST_VERSION_CODE);
AppInfo info = new AppInfo(name, packageName, versionName, versionCode, null);

return new Update(update, sum, info, bundle, data);
return new Update(update, info, bundle, data);
}

private Update getApkInfo(boolean calcSum) throws UpdateNotFoundException, IOException,
private Update getApkInfo() throws UpdateNotFoundException, IOException,
InvalidPackageException, PackageManager.NameNotFoundException {

List<File> updateFiles = FileTools.findByFileType(downloadDir, APK);
Expand All @@ -244,22 +241,21 @@ private Update getApkInfo(boolean calcSum) throws UpdateNotFoundException, IOExc
}

File update = updateFiles.get(0);
String sum = calcSum ? ChecksumGenerator.getFileChecksum(update) : null;
AppInfo info = AppData.getPackageInfo(context, update);

return new Update(update, sum, info);
return new Update(update, info);
}

public Update getUpdate(boolean calcSum) throws IOException, UpdateNotFoundException, JSONException,
public Update getUpdate() throws IOException, UpdateNotFoundException, JSONException,
InvalidPackageException, PackageManager.NameNotFoundException {
File bundleManifest = new File(downloadDir, MANIFEST);
if (bundleManifest.exists()) {
return getBundleInfo(bundleManifest, calcSum);
return getBundleInfo(bundleManifest);
}
return getApkInfo(calcSum);
return getApkInfo();
}

public Update download(String path, String basicAuth, String zipPassword, boolean calcSum) throws IOException,
public Update download(String path, String basicAuth, String zipPassword) throws IOException,
UnzipException, DownloadFailedException, JSONException, UpdateNotFoundException,
InvalidPackageException, PackageManager.NameNotFoundException {

Expand All @@ -270,7 +266,7 @@ public Update download(String path, String basicAuth, String zipPassword, boolea
unzipUpdate(downloadedFile, zipPassword);
unzipManifest();

return getUpdate(calcSum);
return getUpdate();
} catch (Exception e) {
try {
reset();
Expand Down

0 comments on commit 63ccd3d

Please sign in to comment.