package com.fq.channel.sdk.base.utils;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.fq.channel.sdk.base.constants.FqConfig;

/**
 * Created by Ethan on 2017/9/2.
 * 读取配置在AndroidManifest中的配置信息
 *
 * @author Ethan
 */

public class AppInfoUtils {

    /**
     * 声明成volatile
     */
    private volatile static AppInfoUtils sInstance;

    private AppInfoUtils() {
    }

    public static AppInfoUtils getInstance() {

        if (sInstance == null) {
            synchronized (AppInfoUtils.class) {
                if (sInstance == null) {
                    sInstance = new AppInfoUtils();
                }
            }
        }
        return sInstance;
    }


    /**
     * 获取AppId
     */
    public String getAppId() {

        return FqConfig.get().getAppId();
    }

    /**
     * 获取配置写在strings.xml中的版本号信息
     */
    public String getFqGameSdkVersionCode() {
        return Utils.FQSDK_VERSION;
    }


    /**
     * 获取渠道号 ChannelId
     * 如果获取不到 则使用默认的channelId
     */
    public String getChannelId() {
        return FqConfig.get().getChannelId();
    }

    /**
     * 获取adId
     * 如果获取不到 则使用默认的adId
     */
    public String getAdId() {
        return FqConfig.get().getAdId();
    }

    /**
     * 获取adFlag
     *
     * @return
     */
    public String getAdFlag() {
        return FqConfig.get().getAdFlag();
    }

    /**
     * 获取VersionCode
     *
     * @return
     */
    public String getVersionCode() {

        String versionCode = "";
        try {
            PackageManager pm = Utils.getContext().getPackageManager();
            PackageInfo pi = pm.getPackageInfo(Utils.getContext().getPackageName(), 0);
            versionCode = pi.versionCode + "";
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return versionCode;
    }

    /**
     * 获取VersionName
     *
     * @return
     */
    public String getVersionName() {

        String versionName = "";
        try {
            PackageManager pm = Utils.getContext().getPackageManager();
            PackageInfo pi = pm.getPackageInfo(Utils.getContext().getPackageName(), 0);
            versionName = pi.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return versionName;
    }

    /**
     * 通过WiFiManager获取mac地址
     *
     * @return
     */
    public String tryGetWifiMac() {
        return DeviceUtils.tryGetWifiMac();
    }

}
