Skip to content

Commit 1a45f98

Browse files
fix crashes related to broken excludes parsing
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent aa34e36 commit 1a45f98

3 files changed

Lines changed: 51 additions & 45 deletions

File tree

app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,26 +157,28 @@ static void doCheck(Context context) {
157157
if (repoModule != null) {
158158
remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode);
159159
}
160-
int localVersionCode = Integer.parseInt(String.valueOf(localModuleInfo.versionCode));
161-
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
162-
int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", ""));
163-
// now find out if user wants up to and including this version, or this version and newer
164-
// if it starts with ^, it's this version and newer, if it ends with $, it's this version and older
165-
if (version.startsWith("^")) {
166-
// this version and newer
167-
if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) {
160+
if (!version.isEmpty()) {
161+
int localVersionCode = Integer.parseInt(String.valueOf(localModuleInfo.versionCode));
162+
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
163+
int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", ""));
164+
// now find out if user wants up to and including this version, or this version and newer
165+
// if it starts with ^, it's this version and newer, if it ends with $, it's this version and older
166+
if (version.startsWith("^")) {
167+
// this version and newer
168+
if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) {
169+
// if it is, we skip it
170+
continue;
171+
}
172+
} else if (version.endsWith("$")) {
173+
// this version and older
174+
if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) {
175+
// if it is, we skip it
176+
continue;
177+
}
178+
} else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) {
168179
// if it is, we skip it
169180
continue;
170181
}
171-
} else if (version.endsWith("$")) {
172-
// this version and older
173-
if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) {
174-
// if it is, we skip it
175-
continue;
176-
}
177-
} else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) {
178-
// if it is, we skip it
179-
continue;
180182
}
181183
if (localModuleInfo.updateVersionCode > localModuleInfo.versionCode && !PropUtils.isNullString(localModuleInfo.updateVersion)) {
182184
moduleUpdateCount++;

app/src/main/java/com/fox2code/mmm/module/ModuleHolder.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -156,40 +156,43 @@ public Type getType() {
156156
if (repoModule != null) {
157157
remoteVersionCode = String.valueOf(repoModule.moduleInfo.versionCode);
158158
}
159-
// now, coerce everything into an int
160-
int localVersionCode = Integer.parseInt(String.valueOf(moduleInfo.versionCode));
161-
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
162-
int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", ""));
163-
// now find out if user wants up to and including this version, or this version and newer
164-
// if it starts with ^, it's this version and newer, if it ends with $, it's this version and older
165-
if (version.startsWith("^")) {
166-
// this version and newer
167-
if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) {
159+
if (!version.isEmpty()) {
160+
// now, coerce everything into an int
161+
int localVersionCode = Integer.parseInt(String.valueOf(moduleInfo.versionCode));
162+
int remoteVersionCodeInt = Integer.parseInt(remoteVersionCode);
163+
int wantsVersion = Integer.parseInt(version.split(":")[1].replaceAll("[^0-9]", ""));
164+
// now find out if user wants up to and including this version, or this version and newer
165+
// if it starts with ^, it's this version and newer, if it ends with $, it's this version and older
166+
if (version.startsWith("^")) {
167+
// this version and newer
168+
if (wantsVersion <= remoteVersionCodeInt || wantsVersion <= localVersionCode) {
169+
// if it is, we skip it
170+
ignoreUpdate = true;
171+
}
172+
} else if (version.endsWith("$")) {
173+
// this version and older
174+
if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) {
175+
// if it is, we skip it
176+
ignoreUpdate = true;
177+
}
178+
} else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) {
168179
// if it is, we skip it
169180
ignoreUpdate = true;
170181
}
171-
} else if (version.endsWith("$")) {
172-
// this version and older
173-
if (wantsVersion >= remoteVersionCodeInt || wantsVersion >= localVersionCode) {
174-
// if it is, we skip it
175-
ignoreUpdate = true;
176-
}
177-
} else if (wantsVersion == remoteVersionCodeInt || wantsVersion == localVersionCode) {
178-
// if it is, we skip it
179-
ignoreUpdate = true;
180182
}
181-
MainApplication.getINSTANCE().modulesHaveUpdates = true;
182-
if (!MainApplication.getINSTANCE().updateModules.contains(this.moduleId)) {
183-
MainApplication.getINSTANCE().updateModules.add(this.moduleId);
184-
MainApplication.getINSTANCE().updateModuleCount++;
185-
}
186-
Timber.d("modulesHaveUpdates = %s, updateModuleCount = %s", MainApplication.getINSTANCE().modulesHaveUpdates, MainApplication.getINSTANCE().updateModuleCount);
187183
if (ignoreUpdate) {
188184
Timber.d("Module %s has update, but is ignored", this.moduleId);
189185
return Type.INSTALLABLE;
186+
} else {
187+
MainApplication.getINSTANCE().modulesHaveUpdates = true;
188+
if (!MainApplication.getINSTANCE().updateModules.contains(this.moduleId)) {
189+
MainApplication.getINSTANCE().updateModules.add(this.moduleId);
190+
MainApplication.getINSTANCE().updateModuleCount++;
191+
}
192+
Timber.d("modulesHaveUpdates = %s, updateModuleCount = %s", MainApplication.getINSTANCE().modulesHaveUpdates, MainApplication.getINSTANCE().updateModuleCount);
193+
Timber.d("Module %s has update", this.moduleId);
194+
return Type.UPDATABLE;
190195
}
191-
Timber.d("Module %s has update", this.moduleId);
192-
return Type.UPDATABLE;
193196
} else {
194197
return Type.INSTALLED;
195198
}

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,9 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
671671
EditText editText = (EditText) layout.getChildAt(i);
672672
String text = editText.getText().toString();
673673
if (!text.isEmpty()) {
674-
// text can only contain numbers
675-
text = text.replaceAll("[^0-9]", "");
674+
// text can only contain numbers and the characters ^ and $
675+
// so we remove all non-numbers and non ^ and $
676+
text = text.replaceAll("[^0-9^$]", "");
676677
// we have to use module id even though we show name
677678
stringSetTemp.add(localModuleInfos.stream().filter(localModuleInfo -> localModuleInfo.name.equals(editText.getHint().toString())).findFirst().orElse(null).id + ":" + text);
678679
Timber.d("text is %s for %s", text, editText.getHint().toString());

0 commit comments

Comments
 (0)