Check if package is installed

@param  PackageInterface $package
@return bool
186432
public function isPackageInstalled(PackageInterface $package)
    {
        return $this->filesystem->exists($this->config->getInstallDir() . '/' . $package->getName() . '/.bower.json');
    }
968599
public function isForPackage(PackageInterface $package)
    {
        if ($this->getForPackage() !== $package->getName()) {
            return false;
        }
        $fpv = $this->getForPackageVersion();
        if ($fpv !== null) {
            $pv = new Constraint('=', $package->getVersion());
            if (!$fpv->matches($pv)) {
                return false;
            }
        }

        return true;
    }
956606
private function findSubPackages(PackageInterface $package): Generator
    {
        $readMes = new \Symfony\Component\Finder\Finder();
        $readMes->files()
                ->in($package->getPaths())
                ->depth(1)
                ->name('readme.md');

        // If no sub-folders have a readme, there aren't any sub-packages here.
        if (!$readMes->count()) {
            return;
        }
        yield from $this->scanNamespaceForPackages($package, $package);
    }
345361
private function checkPackagesFlag(InputInterface $input)
    {
        $result = [];
        if (count($input->getOption('packages')) > 0) {
            if (!$this->app->isInstalled()) {
                throw new Exception('concrete5 is not installed: you can only work with core language files.');
            }
            $proceed = true;
        } elseif (!$input->getOption('core')) {
            $proceed = $this->app->isInstalled();
        } else {
            $proceed = false;
        }
        if ($proceed) {
            $pkgList = $input->getOption('packages');
            if ($pkgList === [null]) {
                $pkgList = [];
            }
            $ps = $this->app->make(PackageService::class);
            /* @var PackageService $ps */
            $allPackages = $ps->getAvailablePackages(false);
            if (count($pkgList) === 0) {
                $result = $allPackages;
            } else {
                foreach ($pkgList as $pkg) {
                    $package = null;
                    foreach ($allPackages as $p) {
                        if (strcasecmp($p->getPackageHandle(), $pkg) === 0) {
                            $package = $p;
                            break;
                        }
                    }
                    if ($package === null) {
                        throw new Exception(sprintf('Unable to find a package with handle %s', $pkg));
                    }
                    if (!in_array($package, $result, true)) {
                        $result[] = $package;
                    }
                }
            }
        }

        return $result;
    }
1327094
public function getPatchesFor(PackageInterface $package)
    {
        $patches = array();
        foreach ($this->getPatches() as $patch) {
            if ($patch->isForPackage($package)) {
                $patches[] = $patch;
            }
        }
        $result = new static();
        $result->patches = $patches;

        return $result;
    }
1326639
public function getInstallPath(PackageInterface $package)
    {
        $textpattern = new Textpattern();
        $path = $textpattern->getRelativePath();
        $themes = $path . '/admin-themes';

        // Textpattern <= 4.5.x uses 'theme' directory.
        if (!file_exists($themes)) {
            $themes = $path . '/theme';
        }

        return $themes . '/' . basename($package->getPrettyName());
    }
322291
public static function unregisterPackage(PackageInterface $package, AssetsInstallerInterface $installer = null)
    {
        self::$__autoloader->unregisterPackage($package, $installer);
    }
663770
private function checkPackageRequirements($package = '')
	{
		if ($package == '')
		{
			return false;
		}

		$installed_exts = get_loaded_extensions();
		if (!in_array($package, $installed_exts))
		{
			$this->setError(\Lang::txt('[ERROR] You are missing the required PHP package %s.', $package));
			return false;
		}

		return true;
	}
1075203
public static function isAsset(PackageInterface $package, array $configPackages = array())
    {
        $projectConfig = self::getProjectActivation($package, $configPackages);
        $enabled = false !== $projectConfig;

        return $enabled && (static::hasExtraActivation($package)
            || static::hasPluginDependency($package->getRequires())
            || static::hasPluginDependency($package->getDevRequires())
            || true === $projectConfig);
    }
502821
private function getExcludedFiles(PackageInterface $package)
    {
        $type = self::EXCLUDE_FILES_PROPERTY;

        $autoload = $package->getAutoload();

        // Skip misconfigured or empty packages
        if (isset($autoload[$type]) && is_array($autoload[$type])) {
            return $autoload[$type];
        }

        $extra = $package->getExtra();

        // Skip misconfigured or empty packages
        if (isset($extra[$type]) && is_array($extra[$type])) {
            return $extra[$type];
        }

        return null;
    }
581726
protected function uninstallEntryFiles(PackageInterface $package)
    {
        foreach ($this->getEntryFileLocations($package) as $dest) {
            $unlinked = $this->filesystem->unlinkFile($dest);

            $this->io->notice(
                sprintf(
                    '    <fg=default>Removing <fg=magenta>%1$s</> -</> %2$s',
                    $dest,
                    $unlinked ? '<fg=green>OK</>' : '<fg=red>FAILED</>'
                )
            );

            if (! $unlinked) {
                throw new RuntimeException('Cannot unlink ' . $dest);
            }
        }
    }
692937
private boolean isAnyPackageFromListInstalled(List<String> packages){
        boolean result = false;

        PackageManager pm = mContext.getPackageManager();

        for (String packageName : packages) {
            try {
                // Root app detected
                pm.getPackageInfo(packageName, 0);
                QLog.e(packageName + " ROOT management app detected!");
                result = true;
            } catch (PackageManager.NameNotFoundException e) {
                // Exception thrown, package is not installed into the system
            }
        }

        return result;
    }
1001152
public function getInstallPath(PackageInterface $package)
    {
        if ($this->solver->isSharedPackage($package)) {
            return $this->symlinkInstaller->getInstallPath($package);
        }

        return $this->defaultInstaller->getInstallPath($package);
    }
1130313
private function getPackageName(PackageInterface $package)
    {
        if (is_array($package->getExtra()) && isset($package->getExtra()['installer-name'])) {
            return $package->getExtra()['installer-name'];
        }

        $name = explode('/', $package->getPrettyName());
        $packageName = $name[1];

        if (count(explode('-', $packageName)) < 2) {
            throw new Exception('Bundle names should be like "vendor/NAME-bundle"');
        }

        $packageName = str_replace('-bundle', '', $packageName);

        return str_replace(' ', '', ucwords(str_replace('-', ' ', $packageName)));
    }
312834
protected function isDrupalPackage($package)
    {
        if (isset($package) && $package instanceof PackageInterface && strstr($package->getName(), 'drupal/')) {
            return true;
        }
        return false;
    }
114458
public function hasSource($source, $package=null) {
		try {
			return !!static::getFilePath($source, $package);
		} catch( Exception $e ) {
			return false;
		}
	}
599239
public function processPackage(PackageInterface $package)
    {
        $extra = $package->getExtra();
        $files = isset($extra[self::EXTRA_OPTION_NAME]) ? $extra[self::EXTRA_OPTION_NAME] : null;
        if ($package->getType() !== self::PACKAGE_TYPE && is_null($files)) {
            return;
        }

        $extension = [
            'name'    => $package->getName(),
            'version' => $package->getVersion(),
        ];
        if ($package->getVersion() === '9999999-dev') {
            $reference = $package->getSourceReference() ?: $package->getDistReference();
            if ($reference) {
                $extension['reference'] = $reference;
            }
        }
        $this->data['extensions'][$package->getName()] = $extension;

        $aliases = array_merge(
            $this->prepareAliases($package, 'psr-0'),
            $this->prepareAliases($package, 'psr-4')
        );
        $this->data['aliases'] = array_merge($this->data['aliases'], $aliases);
        foreach ((array) $files as $name => $path) {
            $config = $this->readExtensionConfig($package, $path);
            $config['aliases'] = array_merge(
                $aliases,
                isset($config['aliases']) ? (array) $config['aliases'] : []
            );
            $this->data['aliases'] = array_merge($this->data['aliases'], $config['aliases']);
            $this->data[$name] = isset($this->data[$name]) ? Helper::mergeConfig($this->data[$name], $config) : $config;
        }
    }