Use new version detection method

This commit is contained in:
topjohnwu 2017-05-12 02:25:07 +08:00
parent 20e4a960f7
commit 962f8354ac
27 changed files with 70 additions and 58 deletions

View File

@ -79,7 +79,7 @@ public class InstallFragment extends Fragment implements CallbackEvent.Listener<
}
}
final String finalBootImage = bootImage;
String filename = "Magisk-v" + magiskManager.remoteMagiskVersion + ".zip";
String filename = "Magisk-v" + magiskManager.remoteMagiskVersionCode + ".zip";
new AlertDialogBuilder(getActivity())
.setTitle(getString(R.string.repo_install_title, getString(R.string.magisk)))
.setMessage(getString(R.string.repo_install_msg, filename))
@ -160,12 +160,12 @@ public class InstallFragment extends Fragment implements CallbackEvent.Listener<
View v = inflater.inflate(R.layout.fragment_install, container, false);
unbinder = ButterKnife.bind(this, v);
magiskManager = getApplication();
if (magiskManager.magiskVersion < 0) {
if (magiskManager.magiskVersionCode < 0) {
currentVersionTitle.setText(getString(R.string.current_magisk_title, getString(R.string.version_none)));
} else {
currentVersionTitle.setText(getString(R.string.current_magisk_title, "v" + magiskManager.magiskVersionString));
}
installTitle.setText(getString(R.string.install_magisk_title, "v" + String.format(Locale.US, "%.1f", magiskManager.remoteMagiskVersion)));
installTitle.setText(getString(R.string.install_magisk_title, "v" + magiskManager.remoteMagiskVersionString));
updateUI();
return v;
@ -185,7 +185,7 @@ public class InstallFragment extends Fragment implements CallbackEvent.Listener<
keepVerityChkbox.setEnabled(false);
spinner.setEnabled(false);
} else {
uninstallButton.setVisibility(magiskManager.magiskVersion > 10.3 ? View.VISIBLE : View.GONE);
uninstallButton.setVisibility(magiskManager.magiskVersionCode >= 130 ? View.VISIBLE : View.GONE);
installText.setText(R.string.download_install);
detectButton.setEnabled(true);
keepEncChkbox.setEnabled(true);

View File

@ -38,9 +38,10 @@ public class MagiskManager extends Application {
public final SparseArray<CallbackEvent<Policy>> uidSuRequest = new SparseArray<>();
// Info
public double magiskVersion;
public String magiskVersionString;
public double remoteMagiskVersion = -1;
public int magiskVersionCode = -1;
public String remoteMagiskVersionString;
public int remoteMagiskVersionCode = -1;
public String magiskLink;
public String releaseNoteLink;
public int SNCheckResult = -1;
@ -91,8 +92,13 @@ public class MagiskManager extends Application {
public void init() {
isDarkTheme = prefs.getBoolean("dark_theme", false);
if (BuildConfig.DEBUG) {
devLogging = prefs.getBoolean("developer_logging", false);
shellLogging = prefs.getBoolean("shell_logging", false);
} else {
devLogging = false;
shellLogging = false;
}
magiskHide = prefs.getBoolean("magiskhide", false);
updateNotification = prefs.getBoolean("notification", true);
// Always start a new root shell manually, just for safety
@ -139,17 +145,22 @@ public class MagiskManager extends Application {
}
public void updateMagiskInfo() {
List<String> ret = Shell.sh("getprop magisk.version");
List<String> ret;
ret = Shell.sh("magisk -v");
if (!Utils.isValidShellResponse(ret)) {
magiskVersion = -1;
} else {
ret = Shell.sh("getprop magisk.version");
if (Utils.isValidShellResponse(ret)) {
try {
magiskVersionString = ret.get(0);
magiskVersion = Double.parseDouble(ret.get(0));
} catch (NumberFormatException e) {
// Custom version don't need to receive updates
magiskVersion = Double.POSITIVE_INFINITY;
magiskVersionCode = (int) Double.parseDouble(ret.get(0)) * 10;
} catch (NumberFormatException ignored) {}
}
} else {
magiskVersionString = ret.get(0).split(":")[0];
ret = Shell.sh("magisk -V");
try {
magiskVersionCode = Integer.parseInt(ret.get(0));
} catch (NumberFormatException ignored) {}
}
ret = Shell.sh("getprop persist.magisk.busybox");
try {

View File

@ -138,16 +138,16 @@ public class MainActivity extends Activity
private void checkHideSection() {
Menu menu = navigationView.getMenu();
menu.findItem(R.id.magiskhide).setVisible(
Shell.rootAccess() && getApplicationContext().magiskVersion >= 8
Shell.rootAccess() && getApplicationContext().magiskVersionCode >= 130
&& prefs.getBoolean("magiskhide", false));
menu.findItem(R.id.modules).setVisible(
Shell.rootAccess() && getApplicationContext().magiskVersion >= 4);
Shell.rootAccess() && getApplicationContext().magiskVersionCode >= 0);
menu.findItem(R.id.downloads).setVisible(
Shell.rootAccess() && getApplicationContext().magiskVersion >= 4);
Shell.rootAccess() && getApplicationContext().magiskVersionCode >= 0);
menu.findItem(R.id.log).setVisible(Shell.rootAccess());
menu.findItem(R.id.superuser).setVisible(
Shell.rootAccess() && getApplicationContext().isSuClient);
menu.findItem(R.id.install).setVisible(getApplicationContext().remoteMagiskVersion > 0);
menu.findItem(R.id.install).setVisible(getApplicationContext().remoteMagiskVersionCode > 0);
}
public void navigate(String item) {

View File

@ -90,6 +90,7 @@ public class SettingsActivity extends Activity {
PreferenceCategory magiskCategory = (PreferenceCategory) findPreference("magisk");
PreferenceCategory suCategory = (PreferenceCategory) findPreference("superuser");
PreferenceCategory developer = (PreferenceCategory) findPreference("developer");
suAccess = (ListPreference) findPreference("su_access");
autoRes = (ListPreference) findPreference("su_auto_response");
@ -103,6 +104,10 @@ public class SettingsActivity extends Activity {
return true;
});
if (!BuildConfig.DEBUG) {
prefScreen.removePreference(developer);
}
if (!Shell.rootAccess()) {
prefScreen.removePreference(magiskCategory);
prefScreen.removePreference(suCategory);
@ -110,7 +115,7 @@ public class SettingsActivity extends Activity {
if (!getApplication().isSuClient) {
prefScreen.removePreference(suCategory);
}
if (getApplication().magiskVersion < 11) {
if (getApplication().magiskVersionCode < 130) {
prefScreen.removePreference(magiskCategory);
}
}

View File

@ -44,10 +44,6 @@ public class SplashActivity extends Activity{
// Now fire all async tasks
new GetBootBlocks(this).exec();
if (magiskManager.magiskHide && magiskManager.magiskVersion > 11 &&
!magiskManager.magiskHideStarted) {
new MagiskHide().enable();
}
new LoadModules(this) {
@Override
protected void onPostExecute(Void v) {

View File

@ -65,7 +65,7 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
@OnClick(R.id.magisk_status_container)
public void gotoInstall() {
if (getApplication().remoteMagiskVersion > 0) {
if (getApplication().remoteMagiskVersionCode > 0) {
((MainActivity) getActivity()).navigate(R.id.install);
}
}
@ -100,7 +100,7 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
new CheckUpdates(getActivity()).exec();
});
if (getApplication().magiskVersion < 0 && Shell.rootAccess() && !noDialog) {
if (getApplication().magiskVersionCode < 0 && Shell.rootAccess() && !noDialog) {
noDialog = true;
new AlertDialogBuilder(getActivity())
.setTitle(R.string.no_magisk_title)
@ -158,7 +158,7 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
getApplication().updateMagiskInfo();
if (getApplication().magiskVersion < 0) {
if (getApplication().magiskVersionCode < 0) {
magiskVersionText.setText(R.string.magisk_version_error);
} else if (getApplication().disabled) {
magiskVersionText.setText(getString(R.string.magisk_version_core_only, getApplication().magiskVersionString));
@ -197,21 +197,21 @@ public class StatusFragment extends Fragment implements CallbackEvent.Listener<V
private void updateCheckUI() {
int image, color;
if (getApplication().remoteMagiskVersion < 0) {
if (getApplication().remoteMagiskVersionCode < 0) {
color = colorNeutral;
image = R.drawable.ic_help;
magiskUpdateText.setText(R.string.cannot_check_updates);
} else if (getApplication().remoteMagiskVersion > getApplication().magiskVersion) {
} else if (getApplication().remoteMagiskVersionCode > getApplication().magiskVersionCode) {
color = colorInfo;
image = R.drawable.ic_update;
magiskUpdateText.setText(getString(R.string.magisk_update_available, getApplication().remoteMagiskVersion));
magiskUpdateText.setText(getString(R.string.magisk_update_available, getApplication().remoteMagiskVersionString));
} else {
color = colorOK;
image = R.drawable.ic_check_circle;
magiskUpdateText.setText(getString(R.string.up_to_date, getString(R.string.magisk)));
}
if (getApplication().magiskVersion < 0) {
if (getApplication().magiskVersionCode < 0) {
color = colorBad;
image = R.drawable.ic_cancel;
}

View File

@ -18,7 +18,7 @@ import org.json.JSONObject;
public class CheckUpdates extends ParallelTask<Void, Void, Void> {
private static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
private static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/update/magisk_update.json";
private static final int NOTIFICATION_ID = 1;
private boolean showNotification = false;
@ -38,22 +38,22 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
try {
JSONObject json = new JSONObject(jsonStr);
JSONObject magisk = json.getJSONObject("magisk");
magiskManager.remoteMagiskVersion = magisk.getDouble("versionCode");
magiskManager.remoteMagiskVersionString = magisk.getString("version");
magiskManager.remoteMagiskVersionCode = magisk.getInt("versionCode");
magiskManager.magiskLink = magisk.getString("link");
magiskManager.releaseNoteLink = magisk.getString("note");
} catch (JSONException ignored) {
}
} catch (JSONException ignored) {}
return null;
}
@Override
protected void onPostExecute(Void v) {
if (magiskManager.magiskVersion < magiskManager.remoteMagiskVersion
if (magiskManager.magiskVersionCode < magiskManager.remoteMagiskVersionCode
&& showNotification && magiskManager.updateNotification) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(magiskManager);
builder.setSmallIcon(R.drawable.ic_magisk)
.setContentTitle(magiskManager.getString(R.string.magisk_update_title))
.setContentText(magiskManager.getString(R.string.magisk_update_available, magiskManager.remoteMagiskVersion))
.setContentText(magiskManager.getString(R.string.magisk_update_available, magiskManager.remoteMagiskVersionString))
.setVibrate(new long[]{0, 100, 100, 100})
.setAutoCancel(true);
Intent intent = new Intent(magiskManager, SplashActivity.class);

View File

@ -81,7 +81,7 @@ public class ProcessMagiskZip extends ParallelTask<Void, Void, Boolean> {
@Override
protected Void doInBackground(Void... params) {
Shell.su("setprop magisk.version "
+ String.valueOf(magiskManager.remoteMagiskVersion));
+ String.valueOf(magiskManager.remoteMagiskVersionCode));
magiskManager.updateCheckDone.trigger();
return null;
}

View File

@ -21,7 +21,7 @@ public class BootupIntentService extends IntentService {
magiskManager.initSuAccess();
magiskManager.updateMagiskInfo();
if (magiskManager.prefs.getBoolean("magiskhide", false) &&
!magiskManager.disabled && !magiskManager.magiskHideStarted && magiskManager.magiskVersion > 11) {
!magiskManager.disabled && !magiskManager.magiskHideStarted && magiskManager.magiskVersionCode >= 130) {
magiskManager.toast(R.string.start_magiskhide, Toast.LENGTH_LONG);
Shell.su(true, MagiskManager.MAGISK_HIDE_PATH + "enable",
"setprop persist.magisk.hide 1");

View File

@ -13,7 +13,7 @@
<string name="magisk_version">المثبت Magisk v%1$s</string>
<string name="magisk_version_error">هل قمت بتثبيت Magisk؟</string>
<string name="magisk_update_available">Magisk v%1$.1f تحديث!</string>
<string name="magisk_update_available">Magisk v%1$s تحديث!</string>
<string name="cannot_check_updates">لا يمكن التحقق من التحديثات</string>
<string name="up_to_date">أحدث إصدار من %1$s مثبت</string>

View File

@ -17,7 +17,7 @@
<string name="magisk_version_error">Magisk není nainstalován</string>
<string name="checking_for_updates">Kontrola aktualizací…</string>
<string name="magisk_update_available">Magisk v%1$.1f je dostupný!</string>
<string name="magisk_update_available">Magisk v%1$s je dostupný!</string>
<string name="cannot_check_updates">Nelze zkontrolovat aktualizace. Jste připojeni k Internetu?</string>
<string name="up_to_date">Poslední verze z %1$s nainstalovaných</string>
<string name="root_error">Zařízení s rootem ale chybí root povolení, máte jej zpřístupněno?</string>

View File

@ -20,7 +20,7 @@
<string name="magisk_version_error">Magisk ist nicht installiert</string>
<string name="checking_for_updates">Suche nach Updates…</string>
<string name="magisk_update_available">Magisk %1$.1f ist verfügbar!</string>
<string name="magisk_update_available">Magisk %1$s ist verfügbar!</string>
<string name="cannot_check_updates">Updatesuche fehlgeschlagen.\nIst eine Internetverbindung verfügbar?</string>
<string name="up_to_date">Die neueste Version von %1$s ist bereits installiert</string>
<string name="root_error">Gerootet, aber keine root-Rechte. Wurde der root-Zugriff verweigert?</string>

View File

@ -17,7 +17,7 @@
<string name="magisk_version_error">Magisk no está instalado</string>
<string name="checking_for_updates">Comprobando actualizaciones…</string>
<string name="magisk_update_available">¡Disponible Magisk v%1$.1f!</string>
<string name="magisk_update_available">¡Disponible Magisk v%1$s!</string>
<string name="cannot_check_updates">No se pueden comprobar actualizaciones ¿No tiene internet?</string>
<string name="up_to_date">Última versión de %1$s instalada</string>
<string name="root_error">Rooteado pero sin permiso root, ¿No lo permitiste?</string>

View File

@ -15,7 +15,7 @@
<string name="magisk_version_core_only">Magisk v%1$s installée (Mode Core uniquement)</string>
<string name="magisk_version_error">Magisk non installé</string>
<string name="checking_for_updates">Vérification de mises à jour…</string>
<string name="magisk_update_available">Magisk v%1$.1f disponible !</string>
<string name="magisk_update_available">Magisk v%1$s disponible !</string>
<string name="cannot_check_updates">Impossible de vérifier les mises à jour, pas d\'Internet ?</string>
<string name="up_to_date">Dernière version %1$s installée</string>
<string name="root_error">Rooté mais aucune permission root, non acceptée ?</string>

View File

@ -18,7 +18,7 @@
<string name="magisk_version_error">Hai installato Magisk?</string>
<string name="checking_for_updates">Controllo aggiornamenti…</string>
<string name="magisk_update_available">È disponibile Magisk v%1$.1f!</string>
<string name="magisk_update_available">È disponibile Magisk v%1$s!</string>
<string name="cannot_check_updates">Impossibile controllare aggiornamenti</string>
<string name="up_to_date">La versione di %1$s è aggiornata</string>
<string name="root_error">Rootato ma senza permessi. Non sei autorizzato?</string>

View File

@ -18,7 +18,7 @@
<string name="magisk_version_error">Magisk がインストールされていません</string>
<string name="checking_for_updates">更新を確認中...</string>
<string name="magisk_update_available">Magisk v%1$.1f が利用可能です!</string>
<string name="magisk_update_available">Magisk v%1$s が利用可能です!</string>
<string name="cannot_check_updates">更新を確認できませんでした。インターネットに接続されていますか?</string>
<string name="up_to_date">最新の %1$s がインストール済です</string>
<string name="root_error">Root化はされていますが権限がありません。拒否していませんか</string>

View File

@ -18,7 +18,7 @@
<string name="magisk_version_error">Magisk가 설치되지 않음</string>
<string name="checking_for_updates">업데이트 확인 중…</string>
<string name="magisk_update_available">Magisk v%1$.1f 사용 가능!</string>
<string name="magisk_update_available">Magisk v%1$s 사용 가능!</string>
<string name="cannot_check_updates">업데이트를 확인할 수 없음. 인터넷 연결을 확인하세요.</string>
<string name="up_to_date">최신 버전의 %1$s 설치됨</string>
<string name="root_error">루팅은 되어 있으나 루트 권한을 얻을 수 없음. 루트 권한 허용 상태를 확인하세요.</string>

View File

@ -13,7 +13,6 @@
<string name="magisk_version">Geïnstalleerde Magisk: v%1$s</string>
<string name="magisk_version_error">Heb jij Magisk wel geïnstalleerd?</string>
<string name="magisk_update_available">Magisk v%1$.1f update!</string>
<string name="cannot_check_updates">Kan niet controleren op updates.</string>
<string name="up_to_date">Nieuwste versie van %1$s geïnstalleerd</string>

View File

@ -21,7 +21,7 @@
<string name="magisk_version_error">Magisk nie jest zainstalowany</string>
<string name="checking_for_updates">Sprawdzanie aktualizacji…</string>
<string name="magisk_update_available">Magisk v%1$.1f dostępny!</string>
<string name="magisk_update_available">Magisk v%1$s dostępny!</string>
<string name="cannot_check_updates">Nie można sprawdzić dostępności aktualizacji, brak internetu</string>
<string name="up_to_date">Zainstalowana najnowsza wersja %1$s</string>
<string name="root_error">Root dostępny, ale dostęp nie przyznany</string>

View File

@ -21,7 +21,7 @@
<string name="magisk_version_error">Magisk não instalado</string>
<string name="checking_for_updates">Checando por atualizações…</string>
<string name="magisk_update_available">Magisk v%1$.1f disponível!</string>
<string name="magisk_update_available">Magisk v%1$s disponível!</string>
<string name="cannot_check_updates">Não é possível verificar se há atualizações</string>
<string name="up_to_date">Última versão do %1$s instalado</string>
<string name="root_error">Rooteado mas sem permissão de root, o acesso foi permitido?</string>

View File

@ -15,7 +15,7 @@
<string name="magisk_version_error">Magisk не установлен</string>
<string name="checking_for_updates">Проверка обновлений…</string>
<string name="magisk_update_available">Доступен Magisk v%1$.1f!</string>
<string name="magisk_update_available">Доступен Magisk v%1$s!</string>
<string name="cannot_check_updates">Невозможно проверить обновления, нет соединения?</string>
<string name="up_to_date">Установлена последняя версия %1$s</string>
<string name="root_error">Рут есть, но нет разрешения, не разрешено?</string>

View File

@ -15,7 +15,7 @@
<string name="magisk_version_error">Magisk yüklü değil</string>
<string name="checking_for_updates">Güncelleştirmeler denetleniyor…</string>
<string name="magisk_update_available">Magisk v%1$.1f mevcut!</string>
<string name="magisk_update_available">Magisk v%1$s mevcut!</string>
<string name="cannot_check_updates">Güncelleştirmeler denetlenemiyor, İnternet yok mu?</string>
<string name="up_to_date">%1$s\'in son sürümü yüklü</string>
<string name="root_error">Rootlu ama root izni yok, izin verilmedi mi?</string>

View File

@ -17,7 +17,7 @@
<string name="magisk_version_error">Magisk chưa được cài đặt</string>
<string name="checking_for_updates">Đang kiểm tra cập nhật…</string>
<string name="magisk_update_available">Magisk v%1$.1f available!</string>
<string name="magisk_update_available">Magisk v%1$s available!</string>
<string name="cannot_check_updates">Không thể kiểm tra cập nhật, không có Internet?</string>
<string name="up_to_date">Đã cài đặt phiên bản mới nhất của %1$s</string>
<string name="root_error">Đã root nhưng không có quyền root, chưa được cho phép?</string>

View File

@ -18,7 +18,7 @@
<string name="magisk_version_error">未安装 Magisk</string>
<string name="checking_for_updates">正在检查更新…</string>
<string name="magisk_update_available">Magisk 可更新到 v%1$.1f</string>
<string name="magisk_update_available">Magisk 可更新到 v%1$s</string>
<string name="cannot_check_updates">无法检查更新,没有网络连接?</string>
<string name="up_to_date">已安装最新版本的 %1$s</string>
<string name="root_error">已 ROOT 但没有 ROOT 权限,未授予权限?</string>

View File

@ -17,7 +17,7 @@
<string name="magisk_version_error">未安裝 Magisk</string>
<string name="checking_for_updates">正在檢查更新…</string>
<string name="magisk_update_available">Magisk 可更新到 v%1$.1f</string>
<string name="magisk_update_available">Magisk 可更新到 v%1$s</string>
<string name="cannot_check_updates">無法檢查更新,沒有網絡連線?</string>
<string name="up_to_date">已安裝最新版本的 %1$s</string>
<string name="root_error">已 ROOT 但沒有 ROOT 權限,未授予權限?</string>

View File

@ -21,7 +21,7 @@
<string name="magisk_version_error">Magisk not installed</string>
<string name="checking_for_updates">Checking for updates…</string>
<string name="magisk_update_available">Magisk v%1$.1f available!</string>
<string name="magisk_update_available">Magisk v%1$s available!</string>
<string name="cannot_check_updates">Cannot check for updates, no Internet?</string>
<string name="up_to_date">Latest version of %1$s installed</string>
<string name="root_error">Rooted but no root permission, not allowed?</string>

View File

@ -82,6 +82,7 @@
</PreferenceCategory>
<PreferenceCategory
android:key="developer"
android:title="@string/settings_development_category">
<SwitchPreference