Updater: Allow Updater to handle major upgrades via property

* If the user has GMS installed, they'll need to install an updated
  copy, as addon.d won't restore it, and if it did it likely wouldn't
  work. So we can't support this unconditionally.
* If the user has no-GMS, this should be totally fine to do, so the
  user could set the property, upgrade, and go on their merry way.
  This use-case is why I didn't make this an `ro.` property.
* If someone building LineageOS builds GMS into the images, upgrade
  via this method would also be feasible.

Change-Id: If2a6e6767dcb182d3dbd2a95c81a940fdb53547e
This commit is contained in:
Nolen Johnson
2024-12-25 00:28:01 -05:00
committed by Jan Altensen
parent 5ab3076f91
commit c9159bf47b
2 changed files with 11 additions and 2 deletions

View File

@@ -39,6 +39,7 @@ public final class Constants {
public static final String UNCRYPT_FILE_EXT = ".uncrypt"; public static final String UNCRYPT_FILE_EXT = ".uncrypt";
public static final String PROP_AB_DEVICE = "ro.build.ab_update"; public static final String PROP_AB_DEVICE = "ro.build.ab_update";
public static final String PROP_ALLOW_MAJOR_UPGRADES = "lineage.updater.allow_major_upgrades";
public static final String PROP_BUILD_DATE = "ro.build.date.utc"; public static final String PROP_BUILD_DATE = "ro.build.date.utc";
public static final String PROP_BUILD_VERSION = "ro.lineage.build.version"; public static final String PROP_BUILD_VERSION = "ro.lineage.build.version";
public static final String PROP_BUILD_VERSION_INCREMENTAL = "ro.build.version.incremental"; public static final String PROP_BUILD_VERSION_INCREMENTAL = "ro.build.version.incremental";

View File

@@ -112,7 +112,7 @@ public class Utils {
return true; return true;
} }
private static boolean compareVersions(String a, String b) { private static boolean compareVersions(String a, String b, boolean allowMajorUpgrades) {
try { try {
int majorA = Integer.parseInt(a.split("\\.")[0]); int majorA = Integer.parseInt(a.split("\\.")[0]);
int minorA = Integer.parseInt(a.split("\\.")[1]); int minorA = Integer.parseInt(a.split("\\.")[1]);
@@ -120,6 +120,9 @@ public class Utils {
int majorB = Integer.parseInt(b.split("\\.")[0]); int majorB = Integer.parseInt(b.split("\\.")[0]);
int minorB = Integer.parseInt(b.split("\\.")[1]); int minorB = Integer.parseInt(b.split("\\.")[1]);
// Return early and allow if we allow major version upgrades
return (allowMajorUpgrades && majorA > majorB) || (majorA == majorB && minorA >= minorB)
return majorA == majorB && minorA >= minorB; return majorA == majorB && minorA >= minorB;
} catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) {
return false; return false;
@@ -127,10 +130,15 @@ public class Utils {
} }
public static boolean canInstall(UpdateBaseInfo update) { public static boolean canInstall(UpdateBaseInfo update) {
boolean allowMajorUpgrades = SystemProperties.getBoolean(
Constants.PROP_ALLOW_MAJOR_UPGRADES, false);
return (SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) || return (SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) ||
update.getTimestamp() > SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) && update.getTimestamp() > SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) &&
compareVersions( compareVersions(
update.getVersion(), SystemProperties.get(Constants.PROP_BUILD_VERSION)); update.getVersion(),
SystemProperties.get(Constants.PROP_BUILD_VERSION),
allowMajorUpgrades);
} }
public static List<UpdateInfo> parseJson(File file, boolean compatibleOnly) public static List<UpdateInfo> parseJson(File file, boolean compatibleOnly)