[core] Remove PowerService

This commit is contained in:
vvb2060 2021-08-19 01:22:18 +08:00
parent 818f576f25
commit 036b87caad
6 changed files with 10 additions and 70 deletions

View File

@ -212,9 +212,9 @@ public class ConfigManager {
}
}
public static boolean reboot(boolean confirm, String reason, boolean wait) {
public static boolean reboot(boolean shutdown) {
try {
LSPManagerServiceHolder.getService().reboot(confirm, reason, wait);
LSPManagerServiceHolder.getService().reboot(shutdown);
return true;
} catch (RemoteException e) {
Log.e(App.TAG, Log.getStackTraceString(e));

View File

@ -295,7 +295,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
ConfigManager.startActivityAsUserWithFeature(new Intent(ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", info.packageName, null)), module.userId);
} else if (itemId == R.id.menu_force_stop) {
if (info.packageName.equals("android")) {
ConfigManager.reboot(false, null, false);
ConfigManager.reboot(false);
} else {
new AlertDialog.Builder(activity)
.setTitle(R.string.force_stop_dlg_title)
@ -479,7 +479,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
buttonView.setChecked(!isChecked);
} else if (appInfo.packageName.equals("android")) {
Snackbar.make(fragment.binding.snackbar, R.string.reboot_required, Snackbar.LENGTH_SHORT)
.setAction(R.string.reboot, v -> ConfigManager.reboot(false, null, false))
.setAction(R.string.reboot, v -> ConfigManager.reboot(false))
.show();
}
}

View File

@ -154,7 +154,7 @@ public class SettingsFragment extends BaseFragment {
SettingsFragment fragment = (SettingsFragment) getParentFragment();
if (result && fragment != null) {
Snackbar.make(fragment.binding.snackbar, R.string.reboot_required, Snackbar.LENGTH_SHORT)
.setAction(R.string.reboot, v -> ConfigManager.reboot(false, null, false))
.setAction(R.string.reboot, v -> ConfigManager.reboot(false))
.show();
}
return result;

View File

@ -41,6 +41,7 @@ import org.lsposed.lspd.ILSPManagerService;
import org.lsposed.lspd.models.Application;
import org.lsposed.lspd.models.UserInfo;
import java.io.FileDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedList;
import java.util.List;
@ -194,8 +195,9 @@ public class LSPManagerService extends ILSPManagerService.Stub {
}
@Override
public void reboot(boolean confirm, String reason, boolean wait) throws RemoteException {
PowerService.reboot(confirm, reason, wait);
public void reboot(boolean shutdown) {
var value = shutdown ? "shutdown" : "reboot";
SystemProperties.set("sys.powerctl", value);
}
@Override

View File

@ -1,62 +0,0 @@
/*
* <!--This file is part of LSPosed.
*
* LSPosed is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LSPosed is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LSPosed. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright (C) 2021 LSPosed Contributors-->
*/
package org.lsposed.lspd.service;
import static org.lsposed.lspd.service.ServiceManager.TAG;
import android.os.IBinder;
import android.os.IPowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
public class PowerService {
private static IPowerManager pm = null;
private static IBinder binder = null;
private static final IBinder.DeathRecipient recipient = new IBinder.DeathRecipient() {
@Override
public void binderDied() {
Log.w(TAG, "pm is dead");
binder.unlinkToDeath(this, 0);
binder = null;
pm = null;
}
};
public static IPowerManager getPowerManager() {
if (binder == null && pm == null) {
binder = ServiceManager.getService("power");
if (binder == null) return null;
try {
binder.linkToDeath(recipient, 0);
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(e));
}
pm = IPowerManager.Stub.asInterface(binder);
}
return pm;
}
public static void reboot(boolean confirm, String reason, boolean wait) throws RemoteException {
IPowerManager pm = getPowerManager();
if (pm == null) return;
pm.reboot(confirm, reason, wait);
}
}

View File

@ -42,7 +42,7 @@ interface ILSPManagerService {
void forceStopPackage(String packageName, int userId) = 23;
void reboot(boolean confirm, String reason, boolean wait) = 24;
void reboot(boolean shutdown) = 24;
boolean uninstallPackage(String packageName, int userId) = 25;