diff options
author | Andrew Kaster <andrewdkaster@gmail.com> | 2022-07-11 01:14:53 -0600 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-25 07:58:58 -0700 |
commit | 261f078a28954275291e175cd51a41095d9abcf6 (patch) | |
tree | bd26e1c08a329278ee349da4d23622cb6709a463 /Ladybird/android/src/org | |
parent | 7e42eae1a24c2d3c6c7954e56549f08cd204b842 (diff) | |
download | serenity-261f078a28954275291e175cd51a41095d9abcf6.zip |
Ladybird/Meta: Add Android build
Build an Android APK file that, when configured properly in Qt Creator,
can be used to deploy the browser to an Android device.
The current build requires NDK 24, targets no less than Android API 30,
and Qt Creator 6.4.0.
Diffstat (limited to 'Ladybird/android/src/org')
-rw-r--r-- | Ladybird/android/src/org/serenityos/ladybird/TransferAssets.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Ladybird/android/src/org/serenityos/ladybird/TransferAssets.java b/Ladybird/android/src/org/serenityos/ladybird/TransferAssets.java new file mode 100644 index 0000000000..edf5e8352d --- /dev/null +++ b/Ladybird/android/src/org/serenityos/ladybird/TransferAssets.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +package org.serenityos.ladybird; + +import android.content.Context; +import android.content.res.AssetManager; +import android.util.Log; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import java.lang.String; + +public class TransferAssets +{ + /** + @returns new ladybird resource root + */ + static public String transferAssets(Context context) + { + Log.d("Ladybird", "Hello from java"); + Context applicationContext = context.getApplicationContext(); + File assetDir = applicationContext.getFilesDir(); + AssetManager assetManager = applicationContext.getAssets(); + if (!copyAsset(assetManager, "ladybird-assets.tar", assetDir.getAbsolutePath() + "/ladybird-assets.tar")) { + Log.e("Ladybird", "Unable to copy assets"); + return "Invalid Assets, this won't work"; + } + Log.d("Ladybird", "Copied ladybird-assets.tar to app-specific storage path"); + return assetDir.getAbsolutePath(); + } + + // ty to https://stackoverflow.com/a/22903693 for the sauce + private static boolean copyAsset(AssetManager assetManager, + String fromAssetPath, String toPath) { + InputStream in = null; + OutputStream out = null; + try { + in = assetManager.open(fromAssetPath); + new File(toPath).createNewFile(); + out = new FileOutputStream(toPath); + copyFile(in, out); + in.close(); + in = null; + out.flush(); + out.close(); + out = null; + return true; + } catch(Exception e) { + e.printStackTrace(); + return false; + } + } + + private static void copyFile(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[4096]; + int read; + while((read = in.read(buffer)) != -1){ + out.write(buffer, 0, read); + } + } +}; |