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

Commit d842444

Browse files
MortimerGorobluemarvin
authored andcommitted
Perform Oculus Platform entitlement checks (#1349)
* 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
1 parent 1e611da commit d842444

File tree

9 files changed

+180
-17
lines changed

9 files changed

+180
-17
lines changed

app/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ add_custom_command(TARGET native-lib POST_BUILD
9191
${CMAKE_SOURCE_DIR}/../third_party/ovr_mobile/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so
9292
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libvrapi.so
9393
)
94+
add_custom_command(TARGET native-lib POST_BUILD
95+
COMMAND ${CMAKE_COMMAND} -E copy
96+
${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Android/libs/${ANDROID_ABI}/libovrplatformloader.so
97+
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libovrplatformloader.so
98+
)
9499
endif()
95100

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

118123
add_library(oculusvr-lib SHARED IMPORTED)
119124
set_target_properties(oculusvr-lib PROPERTIES IMPORTED_LOCATION
120-
${CMAKE_SOURCE_DIR}/../third_party/ovr_mobile/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so)
125+
${CMAKE_SOURCE_DIR}/../third_party/ovr_mobile/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so )
126+
127+
add_library(ovrplatform-lib SHARED IMPORTED)
128+
set_target_properties(ovrplatform-lib PROPERTIES IMPORTED_LOCATION
129+
${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Android/libs/${ANDROID_ABI}/libovrplatformloader.so )
121130

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

143152
# Link VR_SDK_LIB exported from gradle flavors
144153
${VR_SDK_LIB}
154+
${VR_SDK_EXTRA_LIB}
145155

146156
# Links the target library to the log library
147157
# included in the NDK.

app/build.gradle

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,38 @@ android {
121121
externalNativeBuild {
122122
cmake {
123123
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
124+
" -I" + file("${project.rootDir}/third_party/OVRPlatformSDK/Include").absolutePath +
124125
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
125-
" -DOCULUSVR"
126-
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DOCULUSVR=ON"
126+
" -DOCULUSVR -DSTORE_BUILD=0"
127+
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON"
128+
}
129+
}
130+
manifestPlaceholders = [ headtrackingRequired:"false" ]
131+
}
132+
133+
oculusvrStore {
134+
dimension "platform"
135+
externalNativeBuild {
136+
cmake {
137+
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
138+
" -I" + file("${project.rootDir}/third_party/OVRPlatformSDK/Include").absolutePath +
139+
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
140+
" -DOCULUSVR -DSTORE_BUILD=1"
141+
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON"
127142
}
128143
}
129144
manifestPlaceholders = [ headtrackingRequired:"true" ]
130145
}
131146

132-
oculusvr3dof {
147+
oculusvr3dofStore {
133148
dimension "platform"
134149
externalNativeBuild {
135150
cmake {
136151
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
152+
" -I" + file("${project.rootDir}/third_party/OVRPlatformSDK/Include").absolutePath +
137153
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
138-
" -DOCULUSVR"
139-
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DOCULUSVR=ON"
154+
" -DOCULUSVR -DSTORE_BUILD=1"
155+
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON"
140156
}
141157
}
142158
manifestPlaceholders = [ headtrackingRequired:"false" ]
@@ -205,10 +221,14 @@ android {
205221
'oculusvrArmRelease',
206222
'oculusvrArm64Debug',
207223
'oculusvrArm64Release',
208-
'oculusvr3dofArmDebug',
209-
'oculusvr3dofArmRelease',
210-
'oculusvr3dofArm64Debug',
211-
'oculusvr3dofArm64Release',
224+
'oculusvrStoreArmDebug',
225+
'oculusvrStoreArmRelease',
226+
'oculusvrStoreArm64Debug',
227+
'oculusvrStoreArm64Release',
228+
'oculusvr3dofStoreArmDebug',
229+
'oculusvr3dofStoreArmRelease',
230+
'oculusvr3dofStoreArm64Debug',
231+
'oculusvr3dofStoreArm64Release',
212232
'svrArmDebug',
213233
'svrArmRelease',
214234
'svrArm64Debug',
@@ -253,7 +273,16 @@ android {
253273
]
254274
}
255275

256-
oculusvr3dof {
276+
oculusvrStore {
277+
java.srcDirs = [
278+
'src/oculusvr/java'
279+
]
280+
assets.srcDirs = [
281+
'src/oculusvr/assets'
282+
]
283+
}
284+
285+
oculusvr3dofStore {
257286
java.srcDirs = [
258287
'src/oculusvr/java'
259288
]
@@ -276,20 +305,38 @@ android {
276305
: "src/oculusvrArmRelease/AndroidManifest.xml"
277306
}
278307

279-
oculusvr3dofArmDebug {
308+
oculusvrStoreArmDebug {
309+
manifest.srcFile "src/oculusvrArmDebug/AndroidManifest.xml"
310+
}
311+
312+
oculusvrStoreArm64Debug {
313+
manifest.srcFile "src/oculusvrArmDebug/AndroidManifest.xml"
314+
}
315+
316+
oculusvrStoreArmRelease {
317+
manifest.srcFile getUseDebugSigningOnRelease() ? "src/oculusvrArmDebug/AndroidManifest.xml"
318+
: "src/oculusvrArmRelease/AndroidManifest.xml"
319+
}
320+
321+
oculusvrStoreArm64Release {
322+
manifest.srcFile getUseDebugSigningOnRelease() ? "src/oculusvrArmDebug/AndroidManifest.xml"
323+
: "src/oculusvrArmRelease/AndroidManifest.xml"
324+
}
325+
326+
oculusvr3dofStoreArmDebug {
280327
manifest.srcFile "src/oculusvrArmDebug/AndroidManifest.xml"
281328
}
282329

283-
oculusvr3dofArm64Debug {
330+
oculusvr3dofStoreArm64Debug {
284331
manifest.srcFile "src/oculusvrArmDebug/AndroidManifest.xml"
285332
}
286333

287-
oculusvr3dofArmRelease {
334+
oculusvr3dofStoreArmRelease {
288335
manifest.srcFile getUseDebugSigningOnRelease() ? "src/oculusvrArmDebug/AndroidManifest.xml"
289336
: "src/oculusvrArmRelease/AndroidManifest.xml"
290337
}
291338

292-
oculusvr3dofArm64Release {
339+
oculusvr3dofStoreArm64Release {
293340
manifest.srcFile getUseDebugSigningOnRelease() ? "src/oculusvrArmDebug/AndroidManifest.xml"
294341
: "src/oculusvrArmRelease/AndroidManifest.xml"
295342
}

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,21 @@ private void setDeviceType(int aType) {
836836
runOnUiThread(() -> DeviceType.setType(aType));
837837
}
838838

839+
@Keep
840+
@SuppressWarnings("unused")
841+
private void haltActivity(final int aReason) {
842+
runOnUiThread(() -> {
843+
if (mConnectionAvailable && mWindowWidget != null) {
844+
mWindowWidget.showAlert(getString(R.string.not_entitled_title), getString(R.string.not_entitled_message, getString(R.string.app_name)), new GeckoSession.PromptDelegate.AlertCallback() {
845+
@Override
846+
public void dismiss() {
847+
VRBrowserActivity.this.finish();
848+
}
849+
});
850+
}
851+
});
852+
}
853+
839854
void createOffscreenDisplay() {
840855
int[] ids = new int[1];
841856
GLES20.glGenTextures(1, ids, 0);

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
3333
import org.mozilla.vrbrowser.ui.widgets.prompts.TextPromptWidget;
3434

35+
import androidx.annotation.NonNull;
36+
3537
import static org.mozilla.vrbrowser.utils.ServoUtils.isInstanceOfServoSession;
3638

3739
public class WindowWidget extends UIWidget implements SessionStore.SessionChangeListener,
@@ -585,6 +587,15 @@ public void setNoInternetToastVisible(boolean aVisible) {
585587
}
586588
}
587589

590+
public void showAlert(String title, @NonNull String msg, @NonNull AlertCallback callback) {
591+
mAlertPrompt = new AlertPromptWidget(getContext());
592+
mAlertPrompt.mWidgetPlacement.parentHandle = getHandle();
593+
mAlertPrompt.setTitle(title);
594+
mAlertPrompt.setMessage(msg);
595+
mAlertPrompt.setDelegate(callback);
596+
mAlertPrompt.show();
597+
}
598+
588599
// PromptDelegate
589600

590601
@Override

app/src/main/cpp/VRBrowser.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const char* kAreLayersEnabled = "areLayersEnabled";
4646
const char* kAreLayersEnabledSignature = "()Z";
4747
const char* kSetDeviceType = "setDeviceType";
4848
const char* kSetDeviceTypeSignature = "(I)V";
49+
const char* kHaltActivity = "haltActivity";
50+
const char* kHaltActivitySignature = "(I)V";
4951

5052
JNIEnv* sEnv;
5153
jclass sBrowserClass;
@@ -68,6 +70,7 @@ jmethodID sGetActiveEnvironment;
6870
jmethodID sGetPointerColor;
6971
jmethodID sAreLayersEnabled;
7072
jmethodID sSetDeviceType;
73+
jmethodID sHaltActivity;
7174
}
7275

7376
namespace crow {
@@ -105,6 +108,7 @@ VRBrowser::InitializeJava(JNIEnv* aEnv, jobject aActivity) {
105108
sGetPointerColor = FindJNIMethodID(sEnv, sBrowserClass, kGetPointerColor, kGetPointerColorSignature);
106109
sAreLayersEnabled = FindJNIMethodID(sEnv, sBrowserClass, kAreLayersEnabled, kAreLayersEnabledSignature);
107110
sSetDeviceType = FindJNIMethodID(sEnv, sBrowserClass, kSetDeviceType, kSetDeviceTypeSignature);
111+
sHaltActivity = FindJNIMethodID(sEnv, sBrowserClass, kHaltActivity, kHaltActivitySignature);
108112
}
109113

110114
void
@@ -137,6 +141,7 @@ VRBrowser::ShutdownJava() {
137141
sGetPointerColor = nullptr;
138142
sAreLayersEnabled = nullptr;
139143
sSetDeviceType = nullptr;
144+
sHaltActivity = nullptr;
140145
sEnv = nullptr;
141146
}
142147

@@ -304,4 +309,12 @@ VRBrowser::SetDeviceType(const jint aType) {
304309
CheckJNIException(sEnv, __FUNCTION__);
305310
}
306311

312+
void
313+
VRBrowser::HaltActivity(const jint aReason) {
314+
if (!ValidateMethodID(sEnv, sActivity, sHaltActivity, __FUNCTION__)) { return; }
315+
sEnv->CallVoidMethod(sActivity, sHaltActivity, aReason);
316+
CheckJNIException(sEnv, __FUNCTION__);
317+
}
318+
319+
307320
} // namespace crow

app/src/main/cpp/VRBrowser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ std::string GetActiveEnvironment();
3636
int32_t GetPointerColor();
3737
bool AreLayersEnabled();
3838
void SetDeviceType(const jint aType);
39+
void HaltActivity(const jint aReason);
3940
} // namespace VRBrowser;
4041

4142
} // namespace crow

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,14 @@
689689
<!-- This string is displayed in the message of the notification message shown when the device loses internet connection. -->
690690
<string name="no_internet_message">Check your device configuration to fix the problem.</string>
691691

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

697+
<!-- 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. -->
698+
<string name="not_entitled_title">Unable To Run</string>
699+
<!-- 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.
700+
'%1$s' will be replace at runtime with the app's name. -->
701+
<string name="not_entitled_message">%1$s does not have permission to run on this device and will now exit.</string>
698702
</resources>

app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "DeviceUtils.h"
88
#include "ElbowModel.h"
99
#include "BrowserEGLContext.h"
10+
#include "VRBrowser.h"
1011
#include "VRLayer.h"
1112

1213
#include <android_native_app_glue.h>
@@ -30,9 +31,14 @@
3031
#include "VrApi_Helpers.h"
3132
#include "VrApi_Input.h"
3233
#include "VrApi_SystemUtils.h"
34+
#include "OVR_Platform.h"
35+
#include "OVR_Message.h"
3336

3437
#include "VRBrowser.h"
3538

39+
#define OCULUS_6DOF_APP_ID "2180252408763702"
40+
#define OCULUS_3DOF_APP_ID "2208418715853974"
41+
3642
namespace crow {
3743

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

696+
const char * appId = OCULUS_6DOF_APP_ID;
697+
689698
const int type = vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_DEVICE_TYPE);
690699
if ((type >= VRAPI_DEVICE_TYPE_OCULUSGO_START ) && (type <= VRAPI_DEVICE_TYPE_OCULUSGO_END)) {
691700
VRB_DEBUG("Detected Oculus Go");
692701
deviceType = device::OculusGo;
702+
appId = OCULUS_3DOF_APP_ID;
693703
} else if ((type >= VRAPI_DEVICE_TYPE_OCULUSQUEST_START) && (type <= VRAPI_DEVICE_TYPE_OCULUSQUEST_END)) {
694704
VRB_DEBUG("Detected Oculus Quest");
695705
deviceType = device::OculusQuest;
706+
} else if ((type >= VRAPI_DEVICE_TYPE_GEARVR_START) && (type <= VRAPI_DEVICE_TYPE_GEARVR_END)) {
707+
VRB_DEBUG("Detected Gear VR");
708+
appId = OCULUS_3DOF_APP_ID;
696709
} else {
697710
VRB_DEBUG("Detected Unknown Oculus device");
698711
}
712+
713+
ovrRequest result = ovr_PlatformInitializeAndroidAsynchronous(appId, java.ActivityObject, java.Env);
714+
715+
if (invalidRequestID == result) {
716+
// Initialization failed which means either the oculus service isn’t on the machine or they’ve hacked their DLL.
717+
VRB_LOG("ovr_PlatformInitializeAndroidAsynchronous failed: %d", (int32_t)result);
718+
#if STORE_BUILD == 1
719+
VRBrowser::HaltActivity(0);
720+
#endif
721+
} else {
722+
VRB_LOG("ovr_PlatformInitializeAndroidAsynchronous succeeded");
723+
ovr_Entitlement_GetIsViewerEntitled();
724+
}
699725
}
700726

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

12181244
void
12191245
DeviceDelegateOculusVR::ProcessEvents() {
1246+
if (m.platformSDKInitialized) {
1247+
return;
1248+
}
12201249

1250+
ovrMessageHandle message;
1251+
while ((message = ovr_PopMessage()) != nullptr) {
1252+
switch (ovr_Message_GetType(message)) {
1253+
case ovrMessage_PlatformInitializeAndroidAsynchronous: {
1254+
ovrPlatformInitializeHandle handle = ovr_Message_GetPlatformInitialize(message);
1255+
ovrPlatformInitializeResult result = ovr_PlatformInitialize_GetResult(handle);
1256+
if (result == ovrPlatformInitialize_Success) {
1257+
VRB_DEBUG("OVR Platform Initialized.");
1258+
} else {
1259+
VRB_ERROR("OVR Platform Initialize failed: %s", ovrPlatformInitializeResult_ToString(result));
1260+
#if STORE_BUILD == 1
1261+
VRBrowser::HaltActivity(0);
1262+
#endif
1263+
}
1264+
}
1265+
break;
1266+
case ovrMessage_Entitlement_GetIsViewerEntitled:
1267+
m.platformSDKInitialized = true;
1268+
if (ovr_Message_IsError(message)) {
1269+
VRB_LOG("User is not entitled");
1270+
#if STORE_BUILD == 1
1271+
VRBrowser::HaltActivity(0);
1272+
#endif
1273+
}
1274+
else {
1275+
VRB_LOG("User is entitled");
1276+
}
1277+
break;
1278+
default:
1279+
break;
1280+
}
1281+
}
12211282
}
12221283

12231284
void

tools/taskcluster/build_targets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434

3535
platforms = {
3636
'oculusvr': ['arm', 'arm64'],
37-
'oculusvr3dof': ['arm', 'arm64'],
37+
'oculusvrStore': ['arm', 'arm64'],
38+
'oculusvr3dofStore': ['arm', 'arm64'],
3839
'wavevr': ['arm'],
3940
'googlevr': ['arm', 'arm64'],
4041
'noapi': ['arm', 'arm64', 'x86'],

0 commit comments

Comments
 (0)