Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 840
oscar Avatar asked Aug 11 '10 08:08

oscar


2 Answers

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.

like image 191
Sarwar Erfan Avatar answered Nov 15 '22 06:11

Sarwar Erfan


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.

like image 21
Aleadam Avatar answered Nov 15 '22 06:11

Aleadam