Skip to content

Commit af02b36

Browse files
committed
Enhance module flashing error handling and capture stderr output
1 parent 5b641d8 commit af02b36

3 files changed

Lines changed: 35 additions & 20 deletions

File tree

app/src/main/java/com/drdisagree/iconify/core/utils/ModuleUtils.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ object ModuleUtils {
156156
var result: Shell.Result? = null
157157

158158
if (RootUtils.isMagiskInstalled) {
159-
result = Shell.cmd("magisk --install-module $modulePath").exec()
159+
result = Shell.cmd("{ magisk --install-module $modulePath ; } 2>&1").exec()
160160
} else if (RootUtils.isKSUInstalled) {
161-
result = Shell.cmd("ksud module install $modulePath").exec()
161+
result = Shell.cmd("{ ksud module install $modulePath ; } 2>&1").exec()
162162
} else if (RootUtils.isApatchInstalled) {
163-
result = Shell.cmd("apd module install $modulePath").exec()
163+
result = Shell.cmd("{ apd module install $modulePath ; } 2>&1").exec()
164164
setPermissionsRecursively(MODULE_DIR)
165165
}
166166

@@ -170,7 +170,10 @@ object ModuleUtils {
170170
Log.i(TAG, "Successfully flashed module")
171171
} else {
172172
Log.e(TAG, "Failed to flash module")
173-
throw Exception(java.lang.String.join("\n", result.out))
173+
val errorOutput = result.out.takeIf { lines ->
174+
lines.any { !it.isNullOrBlank() }
175+
} ?: result.err
176+
throw Exception(java.lang.String.join("\n", errorOutput))
174177
}
175178

176179
return !result.isSuccess

app/src/main/java/com/drdisagree/iconify/core/utils/overlay/compilers/OnboardingCompiler.kt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object OnboardingCompiler {
5050
val command: String = getAAPT2Command(source, name)
5151

5252
while (attempt-- != 0) {
53-
result = Shell.cmd(command).exec()
53+
result = Shell.cmd("{ $command ; } 2>&1").exec()
5454

5555
if (!result.isSuccess) {
5656
val keywords = listOf(
@@ -67,7 +67,7 @@ object OnboardingCompiler {
6767
"find $source/res -type f -name \"*.xml\" -exec sed -i '/$keyword/d' {} +"
6868
).exec()
6969
}
70-
result = Shell.cmd(command).exec()
70+
result = Shell.cmd("{ $command ; } 2>&1").exec()
7171
}
7272
}
7373

@@ -86,11 +86,13 @@ object OnboardingCompiler {
8686
}
8787
}
8888

89-
if (!result!!.isSuccess) writeLog(
90-
"$TAG - AAPT",
91-
"Failed to build APK for $name",
92-
result.out
93-
)
89+
if (!result!!.isSuccess) {
90+
val errorOutput = result.out.takeIf { lines ->
91+
lines.any { !it.isNullOrBlank() }
92+
} ?: result.err
93+
94+
writeLog("$TAG - AAPT", "Failed to build APK for $name", errorOutput)
95+
}
9496

9597
return !result.isSuccess
9698
}
@@ -113,7 +115,7 @@ object OnboardingCompiler {
113115
while (attempt-- != 0) {
114116
result =
115117
Shell.cmd(
116-
"$zipalign -p -f 4 $source $UNSIGNED_DIR/$name"
118+
"{ $zipalign -p -f 4 $source $UNSIGNED_DIR/$name ; } 2>&1"
117119
).exec()
118120

119121
if (result.isSuccess) {
@@ -139,11 +141,17 @@ object OnboardingCompiler {
139141
}
140142
}
141143

142-
if (!result!!.isSuccess) writeLog(
143-
"$TAG - ZipAlign",
144-
"Failed to zip align " + name.replace("-unsigned.apk", ""),
145-
result.out
146-
)
144+
if (!result!!.isSuccess) {
145+
val errorOutput = result.out.takeIf { lines ->
146+
lines.any { !it.isNullOrBlank() }
147+
} ?: result.err
148+
149+
writeLog(
150+
"$TAG - ZipAlign",
151+
"Failed to zip align " + name.replace("-unsigned.apk", ""),
152+
errorOutput
153+
)
154+
}
147155

148156
return !result.isSuccess
149157
}

app/src/main/java/com/drdisagree/iconify/core/utils/overlay/compilers/OverlayCompiler.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,22 @@ object OverlayCompiler {
121121
val result =
122122
Shell.cmd(
123123
"rm -rf $UNSIGNED_DIR/$fileName-unsigned.apk",
124-
"$zipalign 4 $source $UNSIGNED_DIR/$fileName-unsigned.apk"
124+
"{ $zipalign 4 $source $UNSIGNED_DIR/$fileName-unsigned.apk ; } 2>&1"
125125
).exec()
126126

127127
if (result.isSuccess) Log.i(
128128
"$TAG - ZipAlign",
129129
"Successfully zip aligned $fileName"
130130
) else {
131+
val errorOutput = result.out.takeIf { lines ->
132+
lines.any { !it.isNullOrBlank() }
133+
} ?: result.err
134+
131135
Log.e(
132136
"$TAG - ZipAlign",
133-
"Failed to zip align $fileName\n${java.lang.String.join("\n", result.out)}"
137+
"Failed to zip align $fileName\n${errorOutput.joinToString("\n")}"
134138
)
135-
writeLog("$TAG - ZipAlign", "Failed to zip align $fileName", result.out)
139+
writeLog("$TAG - ZipAlign", "Failed to zip align $fileName", errorOutput)
136140
}
137141

138142
return !result.isSuccess

0 commit comments

Comments
 (0)