Small refinements and bugfixes

Close #109
This commit is contained in:
topjohnwu 2017-02-19 08:05:16 +08:00
parent 9bc410dd3d
commit 6785221479
23 changed files with 103 additions and 80 deletions

View File

@ -6,7 +6,7 @@ body {
padding-bottom: 10px;
background-color: #303030;
color: white;
padding: 30px; }
padding: 15px; }
body > *:first-child {
margin-top: 0 !important; }

View File

@ -5,7 +5,7 @@ body {
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
padding: 15px; }
body > *:first-child {
margin-top: 0 !important; }

View File

@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -56,8 +57,11 @@ public class InstallFragment extends Fragment implements CallbackEvent.Listener<
View v = inflater.inflate(R.layout.fragment_install, container, false);
unbinder = ButterKnife.bind(this, v);
detectButton.setOnClickListener(v1 -> toAutoDetect());
currentVersionTitle.setText(getString(R.string.current_magisk_title, getApplication().magiskVersionString));
installTitle.setText(getString(R.string.install_magisk_title, getApplication().remoteMagiskVersion));
if (getApplication().magiskVersion < 0)
currentVersionTitle.setText(getString(R.string.current_magisk_title, getString(R.string.version_none)));
else
currentVersionTitle.setText(getString(R.string.current_magisk_title, "v" + getApplication().magiskVersionString));
installTitle.setText(getString(R.string.install_magisk_title, "v" + String.format(Locale.US, "%.1f", getApplication().remoteMagiskVersion)));
flashButton.setOnClickListener(v1 -> {
String bootImage;
if (getApplication().bootBlock != null) {
@ -73,7 +77,7 @@ public class InstallFragment extends Fragment implements CallbackEvent.Listener<
.setTitle(getString(R.string.repo_install_title, getString(R.string.magisk)))
.setMessage(getString(R.string.repo_install_msg, filename))
.setCancelable(true)
.setPositiveButton(R.string.download_install, (dialogInterface, i) -> Utils.dlAndReceive(
.setPositiveButton(R.string.install, (dialogInterface, i) -> Utils.dlAndReceive(
getActivity(),
new DownloadReceiver() {
private String boot = bootImage;

View File

@ -38,7 +38,7 @@ public class MagiskManager extends Application {
// Info
public double magiskVersion;
public String magiskVersionString = "(none)";
public String magiskVersionString;
public double remoteMagiskVersion = -1;
public String magiskLink;
public String releaseNoteLink;
@ -46,7 +46,8 @@ public class MagiskManager extends Application {
public String bootBlock = null;
public boolean isSuClient = false;
public String suVersion = null;
public boolean disabled = false;
public boolean disabled;
public boolean magiskHideStarted;
// Data
public ValueSortedMap<String, Repo> repoMap;
@ -90,6 +91,8 @@ public class MagiskManager extends Application {
devLogging = prefs.getBoolean("developer_logging", false);
shellLogging = prefs.getBoolean("shell_logging", false);
magiskHide = prefs.getBoolean("magiskhide", false);
// Always start a new root shell manually, just for safety
Shell.init();
updateMagiskInfo();
initSuAccess();
initSuConfigs();
@ -149,6 +152,15 @@ public class MagiskManager extends Application {
} catch (NumberFormatException e) {
disabled = false;
}
ret = Shell.sh("getprop persist.magisk.hide");
try {
magiskHideStarted = Utils.isValidShellResponse(ret) && Integer.parseInt(ret.get(0)) != 0;
} catch (NumberFormatException e) {
magiskHideStarted = false;
}
if (!magiskHide && magiskHideStarted)
magiskHide = true;
}

View File

@ -15,10 +15,6 @@ import com.topjohnwu.magisk.asyncs.LoadRepos;
import com.topjohnwu.magisk.asyncs.MagiskHide;
import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.services.UpdateCheckService;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import java.util.List;
public class SplashActivity extends Activity{
@ -34,10 +30,6 @@ public class SplashActivity extends Activity{
// Init the info and configs and root shell
magiskManager.init();
// Check MagiskHide status
List<String> ret = Shell.sh("getprop persist.magisk.hide");
boolean started = Utils.isValidShellResponse(ret) && Integer.parseInt(ret.get(0)) != 0;
// Initialize the update check service, notify every 3 hours
if (!"install".equals(getIntent().getStringExtra(MainActivity.SECTION))) {
ComponentName service = new ComponentName(magiskManager, UpdateCheckService.class);
@ -53,7 +45,7 @@ public class SplashActivity extends Activity{
// Now fire all async tasks
new GetBootBlocks(this).exec();
if (magiskManager.magiskHide && !magiskManager.disabled &&
magiskManager.magiskVersion > 11 && !started) {
magiskManager.magiskVersion > 11 && !magiskManager.magiskHideStarted) {
new MagiskHide().enable();
}
new LoadModules(this) {

View File

@ -60,7 +60,7 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
.setTitle(mContext.getString(R.string.repo_install_title, repo.getName()))
.setMessage(mContext.getString(R.string.repo_install_msg, filename))
.setCancelable(true)
.setPositiveButton(R.string.download_install, (d, i) -> Utils.dlAndReceive(
.setPositiveButton(R.string.install, (d, i) -> Utils.dlAndReceive(
mContext,
new DownloadReceiver() {
@Override

View File

@ -42,16 +42,19 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
SharedPreferences prefs = magiskManager.prefs;
RepoDatabaseHelper dbHelper = new RepoDatabaseHelper(magiskManager);
// Legacy data cleanup
new File(prefsPath, "RepoMap.xml").delete();
prefs.edit().remove("version").remove("repomap").apply();
File old = new File(prefsPath, "RepoMap.xml");
if (old.exists() || !prefs.getString("repomap", "empty").equals("empty")) {
old.delete();
prefs.edit().remove("version").remove("repomap").remove(ETAG_KEY).apply();
dbHelper.clearRepo();
}
Map<String, String> header = new HashMap<>();
// Get cached ETag to add in the request header
String etag = prefs.getString(ETAG_KEY, "");
// Add header only if db exists
if (magiskManager.getDatabasePath("repo.db").exists())
header.put("If-None-Match", etag);
magiskManager.repoMap = new ValueSortedMap<>();
@ -59,7 +62,6 @@ public class LoadRepos extends ParallelTask<Void, Void, Void> {
// Make a request to main URL for repo info
String jsonString = WebService.request(REPO_URL, WebService.GET, null, header, false);
RepoDatabaseHelper dbHelper = new RepoDatabaseHelper(magiskManager);
ValueSortedMap<String, Repo> cached = dbHelper.getRepoMap();
if (!TextUtils.isEmpty(jsonString)) {

View File

@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.ValueSortedMap;
import java.util.Collection;
@ -65,6 +66,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
try (Cursor c = db.query(TABLE_NAME, null, null, null, null, null, null)) {
while (c.moveToNext()) {
repo = new Repo(c);
Logger.dev("Load from cache: " + repo.getId());
ret.put(repo.getId(), repo);
}
}

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.module;
import android.database.Cursor;
import android.support.annotation.NonNull;
import com.topjohnwu.magisk.utils.Logger;
@ -9,43 +10,52 @@ import java.util.List;
public abstract class BaseModule implements Comparable<BaseModule> {
protected String mId, mName, mVersion, mAuthor, mDescription;
protected int mVersionCode = 0;
private String mId, mName, mVersion, mAuthor, mDescription;
private int mVersionCode = 0;
protected BaseModule() {}
protected BaseModule(Cursor c) {
mId = c.getString(c.getColumnIndex("id"));
mName = c.getString(c.getColumnIndex("name"));
mVersion = c.getString(c.getColumnIndex("version"));
mVersionCode = c.getInt(c.getColumnIndex("versionCode"));
mAuthor = c.getString(c.getColumnIndex("author"));
mDescription = c.getString(c.getColumnIndex("description"));
}
protected void parseProps(List<String> props) throws CacheModException { parseProps(props.toArray(new String[props.size()])); }
protected void parseProps(String[] props) throws CacheModException {
for (String line : props) {
String[] prop = line.split("=", 2);
if (prop.length != 2) {
if (prop.length != 2)
continue;
}
String key = prop[0].trim();
if (key.charAt(0) == '#') {
if (key.charAt(0) == '#')
continue;
}
switch (key) {
case "id":
this.mId = prop[1];
mId = prop[1];
break;
case "name":
this.mName = prop[1];
mName = prop[1];
break;
case "version":
this.mVersion = prop[1];
mVersion = prop[1];
break;
case "versionCode":
try {
this.mVersionCode = Integer.parseInt(prop[1]);
mVersionCode = Integer.parseInt(prop[1]);
} catch (NumberFormatException ignored) {}
break;
case "author":
this.mAuthor = prop[1];
mAuthor = prop[1];
break;
case "description":
this.mDescription = prop[1];
mDescription = prop[1];
break;
case "cacheModule":
if (Boolean.parseBoolean(prop[1]))
@ -61,6 +71,10 @@ public abstract class BaseModule implements Comparable<BaseModule> {
return mName;
}
public void setName(String name) {
mName = name;
}
public String getVersion() {
return mVersion;
}
@ -73,6 +87,10 @@ public abstract class BaseModule implements Comparable<BaseModule> {
return mId;
}
public void setId(String id) {
mId = id;
}
public String getDescription() {
return mDescription;
}
@ -88,7 +106,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
}
@Override
public int compareTo(@NonNull BaseModule o) {
return this.getName().toLowerCase().compareTo(o.getName().toLowerCase());
public int compareTo(@NonNull BaseModule module) {
return this.getName().toLowerCase().compareTo(module.getName().toLowerCase());
}
}

View File

@ -16,15 +16,15 @@ public class Module extends BaseModule {
mDisableFile = path + "/disable";
mUpdateFile = path + "/update";
if (mId == null) {
if (getId() == null) {
int sep = path.lastIndexOf('/');
mId = path.substring(sep + 1);
setId(path.substring(sep + 1));
}
if (mName == null)
mName = mId;
if (getName() == null)
setName(getId());
Logger.dev("Creating Data, id: " + mId);
Logger.dev("Creating Module, id: " + getId());
mEnable = !Utils.itemExist(mDisableFile);
mRemove = Utils.itemExist(mRemoveFile);

View File

@ -23,12 +23,7 @@ public class Repo extends BaseModule {
}
public Repo(Cursor c) {
mId = c.getString(c.getColumnIndex("id"));
mName = c.getString(c.getColumnIndex("name"));
mVersion = c.getString(c.getColumnIndex("version"));
mVersionCode = c.getInt(c.getColumnIndex("versionCode"));
mAuthor = c.getString(c.getColumnIndex("author"));
mDescription = c.getString(c.getColumnIndex("description"));
super(c);
repoName = c.getString(c.getColumnIndex("repo_name"));
mLastUpdate = new Date(c.getLong(c.getColumnIndex("last_update")));
}
@ -50,12 +45,12 @@ public class Repo extends BaseModule {
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);
values.put("id", getId());
values.put("name", getName());
values.put("version", getVersion());
values.put("versionCode", getVersionCode());
values.put("author", getAuthor());
values.put("description", getDescription());
values.put("repo_name", repoName);
values.put("last_update", mLastUpdate.getTime());
return values;

View File

@ -9,8 +9,6 @@ import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import java.util.List;
public class BootupIntentService extends IntentService {
public BootupIntentService() {
@ -22,10 +20,8 @@ public class BootupIntentService extends IntentService {
MagiskManager magiskManager = Utils.getMagiskManager(this);
magiskManager.initSuAccess();
magiskManager.updateMagiskInfo();
List<String> ret = Shell.sh("getprop persist.magisk.hide");
boolean started = Utils.isValidShellResponse(ret) && Integer.parseInt(ret.get(0)) != 0;
if (magiskManager.prefs.getBoolean("magiskhide", false) &&
!magiskManager.disabled && !started && magiskManager.magiskVersion > 11) {
!magiskManager.disabled && !magiskManager.magiskHideStarted && magiskManager.magiskVersion > 11) {
magiskManager.toast(R.string.start_magiskhide, Toast.LENGTH_LONG);
Shell.su(true, MagiskManager.MAGISK_HIDE_PATH + "enable",
"setprop persist.magisk.hide 1");

View File

@ -105,7 +105,7 @@
<string name="copying_msg">نسخ الملف المضغوط إلى دليل مؤقت</string>
<string name="detect_button">تحقق</string>
<string name="downloading_toast">جاري التنزيل %1$s</string>
<string name="install_magisk_title">تثبيت Magisk الإصدار: v%1$.1f</string>
<string name="install_magisk_title">تثبيت Magisk الإصدار: %1$s</string>
<string name="keep_force_encryption">إبقاء التشفير القوى</string>
<string name="keep_dm_verity">إبقاء dm-verity</string>
<string name="root_error">مروت لكن لا يوجد إذن الروت، غير مسموح به؟</string>

View File

@ -46,7 +46,7 @@
<string name="keep_force_encryption">\"force encryption\" beibehalten</string>
<string name="keep_dm_verity">\"dm-verity\"-Test beibehalten</string>
<string name="current_magisk_title">Installierte Magisk-Version: %1$s</string>
<string name="install_magisk_title">Neueste Magisk-Version: %1$.1f</string>
<string name="install_magisk_title">Neueste Magisk-Version: %1$s</string>
<string name="uninstall">Deinstallieren</string>

View File

@ -40,8 +40,8 @@
<string name="advanced_settings_title">Ajustes avanzados</string>
<string name="keep_force_encryption">Mantener cifrado forzado</string>
<string name="keep_dm_verity">Mantener dm-verity</string>
<string name="current_magisk_title">Versión de Magisk instalada: v%1$s</string>
<string name="install_magisk_title">Última versión de Magisk: v%1$.1f</string>
<string name="current_magisk_title">Versión de Magisk instalada: %1$s</string>
<string name="install_magisk_title">Última versión de Magisk: %1$s</string>
<string name="uninstall">Desinstalar</string>
<string name="reboot_countdown">Reiniciando en %1$d</string>

View File

@ -40,8 +40,8 @@
<string name="advanced_settings_title">Impostazioni Avanzate</string>
<string name="keep_force_encryption">Mantieni crittografia forzata</string>
<string name="keep_dm_verity">Mantieni dm-verity</string>
<string name="current_magisk_title">Versione Magisk installata: v%1$s</string>
<string name="install_magisk_title">Ultima versione Magisk: v%1$.1f</string>
<string name="current_magisk_title">Versione Magisk installata: %1$s</string>
<string name="install_magisk_title">Ultima versione Magisk: %1$s</string>
<!--Module Fragment-->

View File

@ -40,8 +40,8 @@
<string name="advanced_settings_title">고급 설정</string>
<string name="keep_force_encryption">강제 암호화 유지</string>
<string name="keep_dm_verity">dm-verity 유지</string>
<string name="current_magisk_title">설치된 Magisk 버전: v%1$s</string>
<string name="install_magisk_title">최신 Magisk 버전: v%1$.1f</string>
<string name="current_magisk_title">설치된 Magisk 버전: %1$s</string>
<string name="install_magisk_title">최신 Magisk 버전: %1$s</string>
<string name="uninstall">제거</string>
<string name="reboot_countdown">%1$d초 안에 다시 시작됨</string>

View File

@ -42,8 +42,8 @@
<string name="advanced_settings_title">Zaawansowane Ustawienia</string>
<string name="keep_force_encryption">Keep force encryption</string>
<string name="keep_dm_verity">Keep dm-verity</string>
<string name="current_magisk_title">Zainstalowana Wersja Magisk: v%1$s</string>
<string name="install_magisk_title">Ostatnia Wersja Magisk: v%1$.1f</string>
<string name="current_magisk_title">Zainstalowana Wersja Magisk: %1$s</string>
<string name="install_magisk_title">Ostatnia Wersja Magisk: %1$s</string>
<string name="uninstall">Odinstaluj</string>
<string name="reboot_countdown">Restartuj do %1$d</string>

View File

@ -41,8 +41,8 @@
<string name="advanced_settings_title">Configurações avançadas</string>
<string name="keep_force_encryption">Keep force encryption</string>
<string name="keep_dm_verity">Keep dm-verity</string>
<string name="current_magisk_title">Versão instalada do Magisk: v%1$s</string>
<string name="install_magisk_title">Última versão do Magisk: v%1$.1f</string>
<string name="current_magisk_title">Versão instalada do Magisk: %1$s</string>
<string name="install_magisk_title">Última versão do Magisk: %1$s</string>
<!--Module Fragment-->

View File

@ -38,8 +38,8 @@
<string name="advanced_settings_title">Дополнительные настройки</string>
<string name="keep_force_encryption">Оставить шифрование</string>
<string name="keep_dm_verity">Оставить dm-verity</string>
<string name="current_magisk_title">Установленная версия Magisk: v%1$s</string>
<string name="install_magisk_title">Последняя версия Magisk: v%1$.1f</string>
<string name="current_magisk_title">Установленная версия Magisk: %1$s</string>
<string name="install_magisk_title">Последняя версия Magisk: %1$s</string>
<string name="uninstall">Удалить</string>
<string name="reboot_countdown">Перезагрузка через %1$d</string>

View File

@ -40,8 +40,8 @@
<string name="advanced_settings_title">高级设置</string>
<string name="keep_force_encryption">保持强制加密</string>
<string name="keep_dm_verity">保留 dm-verity</string>
<string name="current_magisk_title">已安装 Magisk 版本:v%1$s</string>
<string name="install_magisk_title">最新的 Magisk 版本:v%1$.1f</string>
<string name="current_magisk_title">已安装 Magisk 版本:%1$s</string>
<string name="install_magisk_title">最新的 Magisk 版本:%1$s</string>
<string name="uninstall">卸载</string>
<string name="reboot_countdown">将在 %1$d 后重启</string>
<string name="uninstall_magisk_title">卸载 Magisk</string>

View File

@ -40,8 +40,8 @@
<string name="advanced_settings_title">高級設置</string>
<string name="keep_force_encryption">保持強制加密</string>
<string name="keep_dm_verity">保留 dm-verity</string>
<string name="current_magisk_title">已安裝 Magisk 版本:v%1$s</string>
<string name="install_magisk_title">最新的 Magisk 版本:v%1$.1f</string>
<string name="current_magisk_title">已安裝 Magisk 版本:%1$s</string>
<string name="install_magisk_title">最新的 Magisk 版本:%1$s</string>
<string name="uninstall">解除安裝</string>
<string name="reboot_countdown">將在 %1$d 後重啟</string>
@ -188,5 +188,6 @@
<string name="zip_process_title">處理中</string>
<string name="uninstall_magisk_title">解除安裝 Magisk</string>
<string name="uninstall_magisk_msg">這將會刪除所有模組MagiskSU並有可能在目前未加密的情況下加密的的資料\n你確定要繼續嗎</string>
<string name="version_none">(無)</string>
</resources>

View File

@ -43,12 +43,13 @@
<string name="advanced_settings_title">Advanced Settings</string>
<string name="keep_force_encryption">Keep force encryption</string>
<string name="keep_dm_verity">Keep dm-verity</string>
<string name="current_magisk_title">Installed Magisk Version: v%1$s</string>
<string name="install_magisk_title">Latest Magisk Version: v%1$.1f</string>
<string name="current_magisk_title">Installed Magisk Version: %1$s</string>
<string name="install_magisk_title">Latest Magisk Version: %1$s</string>
<string name="uninstall">Uninstall</string>
<string name="reboot_countdown">Rebooting in %1$d</string>
<string name="uninstall_magisk_title">Uninstall Magisk</string>
<string name="uninstall_magisk_msg">This will remove all modules, MagiskSU, and potentially encrypt your data if not encrypted\nAre you sure to continue?</string>
<string name="version_none">(None)</string>
<!--Module Fragment-->
<string name="no_info_provided">(No info provided)</string>