Magisk/app-core/src/main/java/com/topjohnwu/magisk/container/BaseModule.java

156 lines
4.3 KiB
Java
Raw Normal View History

2019-01-30 09:10:12 +01:00
package com.topjohnwu.magisk.container;
2017-09-29 21:25:50 +02:00
import android.content.ContentValues;
import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;
2016-11-12 20:07:16 +01:00
import java.util.List;
2018-09-10 08:27:45 +02:00
import androidx.annotation.NonNull;
public abstract class BaseModule implements Comparable<BaseModule>, Parcelable {
private String mId, mName, mVersion, mAuthor, mDescription;
2017-11-17 16:34:38 +01:00
private int mVersionCode = -1, minMagiskVersion = -1;
protected BaseModule() {
mId = mName = mVersion = mAuthor = mDescription = "";
}
protected BaseModule(Cursor c) {
mId = nonNull(c.getString(c.getColumnIndex("id")));
mName = nonNull(c.getString(c.getColumnIndex("name")));
mVersion = nonNull(c.getString(c.getColumnIndex("version")));
mVersionCode = c.getInt(c.getColumnIndex("versionCode"));
mAuthor = nonNull(c.getString(c.getColumnIndex("author")));
mDescription = nonNull(c.getString(c.getColumnIndex("description")));
2017-11-17 16:34:38 +01:00
minMagiskVersion = c.getInt(c.getColumnIndex("minMagisk"));
}
protected BaseModule(Parcel p) {
mId = p.readString();
mName = p.readString();
mVersion = p.readString();
mAuthor = p.readString();
mDescription = p.readString();
mVersionCode = p.readInt();
minMagiskVersion = p.readInt();
}
@Override
public int compareTo(@NonNull BaseModule module) {
return this.getName().toLowerCase().compareTo(module.getName().toLowerCase());
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mId);
dest.writeString(mName);
dest.writeString(mVersion);
dest.writeString(mAuthor);
dest.writeString(mDescription);
dest.writeInt(mVersionCode);
dest.writeInt(minMagiskVersion);
}
private String nonNull(String s) {
return s == null ? "" : s;
}
2017-09-29 21:25:50 +02:00
public ContentValues getContentValues() {
ContentValues values = new ContentValues();
values.put("id", mId);
values.put("name", mName);
values.put("version", mVersion);
values.put("versionCode", mVersionCode);
values.put("author", mAuthor);
values.put("description", mDescription);
2017-11-17 16:34:38 +01:00
values.put("minMagisk", minMagiskVersion);
2017-09-29 21:25:50 +02:00
return values;
}
2017-09-30 19:38:25 +02:00
protected void parseProps(List<String> props) { parseProps(props.toArray(new String[0])); }
protected void parseProps(String[] props) throws NumberFormatException {
for (String line : props) {
String[] prop = line.split("=", 2);
if (prop.length != 2)
continue;
String key = prop[0].trim();
2018-07-17 22:01:06 +02:00
String value = prop[1].trim();
if (key.isEmpty() || key.charAt(0) == '#')
continue;
switch (key) {
case "id":
2018-07-17 22:01:06 +02:00
mId = value;
break;
case "name":
2018-07-17 22:01:06 +02:00
mName = value;
break;
case "version":
2018-07-17 22:01:06 +02:00
mVersion = value;
break;
case "versionCode":
2018-07-17 22:01:06 +02:00
mVersionCode = Integer.parseInt(value);
break;
case "author":
2018-07-17 22:01:06 +02:00
mAuthor = value;
break;
case "description":
2018-07-17 22:01:06 +02:00
mDescription = value;
break;
2017-11-17 16:34:38 +01:00
case "minMagisk":
2017-03-30 00:52:18 +02:00
case "template":
2018-07-17 22:01:06 +02:00
minMagiskVersion = Integer.parseInt(value);
break;
default:
break;
}
}
}
public String getName() {
return mName;
}
public void setName(String name) {
mName = name;
}
public String getVersion() {
return mVersion;
}
public String getAuthor() {
return mAuthor;
}
2017-02-15 22:45:31 +01:00
public String getId() {
return mId;
}
public void setId(String id) {
mId = id;
}
public String getDescription() {
return mDescription;
}
public int getVersionCode() {
return mVersionCode;
}
2017-11-17 16:34:38 +01:00
public int getMinMagiskVersion() {
return minMagiskVersion;
2017-03-30 00:52:18 +02:00
}
}