@SuppressWarnings("PMD.PreserveStackTrace")
    public static void checkService(@NonNull final Context context,
                                    @NonNull final ComponentName service) {
        final PackageManager packageManager = context.getPackageManager();
        try {
            packageManager.getServiceInfo(service, 0);
        } catch (PackageManager.NameNotFoundException e) {
            throw new IllegalStateException("Service " + service.getClassName()
                    + " hasn't been declared in AndroidManifest.xml");
        }
    }
@ SuppressWarnings ( "PMD.PreserveStackTrace" ) public static void checkService ( @ NonNull final Context context , @ NonNull final ComponentName service ) { final PackageManager packageManager = context . getPackageManager ( ) ; try { packageManager . getServiceInfo ( service , 0 ) ; } catch ( PackageManager . NameNotFoundException e ) { throw new IllegalStateException ( "Service " + service . getClassName ( ) + " hasn't been declared in AndroidManifest.xml" ) ; } }
Checks is a service has been described in the AndroidManifest.xml file.

@param context The instance of {@link android.content.Context}.
@param service The checked service.