shadows/framework/src/main/java/org/robolectric/shadows/ShadowPackageManager.java
public ServiceInfo addServiceIfNotPresent(ComponentName componentName) {
    return addComponent(
        serviceFilters,
        p -> p.services,
        (p, a) -> p.services = a,
        updateName(componentName, new ServiceInfo()),
        false);
  }
public ServiceInfo addServiceIfNotPresent(ComponentName componentName) {
    return addComponent(
        serviceFilters,
        p -> p.services,
        (p, a) -> p.services = a,
        updateName(componentName, new ServiceInfo()),
        false);
  }
Makes sure that given service exists.

If the service doesn't exist yet, it will be created with {@code applicationInfo} set to an
existing application, or if it doesn't exist, a new package will be created.

@return existing or newly created service info.