Skip to content

Commit

Permalink
[app] killProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Apr 28, 2022
1 parent 6f02a88 commit 8ba53d8
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,7 @@ interface IActivityManager {
void updateProcessCpuUsageStats();
List<ProcessCpuUsageStats> queryProcessCpuUsageStats(in long[] pids, boolean update);
float queryCpuUsageRatio(in long[] pids, boolean update);


boolean killProcess(long pid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<github.tornaco.android.thanos.core.app.usage.ProcessCpuUsageStats> 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}
Expand Down Expand Up @@ -345,6 +347,7 @@ private fun ProcessPopupMenu(
viewModel: RunningAppDetailViewModel,
runningProcessState: RunningProcessState
) {
val context = LocalContext.current
DropdownPopUpMenu(
popMenuExpend,
items = listOf(
Expand All @@ -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 -> {

Expand Down
2 changes: 1 addition & 1 deletion android/internal/Thanox-Internal

0 comments on commit 8ba53d8

Please sign in to comment.