Call system service to reboot (#2425)

This commit is contained in:
Howard Wu 2023-03-07 00:40:02 +08:00 committed by GitHub
parent 97f74d8b2e
commit 17e1fe3172
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 11 deletions

View File

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

View File

@ -326,7 +326,7 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
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);
ConfigManager.reboot();
} else {
new BlurBehindDialogBuilder(activity, R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons)
.setTitle(R.string.force_stop_dlg_title)
@ -588,7 +588,7 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
}
buttonView.setChecked(!isChecked);
} else if (appInfo.packageName.equals("android")) {
fragment.showHint(R.string.reboot_required, true, R.string.reboot, v -> ConfigManager.reboot(false));
fragment.showHint(R.string.reboot_required, true, R.string.reboot, v -> ConfigManager.reboot());
} else if (denyList.contains(appInfo.packageName)) {
fragment.showHint(activity.getString(R.string.deny_list, appInfo.label), true);
}

View File

@ -153,7 +153,7 @@ public class SettingsFragment extends BaseFragment {
prefDexObfuscate.setEnabled(installed);
prefDexObfuscate.setChecked(!installed || ConfigManager.isDexObfuscateEnabled());
prefDexObfuscate.setOnPreferenceChangeListener((preference, newValue) -> {
parentFragment.showHint(R.string.reboot_required, true, R.string.reboot, v -> ConfigManager.reboot(false));
parentFragment.showHint(R.string.reboot_required, true, R.string.reboot, v -> ConfigManager.reboot());
return ConfigManager.setDexObfuscateEnabled((boolean) newValue);
});
}

View File

@ -446,9 +446,8 @@ public class LSPManagerService extends ILSPManagerService.Stub {
}
@Override
public void reboot(boolean shutdown) {
var value = shutdown ? "shutdown" : "reboot";
SystemProperties.set("sys.powerctl", value);
public void reboot() throws RemoteException {
PowerService.reboot(false, null, false);
}
@Override
@ -585,7 +584,7 @@ public class LSPManagerService extends ILSPManagerService.Stub {
if (exit == 0) {
fdw.write("- Reboot after 5s\n".getBytes());
Thread.sleep(5000);
reboot(false);
reboot();
} else {
var s = "! Flash failed, exit with " + exit + "\n";
fdw.write(s.getBytes());
@ -594,7 +593,7 @@ public class LSPManagerService extends ILSPManagerService.Stub {
proc.destroy();
fdw.write("! Timeout, abort\n".getBytes());
}
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | RemoteException e) {
Log.e(TAG, "flashZip: ", e);
}
}

View File

@ -0,0 +1,63 @@
/*
* <!--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) 2023 LSPosed Contributors-->
*/
package org.lsposed.lspd.service;
import static android.content.Context.POWER_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, "PowerManager is dead");
binder.unlinkToDeath(this, 0);
binder = null;
pm = null;
}
};
private static IPowerManager getPowerManager() {
if (binder == null || pm == null) {
binder = ServiceManager.getService(POWER_SERVICE);
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

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