package com.gh.common.provider

import android.content.Context
import android.content.pm.PackageInfo
import com.gh.common.util.PackageHelper
import com.gh.common.util.PackageUtils
import com.gh.gamecenter.core.provider.IPackageUtilsProvider
import com.gh.gamecenter.core.utils.ProcessUtil

@com.therouter.inject.ServiceProvider
class PackageUtilsProviderImpl : IPackageUtilsProvider {
    override fun obtainProcessName(): String? {
        return ProcessUtil.getCurrentProcessName()
    }

    override fun getGhVersionName(): String {
        return PackageUtils.getGhVersionName()
    }

    override fun getGhVersionCode(): Int {
        return PackageUtils.getGhVersionCode()
    }

    override fun getInstalledPackages(context: Context, flag: Int): List<PackageInfo> {
        return PackageHelper.getInstalledPackageInfoList(context, flag)
    }

    override fun getApkSignatureByPackageName(context: Context, packageName: String): Array<String> {
        return PackageUtils.getApkSignatureByPackageName(context, packageName)
    }

    override fun getSideLoadedInfo(): MutableMap<String, String>? {
        return PackageUtils.getSideLoadedInfo()
    }

    override fun isSignedByGh(context: Context, packageName: String): Boolean {
        return PackageUtils.isSignedByGh(context, packageName)
    }

    override fun isInstalledWithLauncherIcon(context: Context, packageName: String): Boolean {
        return PackageUtils.isInstalled(context, packageName)
    }

    override fun getInstalledTime(context: Context, packageName: String): Long {
        return PackageUtils.getInstalledTime(context, packageName)
    }

    override fun getVersionNameByPackageName(packageName: String): String {
        return PackageUtils.getVersionNameByPackageName(packageName) ?: ""
    }
}