Skip to content
Permalink
Browse files

Revert "Use newly-provided API level to compare builds."

This reverts commit c118ceb.
  • Loading branch information...
Dazzozo committed Aug 1, 2013
1 parent 65966db commit 7e465a7eb0f1dcf2410f061dd2cdab6de9637fd5
@@ -555,7 +555,7 @@ private void refreshPreferences(LinkedList<UpdateInfo> updates) {
mUpdatesList.removeAll();

// Convert the installed version name to the associated filename
String installedZip = "cm-" + Utils.getInstalledVersion() + ".zip";
String installedZip = "cm-" + Utils.getInstalledVersion(true) + ".zip";

// Add the updates
for (UpdateInfo ui : updates) {
@@ -686,7 +686,7 @@ private void showSysInfo() {
String time = DateFormat.getTimeFormat(this).format(lastCheck);

String message = getString(R.string.sysinfo_device) + " " + Utils.getDeviceType() + "\n\n"
+ getString(R.string.sysinfo_running) + " " + Utils.getInstalledVersion() + "\n\n"
+ getString(R.string.sysinfo_running) + " " + Utils.getInstalledVersion(true) + "\n\n"
+ getString(R.string.sysinfo_last_check) + " " + date + " " + time;

AlertDialog.Builder builder = new AlertDialog.Builder(this)
@@ -31,28 +31,27 @@

private String mUiName;
private String mFileName;
private String mVersion;
private Type mType;
private int mApiLevel;
private long mBuildDate;
private String mDownloadUrl;
private String mMd5Sum;
private String mChangeLog;

private Boolean mIsNewerThanInstalled;

public UpdateInfo(String fileName, long date, int apiLevel, String url,
public UpdateInfo(String fileName, long date, String url,
String md5, Type type, String changeLog) {
initializeName(fileName);
mBuildDate = date;
mApiLevel = apiLevel;
mDownloadUrl = url;
mMd5Sum = md5;
mType = type;
mChangeLog = changeLog;
}

public UpdateInfo(String fileName, String changeLog) {
this(fileName, 0, 0, null, null, Type.UNKNOWN, changeLog);
this(fileName, 0, null, null, Type.UNKNOWN, changeLog);
}

private UpdateInfo(Parcel in) {
@@ -73,6 +72,13 @@ public String getName() {
return mUiName;
}

/**
* Get version
*/
public String getVersion() {
return mVersion;
}

/**
* Get file name
*/
@@ -117,23 +123,57 @@ public boolean isNewerThanInstalled() {
return mIsNewerThanInstalled;
}

int installedApiLevel = Utils.getInstalledApiLevel();
if (installedApiLevel != mApiLevel && mApiLevel > 0) {
mIsNewerThanInstalled = mApiLevel > installedApiLevel;
} else {
// API levels match, so compare build dates.
int[] installedVersion = canonicalizeVersion(Utils.getInstalledVersion(false));
int[] ourVersion = canonicalizeVersion(mVersion);

if (installedVersion.length < ourVersion.length) {
installedVersion = Arrays.copyOf(installedVersion, ourVersion.length);
} else if (installedVersion.length > ourVersion.length) {
ourVersion = Arrays.copyOf(ourVersion, installedVersion.length);
}

for (int i = 0; i < ourVersion.length; i++) {
if (ourVersion[i] > installedVersion[i]) {
mIsNewerThanInstalled = true;
break;
}
if (ourVersion[i] < installedVersion[i]) {
mIsNewerThanInstalled = false;
break;
}
}

if (mIsNewerThanInstalled == null) {
// Version strings match, so compare build dates.
mIsNewerThanInstalled = mBuildDate > Utils.getInstalledBuildDate();
}

return mIsNewerThanInstalled;
}

private int[] canonicalizeVersion(String versionString) {
String[] parts = versionString.split("\\.");
int[] version = new int[parts.length];

for (int i = 0; i < parts.length; i++) {
try {
version[i] = Integer.valueOf(parts[i]);
} catch (NumberFormatException e) {
version[i] = 0;
}
}

return version;
}

private void initializeName(String fileName) {
mFileName = fileName;
if (!TextUtils.isEmpty(fileName)) {
mUiName = extractUiName(fileName);
mVersion = fileName.replaceAll(".*?([0-9.]+?)-.+","$1");
} else {
mUiName = null;
mVersion = null;
}
}

@@ -185,8 +225,8 @@ public int describeContents() {
public void writeToParcel(Parcel out, int flags) {
out.writeString(mUiName);
out.writeString(mFileName);
out.writeString(mVersion);
out.writeString(mType.toString());
out.writeInt(mApiLevel);
out.writeLong(mBuildDate);
out.writeString(mDownloadUrl);
out.writeString(mMd5Sum);
@@ -196,8 +236,8 @@ public void writeToParcel(Parcel out, int flags) {
private void readFromParcel(Parcel in) {
mUiName = in.readString();
mFileName = in.readString();
mVersion = in.readString();
mType = Enum.valueOf(Type.class, in.readString());
mApiLevel = in.readInt();
mBuildDate = in.readLong();
mDownloadUrl = in.readString();
mMd5Sum = in.readString();
@@ -333,7 +333,6 @@ private UpdateInfo parseUpdateJSONObject(JSONObject obj, int updateType,
String fileName = obj.getString("filename");
String url = obj.getString("url");
String md5 = obj.getString("md5sum");
int apiLevel = obj.getInt("api_level");
long timestamp = obj.getLong("timestamp");
String typeString = obj.getString("channel");
UpdateInfo.Type type;
@@ -350,7 +349,7 @@ private UpdateInfo parseUpdateJSONObject(JSONObject obj, int updateType,
type = UpdateInfo.Type.UNKNOWN;
}

UpdateInfo ui = new UpdateInfo(fileName, timestamp, apiLevel, url, md5, type, null);
UpdateInfo ui = new UpdateInfo(fileName, timestamp, url, md5, type, null);
boolean includeAll = updateType == Constants.UPDATE_TYPE_ALL_STABLE
|| updateType == Constants.UPDATE_TYPE_ALL_NIGHTLY;

@@ -57,12 +57,12 @@ public static String getDeviceType() {
return SystemProperties.get("ro.cm.device");
}

public static String getInstalledVersion() {
return SystemProperties.get("ro.cm.version");
}

public static int getInstalledApiLevel() {
return SystemProperties.getInt("ro.build.version.sdk", 0);
public static String getInstalledVersion(boolean fullVersionString) {
String version = SystemProperties.get("ro.cm.version");
if (!fullVersionString) {
version = version.replaceAll("([0-9.]+?)-.+","$1");
}
return version;
}

public static long getInstalledBuildDate() {

0 comments on commit 7e465a7

Please sign in to comment.
You can’t perform that action at this time.