package com.ccwangluo.accelerator.utils

import android.content.Context
import android.content.pm.PackageManager
import android.net.ConnectivityManager

object SysUtils {

    fun getConnectivityStatus(context: Context): Boolean {
        val cm = context
            .getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val activeNetwork = cm.activeNetworkInfo
        if (null != activeNetwork) {
            if (activeNetwork.type == ConnectivityManager.TYPE_WIFI) return true
            if (activeNetwork.type == ConnectivityManager.TYPE_MOBILE) return true
        }
        return false
    }

    /**
     * 正在使用的网络
     */
    fun getActiveNetWork(context: Context): String {
        val networkState = NetUtils.getNetworkState(context)
        return ""
    }

    /**
     * 判断包是否安装
     */
    fun isPackageInstall(context: Context, packageName: String): Boolean {
        val packageManager: PackageManager = context.getPackageManager()
        val packageInfos = packageManager.getInstalledPackages(0)
        val packageNames: MutableList<String> = ArrayList()
        if (packageInfos != null) {
            for (i in packageInfos.indices) {
                val packName = packageInfos[i].packageName
                packageNames.add(packName)
            }
        }
        return packageNames.contains(packageName)
    }

}