2

I need to be able to access the reboot feature. Security does not allow me to do this. The platform is a custom build so this will only be part of my AOSP based build.

I was wondering how I can make changes to the AOSP and be able to call system functions to do the reboot. Is it possible to add a custom INTENT that I can call from user space that will then do the reboot command for me?

The following code does not work from the user level app so I was thinking I could do this from the AOSP build and add a custom intent that I can call. Possible?

Process chperm;
try {
    Runtime rt = Runtime.getRuntime();
    chperm = rt.exec(new String[] {"/system/bin/reboot"});

    chperm.waitFor();

} catch (IOException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
}
aminography
  • 21,986
  • 13
  • 70
  • 74

1 Answers1

1

You have to be a system app. Some permissions like reboot are only given to system apps. You have sign you app with platform certificate ( generate a jks from platform.pk8 and platform.x509.pem )

Then request the reboot permission in the manifest:

<uses-permission android:name="android.permission.REBOOT" />

Then you can call reboot:

PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
pm.reboot(null)

Be sure to use your own certificates, not the default ones from AOSP. Everyone has them and could make their app a system app in you platform

Rick Sanchez
  • 4,528
  • 2
  • 27
  • 53
  • I know about doing that but then I have to sign my app with the platform keys. What I was looking to do was to find out how to add a custom intent to the existing AOSP and rebuild that and I can call this intent from any app and have the system do the reboot. This is a custom system for data logging so there would be no security issues. – Dave McLaughlin Nov 06 '19 at 10:21
  • In that case, if you don't care about security, you can remove the permission check from pm.reboot(null) call. http://androidxref.com/7.1.2_r36/xref/frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java#3625 – Rick Sanchez Nov 06 '19 at 12:09
  • Otherwise, if you really want to do you own Intent... Create a broadcast receiver in PowerManagerService for the ACTION you fire from the app. And call reboot method inside the receiver – Rick Sanchez Nov 06 '19 at 12:11