commit 3559f0c8bff98e64fadb6a92f95b12a9146d730d Author: 5ec1cff Date: Thu Oct 3 21:14:09 2024 +0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb5ffd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties +/.kotlin diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..3238f10 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,49 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.jetbrains.kotlin.android) +} + +android { + namespace = "io.github.a13e300.ksuwebui" + compileSdk = 35 + + defaultConfig { + applicationId = "io.github.a13e300.ksuwebui" + minSdk = 26 + targetSdk = 35 + versionCode = 1 + versionName = "1.0" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 + } + kotlinOptions { + jvmTarget = "21" + } + buildFeatures { + buildConfig = true + } +} + +dependencies { + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.webkit) + + implementation(libs.material) + + implementation(libs.com.github.topjohnwu.libsu.core) + implementation(libs.com.github.topjohnwu.libsu.service) + implementation(libs.com.github.topjohnwu.libsu.io) +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ad549e8 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/io/github/a13e300/ksuwebui/MimeUtil.java b/app/src/main/java/io/github/a13e300/ksuwebui/MimeUtil.java new file mode 100644 index 0000000..3238da7 --- /dev/null +++ b/app/src/main/java/io/github/a13e300/ksuwebui/MimeUtil.java @@ -0,0 +1,88 @@ +package io.github.a13e300.ksuwebui; + +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.net.URLConnection; + +class MimeUtil { + + public static String getMimeFromFileName(String fileName) { + if (fileName == null) { + return null; + } + + // Copying the logic and mapping that Chromium follows. + // First we check against the OS (this is a limited list by default) + // but app developers can extend this. + // We then check against a list of hardcoded mime types above if the + // OS didn't provide a result. + String mimeType = URLConnection.guessContentTypeFromName(fileName); + + if (mimeType != null) { + return mimeType; + } + + return guessHardcodedMime(fileName); + } + + // We should keep this map in sync with the lists under + // //net/base/mime_util.cc in Chromium. + // A bunch of the mime types don't really apply to Android land + // like word docs so feel free to filter out where necessary. + private static String guessHardcodedMime(String fileName) { + int finalFullStop = fileName.lastIndexOf('.'); + if (finalFullStop == -1) { + return null; + } + + final String extension = fileName.substring(finalFullStop + 1).toLowerCase(); + + return switch (extension) { + case "webm" -> "video/webm"; + case "mpeg", "mpg" -> "video/mpeg"; + case "mp3" -> "audio/mpeg"; + case "wasm" -> "application/wasm"; + case "xhtml", "xht", "xhtm" -> "application/xhtml+xml"; + case "flac" -> "audio/flac"; + case "ogg", "oga", "opus" -> "audio/ogg"; + case "wav" -> "audio/wav"; + case "m4a" -> "audio/x-m4a"; + case "gif" -> "image/gif"; + case "jpeg", "jpg", "jfif", "pjpeg", "pjp" -> "image/jpeg"; + case "png" -> "image/png"; + case "apng" -> "image/apng"; + case "svg", "svgz" -> "image/svg+xml"; + case "webp" -> "image/webp"; + case "mht", "mhtml" -> "multipart/related"; + case "css" -> "text/css"; + case "html", "htm", "shtml", "shtm", "ehtml" -> "text/html"; + case "js", "mjs" -> "application/javascript"; + case "xml" -> "text/xml"; + case "mp4", "m4v" -> "video/mp4"; + case "ogv", "ogm" -> "video/ogg"; + case "ico" -> "image/x-icon"; + case "woff" -> "application/font-woff"; + case "gz", "tgz" -> "application/gzip"; + case "json" -> "application/json"; + case "pdf" -> "application/pdf"; + case "zip" -> "application/zip"; + case "bmp" -> "image/bmp"; + case "tiff", "tif" -> "image/tiff"; + default -> null; + }; + } +} diff --git a/app/src/main/java/io/github/a13e300/ksuwebui/SuFilePathHandler.java b/app/src/main/java/io/github/a13e300/ksuwebui/SuFilePathHandler.java new file mode 100644 index 0000000..39de408 --- /dev/null +++ b/app/src/main/java/io/github/a13e300/ksuwebui/SuFilePathHandler.java @@ -0,0 +1,192 @@ +package io.github.a13e300.ksuwebui; + +import android.content.Context; +import android.util.Log; +import android.webkit.WebResourceResponse; + +import androidx.annotation.NonNull; +import androidx.annotation.WorkerThread; +import androidx.webkit.WebViewAssetLoader; + +import com.topjohnwu.superuser.Shell; +import com.topjohnwu.superuser.io.SuFile; +import com.topjohnwu.superuser.io.SuFileInputStream; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.GZIPInputStream; + +/** + * Handler class to open files from file system by root access + * For more information about android storage please refer to + * Android Developers + * Docs: Data and file storage overview. + *

+ * To avoid leaking user or app data to the web, make sure to choose {@code directory} + * carefully, and assume any file under this directory could be accessed by any web page subject + * to same-origin rules. + *

+ * A typical usage would be like: + *

+ * File publicDir = new File(context.getFilesDir(), "public");
+ * // Host "files/public/" in app's data directory under:
+ * // http://appassets.androidplatform.net/public/...
+ * WebViewAssetLoader assetLoader = new WebViewAssetLoader.Builder()
+ *          .addPathHandler("/public/", new InternalStoragePathHandler(context, publicDir))
+ *          .build();
+ * 
+ */ +public final class SuFilePathHandler implements WebViewAssetLoader.PathHandler { + private static final String TAG = "SuFilePathHandler"; + + /** + * Default value to be used as MIME type if guessing MIME type failed. + */ + public static final String DEFAULT_MIME_TYPE = "text/plain"; + + /** + * Forbidden subdirectories of {@link Context#getDataDir} that cannot be exposed by this + * handler. They are forbidden as they often contain sensitive information. + *

+ * Note: Any future addition to this list will be considered breaking changes to the API. + */ + private static final String[] FORBIDDEN_DATA_DIRS = + new String[] {"/data/data", "/data/system"}; + + @NonNull + private final File mDirectory; + + private final Shell mShell; + + /** + * Creates PathHandler for app's internal storage. + * The directory to be exposed must be inside either the application's internal data + * directory {@link Context#getDataDir} or cache directory {@link Context#getCacheDir}. + * External storage is not supported for security reasons, as other apps with + * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} may be able to modify the + * files. + *

+ * Exposing the entire data or cache directory is not permitted, to avoid accidentally + * exposing sensitive application files to the web. Certain existing subdirectories of + * {@link Context#getDataDir} are also not permitted as they are often sensitive. + * These files are ({@code "app_webview/"}, {@code "databases/"}, {@code "lib/"}, + * {@code "shared_prefs/"} and {@code "code_cache/"}). + *

+ * The application should typically use a dedicated subdirectory for the files it intends to + * expose and keep them separate from other files. + * + * @param context {@link Context} that is used to access app's internal storage. + * @param directory the absolute path of the exposed app internal storage directory from + * which files can be loaded. + * @throws IllegalArgumentException if the directory is not allowed. + */ + public SuFilePathHandler(@NonNull Context context, @NonNull File directory, Shell rootShell) { + try { + mDirectory = new File(getCanonicalDirPath(directory)); + if (!isAllowedInternalStorageDir(context)) { + throw new IllegalArgumentException("The given directory \"" + directory + + "\" doesn't exist under an allowed app internal storage directory"); + } + mShell = rootShell; + } catch (IOException e) { + throw new IllegalArgumentException( + "Failed to resolve the canonical path for the given directory: " + + directory.getPath(), e); + } + } + + private boolean isAllowedInternalStorageDir(@NonNull Context context) throws IOException { + String dir = getCanonicalDirPath(mDirectory); + + for (String forbiddenPath : FORBIDDEN_DATA_DIRS) { + if (dir.startsWith(forbiddenPath)) { + return false; + } + } + return true; + } + + /** + * Opens the requested file from the exposed data directory. + *

+ * The matched prefix path used shouldn't be a prefix of a real web path. Thus, if the + * requested file cannot be found or is outside the mounted directory a + * {@link WebResourceResponse} object with a {@code null} {@link InputStream} will be + * returned instead of {@code null}. This saves the time of falling back to network and + * trying to resolve a path that doesn't exist. A {@link WebResourceResponse} with + * {@code null} {@link InputStream} will be received as an HTTP response with status code + * {@code 404} and no body. + *

+ * The MIME type for the file will be determined from the file's extension using + * {@link java.net.URLConnection#guessContentTypeFromName}. Developers should ensure that + * files are named using standard file extensions. If the file does not have a + * recognised extension, {@code "text/plain"} will be used by default. + * + * @param path the suffix path to be handled. + * @return {@link WebResourceResponse} for the requested file. + */ + @Override + @WorkerThread + @NonNull + public WebResourceResponse handle(@NonNull String path) { + try { + File file = getCanonicalFileIfChild(mDirectory, path); + if (file != null) { + InputStream is = openFile(file, mShell); + String mimeType = guessMimeType(path); + return new WebResourceResponse(mimeType, null, is); + } else { + Log.e(TAG, String.format( + "The requested file: %s is outside the mounted directory: %s", path, + mDirectory)); + } + } catch (IOException e) { + Log.e(TAG, "Error opening the requested path: " + path, e); + } + return new WebResourceResponse(null, null, null); + } + + public static String getCanonicalDirPath(@NonNull File file) throws IOException { + String canonicalPath = file.getCanonicalPath(); + if (!canonicalPath.endsWith("/")) canonicalPath += "/"; + return canonicalPath; + } + + public static File getCanonicalFileIfChild(@NonNull File parent, @NonNull String child) + throws IOException { + String parentCanonicalPath = getCanonicalDirPath(parent); + String childCanonicalPath = new File(parent, child).getCanonicalPath(); + if (childCanonicalPath.startsWith(parentCanonicalPath)) { + return new File(childCanonicalPath); + } + return null; + } + + @NonNull + private static InputStream handleSvgzStream(@NonNull String path, + @NonNull InputStream stream) throws IOException { + return path.endsWith(".svgz") ? new GZIPInputStream(stream) : stream; + } + + public static InputStream openFile(@NonNull File file, @NonNull Shell shell) throws IOException { + SuFile suFile = new SuFile(file.getAbsolutePath()); + suFile.setShell(shell); + InputStream fis = SuFileInputStream.open(suFile); + return handleSvgzStream(file.getPath(), fis); + } + + /** + * Use {@link MimeUtil#getMimeFromFileName} to guess MIME type or return the + * {@link #DEFAULT_MIME_TYPE} if it can't guess. + * + * @param filePath path of the file to guess its MIME type. + * @return MIME type guessed from file extension or {@link #DEFAULT_MIME_TYPE}. + */ + @NonNull + public static String guessMimeType(@NonNull String filePath) { + String mimeType = MimeUtil.getMimeFromFileName(filePath); + return mimeType == null ? DEFAULT_MIME_TYPE : mimeType; + } +} + diff --git a/app/src/main/java/io/github/a13e300/ksuwebui/Util.kt b/app/src/main/java/io/github/a13e300/ksuwebui/Util.kt new file mode 100644 index 0000000..7e9ea08 --- /dev/null +++ b/app/src/main/java/io/github/a13e300/ksuwebui/Util.kt @@ -0,0 +1,38 @@ +package io.github.a13e300.ksuwebui + +import android.util.Log +import com.topjohnwu.superuser.Shell + + +private const val TAG = "KsuCli" + +inline fun withNewRootShell( + globalMnt: Boolean = false, + block: Shell.() -> T +): T { + return createRootShell(globalMnt).use(block) +} + +fun createRootShell(globalMnt: Boolean = false): Shell { + Shell.enableVerboseLogging = BuildConfig.DEBUG + val builder = Shell.Builder.create() + return try { + if (globalMnt) { + builder.build("su", "-g") + } else { + builder.build("su") + } + } catch (e: Throwable) { + Log.w(TAG, "ksu failed: ", e) + try { + if (globalMnt) { + builder.build("su") + } else { + builder.build("su", "-mm") + } + } catch (e: Throwable) { + Log.e(TAG, "su failed: ", e) + builder.build("sh") + } + } +} diff --git a/app/src/main/java/io/github/a13e300/ksuwebui/WebUIActivity.kt b/app/src/main/java/io/github/a13e300/ksuwebui/WebUIActivity.kt new file mode 100644 index 0000000..f31a5c8 --- /dev/null +++ b/app/src/main/java/io/github/a13e300/ksuwebui/WebUIActivity.kt @@ -0,0 +1,99 @@ +package io.github.a13e300.ksuwebui + +import android.annotation.SuppressLint +import android.app.ActivityManager +import android.os.Build +import android.os.Bundle +import android.view.ViewGroup.MarginLayoutParams +import android.webkit.WebResourceRequest +import android.webkit.WebResourceResponse +import android.webkit.WebView +import android.webkit.WebViewClient +import androidx.activity.ComponentActivity +import androidx.activity.enableEdgeToEdge +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.updateLayoutParams +import androidx.webkit.WebViewAssetLoader +import com.topjohnwu.superuser.Shell +import java.io.File + +@SuppressLint("SetJavaScriptEnabled") +class WebUIActivity : ComponentActivity() { + private lateinit var webviewInterface: WebViewInterface + + private var rootShell: Shell? = null + + override fun onCreate(savedInstanceState: Bundle?) { + // Enable edge to edge + enableEdgeToEdge() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + window.isNavigationBarContrastEnforced = false + } + + super.onCreate(savedInstanceState) + + val moduleId = intent.getStringExtra("id")!! + val name = intent.getStringExtra("name")!! + if (name.isNotEmpty()) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { + @Suppress("DEPRECATION") + setTaskDescription(ActivityManager.TaskDescription(name)) + } else { + val taskDescription = + ActivityManager.TaskDescription.Builder().setLabel(name).build() + setTaskDescription(taskDescription) + } + } + + val prefs = getSharedPreferences("settings", MODE_PRIVATE) + WebView.setWebContentsDebuggingEnabled(prefs.getBoolean("enable_web_debugging", BuildConfig.DEBUG)) + + val moduleDir = "/data/adb/modules/${moduleId}" + val webRoot = File("${moduleDir}/webroot") + val rootShell = createRootShell(true).also { this.rootShell = it } + val webViewAssetLoader = WebViewAssetLoader.Builder() + .setDomain("mui.kernelsu.org") + .addPathHandler( + "/", + SuFilePathHandler(this, webRoot, rootShell) + ) + .build() + + val webViewClient = object : WebViewClient() { + override fun shouldInterceptRequest( + view: WebView, + request: WebResourceRequest + ): WebResourceResponse? { + return webViewAssetLoader.shouldInterceptRequest(request.url) + } + } + + val webView = WebView(this).apply { + ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets -> + val inset = insets.getInsets(WindowInsetsCompat.Type.systemBars()) + view.updateLayoutParams { + leftMargin = inset.left + rightMargin = inset.right + topMargin = inset.top + bottomMargin = inset.bottom + } + return@setOnApplyWindowInsetsListener insets + } + settings.javaScriptEnabled = true + settings.domStorageEnabled = true + settings.allowFileAccess = false + webviewInterface = WebViewInterface(this@WebUIActivity, this, moduleDir) + addJavascriptInterface(webviewInterface, "ksu") + setWebViewClient(webViewClient) + loadUrl("https://mui.kernelsu.org/index.html") + } + + setContentView(webView) + } + + override fun onDestroy() { + super.onDestroy() + runCatching { rootShell?.close() } + } +} diff --git a/app/src/main/java/io/github/a13e300/ksuwebui/WebViewInterface.kt b/app/src/main/java/io/github/a13e300/ksuwebui/WebViewInterface.kt new file mode 100644 index 0000000..3522a1d --- /dev/null +++ b/app/src/main/java/io/github/a13e300/ksuwebui/WebViewInterface.kt @@ -0,0 +1,194 @@ +package io.github.a13e300.ksuwebui + +import android.app.Activity +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.text.TextUtils +import android.view.Window +import android.webkit.JavascriptInterface +import android.webkit.WebView +import android.widget.Toast +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.WindowInsetsControllerCompat +import com.topjohnwu.superuser.CallbackList +import com.topjohnwu.superuser.ShellUtils +import com.topjohnwu.superuser.internal.UiThreadHandler +import org.json.JSONArray +import org.json.JSONObject +import java.io.File +import java.util.concurrent.CompletableFuture + +class WebViewInterface( + val context: Context, + private val webView: WebView, + private val modDir: String +) { + + @JavascriptInterface + fun exec(cmd: String): String { + return withNewRootShell(true) { ShellUtils.fastCmd(this, cmd) } + } + + @JavascriptInterface + fun exec(cmd: String, callbackFunc: String) { + exec(cmd, null, callbackFunc) + } + + private fun processOptions(sb: StringBuilder, options: String?) { + val opts = if (options == null) JSONObject() else { + JSONObject(options) + } + + val cwd = opts.optString("cwd") + if (!TextUtils.isEmpty(cwd)) { + sb.append("cd ${cwd};") + } + + opts.optJSONObject("env")?.let { env -> + env.keys().forEach { key -> + sb.append("export ${key}=${env.getString(key)};") + } + } + } + + @JavascriptInterface + fun exec( + cmd: String, + options: String?, + callbackFunc: String + ) { + val finalCommand = StringBuilder() + processOptions(finalCommand, options) + finalCommand.append(cmd) + + val result = withNewRootShell(true) { + newJob().add(finalCommand.toString()).to(ArrayList(), ArrayList()).exec() + } + val stdout = result.out.joinToString(separator = "\n") + val stderr = result.err.joinToString(separator = "\n") + + val jsCode = + "javascript: (function() { try { ${callbackFunc}(${result.code}, ${ + JSONObject.quote( + stdout + ) + }, ${JSONObject.quote(stderr)}); } catch(e) { console.error(e); } })();" + webView.post { + webView.loadUrl(jsCode) + } + } + + @JavascriptInterface + fun spawn(command: String, args: String, options: String?, callbackFunc: String) { + val finalCommand = StringBuilder() + + processOptions(finalCommand, options) + + if (!TextUtils.isEmpty(args)) { + finalCommand.append(command).append(" ") + JSONArray(args).let { argsArray -> + for (i in 0 until argsArray.length()) { + finalCommand.append(argsArray.getString(i)) + finalCommand.append(" ") + } + } + } else { + finalCommand.append(command) + } + + val shell = createRootShell(true) + + val emitData = fun(name: String, data: String) { + val jsCode = + "javascript: (function() { try { ${callbackFunc}.${name}.emit('data', ${ + JSONObject.quote( + data + ) + }); } catch(e) { console.error('emitData', e); } })();" + webView.post { + webView.loadUrl(jsCode) + } + } + + val stdout = object : CallbackList(UiThreadHandler::runAndWait) { + override fun onAddElement(s: String) { + emitData("stdout", s) + } + } + + val stderr = object : CallbackList(UiThreadHandler::runAndWait) { + override fun onAddElement(s: String) { + emitData("stderr", s) + } + } + + val future = shell.newJob().add(finalCommand.toString()).to(stdout, stderr).enqueue() + val completableFuture = CompletableFuture.supplyAsync { + future.get() + } + + completableFuture.thenAccept { result -> + val emitExitCode = + "javascript: (function() { try { ${callbackFunc}.emit('exit', ${result.code}); } catch(e) { console.error(`emitExit error: \${e}`); } })();" + webView.post { + webView.loadUrl(emitExitCode) + } + + if (result.code != 0) { + val emitErrCode = + "javascript: (function() { try { var err = new Error(); err.exitCode = ${result.code}; err.message = ${ + JSONObject.quote( + result.err.joinToString( + "\n" + ) + ) + };${callbackFunc}.emit('error', err); } catch(e) { console.error('emitErr', e); } })();" + webView.post { + webView.loadUrl(emitErrCode) + } + } + }.whenComplete { _, _ -> + runCatching { shell.close() } + } + } + + @JavascriptInterface + fun toast(msg: String) { + webView.post { + Toast.makeText(context, msg, Toast.LENGTH_SHORT).show() + } + } + + @JavascriptInterface + fun fullScreen(enable: Boolean) { + if (context is Activity) { + Handler(Looper.getMainLooper()).post { + if (enable) { + hideSystemUI(context.window) + } else { + showSystemUI(context.window) + } + } + } + } + + @JavascriptInterface + fun moduleInfo(): String { + val currentModuleInfo = JSONObject() + currentModuleInfo.put("moduleDir", modDir) + val moduleId = File(modDir).getName() + currentModuleInfo.put("id", moduleId) + // TODO: more + return currentModuleInfo.toString() + } +} + +fun hideSystemUI(window: Window) = + WindowInsetsControllerCompat(window, window.decorView).let { controller -> + controller.hide(WindowInsetsCompat.Type.systemBars()) + controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + } + +fun showSystemUI(window: Window) = + WindowInsetsControllerCompat(window, window.decorView).show(WindowInsetsCompat.Type.systemBars()) diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..44ea19d --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/backup_rules.xml b/app/src/main/res/xml/backup_rules.xml new file mode 100644 index 0000000..fa0f996 --- /dev/null +++ b/app/src/main/res/xml/backup_rules.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/data_extraction_rules.xml b/app/src/main/res/xml/data_extraction_rules.xml new file mode 100644 index 0000000..9ee9997 --- /dev/null +++ b/app/src/main/res/xml/data_extraction_rules.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml new file mode 100644 index 0000000..6dd26cc --- /dev/null +++ b/app/src/main/res/xml/network_security_config.xml @@ -0,0 +1,8 @@ + + + + 127.0.0.1 + 0.0.0.0 + ::1 + + diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..f74b04b --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,5 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + alias(libs.plugins.android.application) apply false + alias(libs.plugins.jetbrains.kotlin.android) apply false +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..20e2a01 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,23 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. For more details, visit +# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..551b3d1 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,24 @@ +[versions] +agp = "8.6.1" +kotlin = "2.0.20" +coreKtx = "1.13.1" +appcompat = "1.7.0" +material = "1.12.0" +webkit = "1.12.0" +libsu = "6.0.0" + +[libraries] +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } +androidx-webkit = { module = "androidx.webkit:webkit", version.ref = "webkit" } + +com-github-topjohnwu-libsu-core = { group = "com.github.topjohnwu.libsu", name = "core", version.ref = "libsu" } +com-github-topjohnwu-libsu-service = { group = "com.github.topjohnwu.libsu", name = "service", version.ref = "libsu" } +com-github-topjohnwu-libsu-io= { group = "com.github.topjohnwu.libsu", name = "io", version.ref = "libsu" } + +material = { group = "com.google.android.material", name = "material", version.ref = "material" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..e67f5b8 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Oct 01 14:03:20 CST 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..046d75f --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,24 @@ +pluginManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + maven("https://jitpack.io") + } +} + +rootProject.name = "KsuWebUI" +include(":app")