fix(android): 审查修复 — Kotlin编译错误+SHA256校验+权限检查
- PackageInstallerModule: fsync作用域修复, PendingIntent改用getLaunchIntentForPackage, 权限预检 - updater: expo-crypto SHA256校验, getLocalBuildTag优先级修正, parseVersion null安全 - ManifestBuild: 增加type字段(js/apk)替代size启发式 - app.json: fallbackToCacheTimeout 0→3000 - shared: catch静默→console.warn
This commit is contained in:
@@ -4,6 +4,7 @@ import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.content.pm.PackageManager
|
||||
import expo.modules.kotlin.modules.Module
|
||||
import expo.modules.kotlin.modules.ModuleDefinition
|
||||
import java.io.File
|
||||
@@ -23,6 +24,11 @@ class PackageInstallerModule : Module() {
|
||||
val apkFile = File(filePath)
|
||||
if (!apkFile.exists()) throw Exception("APK file not found: $filePath")
|
||||
|
||||
// 检查 REQUEST_INSTALL_PACKAGES 权限
|
||||
if (!context.packageManager.canRequestPackageInstalls()) {
|
||||
throw SecurityException("REQUEST_INSTALL_PACKAGES 权限未授予,请在系统设置中允许")
|
||||
}
|
||||
|
||||
val packageInstaller = context.packageManager.packageInstaller
|
||||
val sessionParams = PackageInstaller.SessionParams(
|
||||
PackageInstaller.SessionParams.MODE_FULL_INSTALL
|
||||
@@ -35,15 +41,15 @@ class PackageInstallerModule : Module() {
|
||||
FileInputStream(apkFile).use { input ->
|
||||
session.openWrite("package", 0, apkFile.length()).use { output ->
|
||||
input.copyTo(output)
|
||||
session.fsync(output)
|
||||
}
|
||||
session.fsync(output)
|
||||
}
|
||||
|
||||
// 安装完成后发送通知,用户点击即重启
|
||||
val intent = Intent(context, context.javaClass)
|
||||
intent.action = Intent.ACTION_MAIN
|
||||
val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
||||
?: throw Exception("无法获取启动Intent")
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
context, 0, intent,
|
||||
context, 0, launchIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user