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

Commit

Permalink
Perform Oculus Platform entitlement checks (#1349)
Browse files Browse the repository at this point in the history
* Perform Oculus Platform entitlement checks

* Update build_targets.py and verify OVR platform initializes

* Add HaltActivity for shutting down

* Resolve merge conflict

* Add dialog to inform user application is shutting down due to lack of permission

* Add missing STORE_BUILD #ifdef

* Do not halt window if connection is not available

* Update entitlement check dialog text
  • Loading branch information
MortimerGoro committed Jul 2, 2019
1 parent 2fc56f8 commit cf55682
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 17 deletions.
12 changes: 11 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ add_custom_command(TARGET native-lib POST_BUILD
${CMAKE_SOURCE_DIR}/../third_party/ovr_mobile/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libvrapi.so
)
add_custom_command(TARGET native-lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Android/libs/${ANDROID_ABI}/libovrplatformloader.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libovrplatformloader.so
)
endif()

if(SNAPDRAGONVR)
Expand All @@ -117,7 +122,11 @@ find_library( # Sets the name of the path variable.

add_library(oculusvr-lib SHARED IMPORTED)
set_target_properties(oculusvr-lib PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../third_party/ovr_mobile/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so)
${CMAKE_SOURCE_DIR}/../third_party/ovr_mobile/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so )

add_library(ovrplatform-lib SHARED IMPORTED)
set_target_properties(ovrplatform-lib PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Android/libs/${ANDROID_ABI}/libovrplatformloader.so )

add_library(googlevr-lib SHARED IMPORTED)
set_target_properties(googlevr-lib PROPERTIES IMPORTED_LOCATION
Expand All @@ -142,6 +151,7 @@ target_link_libraries( # Specifies the target library.

# Link VR_SDK_LIB exported from gradle flavors
${VR_SDK_LIB}
${VR_SDK_EXTRA_LIB}

# Links the target library to the log library
# included in the NDK.
Expand Down
75 changes: 61 additions & 14 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,38 @@ android {
externalNativeBuild {
cmake {
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
" -I" + file("${project.rootDir}/third_party/OVRPlatformSDK/Include").absolutePath +
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
" -DOCULUSVR"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DOCULUSVR=ON"
" -DOCULUSVR -DSTORE_BUILD=0"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON"
}
}
manifestPlaceholders = [ headtrackingRequired:"false" ]
}

oculusvrStore {
dimension "platform"
externalNativeBuild {
cmake {
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
" -I" + file("${project.rootDir}/third_party/OVRPlatformSDK/Include").absolutePath +
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
" -DOCULUSVR -DSTORE_BUILD=1"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON"
}
}
manifestPlaceholders = [ headtrackingRequired:"true" ]
}

oculusvr3dof {
oculusvr3dofStore {
dimension "platform"
externalNativeBuild {
cmake {
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
" -I" + file("${project.rootDir}/third_party/OVRPlatformSDK/Include").absolutePath +
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
" -DOCULUSVR"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DOCULUSVR=ON"
" -DOCULUSVR -DSTORE_BUILD=1"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON"
}
}
manifestPlaceholders = [ headtrackingRequired:"false" ]
Expand Down Expand Up @@ -205,10 +221,14 @@ android {
'oculusvrArmRelease',
'oculusvrArm64Debug',
'oculusvrArm64Release',
'oculusvr3dofArmDebug',
'oculusvr3dofArmRelease',
'oculusvr3dofArm64Debug',
'oculusvr3dofArm64Release',
'oculusvrStoreArmDebug',
'oculusvrStoreArmRelease',
'oculusvrStoreArm64Debug',
'oculusvrStoreArm64Release',
'oculusvr3dofStoreArmDebug',
'oculusvr3dofStoreArmRelease',
'oculusvr3dofStoreArm64Debug',
'oculusvr3dofStoreArm64Release',
'svrArmDebug',
'svrArmRelease',
'svrArm64Debug',
Expand Down Expand Up @@ -253,7 +273,16 @@ android {
]
}

oculusvr3dof {
oculusvrStore {
java.srcDirs = [
'src/oculusvr/java'
]
assets.srcDirs = [
'src/oculusvr/assets'
]
}

oculusvr3dofStore {
java.srcDirs = [
'src/oculusvr/java'
]
Expand All @@ -276,20 +305,38 @@ android {
: "src/oculusvrArmRelease/AndroidManifest.xml"
}

oculusvr3dofArmDebug {
oculusvrStoreArmDebug {
manifest.srcFile "src/oculusvrArmDebug/AndroidManifest.xml"
}

oculusvrStoreArm64Debug {
manifest.srcFile "src/oculusvrArmDebug/AndroidManifest.xml"
}

oculusvrStoreArmRelease {
manifest.srcFile getUseDebugSigningOnRelease() ? "src/oculusvrArmDebug/AndroidManifest.xml"
: "src/oculusvrArmRelease/AndroidManifest.xml"
}

oculusvrStoreArm64Release {
manifest.srcFile getUseDebugSigningOnRelease() ? "src/oculusvrArmDebug/AndroidManifest.xml"
: "src/oculusvrArmRelease/AndroidManifest.xml"
}

oculusvr3dofStoreArmDebug {
manifest.srcFile "src/oculusvrArmDebug/AndroidManifest.xml"
}

oculusvr3dofArm64Debug {
oculusvr3dofStoreArm64Debug {
manifest.srcFile "src/oculusvrArmDebug/AndroidManifest.xml"
}

oculusvr3dofArmRelease {
oculusvr3dofStoreArmRelease {
manifest.srcFile getUseDebugSigningOnRelease() ? "src/oculusvrArmDebug/AndroidManifest.xml"
: "src/oculusvrArmRelease/AndroidManifest.xml"
}

oculusvr3dofArm64Release {
oculusvr3dofStoreArm64Release {
manifest.srcFile getUseDebugSigningOnRelease() ? "src/oculusvrArmDebug/AndroidManifest.xml"
: "src/oculusvrArmRelease/AndroidManifest.xml"
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,21 @@ private void setDeviceType(int aType) {
runOnUiThread(() -> DeviceType.setType(aType));
}

@Keep
@SuppressWarnings("unused")
private void haltActivity(final int aReason) {
runOnUiThread(() -> {
if (mConnectionAvailable && mWindowWidget != null) {
mWindowWidget.showAlert(getString(R.string.not_entitled_title), getString(R.string.not_entitled_message, getString(R.string.app_name)), new GeckoSession.PromptDelegate.AlertCallback() {
@Override
public void dismiss() {
VRBrowserActivity.this.finish();
}
});
}
});
}

void createOffscreenDisplay() {
int[] ids = new int[1];
GLES20.glGenTextures(1, ids, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.TextPromptWidget;

import androidx.annotation.NonNull;

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

public class WindowWidget extends UIWidget implements SessionChangeListener,
Expand Down Expand Up @@ -600,6 +602,15 @@ public void setNoInternetToastVisible(boolean aVisible) {
}
}

public void showAlert(String title, @NonNull String msg, @NonNull AlertCallback callback) {
mAlertPrompt = new AlertPromptWidget(getContext());
mAlertPrompt.mWidgetPlacement.parentHandle = getHandle();
mAlertPrompt.setTitle(title);
mAlertPrompt.setMessage(msg);
mAlertPrompt.setDelegate(callback);
mAlertPrompt.show();
}

// PromptDelegate

@Override
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/cpp/VRBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const char* kAreLayersEnabled = "areLayersEnabled";
const char* kAreLayersEnabledSignature = "()Z";
const char* kSetDeviceType = "setDeviceType";
const char* kSetDeviceTypeSignature = "(I)V";
const char* kHaltActivity = "haltActivity";
const char* kHaltActivitySignature = "(I)V";

JNIEnv* sEnv;
jclass sBrowserClass;
Expand All @@ -68,6 +70,7 @@ jmethodID sGetActiveEnvironment;
jmethodID sGetPointerColor;
jmethodID sAreLayersEnabled;
jmethodID sSetDeviceType;
jmethodID sHaltActivity;
}

namespace crow {
Expand Down Expand Up @@ -105,6 +108,7 @@ VRBrowser::InitializeJava(JNIEnv* aEnv, jobject aActivity) {
sGetPointerColor = FindJNIMethodID(sEnv, sBrowserClass, kGetPointerColor, kGetPointerColorSignature);
sAreLayersEnabled = FindJNIMethodID(sEnv, sBrowserClass, kAreLayersEnabled, kAreLayersEnabledSignature);
sSetDeviceType = FindJNIMethodID(sEnv, sBrowserClass, kSetDeviceType, kSetDeviceTypeSignature);
sHaltActivity = FindJNIMethodID(sEnv, sBrowserClass, kHaltActivity, kHaltActivitySignature);
}

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

Expand Down Expand Up @@ -304,4 +309,12 @@ VRBrowser::SetDeviceType(const jint aType) {
CheckJNIException(sEnv, __FUNCTION__);
}

void
VRBrowser::HaltActivity(const jint aReason) {
if (!ValidateMethodID(sEnv, sActivity, sHaltActivity, __FUNCTION__)) { return; }
sEnv->CallVoidMethod(sActivity, sHaltActivity, aReason);
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 @@ -36,6 +36,7 @@ std::string GetActiveEnvironment();
int32_t GetPointerColor();
bool AreLayersEnabled();
void SetDeviceType(const jint aType);
void HaltActivity(const jint aReason);
} // namespace VRBrowser;

} // namespace crow
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,14 @@
<!-- This string is displayed in the message of the notification message shown when the device loses internet connection. -->
<string name="no_internet_message">Check your device configuration to fix the problem.</string>


<!-- This string is displayed in the message of the notification message shown when the user tries to open a new window and
it has already opened the maximum number of allowed windows. %1$s expands to a integer value that represent the maximum windows
that can be opened (initially 3) -->
<string name="max_windows_message">You cannot have more than %1$s windows open at a time. Please close one before opening another.</string>

<!-- This string is displayed in the title of the alert dialog shown when the user does not have permission to run the application on the device. -->
<string name="not_entitled_title">Unable To Run</string>
<!-- This string is displayed in the message body of the alert dialog shown when the user does not have permission to run the application on the device.
'%1$s' will be replace at runtime with the app's name. -->
<string name="not_entitled_message">%1$s does not have permission to run on this device and will now exit.</string>
</resources>
61 changes: 61 additions & 0 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "DeviceUtils.h"
#include "ElbowModel.h"
#include "BrowserEGLContext.h"
#include "VRBrowser.h"
#include "VRLayer.h"

#include <android_native_app_glue.h>
Expand All @@ -30,9 +31,14 @@
#include "VrApi_Helpers.h"
#include "VrApi_Input.h"
#include "VrApi_SystemUtils.h"
#include "OVR_Platform.h"
#include "OVR_Message.h"

#include "VRBrowser.h"

#define OCULUS_6DOF_APP_ID "2180252408763702"
#define OCULUS_3DOF_APP_ID "2208418715853974"

namespace crow {

static ovrMatrix4f ovrMatrixFrom(const vrb::Matrix& aMatrix) {
Expand Down Expand Up @@ -599,6 +605,7 @@ struct DeviceDelegateOculusVR::State {
vrb::RenderContextWeak context;
android_app* app = nullptr;
bool initialized = false;
bool platformSDKInitialized = false;
bool layersEnabled = true;
ovrJava java = {};
ovrMobile* ovr = nullptr;
Expand Down Expand Up @@ -686,16 +693,35 @@ struct DeviceDelegateOculusVR::State {
// Reorient the headset after controller recenter.
vrapi_SetPropertyInt(&java, VRAPI_REORIENT_HMD_ON_CONTROLLER_RECENTER, 1);

const char * appId = OCULUS_6DOF_APP_ID;

const int type = vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_DEVICE_TYPE);
if ((type >= VRAPI_DEVICE_TYPE_OCULUSGO_START ) && (type <= VRAPI_DEVICE_TYPE_OCULUSGO_END)) {
VRB_DEBUG("Detected Oculus Go");
deviceType = device::OculusGo;
appId = OCULUS_3DOF_APP_ID;
} else if ((type >= VRAPI_DEVICE_TYPE_OCULUSQUEST_START) && (type <= VRAPI_DEVICE_TYPE_OCULUSQUEST_END)) {
VRB_DEBUG("Detected Oculus Quest");
deviceType = device::OculusQuest;
} else if ((type >= VRAPI_DEVICE_TYPE_GEARVR_START) && (type <= VRAPI_DEVICE_TYPE_GEARVR_END)) {
VRB_DEBUG("Detected Gear VR");
appId = OCULUS_3DOF_APP_ID;
} else {
VRB_DEBUG("Detected Unknown Oculus device");
}

ovrRequest result = ovr_PlatformInitializeAndroidAsynchronous(appId, java.ActivityObject, java.Env);

if (invalidRequestID == result) {
// Initialization failed which means either the oculus service isn’t on the machine or they’ve hacked their DLL.
VRB_LOG("ovr_PlatformInitializeAndroidAsynchronous failed: %d", (int32_t)result);
#if STORE_BUILD == 1
VRBrowser::HaltActivity(0);
#endif
} else {
VRB_LOG("ovr_PlatformInitializeAndroidAsynchronous succeeded");
ovr_Entitlement_GetIsViewerEntitled();
}
}

void UpdateTrackingMode() {
Expand Down Expand Up @@ -1217,7 +1243,42 @@ DeviceDelegateOculusVR::SetCPULevel(const device::CPULevel aLevel) {

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

ovrMessageHandle message;
while ((message = ovr_PopMessage()) != nullptr) {
switch (ovr_Message_GetType(message)) {
case ovrMessage_PlatformInitializeAndroidAsynchronous: {
ovrPlatformInitializeHandle handle = ovr_Message_GetPlatformInitialize(message);
ovrPlatformInitializeResult result = ovr_PlatformInitialize_GetResult(handle);
if (result == ovrPlatformInitialize_Success) {
VRB_DEBUG("OVR Platform Initialized.");
} else {
VRB_ERROR("OVR Platform Initialize failed: %s", ovrPlatformInitializeResult_ToString(result));
#if STORE_BUILD == 1
VRBrowser::HaltActivity(0);
#endif
}
}
break;
case ovrMessage_Entitlement_GetIsViewerEntitled:
m.platformSDKInitialized = true;
if (ovr_Message_IsError(message)) {
VRB_LOG("User is not entitled");
#if STORE_BUILD == 1
VRBrowser::HaltActivity(0);
#endif
}
else {
VRB_LOG("User is entitled");
}
break;
default:
break;
}
}
}

void
Expand Down
3 changes: 2 additions & 1 deletion tools/taskcluster/build_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

platforms = {
'oculusvr': ['arm', 'arm64'],
'oculusvr3dof': ['arm', 'arm64'],
'oculusvrStore': ['arm', 'arm64'],
'oculusvr3dofStore': ['arm', 'arm64'],
'wavevr': ['arm'],
'googlevr': ['arm', 'arm64'],
'noapi': ['arm', 'arm64', 'x86'],
Expand Down

0 comments on commit cf55682

Please sign in to comment.