Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Oculus App Linking #2998

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
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
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* 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
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 OnAppLink(const std::string& aJSON);
} // 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::OnAppLink(msg);
}
break;
}
default:
break;
}
Expand Down