diff --git a/README.md b/README.md index 99dbea869..58fc22cfa 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,4 @@ # Magisk Manager The project can only be compiled on Android Studio Version 2.2.0+ -I use Java 8 features, which requires Jack compiler and that's only available 2.2.0+ - -# Prebuild Binaries -### libbusybox.so -Static BusyBox binary by @yashdsaraf -Link and source: http://forum.xda-developers.com/showthread.php?t=3348543 +I use Java 8 features, which requires Jack compiler and that's only available in 2.2.0+ +Also, you need to install CMake and NDK to build the zipadjust library for zip preprocessing diff --git a/app/build.gradle b/app/build.gradle index 8142fe1ed..e859fd981 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,7 @@ android { } ndk { moduleName 'zipadjust' -// abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a' - abiFilters 'x86', 'x86_64', 'armeabi' + abiFilters 'x86', 'x86_64', 'armeabi', 'arm64-v8a' } } diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java index 4d765ef3f..691bb68ee 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java @@ -23,6 +23,7 @@ import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.utils.ZipUtils; import java.io.File; import java.util.List; @@ -77,6 +78,19 @@ public class MagiskFragment extends Fragment { @Override public void task(Uri uri) { new Async.FlashZIP(mContext, uri, mFilename) { + @Override + protected boolean unzipAndCheck() { + publishProgress(mContext.getString(R.string.zip_install_unzip_zip_msg)); + // We might not have busybox yet, unzip with Java + // We will have complete busybox after Magisk installation + ZipUtils.unzip(mCachedFile, new File(mCachedFile.getParent(), "magisk")); + Shell.su( + "mkdir -p " + Async.TMP_FOLDER_PATH + "/magisk", + "cp -af " + mCachedFile.getParent() + "/magisk/. " + Async.TMP_FOLDER_PATH + "/magisk" + ); + return super.unzipAndCheck(); + } + @Override protected void done() { Shell.su("setprop magisk.version " + String.valueOf(remoteMagiskVersion)); @@ -110,14 +124,16 @@ public class MagiskFragment extends Fragment { appLink, "MagiskManager-v" + remoteAppVersion + ".apk"); + static { + updateMagiskVersion(); + } + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.magisk_fragment, container, false); ButterKnife.bind(this, v); - updateMagiskVersion(); - prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mSwipeRefreshLayout.setOnRefreshListener(() -> { @@ -167,7 +183,7 @@ public class MagiskFragment extends Fragment { prefs.unregisterOnSharedPreferenceChangeListener(listener); } - private void updateMagiskVersion() { + private static void updateMagiskVersion() { List ret = Shell.sh("getprop magisk.version"); if (ret.get(0).length() == 0) { magiskVersion = -1; @@ -178,6 +194,16 @@ public class MagiskFragment extends Fragment { // Custom version don't need to receive updates magiskVersion = Double.POSITIVE_INFINITY; } + } + + + private void updateUI() { + String theme = prefs.getString("theme", ""); + if (theme.equals("Dark")) { + builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialog_dh); + } else { + builder = new AlertDialog.Builder(getActivity()); + } if (magiskVersion == -1) { magiskStatusContainer.setBackgroundColor(colorNeutral); @@ -192,16 +218,6 @@ public class MagiskFragment extends Fragment { magiskVersionText.setText(getString(R.string.magisk_version, magiskVersionString)); magiskVersionText.setTextColor(colorOK); } - } - - - private void updateUI() { - String theme = prefs.getString("theme", ""); - if (theme.equals("Dark")) { - builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialog_dh); - } else { - builder = new AlertDialog.Builder(getActivity()); - } if (remoteMagiskVersion == -1) { appCheckUpdatesContainer.setBackgroundColor(colorWarn); diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index 748c49021..75b13b691 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -91,8 +91,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } navigationView.setNavigationItemSelectedListener(this); - checkHideSection(); - } @Override @@ -104,13 +102,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - outState.putInt(SELECTED_ITEM_ID, mSelectedId); } @Override public void onBackPressed() { - if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { @@ -123,18 +119,21 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On mSelectedId = menuItem.getItemId(); mDrawerHandler.removeCallbacksAndMessages(null); mDrawerHandler.postDelayed(() -> navigate(menuItem.getItemId()), 250); - drawer.closeDrawer(GravityCompat.START); return true; } private void checkHideSection() { Menu menu = navigationView.getMenu(); - if (PreferenceManager.getDefaultSharedPreferences(getApplication()).getBoolean("magiskhide", false)) { - - menu.findItem(R.id.magiskhide).setVisible(true); - } else { + if (MagiskFragment.magiskVersion == -1) { menu.findItem(R.id.magiskhide).setVisible(false); + menu.findItem(R.id.modules).setVisible(false); + menu.findItem(R.id.downloads).setVisible(false); + } else { + menu.findItem(R.id.modules).setVisible(true); + menu.findItem(R.id.downloads).setVisible(true); + menu.findItem(R.id.magiskhide).setVisible( + PreferenceManager.getDefaultSharedPreferences(this).getBoolean("magiskhide", false)); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index 9dfba6d53..d1406c648 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -37,7 +37,7 @@ public class SplashActivity extends AppCompatActivity { .apply(); new Async.CheckUpdates(prefs).exec(); - new Async.ConstructEnv(getApplicationInfo()).exec(); +// new Async.ConstructEnv(getApplicationInfo()).exec(); new Async.LoadModules(prefs) { @Override diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java index ced32f170..17866cc1a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java @@ -21,15 +21,10 @@ import android.widget.TextView; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.module.Repo; -import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.receivers.RepoDlReceiver; -import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Utils; -import com.topjohnwu.magisk.utils.Utils.ByteArrayInOutStream; import com.topjohnwu.magisk.utils.WebWindow; -import com.topjohnwu.magisk.utils.ZipUtils; -import java.io.OutputStream; import java.util.List; import butterknife.BindView; diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/RepoDlReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/RepoDlReceiver.java index 0c2043e4d..70f132ceb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/RepoDlReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/RepoDlReceiver.java @@ -4,7 +4,6 @@ import android.net.Uri; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Async; -import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils.ByteArrayInOutStream; import com.topjohnwu.magisk.utils.ZipUtils; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index 148d54d3b..554fe1384 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -3,7 +3,6 @@ package com.topjohnwu.magisk.utils; import android.app.ProgressDialog; import android.content.Context; import android.content.SharedPreferences; -import android.content.pm.ApplicationInfo; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; @@ -45,46 +44,7 @@ public class Async { public static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json"; public static final String MAGISK_HIDE_PATH = "/magisk/.core/magiskhide/"; - - public static class ConstructEnv extends NormalTask { - - ApplicationInfo mInfo; - - public ConstructEnv(ApplicationInfo info) { - mInfo = info; - } - - @Override - protected Void doInBackground(Void... voids) { - String toolPath = mInfo.dataDir + "/tools"; - String busybox = mInfo.dataDir + "/lib/libbusybox.so"; - if (!Utils.itemExist(false, toolPath)) { - Shell.sh( - "mkdir " + toolPath, - "chmod 755 " + toolPath, - "cd " + toolPath, - "ln -s " + busybox + " busybox", - "for tool in $(./busybox --list); do", - "ln -s " + busybox + " $tool", - "done", - "rm -f su sh" - ); - } - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - new RootTask() { - @Override - protected Void doInBackground(Void... voids) { - Shell.su("PATH=" + mInfo.dataDir + "/tools:$PATH"); - return null; - } - }.exec(); - } - } + public static final String TMP_FOLDER_PATH = "/dev/tmp"; public static class CheckUpdates extends NormalTask { @@ -226,6 +186,12 @@ public class Async { } } + protected boolean unzipAndCheck() { + ZipUtils.unzip(mCachedFile, mCachedFile.getParentFile(), "META-INF/com/google/android"); + return Utils.readFile(mCachedFile.getParent() + "/META-INF/com/google/android/updater-script") + .get(0).contains("#MAGISK"); + } + @Override protected void onPreExecute() { progress = new ProgressDialog(mContext); @@ -249,27 +215,22 @@ public class Async { e.printStackTrace(); return -1; } + if (!unzipAndCheck()) return 0; publishProgress(mContext.getString(R.string.zip_install_progress_msg, mFilename)); if (Shell.rootAccess()) { ret = Shell.su( - "unzip -o " + mCachedFile.getPath() + " META-INF/com/google/android/* -d " + mCachedFile.getParent(), - "if [ \"$(cat " + mCachedFile.getParent() + "/META-INF/com/google/android/updater-script)\" = \"#MAGISK\" ]; then echo true; else echo false; fi" - ); - if (! Boolean.parseBoolean(ret.get(ret.size() - 1))) { - return 0; - } - ret = Shell.su( - "BOOTMODE=true sh " + mCachedFile.getParent() + "/META-INF/com/google/android/update-binary dummy 1 "+ mCachedFile.getPath(), + "BOOTMODE=true sh " + mCachedFile.getParent() + + "/META-INF/com/google/android/update-binary dummy 1 " + mCachedFile.getPath(), "if [ $? -eq 0 ]; then echo true; else echo false; fi" ); - Shell.su("rm -rf " + mCachedFile.getParent() + "/META-INF"); Logger.dev("FlashZip: Console log:"); for (String line : ret) { Logger.dev(line); } - } - if (mCachedFile != null && mCachedFile.exists() && !mCachedFile.delete()) { - Utils.removeItem(mCachedFile.getPath()); + Shell.su( + "rm -rf " + mCachedFile.getParent() + "/*", + "rm -rf " + TMP_FOLDER_PATH + ); } if (ret != null && Boolean.parseBoolean(ret.get(ret.size() - 1))) { return 1; @@ -284,7 +245,9 @@ public class Async { progress.dismiss(); switch (result) { case -1: - Toast.makeText(mContext, mContext.getString(R.string.manual_install, mUri.getPath()), Toast.LENGTH_LONG).show(); + Toast.makeText(mContext, mContext.getString(R.string.install_error), Toast.LENGTH_LONG).show(); + Toast.makeText(mContext, mContext.getString(R.string.manual_install_1, mUri.getPath()), Toast.LENGTH_LONG).show(); + Toast.makeText(mContext, mContext.getString(R.string.manual_install_2), Toast.LENGTH_LONG).show(); break; case 0: Toast.makeText(mContext, mContext.getString(R.string.invalid_zip), Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java index 9c0fe496e..75dc4080b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Shell.java @@ -39,8 +39,9 @@ public class Shell { rootSTDOUT = new StreamGobbler(rootShell.getInputStream(), rootOutList, true); rootSTDOUT.start(); - // Setup umask + // Setup umask and PATH su("umask 022"); + su("PATH=/data/busybox:$PATH"); List ret = su("echo -BOC-", "id"); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java b/app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java index b89744b45..10214e49c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java @@ -25,6 +25,7 @@ import org.spongycastle.util.encoders.Base64; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.InputStream; @@ -48,6 +49,7 @@ import java.security.spec.PKCS8EncodedKeySpec; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Enumeration; import java.util.Locale; import java.util.Map; import java.util.TreeMap; @@ -98,7 +100,7 @@ public class ZipUtils { byte buffer[] = new byte[4096]; while ((entry = source.getNextJarEntry()) != null) { // Remove the top directory from the path - path = entry.toString().substring(entry.toString().indexOf("/") + 1); + path = entry.getName().substring(entry.getName().indexOf("/") + 1); // If it's the top folder, ignore it if (path.isEmpty()) continue; @@ -118,6 +120,44 @@ public class ZipUtils { } } + public static void unzip(File file, File folder) { + unzip(file, folder, ""); + } + + public static void unzip(File file, File folder, String path) { + try { + int count; + FileOutputStream out; + File dest; + InputStream is; + JarEntry entry; + byte data[] = new byte[4096]; + JarFile zipfile = new JarFile(file); + Enumeration e = zipfile.entries(); + while(e.hasMoreElements()) { + entry = (JarEntry) e.nextElement(); + if (!entry.getName().contains(path)) { + continue; + } + Logger.dev("Extracting: " + entry); + is = zipfile.getInputStream(entry); + dest = new File(folder, entry.getName()); + if (dest.getParentFile().mkdirs()) { + dest.createNewFile(); + } + out = new FileOutputStream(dest); + while ((count = is.read(data, 0, 4096)) != -1) { + out.write(data, 0, count); + } + out.flush(); + out.close(); + is.close(); + } + } catch(Exception e) { + e.printStackTrace(); + } + } + public static void signZip(Context context, InputStream inputStream, OutputStream outputStream, boolean signWholeFile) { JarMap inputJar; diff --git a/app/src/main/jniLibs/armeabi/libbusybox.so b/app/src/main/jniLibs/armeabi/libbusybox.so deleted file mode 100644 index 985254672..000000000 Binary files a/app/src/main/jniLibs/armeabi/libbusybox.so and /dev/null differ diff --git a/app/src/main/jniLibs/x86/libbusybox.so b/app/src/main/jniLibs/x86/libbusybox.so deleted file mode 100644 index a83050ad9..000000000 Binary files a/app/src/main/jniLibs/x86/libbusybox.so and /dev/null differ diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 08c7e7f53..5cd7e57bf 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1,7 +1,5 @@ - Magisk Manager - Magisk Navigationsleiste öffnen @@ -70,7 +68,7 @@ Herunterladen und Installieren Fehler beim Herunterladen Fehler beim Installieren! - Fehler beim Flashen. Datei in %1$s abgelegt\n Bitte in recovery manuell flashen + Fehler beim Flashen. Datei in %1$s abgelegt\n Bitte in recovery manuell flashen Diese Datei ist kein Magisk Modul!! Installation erfolgreich! Wollen Sie jetzt neu starten? diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 4f437612c..54065d58e 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1,7 +1,5 @@ - Magisk Manager - Magisk Abrir menú lateral @@ -72,7 +70,7 @@ Descargar e instalar Error descargando fichero ¡Error en la instalación! - Error flasheando fichero, zip colocado en %1$s\nFlashear manualmente desde recovery + Error flasheando fichero, zip colocado en %1$s\nFlashear manualmente desde recovery ¡El zip no es un Módulo Magisk! ¡Instalación correcta! ¿Deseas reiniciar ahora? diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index dceeac68a..7c5487fdb 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1,7 +1,5 @@ - Magisk Manager - Magisk Apri drawer di navigazione @@ -70,7 +68,7 @@ Scarica e installa Errore nel download del file Errore di installazione! - Errore nel flash del file, il file zip è in %1$s\nFlash esegui il flash manuale + Errore nel flash del file, il file zip è in %1$s\nFlash esegui il flash manuale Lo zip non è un Modulo Magisk!! Installazione completata Vuoi riavviare ora? diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 3e6f88611..f18934bbb 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -1,7 +1,5 @@ - Magisk Manager - Magisk Open navigatie @@ -70,7 +68,7 @@ Downloaden en installeren Er is een fout opgetreden bij het downloaden van het bestand Er is een fout opgetreden in de installatie - Er is een fout opgetreden in het flashen van het bestand. Het zip bestand is opgeslagen in %1$s\nFlash het handmatig in recovery modus. + Er is een fout opgetreden in het flashen van het bestand. Het zip bestand is opgeslagen in %1$s\nFlash het handmatig in recovery modus. Zip bestand is geen Magisk Module! Installatie succesvol! Wilt u nu rebooten? diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 1edc20f2d..5961616f1 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -66,7 +66,7 @@ Baixar e instalar Erro ao baixar o arquivo Erro na instalação! - Erro ao flashear o arquivo, arquivo zip colocado em %1$s\nFlashear isto na recuperação manualmente + Erro ao flashear o arquivo, arquivo zip colocado em %1$s\nFlashear isto na recuperação manualmente O zip não é um Módulo Magisk!! Instalação bem-sucedida! Você quer reiniciar agora? diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index adde5ff7f..c9779df16 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -72,13 +72,15 @@ Download and install Error downloading file Installation error! - Error in flashing file, zip file placed in %1$s\nFlash it in recovery manually + Zip file placed in %1$s + Flash it in recovery manually The zip is not a Magisk Module!! Installation succeeded! Do you want to reboot now? Reboot Installing - Processing zip file ... + Unzipping zip file … + Processing zip file … "Installing %1$s …" No Magisk Installed! Do you want to download and install Magisk?