Reputation: 709
I try to use goToSleep()
method to put phone into deep sleep.
Program was installed into /system/app directory so Android System Info says, that it is a system application, but if i try call goToSleep() i get this error
Neither user 10085 nor current process has android.permission.DEVICE_POWER.
Code sampling:
IPowerManager mPowerManager = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
long time = SystemClock.uptimeMillis() + 1000;
try {
mPowerManager.goToSleep(time);
} catch (RemoteException e) {
Toast.makeText(getApplicationContext(), "error: " + e.toString(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
AndroidManifest.xml
<permission android:name="android.permission.DEVICE_POWER"/>
<uses-permission android:name="android.permission.DEVICE_POWER" />
<permission android:name="android.permission.REBOOT"/>
<uses-permission android:name="android.permission.REBOOT"/>
As i understand, if i run system application than i can gain access to all android hide or system functions, or i'm wrong?
Things that i try to do to run app as system applicaiton:
Maybe someone else has already encountered this problem. Any suggestions would be helpful
Upvotes: 5
Views: 13167
Reputation: 990
The DEVICE_POWER permission is not accessable by third-party applications like yours.
public static final String DEVICE_POWER Added in API level 1
Allows low-level access to power management.
Not for use by third-party applications. Constant Value: "android.permission.DEVICE_POWER"
Upvotes: 2
Reputation: 4936
by looking in source codes I see you need signature permission
, I think it's not enough to be a system app, you need to be signed with same cert of the rom, the one in /system/framework/android/framework-res.apk
Upvotes: 3
Reputation: 3527
Just remove the first and thirds lines in the manifest above and it should be fine. You should call ... and not .... Your code looks fine.
Upvotes: 0