5

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

Vlad Yarovyi
  • 709
  • 1
  • 8
  • 16

3 Answers3

3

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

sherpya
  • 4,890
  • 2
  • 34
  • 50
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"

Hasan Masud
  • 982
  • 9
  • 17
0

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.

Lior Ohana
  • 3,467
  • 4
  • 34
  • 49
  • Thnx for answer, but it doesn't help me - i get the same error. I tried different things and it looks like that if you don't creating your own firmware and don't sign your application with same key as firmware you can't use hide android.os functions. – Vlad Yarovyi Sep 25 '11 at 22:13