diff --git a/build.gradle b/build.gradle index a70690e7..4ce62944 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.1.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.2' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c16c596c..03bae0d1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Nov 14 17:54:35 CST 2017 +#Sun Apr 08 15:35:06 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/qmui/src/main/java/com/qmuiteam/qmui/util/QMUIDeviceHelper.java b/qmui/src/main/java/com/qmuiteam/qmui/util/QMUIDeviceHelper.java index 2e20eb5d..379c78e9 100644 --- a/qmui/src/main/java/com/qmuiteam/qmui/util/QMUIDeviceHelper.java +++ b/qmui/src/main/java/com/qmuiteam/qmui/util/QMUIDeviceHelper.java @@ -1,5 +1,6 @@ package com.qmuiteam.qmui.util; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AppOpsManager; import android.content.Context; @@ -23,6 +24,7 @@ import java.util.regex.Pattern; * @author cginechen * @date 2016-08-11 */ +@SuppressLint("PrivateApi") public class QMUIDeviceHelper { private final static String TAG = "QMUIDeviceHelper"; private final static String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name"; @@ -37,22 +39,31 @@ public class QMUIDeviceHelper { private static boolean sIsTabletValue = false; static { - FileInputStream fileInputStream = null; + Properties properties = new Properties(); + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + // android 8.0,读取 /system/uild.prop 会报 permission denied + FileInputStream fileInputStream = null; + try { + fileInputStream = new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")); + properties.load(fileInputStream); + } catch (Exception e) { + QMUILog.printErrStackTrace(TAG, e, "read file error"); + } finally { + QMUILangHelper.close(fileInputStream); + } + } + + Class clzSystemProperties = null; try { - fileInputStream = new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")); - Properties properties = new Properties(); - properties.load(fileInputStream); - Class clzSystemProperties = Class.forName("android.os.SystemProperties"); + clzSystemProperties = Class.forName("android.os.SystemProperties"); Method getMethod = clzSystemProperties.getDeclaredMethod("get", String.class); // miui - sMiuiVersionName =getLowerCaseName(properties, getMethod, KEY_MIUI_VERSION_NAME); + sMiuiVersionName = getLowerCaseName(properties, getMethod, KEY_MIUI_VERSION_NAME); //flyme sFlymeVersionName = getLowerCaseName(properties, getMethod, KEY_FLYME_VERSION_NAME); - } catch (Exception e) { - QMUILog.printErrStackTrace(TAG, e, "getProperty error"); - } finally { - QMUILangHelper.close(fileInputStream); + QMUILog.printErrStackTrace(TAG, e, "read SystemProperties error"); } } @@ -110,7 +121,7 @@ public class QMUIDeviceHelper { public static boolean isFlymeVersionHigher5_2_4() { //查不到默认高于5.2.4 boolean isHigher = true; - if(sFlymeVersionName != null && !sFlymeVersionName.equals("")){ + if (sFlymeVersionName != null && !sFlymeVersionName.equals("")) { Pattern pattern = Pattern.compile("(\\d+\\.){2}\\d"); Matcher matcher = pattern.matcher(sFlymeVersionName); if (matcher.find()) { @@ -152,9 +163,10 @@ public class QMUIDeviceHelper { /** * 判断是否为小米 + * https://dev.mi.com/doc/?p=254 */ public static boolean isXiaomi() { - return Build.BRAND.toLowerCase().contains("xiaomi"); + return Build.MANUFACTURER.toLowerCase().equals("xiaomi"); } @@ -225,7 +237,8 @@ public class QMUIDeviceHelper { if (name == null) { try { name = (String) get.invoke(null, key); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } } if (name != null) name = name.toLowerCase(); return name;