Skip to content

Commit

Permalink
[app] stop service
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornaco committed Apr 27, 2022
1 parent 44984e8 commit 6f02a88
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,11 +42,15 @@ data class RunningProcessState(
val process: RunningAppProcessInfoCompat,
val runningServices: List<RunningService>,
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
) : Parcelable {
var isStopped by mutableStateOf(false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -92,7 +95,7 @@ private fun RunningAppStateDetailsScreen(
}
},
onBackPressed = {
closeScreen(false)
closeScreen(viewModel.appStateChanged)
}
) {
Column(
Expand Down Expand Up @@ -133,6 +136,9 @@ private fun RunningAppStateDetailsScreen(
}
}
}
BackHandler {
closeScreen(viewModel.appStateChanged)
}
}

@Composable
Expand Down Expand Up @@ -160,7 +166,9 @@ private fun ServiceSection(
)
} else {
runningProcessState.runningServices.forEach { service ->
ServiceTile(runningAppState, service, viewModel)
AnimatedVisibility(visible = !service.isStopped) {
ServiceTile(runningAppState, service, viewModel)
}
}
}
}
Expand Down Expand Up @@ -232,6 +240,8 @@ private fun ServicePopupMenu(
service: RunningService,
viewModel: RunningAppDetailViewModel
) {
val context = LocalContext.current

DropdownPopUpMenu(
popMenuExpend,
items = listOf(
Expand All @@ -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 -> {

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

0 comments on commit 6f02a88

Please sign in to comment.