Skip to content

Commit

Permalink
Add support for Oculus App Linking (#2998)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Mar 24, 2020
1 parent 4d2e9b3 commit 27ba760
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
21 changes: 21 additions & 0 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Expand Up @@ -41,6 +41,7 @@
import androidx.lifecycle.ViewModelStore;
import androidx.lifecycle.ViewModelStoreOwner;

import org.json.JSONObject;
import org.mozilla.geckoview.GeckoRuntime;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoVRManager;
Expand Down Expand Up @@ -80,6 +81,7 @@
import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.LocaleUtils;
import org.mozilla.vrbrowser.utils.ServoUtils;
import org.mozilla.vrbrowser.utils.StringUtils;
import org.mozilla.vrbrowser.utils.SystemUtils;

import java.io.File;
Expand Down Expand Up @@ -1087,6 +1089,25 @@ private void handlePoorPerformance() {
});
}

@Keep
@SuppressWarnings("unused")
private void onAppLink(String aJSON) {
runOnUiThread(() -> {
try {
JSONObject object = new JSONObject(aJSON);
String uri = object.optString("url");
Session session = SessionStore.get().getActiveSession();
if (!StringUtils.isEmpty(uri) && session != null) {
session.loadUri(uri);
}

} catch (Exception ex) {
Log.e(LOGTAG, "Error parsing app link JSON: " + ex.toString());
}

});
}

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
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* kOnAppLink = "onAppLink";
const char* kOnAppLinkSignature = "(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 sOnAppLink = 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);
sOnAppLink = FindJNIMethodID(sEnv, sBrowserClass, kOnAppLink, kOnAppLinkSignature);
}

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

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

void
VRBrowser::OnAppLink(const std::string& aJSON) {
if (!ValidateMethodID(sEnv, sActivity, sOnAppLink, __FUNCTION__)) { return; }
jstring json = sEnv->NewStringUTF(aJSON.c_str());
sEnv->CallVoidMethod(sActivity, sOnAppLink, json);
sEnv->DeleteLocalRef(json);
CheckJNIException(sEnv, __FUNCTION__);
}

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

} // namespace crow
Expand Down
12 changes: 8 additions & 4 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
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::OnAppLink(msg);
}
break;
}
default:
break;
}
Expand Down

0 comments on commit 27ba760

Please sign in to comment.