With robolectric 3.3, I am trying to get the package manager to return correct values for queryIntentServices so that the Firebase Job Dispatcher works.
In my AndroidManifest.xml I have:
<service
android:name="com.jongla.soundmash.service.SoundMashService"
android:exported="false">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
</intent-filter>
</service>
And in my test application class that Robolectric invokes I have put:
val executeIntent = Intent("com.firebase.jobdispatcher.ACTION_EXECUTE")
executeIntent.setClassName(RuntimeEnvironment.application, "com.jongla.soundmash.service.SoundMashService")
Shadows.shadowOf(packageManager)
.addResolveInfoForIntent(executeIntent, ResolveInfo().apply { serviceInfo = ServiceInfo().apply { enabled = true } })
However, Firebase is still throwing this error:
com.firebase.jobdispatcher.ValidationEnforcer$ValidationException: JobParameters is invalid: Couldn't find a registered service with the name
com.jongla.soundmash.service.SoundMashService. Is it declared in the manifest with the right intent-filter?
The relevant code in the Firebase project is below. It looks really straightforward, so I don't think it's a bug on their side.
PackageManager pm = context.getPackageManager();
if (pm == null) {
return getMutableSingletonList("PackageManager is null, can't validate service");
}
final String msg = "Couldn't find a registered service with the name " + service
+ ". Is it declared in the manifest with the right intent-filter?";
Intent executeIntent = new Intent(JobService.ACTION_EXECUTE);
executeIntent.setClassName(context, service);
List<ResolveInfo> intentServices = pm.queryIntentServices(executeIntent, 0);
if (intentServices == null || intentServices.isEmpty()) {
return getMutableSingletonList(msg);
}
for (ResolveInfo info : intentServices) {
if (info.serviceInfo != null && info.serviceInfo.enabled) {
// found a match!
return null;
}
}
Am I doing something wrong w/ my usage of Robolectric?