Android system application DEVICE_POWER permission

2019-04-11 21:31发布

问题:

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:

  1. copy file to /system/app
  2. chown 0:0
  3. chmod 4755
  4. chmod ugo+s

Maybe someone else has already encountered this problem. Any suggestions would be helpful

回答1:

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



回答2:

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"



回答3:

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.