Sorry you can't do this.  Apps now can only kill processes of other apps
that are in the background.

On Sat, Aug 7, 2010 at 12:43 AM, Fabrizio Giudici <
fabrizio.giud...@tidalwave.it> wrote:

>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hello.
>
> I'm trying to have restartPackage() work - please note that I'm aware
> of all the discussions related to APIs for restarting another
> application; I'm not trying to do this in production, but during
> functional tests in order to be sure to have the application under
> test to start clean every time (without it, I'm currently forced to
> run one functional test at a time with adb, which is an annoyance). I
> know that restartPackage() has been deprecated in 2.2 and now is
> equivalent to   killBackgroundProcesses(), which is perfectly fine for
> me.
>
> This is the code I'm trying (from setUp() of an
> ActivityInstrumentationTestCase2):
>
>    private void resetApplication()
>      {
>        logger.info("******** RESTARTING APP");
>        final Context context = getInstrumentation().getContext(); //
> also tried with getTargetContext(), even though I suppose getContext()
> is correct
>        final ActivityManager manager =
> (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
>        manager.restartPackage("it.tidalwave.bluebill.mobile.android");
>      }
>
> but I constantly get:
>
> W/ActivityManager( 1280): Permission Denial: restartPackage() from
> pid=6014, uid=10071 requires android.permission.RESTART_PACKAGES
> I/TestRunner( 6014): failed:
>
> testRun(it.tidalwave.bluebill.mobile.android.test.functional.InsertOneObservationFromScratch)
> I/TestRunner( 6014): ----- begin exception -----
> I/TestRunner( 6014):
> I/TestRunner( 6014): java.lang.SecurityException: Permission Denial:
> restartPackage() from pid=6014, uid=10071 requires
> android.permission.RESTART_PACKAGES
> I/TestRunner( 6014):     at
> android.os.Parcel.readException(Parcel.java:1218)
> I/TestRunner( 6014):     at
> android.os.Parcel.readException(Parcel.java:1206)
> I/TestRunner( 6014):     at
>
> android.app.ActivityManagerProxy.restartPackage(ActivityManagerNative.java:2383)
> I/TestRunner( 6014):     at
> android.app.ActivityManager.restartPackage(ActivityManager.java:910)
> I/TestRunner( 6014):     at
>
> it.tidalwave.bluebill.mobile.android.ScenarioTestSupport.resetApplication(ScenarioTestSupport.java:183)
> I/TestRunner( 6014):     at
>
> it.tidalwave.bluebill.mobile.android.ScenarioTestSupport.setUp(ScenarioTestSupport.java:87)
> I/TestRunner( 6014):     at
>
> it.tidalwave.bluebill.mobile.android.test.functional.ObservationScenarioTestSupport.setUp(ObservationScenarioTestSupport.java:48)
> I/TestRunner( 6014):     at
> junit.framework.TestCase.runBare(TestCase.java:125)
> I/TestRunner( 6014):     at
> junit.framework.TestResult$1.protect(TestResult.java:106)
> I/TestRunner( 6014):     at
> junit.framework.TestResult.runProtected(TestResult.java:124)
> I/TestRunner( 6014):     at
> junit.framework.TestResult.run(TestResult.java:109)
> I/TestRunner( 6014):     at
> junit.framework.TestCase.run(TestCase.java:118)
> I/TestRunner( 6014):     at
> android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
> I/TestRunner( 6014):     at
> android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
> I/TestRunner( 6014):     at
>
> android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
> I/TestRunner( 6014):     at
>
> android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
> I/TestRunner( 6014): ----- end exception -----
>
>
> Of course I put the required permission in the AndroidManifest.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <manifest package="it.tidalwave.bluebill.mobile.android.tests"
> android:versionCode="1545"
> xmlns:android="http://schemas.android.com/apk/res/android";
> android:versionName="0.14.0-SNAPSHOT">
>  <uses-sdk android:minSdkVersion="3"/>
>  <uses-permission android:name="android.permission.INJECT_EVENT"/>
>  <uses-permission android:name="android.permission.RESTART_PACKAGES"/>
>  <application android:label="blueBill Mobile Functional Tests">
>    <uses-library android:name="android.test.runner"/>
>  </application>
>  <instrumentation
> android:name="android.test.InstrumentationTestRunner"
> android:targetPackage="it.tidalwave.bluebill.mobile.android"
> android:label="Tests for blueBill Mobile for Android."/>
> </manifest>
>
> The app with tests is signed with the same signature of the app under
> test (the debug key). It happens both with the emulator (1.5 and 2.2)
> and a Motorola Droid (2.1). Of course the 2.2 with the variant that
> the required permission is android.permission.KILL_BACKGROUND_PROCESSES.
>
>
> Why am I still getting the error? Thanks.
>
> - --
> Fabrizio Giudici - Java Architect, Project Manager
> Tidalwave s.a.s. - "We make Java work. Everywhere."
> java.net/blog/fabriziogiudici - www.tidalwave.it/people
> fabrizio.giud...@tidalwave.it
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkxdDr4ACgkQeDweFqgUGxcRFgCgkkyp8VcxyqPCfUkqs7U6HQ5R
> s5YAn3V2dETNVU7Lga6vHhf7JQB1WQEm
> =kRZ5
> -----END PGP SIGNATURE-----
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to