Home > Google Android > SleepTimer: Stop Services attempt without root [failed]

SleepTimer: Stop Services attempt without root [failed]

Problem: With Android 2.2 (Froyo) packages can’t be force closed through restartPackage() anymore. Exactly this is what SleepTimer relied on to turn off the different Services which are running music.

Thanks to Corsin Camichel I found an example on how Google force closes packages in Android 2.2 (Froyo). This happens over an internal API. Method name is: forceStopPackage(String pkgName).

So I tried my luck with reflection.

1
2
3
4
5
6
7
8
Class c = Class.forName("android.app.ActivityManagerNative");
Method getDefaultMethod = c.getMethod("getDefault");
getDefaultMethod.setAccessible(true);
Object nativeManager = getDefaultMethod.invoke(null);
c = nativeManager.getClass();
Method forceStopPackageMethod = c.getMethod("forceStopPackage", String.class);
forceStopPackageMethod.setAccessible(true);
forceStopPackageMethod.invoke(nativeManager, pkgName);

But I get an exception when calling the last line.

java.lang.SecurityException: Permission Denial: forceStopPackage() from pid=1965, uid=10075 requires android.permission.FORCE_STOP_PACKAGES

I tried adding it to the AndroidManifest.xml. But without luck.

If somebody figures out how to get this working, I would be happy for a message! :) Or an e-mail from Google how to get this working would be nice.

Update:

According to velazcod and rac2030 it is not possible to get the required permissions for this :(

The only problem is that in order to use this method, you need the “android.permission.FORCE_STOP_PACKAGES” permission, and that permission requires a “signature” protectionLevel, so the system will not grant it unless the app is signed with the same signature as the system :(

http://pastebin.com/XYc299Uz

  1. 20. July 2010, 16:26 | #1

    Ok, now you’re in the deep waters. Calling internal API is a nightmare.

    Is there a good reason why Google removed the regular API? It’s not nice to remove stuff, because you always break nice and usefull applications.

  2. 20. July 2010, 16:54 | #2

    Siehe http://pastebin.com/XYc299Uz

    Diese permission bekommst du nur als System applikation bzw. system signiert

  3. 20. July 2010, 17:56 | #3

    Hey Patrick,

    The only problem is that in order to use this method, you need the “android.permission.FORCE_STOP_PACKAGES” permission, and that permission requires a “signature” protectionLevel, so the system will not grant it unless the app is signed with the same signature as the system :(

  4. rikmer
    22. July 2010, 12:52 | #4

    I read that the app musicsleep manages to stop the android standard music player. Never tested it though.

  1. Bisher keine Trackbacks