code: private ServiceReference checkService(ServiceReference serviceReference, String interfaceClassName)
      {
          if (serviceReference != null)
          {
              Object service = bundleContext.getService(serviceReference);
              if (service != null)
              {
                  try {
                      if (interfaceClassName != null)
                          if (!service.getClass().isAssignableFrom(Class.forName(interfaceClassName)))
                              serviceReference = null;
                  } catch (ClassNotFoundException e) {
                      // Ignore this error
                  }
              }
          }
          return serviceReference;
      }
docs: Make sure this service reference is the correct interface/class
  @param serviceReference
  @param interfaceClassName
  @param serviceClassName
  @return