Allow to check if an update is of type AB from anywhere

This commit is contained in:
Gabriele M
2017-07-16 22:28:11 +02:00
parent 4182e3d30e
commit 12688ba761
4 changed files with 20 additions and 14 deletions

View File

@@ -21,6 +21,7 @@ import android.util.Log;
import org.lineageos.updater.UpdateDownload;
import org.lineageos.updater.UpdateStatus;
import org.lineageos.updater.misc.Constants;
import org.lineageos.updater.misc.Utils;
import java.io.BufferedReader;
@@ -39,9 +40,6 @@ class ABUpdateInstaller {
private static String sDownloadId;
private static final String PAYLOAD_BIN_PATH = "payload.bin";
private static final String PAYLOAD_PROPERTIES_PATH = "payload_properties.txt";
private final UpdaterController mUpdaterController;
private final String mDownloadId;
@@ -131,8 +129,8 @@ class ABUpdateInstaller {
String[] headerKeyValuePairs;
try {
ZipFile zipFile = new ZipFile(file);
offset = Utils.getZipEntryOffset(zipFile, PAYLOAD_BIN_PATH);
ZipEntry payloadPropEntry = zipFile.getEntry(PAYLOAD_PROPERTIES_PATH);
offset = Utils.getZipEntryOffset(zipFile, Constants.AB_PAYLOAD_BIN_PATH);
ZipEntry payloadPropEntry = zipFile.getEntry(Constants.AB_PAYLOAD_PROPERTIES_PATH);
try (InputStream is = zipFile.getInputStream(payloadPropEntry);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr)) {
@@ -159,9 +157,4 @@ class ABUpdateInstaller {
return true;
}
static boolean isABUpdate(ZipFile zipFile) {
return zipFile.getEntry(PAYLOAD_BIN_PATH) != null &&
zipFile.getEntry(PAYLOAD_PROPERTIES_PATH) != null;
}
}

View File

@@ -36,6 +36,7 @@ import org.lineageos.updater.UpdateDownload;
import org.lineageos.updater.UpdateStatus;
import org.lineageos.updater.UpdaterReceiver;
import org.lineageos.updater.UpdatesActivity;
import org.lineageos.updater.misc.Utils;
import java.io.IOException;
import java.text.NumberFormat;
@@ -165,10 +166,7 @@ public class UpdaterService extends Service {
throw new IllegalArgumentException(update.getDownloadId() + " is not verified");
}
try {
ZipFile zipFile = new ZipFile(update.getFile());
boolean isABUpdate = ABUpdateInstaller.isABUpdate(zipFile);
zipFile.close();
if (isABUpdate) {
if (Utils.isABUpdate(update.getFile())) {
ABUpdateInstaller.start(mUpdaterController, downloadId);
} else {
android.os.RecoverySystem.installPackage(this, update.getFile());

View File

@@ -20,6 +20,9 @@ public final class Constants {
private Constants() {
}
public static final String AB_PAYLOAD_BIN_PATH = "payload.bin";
public static final String AB_PAYLOAD_PROPERTIES_PATH = "payload_properties.txt";
public static final String PREF_LAST_UPDATE_CHECK = "last_update_check";
public static final String PREF_AUTO_UPDATES_CHECK = "auto_updates_check";

View File

@@ -268,4 +268,16 @@ public class Utils {
}
throw new IllegalStateException();
}
public static boolean isABUpdate(ZipFile zipFile) {
return zipFile.getEntry(Constants.AB_PAYLOAD_BIN_PATH) != null &&
zipFile.getEntry(Constants.AB_PAYLOAD_PROPERTIES_PATH) != null;
}
public static boolean isABUpdate(File file) throws IOException {
ZipFile zipFile = new ZipFile(file);
boolean isAB = isABUpdate(zipFile);
zipFile.close();
return isAB;
}
}