Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Servo support
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Oct 17, 2018
1 parent 81cbd41 commit d29da61
Show file tree
Hide file tree
Showing 19 changed files with 759 additions and 6 deletions.
56 changes: 55 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ android {
} else {
project.archivesBaseName = "FirefoxReality"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled true
Expand Down Expand Up @@ -121,6 +125,27 @@ android {
}
}
}
googlevrServo {
dimension "platform"
externalNativeBuild {
cmake {
cppFlags " -I" + file("${project.rootDir}/gvr-android-sdk/libraries/headers").absolutePath +
" -DVRBROWSER_GOOGLEVR"
arguments "-DVR_SDK_LIB=googlevr-lib", "-DGOOGLEVR=ON"
}
}
}
oculusvrServo {
dimension "platform"
externalNativeBuild {
cmake {
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
" -DOCULUSVR"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DOCULUSVR=ON"
}
}
}

// Supported ABIs
arm {
Expand All @@ -142,8 +167,12 @@ android {
def needed = variant.name in [
'googlevrArmDebug',
'googlevrArmRelease',
'googlevrServoArmDebug',
'googlevrServoArmRelease',
'oculusvrArmDebug',
'oculusvrArmRelease',
'oculusvrServoArmDebug',
'oculusvrServoArmRelease',
'svrArmDebug',
'svrArmRelease',
'wavevrArmDebug',
Expand Down Expand Up @@ -172,6 +201,13 @@ android {
]
}

googlevrServo {
manifest.srcFile 'src/googlevr/AndroidManifest.xml'
java.srcDirs = [
'src/googlevr/java'
]
}

googlevrFlat {
java.srcDirs = [
'src/googlevr/java',
Expand All @@ -186,6 +222,21 @@ android {
jniLibs.srcDirs = ["${project.rootDir}/third_party/ovr_mobile/VrApi/Libs"]
}

oculusvrServo {
java.srcDirs = [
'src/oculusvr/java'
]
jniLibs.srcDirs = ["${project.rootDir}/third_party/ovr_mobile/VrApi/Libs"]
}

oculusvrServoArmRelease {
manifest.srcFile 'src/oculusvrArmRelease/AndroidManifest.xml'
}

oculusvrServoArmDebug {
manifest.srcFile 'src/oculusvrArmDebug/AndroidManifest.xml'
}

svr {
java.srcDirs = [
'src/svr/java'
Expand Down Expand Up @@ -229,6 +280,9 @@ dependencies {
implementation 'com.google.vr:sdk-audio:1.170.0'
implementation "org.mozilla.components:service-telemetry:0.26.0"
implementation "com.github.mozilla:mozillaspeechlibrary:1.0.4"
oculusvrServoImplementation project(':servo')
googlevrServoImplementation project(':servo')
googlevrServoImplementation 'com.google.vr:sdk-base:1.170.0'
}

if (findProject(':wavesdk')) {
Expand Down Expand Up @@ -288,4 +342,4 @@ android.applicationVariants.all { variant ->
println("Build type: " + buildType)
println("Flavor: " + variant.flavorName)
println("Version code: " + variant.mergedFlavor.versionCode)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import java.util.List;
import java.util.Map;

import static org.mozilla.vrbrowser.utils.ServoUtils.*;

public class SessionStore implements GeckoSession.NavigationDelegate, GeckoSession.ProgressDelegate,
GeckoSession.ContentDelegate, GeckoSession.TextInputDelegate, GeckoSession.TrackingProtectionDelegate,
GeckoSession.PromptDelegate {
Expand Down Expand Up @@ -78,6 +80,7 @@ class SessionSettings {
boolean trackingProtection = true;
boolean suspendMediaWhenInactive = true;
int userAgentMode = SettingsStore.getInstance(mContext).getUaMode();
boolean servo = false;
}

class State {
Expand Down Expand Up @@ -307,7 +310,17 @@ public int createSession() {
int createSession(SessionSettings aSettings) {
State state = new State();
state.mSettings = aSettings;
state.mSession = new GeckoSession();

if (aSettings.servo) {
if (isServoAvailable()) {
state.mSession = createServoSession(mContext);
} else {
Log.e(LOGTAG, "Attempt to create a ServoSession. Servo hasn't been enable at build time. Using a GeckoSession instead.");
state.mSession = new GeckoSession();
}
} else {
state.mSession = new GeckoSession();
}

int result = state.mSession.hashCode();
mSessions.put(result, state);
Expand Down Expand Up @@ -555,6 +568,20 @@ public void loadUri(String aUri) {
mCurrentSession.loadUri(aUri);
}

public void toggleServo() {
if (mCurrentSession == null) {
return;
}

boolean was_servo = isInstanceOfServoSession(mCurrentSession);
String uri = getCurrentUri();
SessionStore.SessionSettings settings = new SessionStore.SessionSettings();
settings.servo = !was_servo;
int id = createSession(settings);
setCurrentSession(id);
loadUri(uri);
}

public boolean isInFullScreen() {
if (mCurrentSession == null) {
return false;
Expand Down Expand Up @@ -714,6 +741,15 @@ public void setMaxWindowSize(int width, int height) {
GeckoAppShell.setScreenSizeOverride(new Rect(0, 0, width, height));
}

public void setServo(final boolean enabled) {
if (!enabled && mCurrentSession != null && isInstanceOfServoSession(mCurrentSession)) {
String uri = getCurrentUri();
int id = createSession();
setCurrentSession(id);
loadUri(uri);
}
}

public void setMultiprocess(final boolean enabled) {
if (mCurrentSession != null) {
final GeckoResult<GeckoSession.SessionState> state = mCurrentSession.saveState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;

import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable;

public class SettingsStore {

Expand All @@ -35,6 +36,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean CONSOLE_LOGS_DEFAULT = false;
public final static boolean ENV_OVERRIDE_DEFAULT = false;
public final static boolean MULTIPROCESS_DEFAULT = false;
public final static boolean SERVO_DEFAULT = false;
public final static int UA_MODE_DEFAULT = 0;
public final static int INPUT_MODE_DEFAULT = 1;
public final static float DISPLAY_DENSITY_DEFAULT = 1.0f;
Expand Down Expand Up @@ -148,6 +150,16 @@ public void setMultiprocessEnabled(boolean isEnabled) {
editor.commit();
}

public boolean isServoEnabled() {
return isServoAvailable() && mPrefs.getBoolean(mContext.getString(R.string.settings_key_servo), SERVO_DEFAULT);
}

public void setServoEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_servo), isEnabled);
editor.commit();
}

public int getUaMode() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_desktop_version), UA_MODE_DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.mozilla.vrbrowser.ui.settings.RadioGroupSetting;
import org.mozilla.vrbrowser.ui.settings.SwitchSetting;

import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable;

public class DeveloperOptionsWidget extends UIWidget {

private static final String LOGTAG = "VRB";
Expand All @@ -33,6 +35,7 @@ public class DeveloperOptionsWidget extends UIWidget {
private SwitchSetting mConsoleLogsSwitch;
private SwitchSetting mEnvOverrideSwitch;
private SwitchSetting mMultiprocessSwitch;
private SwitchSetting mServoSwitch;

private RadioGroupSetting mEnvironmentsRadio;
private RadioGroupSetting mPointerColorRadio;
Expand Down Expand Up @@ -97,6 +100,14 @@ public void onClick(View view) {
mMultiprocessSwitch.setOnCheckedChangeListener(mMultiprocessListener);
setMultiprocess(SettingsStore.getInstance(getContext()).isMultiprocessEnabled(), false);

mServoSwitch = findViewById(R.id.servo_switch);
if (!isServoAvailable()) {
mServoSwitch.setVisibility(View.GONE);
} else {
mServoSwitch.setOnCheckedChangeListener(mServoListener);
setServo(SettingsStore.getInstance(getContext()).isServoEnabled(), false);
}

String env = SettingsStore.getInstance(getContext()).getEnvironment();
mEnvironmentsRadio = findViewById(R.id.environment_radio);
mEnvironmentsRadio.setOnCheckedChangeListener(mEnvsListener);
Expand Down Expand Up @@ -218,6 +229,14 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean value, boole
}
};

private SwitchSetting.OnCheckedChangeListener mServoListener = new SwitchSetting.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b, boolean doApply) {
setServo(b, true);
}
};


private RadioGroupSetting.OnCheckedChangeListener mUaModeListener = new RadioGroupSetting.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId, boolean doApply) {
Expand Down Expand Up @@ -303,6 +322,7 @@ public void onClick(View view) {

setConsoleLogs(SettingsStore.CONSOLE_LOGS_DEFAULT, true);
setMultiprocess(SettingsStore.MULTIPROCESS_DEFAULT, true);
setServo(SettingsStore.SERVO_DEFAULT, true);

if (mEnvOverrideSwitch.isChecked() != SettingsStore.ENV_OVERRIDE_DEFAULT) {
setEnvOverride(SettingsStore.ENV_OVERRIDE_DEFAULT);
Expand Down Expand Up @@ -373,6 +393,18 @@ private void setMultiprocess(boolean value, boolean doApply) {
}
}

private void setServo(boolean value, boolean doApply) {
mServoSwitch.setOnCheckedChangeListener(null);
mServoSwitch.setValue(value, false);
mServoSwitch.setOnCheckedChangeListener(mServoListener);

SettingsStore.getInstance(getContext()).setServoEnabled(value);

if (doApply) {
SessionStore.get().setServo(value);
}
}

private void setUaMode(int checkId, boolean doApply) {
mUaModeRadio.setOnCheckedChangeListener(null);
mUaModeRadio.setChecked(checkId, doApply);
Expand Down
Loading

0 comments on commit d29da61

Please sign in to comment.