From 5f739314d9eadeb5cad7f0e6876d2606480fc1f5 Mon Sep 17 00:00:00 2001 From: Blankj Date: Sat, 15 Oct 2022 00:45:11 +0800 Subject: [PATCH] fix: some bugs --- CHANGELOG.md | 1 + buildSrc/src/main/groovy/Config.groovy | 6 +-- lib/utilcode/README-CN.md | 11 +++-- lib/utilcode/README.md | 3 +- .../blankj/utilcode/util/ActivityUtils.java | 9 ++-- .../com/blankj/utilcode/util/BarUtils.java | 4 +- .../com/blankj/utilcode/util/DeviceUtils.java | 46 +++++++++++++++++-- module_config.json | 2 +- 8 files changed, 63 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4bcc19c85..73e8145bf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* `22/10/15` [add] Fix some issue. Publish v1.31.1 * `21/12/06` [add] Publish v1.31.0 * `21/05/13` [add] Support publish mavenCentral. * `21/02/22` [add] Fix ToastUtils rtl bug. Publish v1.30.6. diff --git a/buildSrc/src/main/groovy/Config.groovy b/buildSrc/src/main/groovy/Config.groovy index 268ec666ce..9a8d69d659 100644 --- a/buildSrc/src/main/groovy/Config.groovy +++ b/buildSrc/src/main/groovy/Config.groovy @@ -6,8 +6,8 @@ class Config { static compileSdkVersion = 29 static minSdkVersion = 14 static targetSdkVersion = 29 - static versionCode = 1_030_007 - static versionName = '1.31.0'// E.g. 1.9.72 => 1,009,072 + static versionCode = 1_031_001 + static versionName = '1.31.1'// E.g. 1.9.72 => 1,009,072 // lib version static gradlePluginVersion = '4.1.0' @@ -34,7 +34,7 @@ class Config { lib_base : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/base"), lib_common : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/common"), lib_subutil : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/subutil"), - lib_utilcode : new ModuleConfig(isApply: true , useLocal: false, localPath: "./lib/utilcode", remotePath: "com.blankj:utilcodex:$Config.versionName"), + lib_utilcode : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utilcode", remotePath: "com.blankj:utilcodex:$Config.versionName"), lib_utildebug : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug"), lib_utildebug_no_op : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug-no-op"), /*Don't delete this line*/ diff --git a/lib/utilcode/README-CN.md b/lib/utilcode/README-CN.md index d8b9591fe7..6610b3be99 100644 --- a/lib/utilcode/README-CN.md +++ b/lib/utilcode/README-CN.md @@ -3,7 +3,7 @@ Gradle: ```groovy // if u use AndroidX, use the following -implementation 'com.blankj:utilcodex:1.31.0' +implementation 'com.blankj:utilcodex:1.31.1' // Not in maintenance implementation 'com.blankj:utilcode:1.30.7' @@ -1210,10 +1210,11 @@ removeListener: 移除消息监听器 * ### URI 相关 -> [UriUtils.java][uri.java] ``` -res2Uri : res 转 uri -file2Uri : file 转 uri -uri2File : uri 转 file -uri2Bytes: uri 转 bytes +res2Uri : res 转 uri +file2Uri : file 转 uri +uri2File : uri 转 file +uri2FileNoCacheCopy: uri 转 file 不拷贝缓存 +uri2Bytes : uri 转 bytes ``` * ### UtilsTransActivity -> [UtilsTransActivity.java][trans.java] diff --git a/lib/utilcode/README.md b/lib/utilcode/README.md index b88bcbcfbd..570f58fc46 100644 --- a/lib/utilcode/README.md +++ b/lib/utilcode/README.md @@ -3,7 +3,7 @@ Gradle: ```groovy // if u use AndroidX, use the following -implementation 'com.blankj:utilcodex:1.31.0' +implementation 'com.blankj:utilcodex:1.31.1' // Not in maintenance implementation 'com.blankj:utilcode:1.30.6' @@ -1212,6 +1212,7 @@ removeListener res2Uri file2Uri uri2File +uri2FileNoCacheCopy uri2Bytes ``` diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java index 10858f75f4..056668652c 100644 --- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java +++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/ActivityUtils.java @@ -2013,10 +2013,11 @@ private static boolean startActivity(final Intent intent, } private static boolean isIntentAvailable(final Intent intent) { - return Utils.getApp() - .getPackageManager() - .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY) - .size() > 0; +// return Utils.getApp() +// .getPackageManager() +// .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY) +// .size() > 0; + return true; } private static boolean startActivityForResult(final Activity activity, diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java index ece4f7faba..e8cacc5f0c 100644 --- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java +++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/BarUtils.java @@ -57,7 +57,7 @@ private BarUtils() { * @return the status bar's height */ public static int getStatusBarHeight() { - Resources resources = Utils.getApp().getResources(); + Resources resources = Resources.getSystem(); int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); return resources.getDimensionPixelSize(resourceId); } @@ -483,7 +483,7 @@ private static void invokePanels(final String methodName) { * @return the navigation bar's height */ public static int getNavBarHeight() { - Resources res = Utils.getApp().getResources(); + Resources res = Resources.getSystem(); int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId != 0) { return res.getDimensionPixelSize(resourceId); diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/DeviceUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/DeviceUtils.java index e6feb5fdaa..9cd01108e1 100644 --- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/DeviceUtils.java +++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/DeviceUtils.java @@ -13,16 +13,19 @@ import android.telephony.TelephonyManager; import android.text.TextUtils; -import androidx.annotation.RequiresApi; -import androidx.annotation.RequiresPermission; - +import java.io.BufferedReader; import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; import java.util.UUID; +import androidx.annotation.RequiresApi; +import androidx.annotation.RequiresPermission; + import static android.Manifest.permission.ACCESS_WIFI_STATE; import static android.Manifest.permission.CHANGE_WIFI_STATE; import static android.Manifest.permission.INTERNET; @@ -382,6 +385,7 @@ public static boolean isEmulator() { intent.setAction(Intent.ACTION_DIAL); boolean checkDial = intent.resolveActivity(Utils.getApp().getPackageManager()) == null; if (checkDial) return true; + if (isEmulatorByCpu()) return true; // boolean checkDebuggerConnected = Debug.isDebuggerConnected(); // if (checkDebuggerConnected) return true; @@ -389,6 +393,42 @@ public static boolean isEmulator() { return false; } + /** + * Returns whether is emulator by check cpu info. + * by function of {@link #readCpuInfo}, obtain the device cpu information. + * then compare whether it is intel or amd (because intel and amd are generally not mobile phone cpu), to determine whether it is a real mobile phone + * + * @return {@code true}: yes
{@code false}: no + */ + private static boolean isEmulatorByCpu() { + String cpuInfo = readCpuInfo(); + return cpuInfo.contains("intel") || cpuInfo.contains("amd"); + } + + /** + * Return Cpu information + * + * @return Cpu info + */ + private static String readCpuInfo() { + String result = ""; + try { + String[] args = {"/system/bin/cat", "/proc/cpuinfo"}; + ProcessBuilder cmd = new ProcessBuilder(args); + Process process = cmd.start(); + StringBuilder sb = new StringBuilder(); + String readLine; + BufferedReader responseReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "utf-8")); + while ((readLine = responseReader.readLine()) != null) { + sb.append(readLine); + } + responseReader.close(); + result = sb.toString().toLowerCase(); + } catch (IOException ignored) { + } + return result; + } + /** * Whether user has enabled development settings. * diff --git a/module_config.json b/module_config.json index 18f416382a..87233122b9 100644 --- a/module_config.json +++ b/module_config.json @@ -23,7 +23,7 @@ {"name": "lib_base", "isApply": true, "useLocal": true, "localPath": "./lib/base"}, {"name": "lib_common", "isApply": true, "useLocal": true, "localPath": "./lib/common"}, {"name": "lib_subutil", "isApply": true, "useLocal": true, "localPath": "./lib/subutil"}, - {"name": "lib_utilcode", "isApply": true, "useLocal": false, "localPath": "./lib/utilcode", "remotePath": "com.blankj:utilcodex:$Config.versionName"}, + {"name": "lib_utilcode", "isApply": true, "useLocal": true, "localPath": "./lib/utilcode", "remotePath": "com.blankj:utilcodex:$Config.versionName"}, {"name": "lib_utildebug", "isApply": true, "useLocal": true, "localPath": "./lib/utildebug"}, {"name": "lib_utildebug_no_op", "isApply": true, "useLocal": true, "localPath": "./lib/utildebug-no-op"} ]