0

I have an Android application in which I have implemented a service which has been declared as "exported" in Android Manifest. Lot of different applications are installed on this device which are trying to start this exported service. All of them are using this code to start the exported service :

    MY_ACTION = "com.phantom.foobar.action.xyz"
    PACKAGE_NAME = "com.phantom.foobar"
    CLASS_NAME = "com.phantom.foobar.IpcService"  


    public static void startSaveUrlAction(Context context, String foo, String bar) {
        Intent intent = new Intent(MY_ACTION);
        intent.setClassName(PACKAGE_NAME, CLASS_NAME);
        intent.putExtra(FOO, foo);
        intent.putExtra(BAR, bar);
        context.startService(intent);
    }

Service description inside application tag in Manifest file:

<service
    android:name=".IpcService"
    android:exported="true" />

Now the problem is some applications are able to start it and some are not. Here's logcat information for the applications which are not able to start that service :

01-02 16:04:05.574  1385  2698 W ActivityManager: Unable to start service Intent { cmp=another.music.player/com.phantom.foobar.IpcService } U=0: not found
01-02 16:04:05.575  1385  2699 W ActivityManager: Unable to start service Intent { cmp=another.music.player/com.phantom.foobar.IpcService } U=0: not found

If I'm not wrong, { cmp=another.music.player/com.phantom.foobar.IpcService } this is a component name comprised of { cmp = package_name/class_name }. Even though I have specified PACKAGE_NAME as com.phantom.foobar but it's trying to start the wrong intent. In this case, another.music.player is the package name of the application which is trying to start an exported service.

This only happens with some of the applications. I want to know why this is happening. Is there any attribute or something(some kind of attribute which can be set in Android Manifest) which can prevent an application to start an intent outside the package ?

Abstracted Details :

I'm using Xposed Framework which allows me to hook method of other applications. I have hooked a method from Android API. Now whenever that method is being called in other applications, I extract some information from that application and using its context, I start exported IntentService of com.phantom.foobar, hence passing information to my application using above given function.

Ashish Bansal
  • 79
  • 1
  • 6
  • http://stackoverflow.com/questions/2708915/how-do-i-start-a-service-which-is-defined-in-a-different-package – Raghunandan Jan 02 '17 at 11:12
  • @Raghunandan It's already working with some applications. Moreover, according to logcat, it's trying to start the wrong intent. – Ashish Bansal Jan 02 '17 at 11:19
  • 1
    Is the service maybe still running from another package when it fails? I'm currently digging through the sources, your error gets thrown here: https://android.googlesource.com/platform/frameworks/base/+/master/services/core/java/com/android/server/am/ActiveServices.java#1301 Line 1287 might also be interesting, that's why it even gets into the `if (r==null)` block. – Maxr1998 Jan 05 '17 at 18:08
  • @Maxr1998 I checked code from `Context.startService()` to `ActiveServices.retrieveServiceLocked()`. For this function call, `isBindExternal` would be `false`. In line 1279, it finds the `ServiceRecord` using component name. I think it's returning `null` because the component name is wrong (as printed in `unable to start service....`). So, `r` is `null` in line 1279. Condition 1281 evaluates to true but `r` is still `null` in line 1283 because of wrong component name. So, it gets into `if (r == null)` block. – Ashish Bansal Jan 06 '17 at 18:10
  • Then `rinfo` is again `null` because of wrong component name in intent because of which `slog` statement is executed. – Ashish Bansal Jan 06 '17 at 18:10
  • @Maxr1998 Nope, if the service is still running, then intent is added into the IntentService queue and processed once it's done with the current intent being processed. – Ashish Bansal Jan 06 '17 at 18:11

0 Answers0