判断 Mainifest 中是否包含对应到 Service
如有，则返回 true，反之，则返回 false 并输出日志

@param context
@param service
@return
770513
public static boolean checkService(Context context, Class<?> service) {
    try {
      ServiceInfo info = context.getPackageManager().getServiceInfo(
          new ComponentName(context, service), 0);
      return null != info;
    } catch (PackageManager.NameNotFoundException e) {
      printErrorLog("service " + service.getName() + " is missing!");
      return false;
    }
  }
405896
private Service initService(String serviceName) {
        m_logger.debug("Initializing service: " + serviceName);
        try {
            @SuppressWarnings("unchecked")
            Class<Service> serviceClass = (Class<Service>) Class.forName(serviceName);
            Method instanceMethod = serviceClass.getMethod("instance", (Class<?>[])null);
            Service instance = (Service)instanceMethod.invoke(null, (Object[])null);
            instance.initialize();
            return instance;
        } catch (Exception e) {
            throw new RuntimeException("Error initializing service: " + serviceName, e);
        }
    }
472386
public CacheManagerBuilder<T> using(Service service) {
    Set<Service> newServices = new HashSet<>(services);
    newServices.add(service);
    return new CacheManagerBuilder<>(this, newServices);
  }
695067
public Collection<MultifactorAuthenticationProvider> getAuthenticationProviderForService(final RegisteredService service) {
        val policy = service.getMultifactorPolicy();
        if (policy != null) {
            return policy.getMultifactorAuthenticationProviders().stream()
                .map(MultifactorAuthenticationUtils::getMultifactorAuthenticationProviderFromApplicationContext)
                .filter(Optional::isPresent)
                .map(Optional::get)
                .collect(Collectors.toSet());
        }
        return null;
    }
1182779
public static Tracing getTracing(String serviceName, CurrentTraceContext context) {
        Tracing tracing = Tracing.current();
        if (tracing == null) {
            // TODO reporter based on prop/config
            tracing = getBuilder(serviceName, context).build();
        }
        return tracing;
    }
1148897
@SuppressWarnings("unchecked")
    public <T> T create(Class<T> service) {
        validateServiceClass(service);
        for (Annotation annotation : service.getDeclaredAnnotations()) {
            if (annotation.annotationType() == AllFavor.class)
                allFavor = true;
        }
        return (T) Proxy.newProxyInstance(service.getClassLoader(), new Class<?>[]{service},
                new FavorHandler(getMethodInfoCache(service)));
    }
1008011
public static <T> T bind (T service, String entryPoint)
    {
        ((ServiceDefTarget)service).setServiceEntryPoint(entryPoint);
        return service;
    }
985799
public static Log instance(Context context) {
        Log instance = context.get(logKey);
        if (instance == null)
            instance = new Log(context);
        return instance;
    }
692678
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;
    }
5566
private Map<ScopeService, Service> createServices(final Set<ScopeService> services) {
    Map<ScopeService, Service> actualServices = Maps.newTreeMap();

    for (ScopeService requiredService : services) {
      if (availableServices.containsKey(requiredService)) {
        for (ScopeService availableService : availableServices.keySet()) {
          if (availableService == requiredService) {
            actualServices.put(requiredService, requiredService.newInstance(this));
          }
        }
      }
    }

    return actualServices;
  }
469279
@SuppressWarnings("unchecked")
    @Override
    public <T> T beforeServiceInvoke(T serviceObject, boolean isSingleton,
                                     Object context) {
        if (isSingleton || context == null) {
            return serviceObject;
        }

        Map<Class<?>, ManagedObject<?>> newContext = (Map<Class<?>, ManagedObject<?>>) (context);
        if (newContext.isEmpty()) {
            return null;
        }

        Object newServiceObject = null;

        newServiceObject = getInstanceFromManagedObject(serviceObject, context);

        return (T) newServiceObject;

    }
38934
@Override
    public boolean deleteService(Service service) throws ServiceException {
        if (super.deleteService(service)) {
            // Update cache
            this.removeServiceFromCache(service.getUri());
            return true;
        }

        return false;
    }
183093
public boolean logEvent(Context context) {
        boolean isReqQueued = false;
        String reqPath = isStandardEvent ? Defines.RequestPath.TrackStandardEvent.getPath() : Defines.RequestPath.TrackCustomEvent.getPath();
        if (Branch.getInstance() != null) {
            Branch.getInstance().handleNewRequest(new ServerRequestLogEvent(context, reqPath));
            isReqQueued = true;
        }
        return isReqQueued;
    }
1094344
public B service(PathMapping pathMapping, Service<HttpRequest, HttpResponse> service) {
        services.add(new ServiceConfig(pathMapping, service, null));
        return self();
    }
869638
public boolean shutdownService(Object service, BundleContext context)
    {
        if (service instanceof BaseServiceMessageTransport) // Always
            ((BaseServiceMessageTransport)service).free();
        return super.shutdownService(service, context);
    }
1096712
public DfuServiceController start(@NonNull final Context context, @NonNull final Class<? extends DfuBaseService> service) {
		if (fileType == -1)
			throw new UnsupportedOperationException("You must specify the firmware file before starting the service");

		final Intent intent = new Intent(context, service);

		intent.putExtra(DfuBaseService.EXTRA_DEVICE_ADDRESS, deviceAddress);
		intent.putExtra(DfuBaseService.EXTRA_DEVICE_NAME, deviceName);
		intent.putExtra(DfuBaseService.EXTRA_DISABLE_NOTIFICATION, disableNotification);
		intent.putExtra(DfuBaseService.EXTRA_FOREGROUND_SERVICE, startAsForegroundService);
		intent.putExtra(DfuBaseService.EXTRA_FILE_MIME_TYPE, mimeType);
		intent.putExtra(DfuBaseService.EXTRA_FILE_TYPE, fileType);
		intent.putExtra(DfuBaseService.EXTRA_FILE_URI, fileUri);
		intent.putExtra(DfuBaseService.EXTRA_FILE_PATH, filePath);
		intent.putExtra(DfuBaseService.EXTRA_FILE_RES_ID, fileResId);
		intent.putExtra(DfuBaseService.EXTRA_INIT_FILE_URI, initFileUri);
		intent.putExtra(DfuBaseService.EXTRA_INIT_FILE_PATH, initFilePath);
		intent.putExtra(DfuBaseService.EXTRA_INIT_FILE_RES_ID, initFileResId);
		intent.putExtra(DfuBaseService.EXTRA_KEEP_BOND, keepBond);
		intent.putExtra(DfuBaseService.EXTRA_RESTORE_BOND, restoreBond);
		intent.putExtra(DfuBaseService.EXTRA_FORCE_DFU, forceDfu);
		intent.putExtra(DfuBaseService.EXTRA_DISABLE_RESUME, disableResume);
		intent.putExtra(DfuBaseService.EXTRA_MAX_DFU_ATTEMPTS, numberOfRetries);
		intent.putExtra(DfuBaseService.EXTRA_MBR_SIZE, mbrSize);
		if (mtu > 0)
			intent.putExtra(DfuBaseService.EXTRA_MTU, mtu);
		intent.putExtra(DfuBaseService.EXTRA_CURRENT_MTU, currentMtu);
		intent.putExtra(DfuBaseService.EXTRA_UNSAFE_EXPERIMENTAL_BUTTONLESS_DFU, enableUnsafeExperimentalButtonlessDfu);
		//noinspection StatementWithEmptyBody
		if (packetReceiptNotificationsEnabled != null) {
			intent.putExtra(DfuBaseService.EXTRA_PACKET_RECEIPT_NOTIFICATIONS_ENABLED, packetReceiptNotificationsEnabled);
			intent.putExtra(DfuBaseService.EXTRA_PACKET_RECEIPT_NOTIFICATIONS_VALUE, numberOfPackets);
		} else {
			// For backwards compatibility:
			// If the setPacketsReceiptNotificationsEnabled(boolean) has not been called, the PRN state and value are taken from
			// SharedPreferences the way they were read in DFU Library in 1.0.3 and before, or set to default values.
			// Default values: PRNs enabled on Android 4.3 - 5.1 and disabled starting from Android 6.0. Default PRN value is 12.
		}
		if (legacyDfuUuids != null)
			intent.putExtra(DfuBaseService.EXTRA_CUSTOM_UUIDS_FOR_LEGACY_DFU, legacyDfuUuids);
		if (secureDfuUuids != null)
			intent.putExtra(DfuBaseService.EXTRA_CUSTOM_UUIDS_FOR_SECURE_DFU, secureDfuUuids);
		if (experimentalButtonlessDfuUuids != null)
			intent.putExtra(DfuBaseService.EXTRA_CUSTOM_UUIDS_FOR_EXPERIMENTAL_BUTTONLESS_DFU, experimentalButtonlessDfuUuids);
		if (buttonlessDfuWithoutBondSharingUuids != null)
			intent.putExtra(DfuBaseService.EXTRA_CUSTOM_UUIDS_FOR_BUTTONLESS_DFU_WITHOUT_BOND_SHARING, buttonlessDfuWithoutBondSharingUuids);
		if (buttonlessDfuWithBondSharingUuids != null)
			intent.putExtra(DfuBaseService.EXTRA_CUSTOM_UUIDS_FOR_BUTTONLESS_DFU_WITH_BOND_SHARING, buttonlessDfuWithBondSharingUuids);

		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && startAsForegroundService) {
			// On Android Oreo and above the service must be started as a foreground service to make it accessible from
			// a killed application.
			context.startForegroundService(intent);
		} else {
			context.startService(intent);
		}
		return new DfuServiceController(context);
	}
51313
public static boolean isContextForeground(Context context) {

		ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
		List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
		int pid = getPid();
		for (RunningAppProcessInfo appProcess : appProcesses) {
			if (appProcess.pid == pid) {
				return appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
			}
		}
		return false;
	}