From be34fc0f59740c4e41cf5177d5a59aaa82a12da3 Mon Sep 17 00:00:00 2001 From: androidacy-user Date: Wed, 28 Jun 2023 12:17:08 -0400 Subject: [PATCH] final tweaks in prep for release Signed-off-by: androidacy-user --- app/build.gradle.kts | 2 +- app/proguard-rules.pro | 15 ++++ .../mmm/installer/InstallerInitializer.kt | 79 +++++++++---------- .../com/fox2code/mmm/module/ModuleHolder.kt | 2 - .../fox2code/mmm/settings/SettingsActivity.kt | 57 +++++++------ app/src/main/res/values/strings.xml | 1 + 6 files changed, 82 insertions(+), 74 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 760e6baf..e168c459 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -53,7 +53,7 @@ android { applicationId = "com.fox2code.mmm" minSdk = 24 targetSdk = 33 - versionCode = 77 + versionCode = 78 versionName = "2.2.1" vectorDrawables { useSupportLibrary = true diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index c4d4149d..736f755e 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -196,6 +196,21 @@ -keepclassmembers class org.apache.commons.compress.archivers.zip.* { *; } #-keep class com.fox2code.mmm.installer.InstallerInitializer { *; } +# Strip out debugging stuffs +-assumenosideeffects class com.topjohnwu.superuser.internal.Utils { + public static void log(...); + public static void ex(...); + public static boolean vLog() return false; + public static boolean hasStartupAgents(android.content.Context) return false; +} + +# Keep classes referenced by reflection +-keep,allowobfuscation class * extends com.topjohnwu.superuser.Shell$Initializer { *; } +-keep,allowobfuscation class * extends com.topjohnwu.superuser.ipc.RootService { *; } +-keep class com.topjohnwu.superuser.Shell$Job +-keep class com.topjohnwu.superuser.Shell$Result +-keep class com.topjohnwu.superuser.Shell + # dontwarn -dontwarn android.os.SystemProperties -dontwarn android.view.ThreadedRenderer diff --git a/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt b/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt index 0a67cefb..886812ea 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/installer/InstallerInitializer.kt @@ -30,8 +30,8 @@ class InstallerInitializer : Shell.Initializer() { private val MAGISK_SBIN = File("/sbin/magisk") private val MAGISK_SYSTEM = File("/system/bin/magisk") private val MAGISK_SYSTEM_EX = File("/system/xbin/magisk") - private val HAS_MAGISK = MAGISK_SBIN.exists() || - MAGISK_SYSTEM.exists() || MAGISK_SYSTEM_EX.exists() + private val HAS_MAGISK = + MAGISK_SBIN.exists() || MAGISK_SYSTEM.exists() || MAGISK_SYSTEM_EX.exists() private var mgskPth: String? = null private var mgskVerCode = 0 private var hsRmdsk = false @@ -43,9 +43,7 @@ class InstallerInitializer : Shell.Initializer() { val errorNotification: NotificationType? get() { val hasRoot = Shell.isAppGrantedRoot() - if (mgskPth != null && - hasRoot !== java.lang.Boolean.FALSE - ) { + if (mgskPth != null && hasRoot !== java.lang.Boolean.FALSE) { return null } if (!HAS_MAGISK) { @@ -130,47 +128,46 @@ class InstallerInitializer : Shell.Initializer() { if (mgskPth != null && !forceCheck) return mgskPth val output = ArrayList() try { - if (!Shell.cmd( - "if grep ' / ' /proc/mounts | grep -q '/dev/root' &> /dev/null; " + - "then echo true; else echo false; fi", "magisk -V", "magisk --path" - ) - .to(output).exec().isSuccess - ) { - if (output.size != 0) { - hsRmdsk = "false" == output[0] || - "true".equals( - System.getProperty("ro.build.ab_update"), - ignoreCase = true - ) + if (!Shell.cmd( + "if grep ' / ' /proc/mounts | grep -q '/dev/root' &> /dev/null; " + "then echo true; else echo false; fi", + "magisk -V", + "magisk --path" + ).to(output).exec().isSuccess + ) { + if (output.size != 0) { + hsRmdsk = "false" == output[0] || "true".equals( + System.getProperty("ro.build.ab_update"), ignoreCase = true + ) + } + Companion.hsRmdsk = hsRmdsk + return null } - Companion.hsRmdsk = hsRmdsk - return null - } - mgskPth = if (output.size < 3) "" else output[2] - Timber.i("Magisk runtime path: %s", mgskPth) - mgskVerCode = output[1].toInt() - Timber.i("Magisk version code: %s", mgskVerCode) - if (mgskVerCode >= Constants.MAGISK_VER_CODE_FLAT_MODULES && mgskVerCode < Constants.MAGISK_VER_CODE_PATH_SUPPORT && - (mgskPth.isEmpty() || !File(mgskPth).exists()) - ) { - mgskPth = "/sbin" - } - if (mgskPth.isNotEmpty() && existsSU(File(mgskPth))) { - Companion.mgskPth = mgskPth - } else { - Timber.e("Failed to get Magisk path (Got $mgskPth)") - mgskPth = null - } - Companion.mgskVerCode = mgskVerCode - return mgskPth + mgskPth = if (output.size < 3) "" else output[2] + Timber.i("Magisk runtime path: %s", mgskPth) + mgskVerCode = output[1].toInt() + Timber.i("Magisk version code: %s", mgskVerCode) + if (mgskVerCode >= Constants.MAGISK_VER_CODE_FLAT_MODULES && mgskVerCode < Constants.MAGISK_VER_CODE_PATH_SUPPORT && (mgskPth.isEmpty() || !File( + mgskPth + ).exists()) + ) { + mgskPth = "/sbin" + } + if (mgskPth.isNotEmpty() && existsSU(File(mgskPth))) { + Companion.mgskPth = mgskPth + } else { + Timber.e("Failed to get Magisk path (Got $mgskPth)") + mgskPth = null + } + Companion.mgskVerCode = mgskVerCode + return mgskPth } catch (ignored: Exception) { - if (tries < 5) { + return if (tries < 5) { tries++ - return tryGetMagiskPath(true) + tryGetMagiskPath(true) } else { - return null + null } - } + } } } } diff --git a/app/src/main/kotlin/com/fox2code/mmm/module/ModuleHolder.kt b/app/src/main/kotlin/com/fox2code/mmm/module/ModuleHolder.kt index 85c075ab..a1a76830 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/module/ModuleHolder.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/module/ModuleHolder.kt @@ -189,11 +189,9 @@ class ModuleHolder : Comparable { INSTANCE!!.modulesHaveUpdates, INSTANCE!!.updateModuleCount ) - Timber.d("Module %s has update", moduleId) Type.UPDATABLE } } else { - Timber.i("Module %s is installed", moduleId) Type.INSTALLED } diff --git a/app/src/main/kotlin/com/fox2code/mmm/settings/SettingsActivity.kt b/app/src/main/kotlin/com/fox2code/mmm/settings/SettingsActivity.kt index d4e5fc5f..994565ba 100644 --- a/app/src/main/kotlin/com/fox2code/mmm/settings/SettingsActivity.kt +++ b/app/src/main/kotlin/com/fox2code/mmm/settings/SettingsActivity.kt @@ -1014,40 +1014,37 @@ class SettingsActivity : FoxActivity(), LanguageActivity { try { logsFile.createNewFile() fileOutputStream = FileOutputStream(logsFile) - // first, write some info about the device + // first, some device and app info: namely device oem and model, android version and build, app version and build fileOutputStream.write( - """FoxMagiskModuleManager version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE}) - """.toByteArray() + String.format( + "Device: %s %s\nAndroid Version: %s\nROM: %s\nApp Version: %s (%s)\n\n", + Build.MANUFACTURER, + Build.MODEL, + Build.VERSION.RELEASE, + Build.FINGERPRINT, + BuildConfig.VERSION_NAME, + BuildConfig.VERSION_CODE + ).toByteArray() ) - fileOutputStream.write( - """Android version: ${Build.VERSION.RELEASE} (${Build.VERSION.SDK_INT}) - """.toByteArray() - ) - fileOutputStream.write( - """Device: ${Build.MANUFACTURER} ${Build.MODEL} (${Build.DEVICE}) - """.toByteArray() - ) - fileOutputStream.write( - """Magisk version: ${peekMagiskVersion()} - """.toByteArray() - ) - fileOutputStream.write( - ("Has internet: " + (if (getINSTANCE()!! - .hasConnectivity() - ) "Yes" else "No") + "\n").toByteArray() + // next, the logs + // get our logs from logcat + val process = Runtime.getRuntime().exec("logcat -d") + val bufferedReader = BufferedReader( + InputStreamReader(process.inputStream) ) - fileOutputStream.write("Beginning of logs:\n".toByteArray()) - - // read our logcat but format the output to be more readable - val process = Runtime.getRuntime().exec("logcat -d -v tag") - val bufferedReader = BufferedReader(InputStreamReader(process.inputStream)) - var line: String - while (bufferedReader.readLine().also { line = it } != null) { - fileOutputStream.write( - """$line - """.toByteArray() - ) + var line: String? + val iterator: Iterator = bufferedReader.lines().iterator() + while (iterator.hasNext()) { + line = iterator.next() + fileOutputStream.write(line.toByteArray()) + fileOutputStream.write("\n".toByteArray()) } + fileOutputStream.flush() + Toast.makeText( + requireContext(), + R.string.logs_saved, + Toast.LENGTH_SHORT + ).show() } catch (e: IOException) { e.printStackTrace() Toast.makeText( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 99fbee61..f037c443 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -383,4 +383,5 @@ This build has expired! The build you are using is expired and will no longer run. Please update to the latest stable build. Download latest + Saved logs successfully