Skip to content

Commit

Permalink
Use newly-provided API level to compare builds.
Browse files Browse the repository at this point in the history
Change-Id: I04326a039807c2fc80b3c55f37c115696edf9fa7
  • Loading branch information
maniac103 committed Jul 29, 2013
1 parent c3311aa commit 81d49f1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/com/cyanogenmod/updater/UpdatesSettings.java
Expand Up @@ -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(true) + ".zip";
String installedZip = "cm-" + Utils.getInstalledVersion() + ".zip";

// Add the updates
for (UpdateInfo ui : updates) {
Expand Down Expand Up @@ -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(true) + "\n\n"
+ getString(R.string.sysinfo_running) + " " + Utils.getInstalledVersion() + "\n\n"
+ getString(R.string.sysinfo_last_check) + " " + date + " " + time;

AlertDialog.Builder builder = new AlertDialog.Builder(this)
Expand Down
62 changes: 11 additions & 51 deletions src/com/cyanogenmod/updater/misc/UpdateInfo.java
Expand Up @@ -31,27 +31,28 @@ public enum Type {

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, String url,
public UpdateInfo(String fileName, long date, int apiLevel, 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, null, null, Type.UNKNOWN, changeLog);
this(fileName, 0, 0, null, null, Type.UNKNOWN, changeLog);
}

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

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

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

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.
int installedApiLevel = Utils.getInstalledApiLevel();
if (installedApiLevel != mApiLevel && mApiLevel > 0) {
mIsNewerThanInstalled = mApiLevel > installedApiLevel;
} else {
// API levels 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;
}
}

Expand Down Expand Up @@ -225,8 +185,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);
Expand All @@ -236,8 +196,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();
Expand Down
3 changes: 2 additions & 1 deletion src/com/cyanogenmod/updater/service/UpdateCheckService.java
Expand Up @@ -333,6 +333,7 @@ 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;
Expand All @@ -349,7 +350,7 @@ private UpdateInfo parseUpdateJSONObject(JSONObject obj, int updateType,
type = UpdateInfo.Type.UNKNOWN;
}

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

Expand Down
12 changes: 6 additions & 6 deletions src/com/cyanogenmod/updater/utils/Utils.java
Expand Up @@ -57,12 +57,12 @@ public static String getDeviceType() {
return SystemProperties.get("ro.cm.device");
}

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 String getInstalledVersion() {
return SystemProperties.get("ro.cm.version");
}

public static int getInstalledApiLevel() {
return SystemProperties.getInt("ro.build.version.sdk", 0);
}

public static long getInstalledBuildDate() {
Expand Down

0 comments on commit 81d49f1

Please sign in to comment.