[app] Add force stop and reboot
This commit is contained in:
parent
e844450b23
commit
fad2cf3064
|
|
@ -229,4 +229,24 @@ public class ConfigManager {
|
|||
throw new PackageManager.NameNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean forceStopPackage(String packageName, int userId) {
|
||||
try {
|
||||
LSPosedManagerServiceClient.forceStopPackage(packageName, userId);
|
||||
return true;
|
||||
} catch (RemoteException | NullPointerException e) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean reboot(boolean confirm, String reason, boolean wait) {
|
||||
try {
|
||||
LSPosedManagerServiceClient.reboot(confirm, reason, wait);
|
||||
return true;
|
||||
} catch (RemoteException | NullPointerException e) {
|
||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -327,6 +327,17 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
}
|
||||
} else if (itemId == R.id.menu_app_info) {
|
||||
activity.startActivity(new Intent(ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", info.packageName, null)));
|
||||
} else if (itemId == R.id.menu_force_stop) {
|
||||
if (info.packageName.equals("android")) {
|
||||
ConfigManager.reboot(false, null, false);
|
||||
} else {
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.force_stop_dlg_title)
|
||||
.setMessage(R.string.force_stop_dlg_text)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> ConfigManager.forceStopPackage(info.packageName, info.uid / 100000))
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -488,6 +499,10 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
checkedList.remove(appInfo.application);
|
||||
}
|
||||
buttonView.setChecked(!isChecked);
|
||||
} else if (appInfo.packageName.equals("android")) {
|
||||
Snackbar.make(activity.binding.snackbar, R.string.reboot_required, Snackbar.LENGTH_SHORT)
|
||||
.setAction(R.string.reboot, v -> ConfigManager.reboot(false, null, false))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -130,4 +130,14 @@ public class LSPosedManagerServiceClient {
|
|||
ensureService();
|
||||
return service.getPackageInfo(packageName, flags, uid);
|
||||
}
|
||||
|
||||
public static void forceStopPackage(String packageName, int userId) throws RemoteException, NullPointerException {
|
||||
ensureService();
|
||||
service.forceStopPackage(packageName, userId);
|
||||
}
|
||||
|
||||
public static void reboot(boolean confirm, String reason, boolean wait) throws RemoteException, NullPointerException {
|
||||
ensureService();
|
||||
service.reboot(confirm, reason, wait);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class AppListActivity extends BaseActivity {
|
|||
private ScopeAdapter scopeAdapter;
|
||||
|
||||
private SearchView.OnQueryTextListener searchListener;
|
||||
private ActivityAppListBinding binding;
|
||||
public ActivityAppListBinding binding;
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
public ActivityResultLauncher<String> backupLauncher;
|
||||
public ActivityResultLauncher<String[]> restoreLauncher;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ This file is part of LSPosed.
|
||||
~
|
||||
~ LSPosed is free software: you can redistribute it and/or modify
|
||||
|
|
@ -23,6 +22,9 @@
|
|||
<item
|
||||
android:id="@+id/menu_launch"
|
||||
android:title="@string/app_launch" />
|
||||
<item
|
||||
android:id="@+id/menu_force_stop"
|
||||
android:title="@string/force_stop" />
|
||||
<item
|
||||
android:id="@+id/menu_compile_speed"
|
||||
android:title="@string/compile_speed" />
|
||||
|
|
|
|||
|
|
@ -175,4 +175,9 @@
|
|||
<string name="theme_color">主题颜色</string>
|
||||
<string name="logs_clear_failed_2">日志清理失败</string>
|
||||
<string name="view_in_repo">在仓库中查看</string>
|
||||
<string name="force_stop">强行停止</string>
|
||||
<string name="force_stop_dlg_title">要强行停止吗?</string>
|
||||
<string name="force_stop_dlg_text">强行停止某个应用可能会导致其出现异常。</string>
|
||||
<string name="reboot_required">需要重新启动才能应用此更改</string>
|
||||
<string name="reboot">重新启动</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -174,4 +174,9 @@
|
|||
<string name="theme_color">Theme color</string>
|
||||
<string name="logs_clear_failed_2">Failed to clear the log</string>
|
||||
<string name="view_in_repo">View in Repo</string>
|
||||
<string name="force_stop">Force stop</string>
|
||||
<string name="force_stop_dlg_title">Force stop?</string>
|
||||
<string name="force_stop_dlg_text">If you force stop an app, it may misbehave.</string>
|
||||
<string name="reboot_required">Reboot is required for this change to apply</string>
|
||||
<string name="reboot">Reboot</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -65,4 +65,10 @@ public class ActivityManagerService {
|
|||
if (am == null) return -1;
|
||||
return am.broadcastIntentWithFeature(caller, callingFeatureId, intent, resolvedType, resultTo, resultCode, resultData, map, requiredPermissions, appOp, options, serialized, sticky, userId);
|
||||
}
|
||||
|
||||
public static void forceStopPackage(String packageName, int userId) throws RemoteException {
|
||||
IActivityManager am = getActivityManager();
|
||||
if (am == null) return;
|
||||
am.forceStopPackage(packageName, userId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue