Skip to content

Commit

Permalink
Add support for Oculus App Linking
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Mar 19, 2020
1 parent a52060c commit 0dcaba4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
11 changes: 11 additions & 0 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,17 @@ private void handlePoorPerformance() {
});
}

@Keep
@SuppressWarnings("unused")
private void loadUri(String aURL) {
runOnUiThread(() -> {
Session session = SessionStore.get().getActiveSession();
if (session != null) {
session.loadUri(aURL);
}
});
}

private SurfaceTexture createSurfaceTexture() {
int[] ids = new int[1];
GLES20.glGenTextures(1, ids, 0);
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/cpp/VRBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const char* kHaltActivity = "haltActivity";
const char* kHaltActivitySignature = "(I)V";
const char* kHandlePoorPerformance = "handlePoorPerformance";
const char* kHandlePoorPerformanceSignature = "()V";
const char* kLoadUri = "loadUri";
const char* kLoadUriSignature = "(Ljava/lang/String;)V";

JNIEnv* sEnv = nullptr;
jclass sBrowserClass = nullptr;
Expand All @@ -77,6 +79,7 @@ jmethodID sAreLayersEnabled = nullptr;
jmethodID sSetDeviceType = nullptr;
jmethodID sHaltActivity = nullptr;
jmethodID sHandlePoorPerformance = nullptr;
jmethodID sLoadUri = nullptr;
}

namespace crow {
Expand Down Expand Up @@ -117,6 +120,7 @@ VRBrowser::InitializeJava(JNIEnv* aEnv, jobject aActivity) {
sSetDeviceType = FindJNIMethodID(sEnv, sBrowserClass, kSetDeviceType, kSetDeviceTypeSignature);
sHaltActivity = FindJNIMethodID(sEnv, sBrowserClass, kHaltActivity, kHaltActivitySignature);
sHandlePoorPerformance = FindJNIMethodID(sEnv, sBrowserClass, kHandlePoorPerformance, kHandlePoorPerformanceSignature);
sLoadUri = FindJNIMethodID(sEnv, sBrowserClass, kLoadUri, kLoadUriSignature);
}

void
Expand Down Expand Up @@ -151,6 +155,7 @@ VRBrowser::ShutdownJava() {
sAreLayersEnabled = nullptr;
sSetDeviceType = nullptr;
sHaltActivity = nullptr;
sLoadUri = nullptr;
sEnv = nullptr;
}

Expand Down Expand Up @@ -339,4 +344,13 @@ VRBrowser::HandlePoorPerformance() {
CheckJNIException(sEnv, __FUNCTION__);
}

void
VRBrowser::LoadUri(const std::string& aURL) {
if (!ValidateMethodID(sEnv, sActivity, sLoadUri, __FUNCTION__)) { return; }
jstring uri = sEnv->NewStringUTF(aURL.c_str());
sEnv->CallVoidMethod(sActivity, sLoadUri, uri);
sEnv->DeleteLocalRef(uri);
CheckJNIException(sEnv, __FUNCTION__);
}

} // namespace crow
1 change: 1 addition & 0 deletions app/src/main/cpp/VRBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ bool AreLayersEnabled();
void SetDeviceType(const jint aType);
void HaltActivity(const jint aReason);
void HandlePoorPerformance();
void LoadUri(const std::string& aURL);
} // namespace VRBrowser;

} // namespace crow
Expand Down
12 changes: 8 additions & 4 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,6 @@ DeviceDelegateOculusVR::SetCPULevel(const device::CPULevel aLevel) {

void
DeviceDelegateOculusVR::ProcessEvents() {
if (m.applicationEntitled) {
return;
}

ovrMessageHandle message;
while ((message = ovr_PopMessage()) != nullptr) {
switch (ovr_Message_GetType(message)) {
Expand Down Expand Up @@ -812,6 +808,14 @@ DeviceDelegateOculusVR::ProcessEvents() {
m.applicationEntitled = true;
}
break;
case ovrMessage_Notification_ApplicationLifecycle_LaunchIntentChanged: {
auto details = ovr_ApplicationLifecycle_GetLaunchDetails();
const char *msg = ovr_LaunchDetails_GetDeeplinkMessage(details);
if (msg) {
VRBrowser::LoadUri(msg);
}
break;
}
default:
break;
}
Expand Down

0 comments on commit 0dcaba4

Please sign in to comment.