Why does my app throw an `android.permission.REBOOT SecurityException`?
Asked Answered
H

6

5

I wrote an Android app that uses android.os.PowerManager.reboot(), and I added <uses-permission android:name="android.permission.REBOOT" /> in my AndroidManifest.xml. However, when I run the app, it always throws the following exception:

java.lang.SecurityException: Neither user 10039 nor current process has android.permission.REBOOT. at android.os.Parcel.readException(Parcel.java:1247)
at android.os.Parcel.readException(Parcel.java:1247)
at android.os.Parcel.readException(Parcel.java:1235)
at android.os.IPowerManager$Stub$Proxy.reboot(IPowerManager.java:427)
at android.os.PowerManager.reboot(PowerManager.java:481)
at Test.testPower(Test.java:374)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
at android.os.Parcel.readException(Parcel.java:1247)
at android.os.Parcel.readException(Parcel.java:1235)
at android.os.IPowerManager$Stub$Proxy.reboot(IPowerManager.java:427)
at android.os.PowerManager.reboot(PowerManager.java:481)
at com.fsl.cts.FSLPlaybackTest.testPower(FSLPlaybackTest.java:374)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

Is the anything I'm doing wrong, or does froyo have some problem with rebooting?

Hobgoblin answered 11/8, 2010 at 8:5 Comment(1)
what exactly do you have added in the manifest file? can you post it?Margarine
R
9

You cannot get this permission. Only system applications and applications signed with the same key that was used to sign the firmware will be able to get that permission.

Why do you need to reboot? If you tell the necessity of rebooting, then may be someone can suggest you a better way to accomplish the same thing without rebooting.

Retreat answered 11/8, 2010 at 12:55 Comment(0)
D
6

It can't be done in stock android phones. But, as I posted in other similar question, if the phone is rooted, then you have no problem at all:

try {
    Runtime.getRuntime().exec("su");
    Runtime.getRuntime().exec("reboot"); }
catch (IOException e) { }

For an explanation, follow the link above.

Depilate answered 23/1, 2011 at 7:47 Comment(0)
E
3

As far as I know this permission can only be grated to system apps, "user applications" can't get that permission

Ensue answered 11/8, 2010 at 9:58 Comment(0)
H
2

To reboot the device using code needs REBOOT permission.

This permission is available for system applications. You can make your application a system application only if you have the certificate used in building the system image.

  1. Please check the link below on applications being signed with the platform certificate https://groups.google.com/d/msg/android-developers/wsRr-VhzKZ4/dAUbLPszOQ8J
  2. http://developer.android.com/guide/topics/security/security.html
Hodometer answered 18/8, 2011 at 11:25 Comment(0)
B
1

It can work:

 String cmd = "su -c shutdown";
         try{
         Runtime.getRuntime().exec(cmd);
   }catch(IOException e){
       e.printStackTrace();
   }
         }

OtherWise,you must add android:sharedUserId="android.uid.system" into your application

Berkie answered 17/5, 2012 at 16:14 Comment(0)
F
0

If you have root, you can use any of those commands:

"hard root" :

reboot

"soft reboot" :

setprop ctl.restart surfaceflinger; setprop ctl.restart zygote
Furnace answered 3/11, 2014 at 23:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.