Skip to content

Commit

Permalink
handle corrupted detach.bin
Browse files Browse the repository at this point in the history
  • Loading branch information
j-hc committed Jan 24, 2024
1 parent 451bd83 commit 6f792c7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId = "com.jhc.detach"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionCode = 2
versionName = "1.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -55,15 +55,15 @@ dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3:1.1.2")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
androidTestImplementation(platform("androidx.compose:compose-bom:2023.10.01"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
Expand Down
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
Expand Down
19 changes: 16 additions & 3 deletions app/src/main/java/com/jhc/detach/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ class DetachBin(filesDir: File, private val context: Context) {
private val remote = "/data/adb/modules/zygisk-detach/detach.bin"
var detached = listOf<String>()

fun deleteBin() {
File(internal).delete()
Shell.cmd("rm -f $remote").exec()
}

fun getDetached(a: Int = 0): List<String> {
File(internal).delete()
if (Shell.cmd("cp -f $remote $internal").exec().code == 0) {
Expand Down Expand Up @@ -250,9 +255,11 @@ class DetachBin(filesDir: File, private val context: Context) {
fileOutputStream.close()
val r = Shell.cmd("cp -f $internal $remote").exec()
if (r.code != 0) {
Toast.makeText(context, "ERROR", Toast.LENGTH_LONG).show()
Toast.makeText(context, "ERROR: make sure you flashed zygisk-detach", Toast.LENGTH_LONG)
.show()
} else {
Shell.cmd("am force-stop com.android.vending").exec()
}
Shell.cmd("am force-stop com.android.vending").exec()
}
}

Expand All @@ -271,7 +278,13 @@ class MainActivity : ComponentActivity() {
it, packageManager.getApplicationLabel(it.applicationInfo).toString()
)
}.sortedBy { it.label }
val alDetach = detachBin.getDetached()
val alDetach = try {
detachBin.getDetached()
} catch (e: IndexOutOfBoundsException) {
detachBin.deleteBin()
listOf()
}

apps.forEach { it.detached = alDetach.contains(it.pi.packageName) }
apps = apps.sortedBy { it.label }.sortedBy { !it.detached }
setContent {
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/res/values/colors.xml

This file was deleted.

0 comments on commit 6f792c7

Please sign in to comment.