From 6f02a88d9807b23a402adcf00b2c8d133fb76521 Mon Sep 17 00:00:00 2001 From: tornaco Date: Wed, 27 Apr 2022 21:34:32 +0800 Subject: [PATCH] [app] stop service --- .../thanos/core/app/ActivityManager.java | 4 +-- .../thanos/core/app/IActivityManager.aidl | 4 +-- .../thanos/core/app/IActivityManager.java | 32 ++++++++++++------- .../process/v2/RunningAppDetailViewModel.kt | 13 ++++++-- .../thanos/process/v2/RunningAppState.kt | 11 +++++-- .../v2/RunningAppStateDetailsScreen.kt | 21 ++++++++++-- android/internal/Thanox-Internal | 2 +- 7 files changed, 62 insertions(+), 25 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 cc5839c7e..6e6d31f9c 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 @@ -445,8 +445,8 @@ public UserInfo getUserInfo(int userHandle) { } @SneakyThrows - public void stopService(Intent intent) { - server.stopService(intent); + public boolean stopService(Intent intent) { + return server.stopService(intent); } @SneakyThrows 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 9cafc2b6d..91593d614 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 @@ -132,8 +132,8 @@ interface IActivityManager { UserInfo getUserInfo(int userHandle); - void stopService(in Intent intent); - void killBackgroundProcesses(in Pkg pkg); + boolean stopService(in Intent intent); + boolean killBackgroundProcesses(in Pkg pkg); boolean isSmartStandByStopServiceEnabled(); void setSmartStandByStopServiceEnabled(boolean enable); 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 1a51d00c9..0a36cbdfb 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 @@ -297,11 +297,13 @@ public static class Default implements github.tornaco.android.thanos.core.app.IA { return null; } - @Override public void stopService(android.content.Intent intent) throws android.os.RemoteException + @Override public boolean stopService(android.content.Intent intent) throws android.os.RemoteException { + return false; } - @Override public void killBackgroundProcesses(github.tornaco.android.thanos.core.pm.Pkg pkg) throws android.os.RemoteException + @Override public boolean killBackgroundProcesses(github.tornaco.android.thanos.core.pm.Pkg pkg) throws android.os.RemoteException { + return false; } @Override public boolean isSmartStandByStopServiceEnabled() throws android.os.RemoteException { @@ -1247,8 +1249,9 @@ public static github.tornaco.android.thanos.core.app.IActivityManager asInterfac else { _arg0 = null; } - this.stopService(_arg0); + boolean _result = this.stopService(_arg0); reply.writeNoException(); + reply.writeInt(((_result)?(1):(0))); return true; } case TRANSACTION_killBackgroundProcesses: @@ -1261,8 +1264,9 @@ public static github.tornaco.android.thanos.core.app.IActivityManager asInterfac else { _arg0 = null; } - this.killBackgroundProcesses(_arg0); + boolean _result = this.killBackgroundProcesses(_arg0); reply.writeNoException(); + reply.writeInt(((_result)?(1):(0))); return true; } case TRANSACTION_isSmartStandByStopServiceEnabled: @@ -3192,10 +3196,11 @@ public java.lang.String getInterfaceDescriptor() } return _result; } - @Override public void stopService(android.content.Intent intent) throws android.os.RemoteException + @Override public boolean stopService(android.content.Intent intent) 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); if ((intent!=null)) { @@ -3207,20 +3212,22 @@ public java.lang.String getInterfaceDescriptor() } boolean _status = mRemote.transact(Stub.TRANSACTION_stopService, _data, _reply, 0); if (!_status && getDefaultImpl() != null) { - getDefaultImpl().stopService(intent); - return; + return getDefaultImpl().stopService(intent); } _reply.readException(); + _result = (0!=_reply.readInt()); } finally { _reply.recycle(); _data.recycle(); } + return _result; } - @Override public void killBackgroundProcesses(github.tornaco.android.thanos.core.pm.Pkg pkg) throws android.os.RemoteException + @Override public boolean killBackgroundProcesses(github.tornaco.android.thanos.core.pm.Pkg pkg) 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); if ((pkg!=null)) { @@ -3232,15 +3239,16 @@ public java.lang.String getInterfaceDescriptor() } boolean _status = mRemote.transact(Stub.TRANSACTION_killBackgroundProcesses, _data, _reply, 0); if (!_status && getDefaultImpl() != null) { - getDefaultImpl().killBackgroundProcesses(pkg); - return; + return getDefaultImpl().killBackgroundProcesses(pkg); } _reply.readException(); + _result = (0!=_reply.readInt()); } finally { _reply.recycle(); _data.recycle(); } + return _result; } @Override public boolean isSmartStandByStopServiceEnabled() throws android.os.RemoteException { @@ -4080,8 +4088,8 @@ public static github.tornaco.android.thanos.core.app.IActivityManager getDefault public github.tornaco.android.thanos.core.app.RunningServiceInfoCompat[] getRunningAppServiceForPackage(java.lang.String pkgName) throws android.os.RemoteException; public boolean hasRunningServiceForPackage(java.lang.String pkgName) throws android.os.RemoteException; public android.content.pm.UserInfo getUserInfo(int userHandle) throws android.os.RemoteException; - public void stopService(android.content.Intent intent) throws android.os.RemoteException; - public void killBackgroundProcesses(github.tornaco.android.thanos.core.pm.Pkg pkg) throws android.os.RemoteException; + public boolean stopService(android.content.Intent intent) throws android.os.RemoteException; + public boolean killBackgroundProcesses(github.tornaco.android.thanos.core.pm.Pkg pkg) throws android.os.RemoteException; public boolean isSmartStandByStopServiceEnabled() throws android.os.RemoteException; public void setSmartStandByStopServiceEnabled(boolean enable) throws android.os.RemoteException; public boolean isSmartStandByInactiveEnabled() 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 3389dd8a9..3e9647762 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 @@ -27,6 +27,9 @@ class RunningAppDetailViewModel @Inject constructor(@ApplicationContext private ) val state = _state.asStateFlow() + val appStateChanged get() = _appStateChanged + private var _appStateChanged: Boolean = false + fun copyProcessName(state: RunningProcessState) { ClipboardUtils.copyToClipboard(context, "Process name", state.process.processName) ToastUtils.copiedToClipboard(context) @@ -45,9 +48,13 @@ class RunningAppDetailViewModel @Inject constructor(@ApplicationContext private ToastUtils.copiedToClipboard(context) } - fun stopService(service: RunningService) { - thanox.activityManager.stopService(Intent().apply { component = service.running.service }) - ToastUtils.ok(context) + fun stopService(service: RunningService): Boolean { + return thanox.activityManager.stopService(Intent().apply { + component = service.running.service + putExtra("uid", service.running.uid) + }).also { + if (it) _appStateChanged = true + } } fun forceStop(runningAppState: RunningAppState) { diff --git a/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppState.kt b/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppState.kt index caed18f71..ac789431a 100644 --- a/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppState.kt +++ b/android/app/src/main/java/github/tornaco/android/thanos/process/v2/RunningAppState.kt @@ -19,6 +19,9 @@ package github.tornaco.android.thanos.process.v2 import android.app.ActivityManager import android.os.Parcelable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue import github.tornaco.android.thanos.core.app.RunningAppProcessInfoCompat import github.tornaco.android.thanos.core.pm.AppInfo import kotlinx.parcelize.Parcelize @@ -39,11 +42,15 @@ data class RunningProcessState( val process: RunningAppProcessInfoCompat, val runningServices: List, val sizeStr: String, -) : Parcelable +) : Parcelable { + var isStopped by mutableStateOf(false) +} @Parcelize data class RunningService( val running: ActivityManager.RunningServiceInfo, val serviceLabel: String, val clientLabel: String? = null -) : Parcelable \ No newline at end of file +) : Parcelable { + var isStopped by mutableStateOf(false) +} \ No newline at end of file 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 9836ed03c..3ccdab1b3 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 @@ -20,6 +20,8 @@ package github.tornaco.android.thanos.process.v2 import android.app.ActivityManager import android.os.SystemClock import android.text.format.DateUtils +import androidx.activity.compose.BackHandler +import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll @@ -45,6 +47,7 @@ import github.tornaco.android.thanos.module.compose.common.theme.TypographyDefau import github.tornaco.android.thanos.module.compose.common.widget.AppIcon import github.tornaco.android.thanos.module.compose.common.widget.MD3Badge import github.tornaco.android.thanos.module.compose.common.widget.ThanoxSmallAppBarScaffold +import github.tornaco.android.thanos.util.ToastUtils import kotlinx.coroutines.delay @@ -92,7 +95,7 @@ private fun RunningAppStateDetailsScreen( } }, onBackPressed = { - closeScreen(false) + closeScreen(viewModel.appStateChanged) } ) { Column( @@ -133,6 +136,9 @@ private fun RunningAppStateDetailsScreen( } } } + BackHandler { + closeScreen(viewModel.appStateChanged) + } } @Composable @@ -160,7 +166,9 @@ private fun ServiceSection( ) } else { runningProcessState.runningServices.forEach { service -> - ServiceTile(runningAppState, service, viewModel) + AnimatedVisibility(visible = !service.isStopped) { + ServiceTile(runningAppState, service, viewModel) + } } } } @@ -232,6 +240,8 @@ private fun ServicePopupMenu( service: RunningService, viewModel: RunningAppDetailViewModel ) { + val context = LocalContext.current + DropdownPopUpMenu( popMenuExpend, items = listOf( @@ -252,7 +262,12 @@ private fun ServicePopupMenu( viewModel.copyServiceName(service) } "stop" -> { - viewModel.stopService(service) + if (viewModel.stopService(service)) { + ToastUtils.ok(context) + service.isStopped = true + } else { + ToastUtils.nook(context) + } } else -> { diff --git a/android/internal/Thanox-Internal b/android/internal/Thanox-Internal index 3cde5f810..52aaca164 160000 --- a/android/internal/Thanox-Internal +++ b/android/internal/Thanox-Internal @@ -1 +1 @@ -Subproject commit 3cde5f81093644ed681a679b6b0843b494651d02 +Subproject commit 52aaca164fc2b9996c9f44ddc4b860063467dfbd