Call system service to reboot (#2425)
This commit is contained in:
parent
97f74d8b2e
commit
17e1fe3172
|
|
@ -211,9 +211,9 @@ public class ConfigManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean reboot(boolean shutdown) {
|
public static boolean reboot() {
|
||||||
try {
|
try {
|
||||||
LSPManagerServiceHolder.getService().reboot(shutdown);
|
LSPManagerServiceHolder.getService().reboot();
|
||||||
return true;
|
return true;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(App.TAG, Log.getStackTraceString(e));
|
Log.e(App.TAG, Log.getStackTraceString(e));
|
||||||
|
|
|
||||||
|
|
@ -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);
|
ConfigManager.startActivityAsUserWithFeature(new Intent(ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", info.packageName, null)), module.userId);
|
||||||
} else if (itemId == R.id.menu_force_stop) {
|
} else if (itemId == R.id.menu_force_stop) {
|
||||||
if (info.packageName.equals("android")) {
|
if (info.packageName.equals("android")) {
|
||||||
ConfigManager.reboot(false);
|
ConfigManager.reboot();
|
||||||
} else {
|
} else {
|
||||||
new BlurBehindDialogBuilder(activity, R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons)
|
new BlurBehindDialogBuilder(activity, R.style.ThemeOverlay_MaterialAlertDialog_Centered_FullWidthButtons)
|
||||||
.setTitle(R.string.force_stop_dlg_title)
|
.setTitle(R.string.force_stop_dlg_title)
|
||||||
|
|
@ -588,7 +588,7 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
|
||||||
}
|
}
|
||||||
buttonView.setChecked(!isChecked);
|
buttonView.setChecked(!isChecked);
|
||||||
} else if (appInfo.packageName.equals("android")) {
|
} 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)) {
|
} else if (denyList.contains(appInfo.packageName)) {
|
||||||
fragment.showHint(activity.getString(R.string.deny_list, appInfo.label), true);
|
fragment.showHint(activity.getString(R.string.deny_list, appInfo.label), true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ public class SettingsFragment extends BaseFragment {
|
||||||
prefDexObfuscate.setEnabled(installed);
|
prefDexObfuscate.setEnabled(installed);
|
||||||
prefDexObfuscate.setChecked(!installed || ConfigManager.isDexObfuscateEnabled());
|
prefDexObfuscate.setChecked(!installed || ConfigManager.isDexObfuscateEnabled());
|
||||||
prefDexObfuscate.setOnPreferenceChangeListener((preference, newValue) -> {
|
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);
|
return ConfigManager.setDexObfuscateEnabled((boolean) newValue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -446,9 +446,8 @@ public class LSPManagerService extends ILSPManagerService.Stub {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reboot(boolean shutdown) {
|
public void reboot() throws RemoteException {
|
||||||
var value = shutdown ? "shutdown" : "reboot";
|
PowerService.reboot(false, null, false);
|
||||||
SystemProperties.set("sys.powerctl", value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -585,7 +584,7 @@ public class LSPManagerService extends ILSPManagerService.Stub {
|
||||||
if (exit == 0) {
|
if (exit == 0) {
|
||||||
fdw.write("- Reboot after 5s\n".getBytes());
|
fdw.write("- Reboot after 5s\n".getBytes());
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
reboot(false);
|
reboot();
|
||||||
} else {
|
} else {
|
||||||
var s = "! Flash failed, exit with " + exit + "\n";
|
var s = "! Flash failed, exit with " + exit + "\n";
|
||||||
fdw.write(s.getBytes());
|
fdw.write(s.getBytes());
|
||||||
|
|
@ -594,7 +593,7 @@ public class LSPManagerService extends ILSPManagerService.Stub {
|
||||||
proc.destroy();
|
proc.destroy();
|
||||||
fdw.write("! Timeout, abort\n".getBytes());
|
fdw.write("! Timeout, abort\n".getBytes());
|
||||||
}
|
}
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException | RemoteException e) {
|
||||||
Log.e(TAG, "flashZip: ", e);
|
Log.e(TAG, "flashZip: ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ interface ILSPManagerService {
|
||||||
|
|
||||||
void forceStopPackage(String packageName, int userId) = 23;
|
void forceStopPackage(String packageName, int userId) = 23;
|
||||||
|
|
||||||
void reboot(boolean shutdown) = 24;
|
void reboot() = 24;
|
||||||
|
|
||||||
boolean uninstallPackage(String packageName, int userId) = 25;
|
boolean uninstallPackage(String packageName, int userId) = 25;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue