package com.android.launcher3.util;

import android.os.Build;
import android.text.TextUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SystemUtils {

    private static final String TAG = "SystemUtils";

    public static String getDeviceBrand() {
        return Build.BRAND;
    }

    /**
     * 是否是小米
     *
     * @return
     */
    public static boolean isMIUI() {
        return getDeviceBrand().toUpperCase().equals("XIAOMI")||getDeviceBrand().toUpperCase().equals("MEITU");
    }


    /**
     * 是否是华为
     *
     * @return
     */
    public static boolean isHW() {
        return getDeviceBrand().toUpperCase().equals("HUAWEI");
    }


    public static boolean isHONOR() {
        return getDeviceBrand().toUpperCase().equals("HONOR");
    }

    /**
     * 是否是魅族
     *
     * @return
     */
    public static boolean isMEIZU() {
        return getDeviceBrand().toUpperCase().equals("MEIZU");
    }

    /**
     * 是否是OPPO
     *
     * @return
     */
    public static boolean isOPPO() {
        return getDeviceBrand().toUpperCase().equals("OPPO");
    }

    /**
     * 是否是VIVO
     *
     * @return
     */
    public static boolean isVIVO() {
        return getDeviceBrand().toUpperCase().equals("VIVO");
    }

    /**
     * 是否是三星
     *
     * @return
     */
    public static boolean isSAMSUNG() {
        return getDeviceBrand().toUpperCase().equals("SAMSUNG");
    }

    public static boolean isNOKIA(){
        return getDeviceBrand().toUpperCase().equals("NOKIA");
    }

    public static String getMIUIVersion() {
        String versionCode = "";
        String manufacturer = Build.MANUFACTURER;
        String model = Build.MODEL;
        if (!TextUtils.isEmpty(manufacturer) && manufacturer.equals("Xiaomi")) {
            versionCode = getSystemProperty("ro.miui.ui.version.name");
        }
        return versionCode;
    }

    public static String getSystemProperty(String propName) {
        String line;
        BufferedReader input = null;
        try {
            Process p = Runtime.getRuntime().exec("getprop " + propName);
            input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
            line = input.readLine();
            input.close();
        } catch (IOException ex) {
            return null;
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                }
            }
        }
        return line;
    }

}
