Android: load url from Intent, plus fixed some warnings (#32160)

* update gitignore folder with android build files

* address some warnings

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* fix servo not loading url from Intent

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* format

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* InitOptions, added url field to avoid override homepage url

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* actually there is a gitignore file in the android folder

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* Restore buildToolsVersion property

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This commit is contained in:
Gae24 2024-04-29 15:14:10 +02:00 committed by GitHub
parent 5a4c81f841
commit fe6e1cfb29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 50 additions and 66 deletions

4
.gitignore vendored
View file

@ -8,10 +8,6 @@
/android-toolchains /android-toolchains
/target /target
/tests/wpt/reftests-report/report.html /tests/wpt/reftests-report/report.html
/ports/android/bin
/ports/android/libs
/ports/android/local.properties
/ports/android/obj
/python/_virtualenv* /python/_virtualenv*
/python/_venv* /python/_venv*
/python/tidy/servo_tidy.egg-info /python/tidy/servo_tidy.egg-info

View file

@ -73,7 +73,7 @@ pub extern "C" fn Java_org_mozilla_servoview_JNIServo_init(
callbacks_obj: JObject, callbacks_obj: JObject,
surface: JObject, surface: JObject,
) { ) {
let (mut opts, log, log_str, _gst_debug_str) = match get_options(&env, opts, surface) { let (opts, log, log_str, _gst_debug_str) = match get_options(&env, opts, surface) {
Ok((opts, log, log_str, gst_debug_str)) => (opts, log, log_str, gst_debug_str), Ok((opts, log, log_str, gst_debug_str)) => (opts, log, log_str, gst_debug_str),
Err(err) => { Err(err) => {
throw(&env, &err); throw(&env, &err);
@ -875,6 +875,7 @@ fn get_options(
let opts = InitOptions { let opts = InitOptions {
args: args.unwrap_or(vec![]), args: args.unwrap_or(vec![]),
url,
coordinates, coordinates,
density, density,
xr_discovery: None, xr_discovery: None,

View file

@ -52,6 +52,7 @@ pub use servo::embedder_traits::EventLoopWaker;
pub struct InitOptions { pub struct InitOptions {
pub args: Vec<String>, pub args: Vec<String>,
pub url: Option<String>,
pub coordinates: Coordinates, pub coordinates: Coordinates,
pub density: f32, pub density: f32,
pub xr_discovery: Option<webxr::Discovery>, pub xr_discovery: Option<webxr::Discovery>,
@ -253,10 +254,11 @@ pub fn init(
args.insert(0, "servo".to_string()); args.insert(0, "servo".to_string());
opts::from_cmdline_args(Options::new(), &args); opts::from_cmdline_args(Options::new(), &args);
let embedder_url = init_opts.url.as_ref().and_then(|s| ServoUrl::parse(s).ok());
let pref_url = ServoUrl::parse(&pref!(shell.homepage)).ok(); let pref_url = ServoUrl::parse(&pref!(shell.homepage)).ok();
let blank_url = ServoUrl::parse("about:blank").ok(); let blank_url = ServoUrl::parse("about:blank").ok();
let url = pref_url.or(blank_url).unwrap(); let url = embedder_url.or(pref_url).or(blank_url).unwrap();
gl.clear_color(1.0, 1.0, 1.0, 1.0); gl.clear_color(1.0, 1.0, 1.0, 1.0);
gl.clear(gl::COLOR_BUFFER_BIT); gl.clear(gl::COLOR_BUFFER_BIT);

View file

@ -3,4 +3,5 @@
/gen/ /gen/
/libs/ /libs/
/local.properties /local.properties
/obj/
/proguard-project.txt /proguard-project.txt

View file

@ -25,8 +25,8 @@ ext.getJniLibsPath = { boolean debug, String arch ->
ext.getRustTarget = { String arch -> ext.getRustTarget = { String arch ->
switch (arch.toLowerCase()) { switch (arch.toLowerCase()) {
case 'armv7' : return 'armv7-linux-androideabi' case 'armv7': return 'armv7-linux-androideabi'
case 'arm64' : return 'aarch64-linux-android' case 'arm64': return 'aarch64-linux-android'
case 'x86': return 'i686-linux-android' case 'x86': return 'i686-linux-android'
case 'x64': return 'x86_64-linux-android' case 'x64': return 'x86_64-linux-android'
default: throw new GradleException("Invalid target architecture " + arch) default: throw new GradleException("Invalid target architecture " + arch)
@ -35,8 +35,8 @@ ext.getRustTarget = { String arch ->
ext.getNDKAbi = { String arch -> ext.getNDKAbi = { String arch ->
switch (arch.toLowerCase()) { switch (arch.toLowerCase()) {
case 'armv7' : return 'armeabi-v7a' case 'armv7': return 'armeabi-v7a'
case 'arm64' : return 'arm64-v8a' case 'arm64': return 'arm64-v8a'
case 'x86': return 'x86' case 'x86': return 'x86'
case 'x64': return 'x86_64' case 'x64': return 'x86_64'
default: throw new GradleException("Invalid target architecture " + arch) default: throw new GradleException("Invalid target architecture " + arch)
@ -60,8 +60,8 @@ ext.getNdkDir = { ->
def ndkDir = ndkRoot != null ? new File(ndkRoot) : null def ndkDir = ndkRoot != null ? new File(ndkRoot) : null
if (!ndkDir || !ndkDir.exists()) { if (!ndkDir || !ndkDir.exists()) {
throw new GradleException("Please set a valid ANDROID_NDK_ROOT environment variable" + throw new GradleException("Please set a valid ANDROID_NDK_ROOT environment variable " +
"or ndk.dir path in local.properties file"); "or ndk.dir path in local.properties file")
} }
return ndkDir.absolutePath return ndkDir.absolutePath
} }

View file

@ -7,7 +7,7 @@ import java.util.regex.Pattern
android { android {
compileSdk 33 compileSdk 33
buildToolsVersion "33.0.2" buildToolsVersion = "33.0.2"
namespace 'org.mozilla.servo' namespace 'org.mozilla.servo'
@ -27,7 +27,7 @@ android {
} }
// Share all of that with servoview // Share all of that with servoview
flavorDimensions "default" flavorDimensions = ["default"]
productFlavors { productFlavors {
basic { basic {
@ -113,8 +113,8 @@ android {
// Ignore default 'debug' and 'release' build types // Ignore default 'debug' and 'release' build types
variantFilter { variant -> variantFilter { variant ->
if(variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) { if(variant.buildType.name == 'release' || variant.buildType.name == 'debug') {
variant.setIgnore(true); variant.setIgnore(true)
} }
} }

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<uses-feature android:glEsVersion="0x00030000" android:required="true" /> <uses-feature android:glEsVersion="0x00030000" android:required="true" />
@ -12,8 +11,8 @@
<application android:label="Servo" android:icon="@mipmap/servo"> <application android:label="Servo" android:icon="@mipmap/servo">
<activity android:name=".MainActivity" <activity android:name=".MainActivity"
android:label="Servo" android:configChanges="density|keyboardHidden|navigation|orientation|screenSize|uiMode"
android:configChanges="density|keyboardHidden|navigation|orientation|screenSize|uiMode"> android:exported="true">
<meta-data android:name="android.app.lib_name" android:value="servo" /> <meta-data android:name="android.app.lib_name" android:value="servo" />
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -45,4 +44,3 @@
</application> </application>
</manifest> </manifest>
<!-- END_INCLUDE(manifest) -->

View file

@ -13,6 +13,7 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.system.ErrnoException; import android.system.ErrnoException;
import android.system.Os; import android.system.Os;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@ -21,11 +22,9 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.util.Log;
import org.mozilla.servo.MediaSession;
import org.mozilla.servoview.ServoView;
import org.mozilla.servoview.Servo; import org.mozilla.servoview.Servo;
import org.mozilla.servoview.ServoView;
import java.io.File; import java.io.File;
@ -65,16 +64,15 @@ public class MainActivity extends Activity implements Servo.Client {
mServoView.setClient(this); mServoView.setClient(this);
mServoView.requestFocus(); mServoView.requestFocus();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { File sdcard = getExternalFilesDir("");
File sdcard = getExternalFilesDir(""); String host = sdcard.toPath().resolve("android_hosts").toString();
String host = sdcard.toPath().resolve("android_hosts").toString(); try {
try {
Os.setenv("HOST_FILE", host, false); Os.setenv("HOST_FILE", host, false);
} catch (ErrnoException e) { } catch (ErrnoException e) {
e.printStackTrace(); e.printStackTrace();
}
} }
Intent intent = getIntent(); Intent intent = getIntent();
String args = intent.getStringExtra("servoargs"); String args = intent.getStringExtra("servoargs");
String log = intent.getStringExtra("servolog"); String log = intent.getStringExtra("servolog");
@ -253,7 +251,6 @@ public class MainActivity extends Activity implements Servo.Client {
if (state == MediaSession.PLAYBACK_STATE_PLAYING || if (state == MediaSession.PLAYBACK_STATE_PLAYING ||
state == MediaSession.PLAYBACK_STATE_PAUSED) { state == MediaSession.PLAYBACK_STATE_PAUSED) {
mMediaSession.showMediaSessionControls(); mMediaSession.showMediaSessionControls();
return;
} }
} }
@ -265,6 +262,5 @@ public class MainActivity extends Activity implements Servo.Client {
} }
mMediaSession.setPositionState(duration, position, playbackRate); mMediaSession.setPositionState(duration, position, playbackRate);
return;
} }
} }

View file

@ -5,7 +5,6 @@
package org.mozilla.servo; package org.mozilla.servo;
import android.app.Activity;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
@ -124,7 +123,7 @@ public class MediaSession {
mContext.registerReceiver(mMediaSessionActionReceiver, filter); mContext.registerReceiver(mMediaSessionActionReceiver, filter);
Notification.Builder builder = new Notification.Builder(mContext, this.MEDIA_CHANNEL_ID); Notification.Builder builder = new Notification.Builder(mContext, MEDIA_CHANNEL_ID);
builder builder
.setSmallIcon(R.drawable.media_session_icon) .setSmallIcon(R.drawable.media_session_icon)
.setContentTitle(mTitle) .setContentTitle(mTitle)

View file

@ -8,7 +8,7 @@ import java.util.regex.Pattern
android { android {
compileSdk 33 compileSdk 33
buildToolsVersion "33.0.2" buildToolsVersion = "33.0.2"
namespace 'org.mozilla.servoview' namespace 'org.mozilla.servoview'
@ -28,7 +28,7 @@ android {
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
flavorDimensions "default" flavorDimensions = ["default"]
productFlavors { productFlavors {
basic { basic {
@ -115,8 +115,8 @@ android {
// Ignore default 'debug' and 'release' build types // Ignore default 'debug' and 'release' build types
variantFilter { variant -> variantFilter { variant ->
if(variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) { if(variant.buildType.name == 'release' || variant.buildType.name == 'debug') {
variant.setIgnore(true); variant.setIgnore(true)
} }
} }
@ -140,7 +140,7 @@ android {
tasks.all { tasks.all {
compileTask -> compileTask ->
// This matches the task `mergeBasicArmv7DebugJniLibFolders`. // This matches the task `mergeBasicArmv7DebugJniLibFolders`.
Pattern pattern = Pattern.compile(/^merge[A-Z][\w\d]+([A-Z][\w\d]+)(Debug|Release)JniLibFolders/) Pattern pattern = Pattern.compile(/^merge[A-Z]\w+([A-Z]\w+)(Debug|Release)JniLibFolders/)
Matcher matcher = pattern.matcher(compileTask.name) Matcher matcher = pattern.matcher(compileTask.name)
if (!matcher.find()) { if (!matcher.find()) {
return return
@ -217,7 +217,7 @@ dependencies {
// folderFilter can be used to improve search performance // folderFilter can be used to improve search performance
static String findDependencyPath(String basePath, String filename, String folderFilter) { static String findDependencyPath(String basePath, String filename, String folderFilter) {
File path = new File(basePath); File path = new File(basePath)
if (!path.exists()) { if (!path.exists()) {
return '' return ''
} }
@ -231,7 +231,7 @@ static String findDependencyPath(String basePath, String filename, String folder
} }
def result = '' def result = ''
path.eachFileRecurse(FileType.FILES) { path.eachFileRecurse(FileType.FILES) {
if(it.name.equals(filename)) { if(it.name == filename) {
result = it.absolutePath result = it.absolutePath
} }
} }
@ -241,9 +241,9 @@ static String findDependencyPath(String basePath, String filename, String folder
class ServoDependency { class ServoDependency {
ServoDependency(String fileName, String folderFilter = null) { ServoDependency(String fileName, String folderFilter = null) {
this.fileName = fileName; this.fileName = fileName
this.folderFilter = folderFilter; this.folderFilter = folderFilter
} }
public String fileName; public String fileName
public String folderFilter; public String folderFilter
} }

View file

@ -6,17 +6,14 @@
package org.mozilla.servoview; package org.mozilla.servoview;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Surface; import android.view.Surface;
import org.mozilla.servoview.JNIServo.ServoCoordinates;
import org.mozilla.servoview.JNIServo.ServoOptions;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask; import java.util.concurrent.FutureTask;
import org.freedesktop.gstreamer.GStreamer;
import org.mozilla.servoview.JNIServo.ServoCoordinates;
import org.mozilla.servoview.JNIServo.ServoOptions;
public class Servo { public class Servo {
private static final String LOGTAG = "Servo"; private static final String LOGTAG = "Servo";
private JNIServo mJNI = new JNIServo(); private JNIServo mJNI = new JNIServo();
@ -38,9 +35,7 @@ public class Servo {
mServoCallbacks = new Callbacks(client, gfxcb); mServoCallbacks = new Callbacks(client, gfxcb);
mRunCallback.inGLThread(() -> { mRunCallback.inGLThread(() -> mJNI.init(activity, options, mServoCallbacks, surface));
mJNI.init(activity, options, mServoCallbacks, surface);
});
} }
public void resetGfxCallbacks(GfxCallbacks gfxcb) { public void resetGfxCallbacks(GfxCallbacks gfxcb) {
@ -49,7 +44,7 @@ public class Servo {
public void shutdown() { public void shutdown() {
mShuttingDown = true; mShuttingDown = true;
FutureTask<Void> task = new FutureTask<Void>(new Callable<Void>() { FutureTask<Void> task = new FutureTask<>(new Callable<Void>() {
public Void call() throws Exception { public Void call() throws Exception {
mJNI.requestShutdown(); mJNI.requestShutdown();
// Wait until Servo gets back to us to finalize shutdown. // Wait until Servo gets back to us to finalize shutdown.

View file

@ -27,6 +27,7 @@ import android.view.Choreographer;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.ScaleGestureDetector; import android.view.ScaleGestureDetector;
import android.view.View;
import android.widget.OverScroller; import android.widget.OverScroller;
import java.util.ArrayList; import java.util.ArrayList;
@ -78,7 +79,7 @@ public class ServoView extends SurfaceView
setFocusable(true); setFocusable(true);
setFocusableInTouchMode(true); setFocusableInTouchMode(true);
setClickable(true); setClickable(true);
ArrayList view = new ArrayList(); ArrayList<View> view = new ArrayList<>();
view.add(this); view.add(this);
addTouchables(view); addTouchables(view);
setWillNotCacheDrawing(false); setWillNotCacheDrawing(false);
@ -89,7 +90,6 @@ public class ServoView extends SurfaceView
mGLThread.start(); mGLThread.start();
} }
public void setClient(Client client) { public void setClient(Client client) {
mClient = client; mClient = client;
} }
@ -99,7 +99,6 @@ public class ServoView extends SurfaceView
mServoLog = log; mServoLog = log;
} }
// RunCallback // RunCallback
public void inGLThread(Runnable r) { public void inGLThread(Runnable r) {
mGLLooperHandler.post(r); mGLLooperHandler.post(r);
@ -212,16 +211,12 @@ public class ServoView extends SurfaceView
mServo.stop(); mServo.stop();
} }
public void loadUri(String uri) {
if (mServo != null) {
mServo.loadUri(uri);
} else {
mInitialUri = uri;
}
}
public void loadUri(Uri uri) { public void loadUri(Uri uri) {
loadUri(uri.toString()); if (mServo != null) {
mServo.loadUri(uri.toString());
} else {
mInitialUri = uri.toString();
}
} }
public void scrollStart(int dx, int dy, int x, int y) { public void scrollStart(int dx, int dy, int x, int y) {
@ -373,6 +368,7 @@ public class ServoView extends SurfaceView
Surface surface = holder.getSurface(); Surface surface = holder.getSurface();
ServoOptions options = new ServoOptions(); ServoOptions options = new ServoOptions();
options.args = mServoView.mServoArgs; options.args = mServoView.mServoArgs;
options.url = mServoView.mInitialUri;
options.coordinates = coords; options.coordinates = coords;
options.enableLogs = true; options.enableLogs = true;
options.enableSubpixelTextAntialiasing = true; options.enableSubpixelTextAntialiasing = true;