2

I have a library called com.example.library, containing a service called com.example.library.http.RestService. The library's manifest contains these elements:

<uses-permission android:name="com.example.library.permission.REST_PERMISSION" />

<permission
    android:name="com.example.library.permission.REST_PERMISSION"
    android:protectionLevel="signature" />

<application ...>
    <service
        android:name="com.example.library.http.RestService"
        android:enabled="true"
        android:permission="com.example.library.permission.REST_PERMISSION" 
        android:exported="true" >
        <intent-filter>
            <action android:name="com.example.library.LAUNCH_REST_SERVICE" />
        </intent-filter>
    </service>
</application>

I'm using that library in an app called com.example.testapp. TestApp's manifest repeats exactly the same elements as the library above. This works fine in the emulator running 4.0.3, and on a nexus 4 running 4.2.2, but when I try to use it on an HTC Wildfire S running 2.3.5, it falls over the moment it tries to launch the service, with the following exception:

java.lang.SecurityException: Not allowed to start service Intent 
{ act=com.example.library.LAUNCH_REST_SERVICE pkg=com.example.testapp (has extras) }
without permission com.example.library.permission.REST_PERMISSION

I'm launching the service with the following code:

Intent intent = new Intent();
intent.setAction( "com.example.library.LAUNCH_REST_SERVICE" );
intent.setPackage( "com.example.testapp" );

[setting some extras]

startService( intent );

I've been scouring the web for help, and have read every related Stack Overflow question I can find, but just can't find anything I'm missing.

Niall
  • 457
  • 3
  • 8
  • Try reversing the order of your `` and `` elements, to define the permission before you try using it. – CommonsWare Jun 05 '13 at 12:04
  • @CommonsWare thanks for the suggestion, but unfortunately it made no difference. – Niall Jun 05 '13 at 13:05
  • Try fully uninstalling both apps after making the aforementioned change, then install them again and see if that helps. – CommonsWare Jun 05 '13 at 13:06
  • @CommonsWare I may have explained something badly, as there's only the 1 app to remove, it has the library built into it. I tried uninstalling it but am still getting the same issue. I have just tried it on a 2.2 emulator and it launched fine though, so now I'm going to try factory resetting the Wildfire. – Niall Jun 05 '13 at 14:05
  • So, after it worked on a 2.2 and 2.3 emulator, I tried factory resetting the Wildfire S. Now it works fine. – Niall Jun 05 '13 at 14:24
  • If the Wildfire continues to give you grief, consider a sledgehammer. :-) – CommonsWare Jun 05 '13 at 14:25
  • @CommonsWare thanks for your attempts to help - tricky to solve such an illogical problem. – Niall Jun 28 '13 at 16:27

1 Answers1

0

So, after it worked on a 2.2 and 2.3 emulator, I tried factory resetting the Wildfire S. Now it works fine.

I think this is similar to this problem: Intent custom permission not working - if I'd renamed my app's package it probably would've worked too.

Community
  • 1
  • 1
Niall
  • 457
  • 3
  • 8