summaryrefslogtreecommitdiffstats
path: root/platform/android/java/lib
diff options
context:
space:
mode:
authorFredia Huya-Kouadio <fhuyakou@gmail.com>2024-06-16 12:14:34 -0700
committerFredia Huya-Kouadio <fhuyakou@gmail.com>2024-08-26 11:16:38 -0700
commita5897d579bb0af496a18f7430345a67fe27ff0df (patch)
tree6fee6886d95ce778af80ecd6b0467a4f86de9e06 /platform/android/java/lib
parent794ea99240607a7afbc1512582083db82d81ff83 (diff)
downloadredot-engine-a5897d579bb0af496a18f7430345a67fe27ff0df.tar.gz
Update the `GodotHost` interface to support signing and verifying Android apks
Update the export logic to enable apk generation and signing for Android editor builds Note: Only legacy builds are supported. Gradle builds are not supported at this point in time.
Diffstat (limited to 'platform/android/java/lib')
-rw-r--r--platform/android/java/lib/THIRDPARTY.md39
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.kt18
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java17
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotHost.java28
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt8
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/io/file/FileAccessHandler.kt2
6 files changed, 71 insertions, 41 deletions
diff --git a/platform/android/java/lib/THIRDPARTY.md b/platform/android/java/lib/THIRDPARTY.md
deleted file mode 100644
index 2496b59263..0000000000
--- a/platform/android/java/lib/THIRDPARTY.md
+++ /dev/null
@@ -1,39 +0,0 @@
-# Third-party libraries
-
-This file list third-party libraries used in the Android source folder,
-with their provenance and, when relevant, modifications made to those files.
-
-## com.android.vending.billing
-
-- Upstream: https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive/app/src/main
-- Version: git (7a94c69, 2019)
-- License: Apache 2.0
-
-Overwrite the file `aidl/com/android/vending/billing/IInAppBillingService.aidl`.
-
-## com.google.android.vending.expansion.downloader
-
-- Upstream: https://github.com/google/play-apk-expansion/tree/master/apkx_library
-- Version: git (9ecf54e, 2017)
-- License: Apache 2.0
-
-Overwrite all files under:
-
-- `src/com/google/android/vending/expansion/downloader`
-
-Some files have been modified for yet unclear reasons.
-See the `patches/com.google.android.vending.expansion.downloader.patch` file.
-
-## com.google.android.vending.licensing
-
-- Upstream: https://github.com/google/play-licensing/tree/master/lvl_library/
-- Version: git (eb57657, 2018) with modifications
-- License: Apache 2.0
-
-Overwrite all files under:
-
-- `aidl/com/android/vending/licensing`
-- `src/com/google/android/vending/licensing`
-
-Some files have been modified to silence linter errors or fix downstream issues.
-See the `patches/com.google.android.vending.licensing.patch` file.
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
index 1e0027089c..49e8ffb008 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt
@@ -50,6 +50,7 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsAnimationCompat
import androidx.core.view.WindowInsetsCompat
import com.google.android.vending.expansion.downloader.*
+import org.godotengine.godot.error.Error
import org.godotengine.godot.input.GodotEditText
import org.godotengine.godot.input.GodotInputHandler
import org.godotengine.godot.io.directory.DirectoryAccessHandler
@@ -96,7 +97,6 @@ class Godot(private val context: Context) {
fun isEditorBuild() = BuildConfig.FLAVOR == EDITOR_FLAVOR
}
- private val windowManager: WindowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
private val mSensorManager: SensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
private val mClipboard: ClipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
private val vibratorService: Vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
@@ -1054,4 +1054,20 @@ class Godot(private val context: Context) {
private fun nativeDumpBenchmark(benchmarkFile: String) {
dumpBenchmark(fileAccessHandler, benchmarkFile)
}
+
+ @Keep
+ private fun nativeSignApk(inputPath: String,
+ outputPath: String,
+ keystorePath: String,
+ keystoreUser: String,
+ keystorePassword: String): Int {
+ val signResult = primaryHost?.signApk(inputPath, outputPath, keystorePath, keystoreUser, keystorePassword) ?: Error.ERR_UNAVAILABLE
+ return signResult.toNativeValue()
+ }
+
+ @Keep
+ private fun nativeVerifyApk(apkPath: String): Int {
+ val verifyResult = primaryHost?.verifyApk(apkPath) ?: Error.ERR_UNAVAILABLE
+ return verifyResult.toNativeValue()
+ }
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java
index fdda766594..e0f5744368 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotFragment.java
@@ -30,6 +30,7 @@
package org.godotengine.godot;
+import org.godotengine.godot.error.Error;
import org.godotengine.godot.plugin.GodotPlugin;
import org.godotengine.godot.utils.BenchmarkUtils;
@@ -484,4 +485,20 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
}
return Collections.emptySet();
}
+
+ @Override
+ public Error signApk(@NonNull String inputPath, @NonNull String outputPath, @NonNull String keystorePath, @NonNull String keystoreUser, @NonNull String keystorePassword) {
+ if (parentHost != null) {
+ return parentHost.signApk(inputPath, outputPath, keystorePath, keystoreUser, keystorePassword);
+ }
+ return Error.ERR_UNAVAILABLE;
+ }
+
+ @Override
+ public Error verifyApk(@NonNull String apkPath) {
+ if (parentHost != null) {
+ return parentHost.verifyApk(apkPath);
+ }
+ return Error.ERR_UNAVAILABLE;
+ }
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotHost.java b/platform/android/java/lib/src/org/godotengine/godot/GodotHost.java
index 1862b9fa9b..f1c84e90a7 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotHost.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotHost.java
@@ -30,10 +30,13 @@
package org.godotengine.godot;
+import org.godotengine.godot.error.Error;
import org.godotengine.godot.plugin.GodotPlugin;
import android.app.Activity;
+import androidx.annotation.NonNull;
+
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -108,4 +111,29 @@ public interface GodotHost {
default Set<GodotPlugin> getHostPlugins(Godot engine) {
return Collections.emptySet();
}
+
+ /**
+ * Signs the given Android apk
+ *
+ * @param inputPath Path to the apk that should be signed
+ * @param outputPath Path for the signed output apk; can be the same as inputPath
+ * @param keystorePath Path to the keystore to use for signing the apk
+ * @param keystoreUser Keystore user credential
+ * @param keystorePassword Keystore password credential
+ *
+ * @return {@link Error#OK} if signing is successful
+ */
+ default Error signApk(@NonNull String inputPath, @NonNull String outputPath, @NonNull String keystorePath, @NonNull String keystoreUser, @NonNull String keystorePassword) {
+ return Error.ERR_UNAVAILABLE;
+ }
+
+ /**
+ * Verifies the given Android apk is signed
+ *
+ * @param apkPath Path to the apk that should be verified
+ * @return {@link Error#OK} if verification was successful
+ */
+ default Error verifyApk(@NonNull String apkPath) {
+ return Error.ERR_UNAVAILABLE;
+ }
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt b/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt
index 2e5649b563..574ecd58eb 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt
+++ b/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt
@@ -74,6 +74,14 @@ internal enum class StorageScope {
private val documentsSharedDir: String? = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).canonicalPath
/**
+ * Determine if the given path is accessible.
+ */
+ fun canAccess(path: String?): Boolean {
+ val storageScope = identifyStorageScope(path)
+ return storageScope == APP || storageScope == SHARED
+ }
+
+ /**
* Determines which [StorageScope] the given path falls under.
*/
fun identifyStorageScope(path: String?): StorageScope {
diff --git a/platform/android/java/lib/src/org/godotengine/godot/io/file/FileAccessHandler.kt b/platform/android/java/lib/src/org/godotengine/godot/io/file/FileAccessHandler.kt
index 5d57052ce6..5d87f23b4a 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/io/file/FileAccessHandler.kt
+++ b/platform/android/java/lib/src/org/godotengine/godot/io/file/FileAccessHandler.kt
@@ -107,7 +107,7 @@ class FileAccessHandler(val context: Context) {
}
}
- private val storageScopeIdentifier = StorageScope.Identifier(context)
+ internal val storageScopeIdentifier = StorageScope.Identifier(context)
private val files = SparseArray<DataAccess>()
private var lastFileId = STARTING_FILE_ID