diff --git a/manager/app/build.gradle.kts b/manager/app/build.gradle.kts index b2757159..5ec95f12 100644 --- a/manager/app/build.gradle.kts +++ b/manager/app/build.gradle.kts @@ -114,4 +114,5 @@ dependencies { implementation(libs.sheet.compose.dialogs.input) implementation(libs.markdown) + implementation(libs.androidx.webkit) } diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/WebScreen.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/WebScreen.kt index a40d9477..05d72f30 100644 --- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/WebScreen.kt +++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/WebScreen.kt @@ -8,6 +8,8 @@ import android.os.Looper import android.text.TextUtils import android.view.Window import android.webkit.JavascriptInterface +import android.webkit.WebResourceRequest +import android.webkit.WebResourceResponse import android.webkit.WebView import android.widget.Toast import androidx.compose.foundation.layout.fillMaxSize @@ -21,6 +23,8 @@ import androidx.compose.ui.platform.LocalContext import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsControllerCompat +import androidx.webkit.WebViewAssetLoader +import com.google.accompanist.web.AccompanistWebViewClient import com.google.accompanist.web.WebView import com.google.accompanist.web.rememberWebViewState import com.ramcosta.composedestinations.annotation.Destination @@ -31,6 +35,7 @@ import me.weishu.kernelsu.ui.util.createRootShell import me.weishu.kernelsu.ui.util.serveModule import org.json.JSONArray import org.json.JSONObject +import java.io.File import java.util.concurrent.CompletableFuture @SuppressLint("SetJavaScriptEnabled") @@ -53,23 +58,37 @@ fun WebScreen(navigator: DestinationsNavigator, moduleId: String, moduleName: St } Scaffold { innerPadding -> + val webRoot = File(context.dataDir, "webroot") + val webViewAssetLoader = WebViewAssetLoader.Builder() + .addPathHandler("/", WebViewAssetLoader.InternalStoragePathHandler(context, webRoot)) + .build() + + val webViewClient = object : AccompanistWebViewClient() { + override fun shouldInterceptRequest( + view: WebView, + request: WebResourceRequest + ): WebResourceResponse? { + return webViewAssetLoader.shouldInterceptRequest(request.url) + } + } WebView( - state = rememberWebViewState(url = "file:///data/data/me.weishu.kernelsu/webroot/index.html"), + state = rememberWebViewState(url = "https://appassets.androidplatform.net/index.html"), Modifier .fillMaxSize() .padding(innerPadding), + client = webViewClient, factory = { context -> WebView(context).apply { settings.javaScriptEnabled = true settings.domStorageEnabled = true - settings.allowFileAccess = true + settings.allowFileAccess = false addJavascriptInterface(WebViewInterface(context, this), "ksu") } }) } } -class WebViewInterface(val context: Context, val webView: WebView) { +class WebViewInterface(val context: Context, private val webView: WebView) { companion object { var isHideSystemUI: Boolean = false @@ -109,10 +128,6 @@ class WebViewInterface(val context: Context, val webView: WebView) { options: String?, callbackFunc: String ) { - val opts = if (options == null) JSONObject() else { - JSONObject(options) - } - val finalCommand = StringBuilder() processOptions(finalCommand, options) finalCommand.append(cmd) diff --git a/manager/build.gradle.kts b/manager/build.gradle.kts index 030ac9fd..01fafd81 100644 --- a/manager/build.gradle.kts +++ b/manager/build.gradle.kts @@ -34,8 +34,8 @@ cmaker { val androidMinSdkVersion = 26 val androidTargetSdkVersion = 33 -val androidCompileSdkVersion = 33 -val androidBuildToolsVersion = "33.0.2" +val androidCompileSdkVersion = 34 +val androidBuildToolsVersion = "34.0.0" val androidCompileNdkVersion = "25.2.9519653" val androidSourceCompatibility = JavaVersion.VERSION_17 val androidTargetCompatibility = JavaVersion.VERSION_17 diff --git a/manager/gradle/libs.versions.toml b/manager/gradle/libs.versions.toml index bb737b24..11873e1b 100644 --- a/manager/gradle/libs.versions.toml +++ b/manager/gradle/libs.versions.toml @@ -10,6 +10,7 @@ compose-destination = "1.9.42-beta" libsu = "5.2.1" sheets-compose-dialogs = "1.2.0" markdown = "4.6.2" +webkit = "1.10.0" [plugins] agp-app = { id = "com.android.application", version.ref = "agp" } @@ -36,6 +37,7 @@ androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecyc androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycle" } androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycle" } +androidx-webkit = { module = "androidx.webkit:webkit", version.ref = "webkit" } com-google-accompanist-drawablepainter = { group = "com.google.accompanist", name = "accompanist-drawablepainter", version.ref = "accompanist" } com-google-accompanist-navigation-animation = { group = "com.google.accompanist", name = "accompanist-navigation-animation", version.ref = "accompanist" } com-google-accompanist-systemuicontroller = { group = "com.google.accompanist", name = "accompanist-systemuicontroller", version.ref = "accompanist" }