From 8ba53d845d34309d862a67b3d1d47100333bba58 Mon Sep 17 00:00:00 2001 From: tornaco Date: Thu, 28 Apr 2022 20:57:08 +0800 Subject: [PATCH] [app] killProcess --- .../thanos/core/app/ActivityManager.java | 6 +++ .../thanos/core/app/IActivityManager.aidl | 3 ++ .../thanos/core/app/IActivityManager.java | 37 +++++++++++++++++ .../process/v2/RunningAppDetailViewModel.kt | 6 ++- .../v2/RunningAppStateDetailsScreen.kt | 40 +++++++++++-------- android/internal/Thanox-Internal | 2 +- 6 files changed, 75 insertions(+), 19 deletions(-) diff --git a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/ActivityManager.java b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/ActivityManager.java index 6e6d31f9c..5d510bed5 100644 --- a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/ActivityManager.java +++ b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/ActivityManager.java @@ -5,6 +5,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.UserInfo; import android.os.IBinder; +import android.os.RemoteException; import com.elvishew.xlog.XLog; @@ -454,6 +455,11 @@ public void killBackgroundProcesses(String packageName) { server.killBackgroundProcesses(Pkg.systemUserPkg(packageName)); } + @SneakyThrows + public boolean killProcess(long pid) { + return server.killProcess(pid); + } + @SneakyThrows public String getPackageNameForTaskId(int taskId) { return server.getPackageNameForTaskId(taskId); diff --git a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/IActivityManager.aidl b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/IActivityManager.aidl index 91593d614..95e3e80e0 100644 --- a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/IActivityManager.aidl +++ b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/IActivityManager.aidl @@ -184,4 +184,7 @@ interface IActivityManager { void updateProcessCpuUsageStats(); List queryProcessCpuUsageStats(in long[] pids, boolean update); float queryCpuUsageRatio(in long[] pids, boolean update); + + + boolean killProcess(long pid); } \ No newline at end of file diff --git a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/IActivityManager.java b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/IActivityManager.java index 0a36cbdfb..053b2af3f 100644 --- a/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/IActivityManager.java +++ b/android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/app/IActivityManager.java @@ -418,6 +418,10 @@ public static class Default implements github.tornaco.android.thanos.core.app.IA { return 0.0f; } + @Override public boolean killProcess(long pid) throws android.os.RemoteException + { + return false; + } @Override public android.os.IBinder asBinder() { return null; @@ -1560,6 +1564,16 @@ public static github.tornaco.android.thanos.core.app.IActivityManager asInterfac reply.writeFloat(_result); return true; } + case TRANSACTION_killProcess: + { + data.enforceInterface(descriptor); + long _arg0; + _arg0 = data.readLong(); + boolean _result = this.killProcess(_arg0); + reply.writeNoException(); + reply.writeInt(((_result)?(1):(0))); + return true; + } default: { return super.onTransact(code, data, reply, flags); @@ -3869,6 +3883,27 @@ public java.lang.String getInterfaceDescriptor() } return _result; } + @Override public boolean killProcess(long pid) throws android.os.RemoteException + { + android.os.Parcel _data = android.os.Parcel.obtain(); + android.os.Parcel _reply = android.os.Parcel.obtain(); + boolean _result; + try { + _data.writeInterfaceToken(DESCRIPTOR); + _data.writeLong(pid); + boolean _status = mRemote.transact(Stub.TRANSACTION_killProcess, _data, _reply, 0); + if (!_status && getDefaultImpl() != null) { + return getDefaultImpl().killProcess(pid); + } + _reply.readException(); + _result = (0!=_reply.readInt()); + } + finally { + _reply.recycle(); + _data.recycle(); + } + return _result; + } public static github.tornaco.android.thanos.core.app.IActivityManager sDefaultImpl; } static final int TRANSACTION_getCurrentFrontApp = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0); @@ -3979,6 +4014,7 @@ public java.lang.String getInterfaceDescriptor() static final int TRANSACTION_updateProcessCpuUsageStats = (android.os.IBinder.FIRST_CALL_TRANSACTION + 105); static final int TRANSACTION_queryProcessCpuUsageStats = (android.os.IBinder.FIRST_CALL_TRANSACTION + 106); static final int TRANSACTION_queryCpuUsageRatio = (android.os.IBinder.FIRST_CALL_TRANSACTION + 107); + static final int TRANSACTION_killProcess = (android.os.IBinder.FIRST_CALL_TRANSACTION + 108); public static boolean setDefaultImpl(github.tornaco.android.thanos.core.app.IActivityManager impl) { // Only one user of this interface can use this function // at a time. This is a heuristic to detect if two different @@ -4126,4 +4162,5 @@ public static github.tornaco.android.thanos.core.app.IActivityManager getDefault public void updateProcessCpuUsageStats() throws android.os.RemoteException; public java.util.List queryProcessCpuUsageStats(long[] pids, boolean update) throws android.os.RemoteException; public float queryCpuUsageRatio(long[] pids, boolean update) throws android.os.RemoteException; + public boolean killProcess(long pid) throws android.os.RemoteException; } diff --git a/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppDetailViewModel.kt b/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppDetailViewModel.kt index 3e9647762..390278b95 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppDetailViewModel.kt +++ b/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppDetailViewModel.kt @@ -35,8 +35,10 @@ class RunningAppDetailViewModel @Inject constructor(@ApplicationContext private ToastUtils.copiedToClipboard(context) } - fun stopProcess(state: RunningProcessState) { - ToastUtils.nook(context) + fun stopProcess(state: RunningProcessState): Boolean { + return thanox.activityManager.killProcess(state.process.pid.toLong()).also { + if (it) _appStateChanged = true + } } fun copyServiceName(service: RunningService) { diff --git a/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppStateDetailsScreen.kt b/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppStateDetailsScreen.kt index 3ccdab1b3..b7802b755 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppStateDetailsScreen.kt +++ b/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppStateDetailsScreen.kt @@ -105,21 +105,23 @@ private fun RunningAppStateDetailsScreen( .verticalScroll(rememberScrollState()) ) { runningAppState.processState.forEach { runningProcessState -> - Card( - modifier = Modifier.padding(16.dp), - containerColor = ColorDefaults.backgroundSurfaceColor() - ) { - Column { - StandardSpacer() - ProcessSection( - runningAppState.appInfo, - runningProcessState, - cpuUsageStatsState, - viewModel - ) - StandardSpacer() - ServiceSection(runningAppState, runningProcessState, viewModel) - StandardSpacer() + AnimatedVisibility(visible = !runningProcessState.isStopped) { + Card( + modifier = Modifier.padding(16.dp), + containerColor = ColorDefaults.backgroundSurfaceColor() + ) { + Column { + StandardSpacer() + ProcessSection( + runningAppState.appInfo, + runningProcessState, + cpuUsageStatsState, + viewModel + ) + StandardSpacer() + ServiceSection(runningAppState, runningProcessState, viewModel) + StandardSpacer() + } } } } @@ -345,6 +347,7 @@ private fun ProcessPopupMenu( viewModel: RunningAppDetailViewModel, runningProcessState: RunningProcessState ) { + val context = LocalContext.current DropdownPopUpMenu( popMenuExpend, items = listOf( @@ -365,7 +368,12 @@ private fun ProcessPopupMenu( viewModel.copyProcessName(runningProcessState) } "stop" -> { - viewModel.stopProcess(runningProcessState) + if (viewModel.stopProcess(runningProcessState)) { + ToastUtils.ok(context) + runningProcessState.isStopped = true + } else { + ToastUtils.nook(context) + } } else -> { diff --git a/android/internal/Thanox-Internal b/android/internal/Thanox-Internal index 52aaca164..5aa9c4aa0 160000 --- a/android/internal/Thanox-Internal +++ b/android/internal/Thanox-Internal @@ -1 +1 @@ -Subproject commit 52aaca164fc2b9996c9f44ddc4b860063467dfbd +Subproject commit 5aa9c4aa0f483b693b684c5f584e2f39758ca565