code: public static <T> T getService(BundleContext bundleContext, Class<T> serviceClass) {
          T service = null;
          if (FrameworkState.isValid()) {
              ServiceReference<T> ref = bundleContext.getServiceReference(serviceClass);
  
              if (ref != null) {
                  service = bundleContext.getService(ref);
              }
          }
          return service;
      }
docs: Find a service of the given type
  
  @param bundleContext The context to use to find the service
  @param serviceClass The class of the required service
  @return the service instance or null