Allow to check if an update is of type AB from anywhere
This commit is contained in:
@@ -21,6 +21,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.lineageos.updater.UpdateDownload;
|
import org.lineageos.updater.UpdateDownload;
|
||||||
import org.lineageos.updater.UpdateStatus;
|
import org.lineageos.updater.UpdateStatus;
|
||||||
|
import org.lineageos.updater.misc.Constants;
|
||||||
import org.lineageos.updater.misc.Utils;
|
import org.lineageos.updater.misc.Utils;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -39,9 +40,6 @@ class ABUpdateInstaller {
|
|||||||
|
|
||||||
private static String sDownloadId;
|
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 UpdaterController mUpdaterController;
|
||||||
private final String mDownloadId;
|
private final String mDownloadId;
|
||||||
|
|
||||||
@@ -131,8 +129,8 @@ class ABUpdateInstaller {
|
|||||||
String[] headerKeyValuePairs;
|
String[] headerKeyValuePairs;
|
||||||
try {
|
try {
|
||||||
ZipFile zipFile = new ZipFile(file);
|
ZipFile zipFile = new ZipFile(file);
|
||||||
offset = Utils.getZipEntryOffset(zipFile, PAYLOAD_BIN_PATH);
|
offset = Utils.getZipEntryOffset(zipFile, Constants.AB_PAYLOAD_BIN_PATH);
|
||||||
ZipEntry payloadPropEntry = zipFile.getEntry(PAYLOAD_PROPERTIES_PATH);
|
ZipEntry payloadPropEntry = zipFile.getEntry(Constants.AB_PAYLOAD_PROPERTIES_PATH);
|
||||||
try (InputStream is = zipFile.getInputStream(payloadPropEntry);
|
try (InputStream is = zipFile.getInputStream(payloadPropEntry);
|
||||||
InputStreamReader isr = new InputStreamReader(is);
|
InputStreamReader isr = new InputStreamReader(is);
|
||||||
BufferedReader br = new BufferedReader(isr)) {
|
BufferedReader br = new BufferedReader(isr)) {
|
||||||
@@ -159,9 +157,4 @@ class ABUpdateInstaller {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isABUpdate(ZipFile zipFile) {
|
|
||||||
return zipFile.getEntry(PAYLOAD_BIN_PATH) != null &&
|
|
||||||
zipFile.getEntry(PAYLOAD_PROPERTIES_PATH) != null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,7 @@ import org.lineageos.updater.UpdateDownload;
|
|||||||
import org.lineageos.updater.UpdateStatus;
|
import org.lineageos.updater.UpdateStatus;
|
||||||
import org.lineageos.updater.UpdaterReceiver;
|
import org.lineageos.updater.UpdaterReceiver;
|
||||||
import org.lineageos.updater.UpdatesActivity;
|
import org.lineageos.updater.UpdatesActivity;
|
||||||
|
import org.lineageos.updater.misc.Utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
@@ -165,10 +166,7 @@ public class UpdaterService extends Service {
|
|||||||
throw new IllegalArgumentException(update.getDownloadId() + " is not verified");
|
throw new IllegalArgumentException(update.getDownloadId() + " is not verified");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ZipFile zipFile = new ZipFile(update.getFile());
|
if (Utils.isABUpdate(update.getFile())) {
|
||||||
boolean isABUpdate = ABUpdateInstaller.isABUpdate(zipFile);
|
|
||||||
zipFile.close();
|
|
||||||
if (isABUpdate) {
|
|
||||||
ABUpdateInstaller.start(mUpdaterController, downloadId);
|
ABUpdateInstaller.start(mUpdaterController, downloadId);
|
||||||
} else {
|
} else {
|
||||||
android.os.RecoverySystem.installPackage(this, update.getFile());
|
android.os.RecoverySystem.installPackage(this, update.getFile());
|
||||||
|
@@ -20,6 +20,9 @@ public final class Constants {
|
|||||||
private 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_LAST_UPDATE_CHECK = "last_update_check";
|
||||||
public static final String PREF_AUTO_UPDATES_CHECK = "auto_updates_check";
|
public static final String PREF_AUTO_UPDATES_CHECK = "auto_updates_check";
|
||||||
|
|
||||||
|
@@ -268,4 +268,16 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
throw new IllegalStateException();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user