content: /*
   * Copyright (C) 2016 Facishare Technology Co., Ltd. All Rights Reserved.
   */
  package io.agora.api.example.common.floatwindow.rom;
  
  import android.os.Build;
  import android.text.TextUtils;
  import android.util.Log;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  
  /**
   * The type Rom utils.
   */
  public final class RomUtils {
      private static final String TAG = "RomUtils";
  
      private RomUtils() {
  
      }
  
      /**
       * 获取 emui 版本号
       *
       * @return emui version
       */
      public static double getEmuiVersion() {
          final double defaultVersion = 4.0;
          try {
              String emuiVersion = getSystemProperty("ro.build.version.emui");
              String version = emuiVersion.substring(emuiVersion.indexOf("_") + 1);
              return Double.parseDouble(version);
          } catch (Exception e) {
              e.printStackTrace();
          }
          return defaultVersion;
      }
  
      /**
       * 获取小米 rom 版本号，获取失败返回 -1
       *
       * @return miui rom version code, if fail , return -1
       */
      public static int getMiuiVersion() {
          String version = getSystemProperty("ro.miui.ui.version.name");
          if (version != null) {
              try {
                  return Integer.parseInt(version.substring(1));
              } catch (Exception e) {
                  Log.e(TAG, "get miui version code error, version : " + version);
              }
          }
          return -1;
      }
  
      /**
       * Gets system property.
       *
       * @param propName the prop name
       * @return the system property
       */
      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) {
              Log.e(TAG, "Unable to read sysprop " + propName, ex);
              return null;
          } finally {
              if (input != null) {
                  try {
                      input.close();
                  } catch (IOException e) {
                      Log.e(TAG, "Exception while closing InputStream", e);
                  }
              }
          }
          return line;
      }
  
      /**
       * Check is huawei rom boolean.
       *
       * @return the boolean
       */
      public static boolean checkIsHuaweiRom() {
          return Build.MANUFACTURER.contains("HUAWEI");
      }
  
      /**
       * check if is miui ROM
       *
       * @return the boolean
       */
      public static boolean checkIsMiuiRom() {
          return !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"));
      }
  
      /**
       * Check is meizu rom boolean.
       *
       * @return the boolean
       */
      public static boolean checkIsMeizuRom() {
          //return Build.MANUFACTURER.contains("Meizu");
          String meizuFlymeOSFlag = getSystemProperty("ro.build.display.id");
          if (TextUtils.isEmpty(meizuFlymeOSFlag)) {
              return false;
          } else {
              return meizuFlymeOSFlag.contains("flyme") || meizuFlymeOSFlag.toLowerCase().contains("flyme");
          }
      }
  
      /**
       * Check is 360 rom boolean.
       *
       * @return the boolean
       */
      public static boolean checkIs360Rom() {
          //fix issue https://github.com/zhaozepeng/FloatWindowPermission/issues/9
          return Build.MANUFACTURER.contains("QiKU")
                  || Build.MANUFACTURER.contains("360");
      }
  
      /**
       * Check is oppo rom boolean.
       *
       * @return the boolean
       */
      public static boolean checkIsOppoRom() {
          //https://github.com/zhaozepeng/FloatWindowPermission/pull/26
          return Build.MANUFACTURER.contains("OPPO") || Build.MANUFACTURER.contains("oppo");
      }
  }
  