feat: 尝试避免安装错误版本 WebView 的用户闪退 https://git.shanqu.cc/halo/android/assistant-android/-/issues/78
This commit is contained in:
@ -61,6 +61,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipException;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@ -915,32 +916,58 @@ public class PackageUtils {
|
||||
File file = new File(path);
|
||||
List<String> abiList = new ArrayList<>();
|
||||
if (!file.exists()) return abiList;
|
||||
InputStream inputStream;
|
||||
ZipFile zipFile = null;
|
||||
String elementName;
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
|
||||
ZipEntry zipEntry;
|
||||
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
|
||||
final String name = zipEntry.getName();
|
||||
if (name.startsWith("lib/armeabi-v7a")
|
||||
|| name.startsWith("lib/arm64-v8a")
|
||||
|| name.startsWith("lib/x86")
|
||||
|| name.startsWith("lib/armeabi")
|
||||
|| name.startsWith("lib/x86_64")) {
|
||||
String abiName = name.substring(4, name.lastIndexOf("/"));
|
||||
if (!abiList.contains(abiName)) {
|
||||
abiList.add(abiName);
|
||||
zipFile = new ZipFile(file);
|
||||
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
if (entry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
elementName = entry.getName();
|
||||
if (elementName.startsWith("lib/")) {
|
||||
if (elementName.startsWith("lib/armeabi-v7a")
|
||||
|| elementName.startsWith("lib/arm64-v8a")
|
||||
|| elementName.startsWith("lib/x86")
|
||||
|| elementName.startsWith("lib/armeabi")
|
||||
|| elementName.startsWith("lib/x86_64")) {
|
||||
String abiName = elementName.substring(4, elementName.lastIndexOf("/"));
|
||||
if (!abiList.contains(abiName)) {
|
||||
abiList.add(abiName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
zipInputStream.close();
|
||||
inputStream.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
return abiList;
|
||||
} catch (ZipException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (zipFile != null) {
|
||||
try {
|
||||
zipFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return abiList;
|
||||
}
|
||||
|
||||
public static boolean checkWebViewIsAvailable(Context context) {
|
||||
List<String> webViewAbiList = HaloApp.getInstance().webViewAbiList;
|
||||
if (webViewAbiList != null) {
|
||||
return Build.CPU_ABI.equals("arm64-v8a") && webViewAbiList.contains(Build.CPU_ABI);
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
return true;
|
||||
} else {
|
||||
return WebViewCompat.getCurrentWebViewPackage(context) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user