Skip to content

Commit 3777904

Browse files
committed
Update
1 parent a0b0152 commit 3777904

3 files changed

Lines changed: 12 additions & 45 deletions

File tree

.github/addon/patch_rom/patch-rom

-19.5 KB
Binary file not shown.

app/src/main/assets/home/etc/boot

272 Bytes
Binary file not shown.

app/src/main/java/com/omarea/krscript/model/ShellHandlerBase.java

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -56,32 +56,10 @@ public abstract class ShellHandlerBase extends Handler {
5656
// (gọi từ release() khi dialog bị huỷ) để không giữ rác sau khi không cần nữa.
5757
private DataOutputStream stdin;
5858

59-
// Runnable do ShellExecutor.execute() cung cấp qua onStart(Runnable) — khi gọi sẽ thực thi
60-
// "killtree" (kill toàn bộ cây tiến trình con sinh ra bởi phiên shell hiện tại, không chỉ
61-
// riêng process của app) rồi đóng stream + destroy process shell chính. Cần lưu lại tham
62-
// chiếu này ở lớp cha vì killApp() (phục vụ "exit:[kill]"/"exit:[restart]") cần gọi tới nó
63-
// TRƯỚC khi kill process của app — nếu không, các lệnh shell chạy ngầm (con của su/sh) sẽ
64-
// bị mồ côi và tiếp tục chạy nền dù app đã bị kill/restart.
65-
private Runnable forceStop;
66-
6759
public ShellHandlerBase(Context context) {
6860
this.context = context;
6961
}
7062

71-
/**
72-
* Lưu lại runnable kill-tree do ShellExecutor cung cấp. Lớp con override onStart(Runnable)
73-
* (ví dụ để gắn vào nút "Dừng") CẦN gọi thêm dòng này trong phần implement của mình, ví dụ:
74-
*
75-
* {@literal @}Override
76-
* public void onStart(Runnable forceStop) {
77-
* bindForceStop(forceStop);
78-
* this.stopButtonAction = forceStop; // logic cũ của lớp con vẫn giữ nguyên
79-
* }
80-
*/
81-
public void bindForceStop(Runnable forceStop) {
82-
this.forceStop = forceStop;
83-
}
84-
8563
/**
8664
* Gắn luồng stdin của process shell hiện tại, để UI (ô nhập liệu) có thể ghi dữ liệu
8765
* người dùng gõ vào ngay trong lúc script đang chạy (phục vụ lệnh `read` trong script).
@@ -258,32 +236,21 @@ private void killApp(boolean restart) {
258236
onKillRequest();
259237
} catch (Exception ignored) {
260238
// Không để lỗi dọn dẹp UI cản trở việc kill
261-
}
262-
// Kill cây tiến trình shell (root killtree theo sessionTag) TRƯỚC khi kill app process.
263-
// Nếu bỏ qua bước này, killProcess() bên dưới chỉ giết process Java của app — các tiến
264-
// trình su/sh/script con sẽ bị mồ côi, được init nhận nuôi, và tiếp tục chạy nền bình
265-
// thường dù app đã biến mất khỏi Recent Apps.
266-
Runnable forceStop = this.forceStop;
267-
if (forceStop != null) {
268-
try {
269-
forceStop.run();
270-
} catch (Exception ignored) {
271-
// Không để lỗi kill-tree cản trở việc kill process của app
272-
}
273-
}
274-
if (restart) {
275-
try {
276-
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
277-
if (launch != null) {
278-
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
279-
context.startActivity(launch);
239+
} finally {
240+
if (restart) {
241+
try {
242+
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
243+
if (launch != null) {
244+
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
245+
context.startActivity(launch);
246+
}
247+
} catch (Exception ignored) {
248+
// Không để lỗi khởi động lại cản trở việc kill process cũ
280249
}
281-
} catch (Exception ignored) {
282-
// Không để lỗi khởi động lại cản trở việc kill process cũ
283250
}
251+
android.os.Process.killProcess(android.os.Process.myPid());
252+
System.exit(10);
284253
}
285-
android.os.Process.killProcess(android.os.Process.myPid());
286-
System.exit(10);
287254
}
288255

289256
private String getAmHelp() {

0 commit comments

Comments
 (0)