framework层修改:
t0_sys/frameworks/base/core/api/current.txt
method @RequiresPermission(android.Manifest.permission.REBOOT) public void reboot(@Nullable String);
+ method public void rebootp();
t0_sys/frameworks/base/core/java/android/os/IPowerManager.aidl
+void rebootp();
t0_sys/frameworks/base/core/java/android/os/PowerManager.java
+ public void rebootp(){
+ try{
+ mService.rebootp();
+ } catch (RemoteException e){
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
t0_sys/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java
+import java.io.IOException;+ @Override // Binder call
+ public void rebootp(){
+ try {
+ Runtime.getRuntime().exec("reboot -p"); //关机
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
由于添加了系统API,执行lunch后,先执行 make update-api 命令更新系统API 后再执行 make -j24编译源码
APP使用反射调用关机接口
1.编写反射接口
public class PowerManagerUtils {private static final String CLASS = "android.os.PowerManager";private static final String UART_POWER_OPEN = "rebootp";public static void open(PowerManager manager) {try {Class<?> spClass = Class.forName(CLASS);Method getMethod = spClass.getMethod(UART_POWER_OPEN);getMethod.invoke(manager);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (NoSuchMethodException e) {e.printStackTrace();} catch (IllegalArgumentException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();}}
2.调用反射执行PowerManager类中的rebootp方法
PowerManager powerManager;
powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManagerUtils.open(powerManager);