public void OnPostGenerateGradleAndroidProject(string path) { if (!OculusBuildTools.OculusLoaderPresentInSettingsForBuildTarget(BuildTargetGroup.Android)) { return; } var manifestPath = path + k_AndroidManifestPath; var manifestDoc = new XmlDocument(); manifestDoc.Load(manifestPath); var sdkVersion = (int)PlayerSettings.Android.minSdkVersion; UpdateOrCreateAttributeInTag(manifestDoc, "/", "manifest", "installLocation", "auto"); var nodePath = "/manifest/application"; UpdateOrCreateNameValueElementsInTag(manifestDoc, nodePath, "meta-data", "name", "com.samsung.android.vr.application.mode", "value", "vr_only"); var settings = OculusBuildTools.GetSettings(); var lowOverheadModeVal = ((settings != null) && settings.LowOverheadMode) ? "true" : "false"; UpdateOrCreateNameValueElementsInTag(manifestDoc, nodePath, "meta-data", "name", "com.unity.xr.oculus.LowOverheadMode", "value", lowOverheadModeVal); nodePath = "/manifest/application"; UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "screenOrientation", "landscape"); UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "theme", "@android:style/Theme.Black.NoTitleBar.Fullscreen"); var configChangesValue = "keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|uiMode"; configChangesValue = ((sdkVersion >= 24) ? configChangesValue + "|density" : configChangesValue); UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "configChanges", configChangesValue); if (sdkVersion >= 24) { UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "resizeableActivity", "false"); } UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "launchMode", "singleTask"); if (!OculusBuildTools.GetSettings() || OculusBuildTools.GetSettings().V2Signing) { nodePath = "/manifest"; CreateNameValueElementsInTag(manifestDoc, nodePath, "uses-feature", "name", "android.hardware.vr.headtracking", "required", "true", "version", "1"); } if (!OculusBuildTools.GetSettings() || OculusBuildTools.GetSettings().FocusAware) { nodePath = "/manifest/application/activity"; UpdateOrCreateNameValueElementsInTag(manifestDoc, nodePath, "meta-data", "name", "com.oculus.vr.focusaware", "value", "true"); } nodePath = "/manifest/application/activity/intent-filter"; CreateNameValueElementsInTag(manifestDoc, nodePath, "category", "name", "com.oculus.intent.category.VR"); manifestDoc.Save(manifestPath); }
public void OnPostGenerateGradleAndroidProject(string path) { if (!OculusBuildTools.OculusLoaderPresentInSettingsForBuildTarget(BuildTargetGroup.Android)) { return; } AddProGuardRule(path); var manifestPath = path + k_AndroidManifestPath; var manifestDoc = new XmlDocument(); manifestDoc.Load(manifestPath); var sdkVersion = (int)PlayerSettings.Android.minSdkVersion; UpdateOrCreateAttributeInTag(manifestDoc, "/", "manifest", "installLocation", "auto"); var nodePath = "/manifest/application"; UpdateOrCreateNameValueElementsInTag(manifestDoc, nodePath, "meta-data", "name", "com.samsung.android.vr.application.mode", "value", "vr_only"); var settings = OculusBuildTools.GetSettings(); var lowOverheadModeVal = ((settings != null) && settings.LowOverheadMode) ? "true" : "false"; UpdateOrCreateNameValueElementsInTag(manifestDoc, nodePath, "meta-data", "name", "com.unity.xr.oculus.LowOverheadMode", "value", lowOverheadModeVal); nodePath = "/manifest/application"; UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "screenOrientation", "landscape"); UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "theme", "@android:style/Theme.Black.NoTitleBar.Fullscreen"); var configChangesValue = "keyboard|keyboardHidden|navigation|orientation|screenLayout|screenSize|uiMode"; configChangesValue = ((sdkVersion >= 24) ? configChangesValue + "|density" : configChangesValue); UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "configChanges", configChangesValue); if (sdkVersion >= 24) { UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "resizeableActivity", "false"); } UpdateOrCreateAttributeInTag(manifestDoc, nodePath, "activity", "launchMode", "singleTask"); nodePath = "/manifest"; CreateNameValueElementsInTag(manifestDoc, nodePath, "uses-feature", "name", "android.hardware.vr.headtracking", "required", "true", "version", "1"); string supportedDevices = null; if (settings != null) { var deviceList = new List <string>(); if (settings.TargetQuest) { deviceList.Add("quest"); } if (settings.TargetQuest2) { deviceList.Add("quest2"); } if (deviceList.Count > 0) { StringBuilder sb = new StringBuilder(); string delim = ""; foreach (string device in deviceList) { sb.Append(delim); sb.Append(device); delim = "|"; } supportedDevices = sb.ToString(); } else { Debug.LogWarning("No target devices selected in Oculus Android project settings. No devices will be listed as supported in the application Android manifest."); } } else { supportedDevices = "quest|quest2"; } if (supportedDevices != null) { nodePath = "/manifest/application"; UpdateOrCreateNameValueElementsInTag(manifestDoc, nodePath, "meta-data", "name", "com.oculus.supportedDevices", "value", supportedDevices); } nodePath = "/manifest/application/activity"; UpdateOrCreateNameValueElementsInTag(manifestDoc, nodePath, "meta-data", "name", "com.oculus.vr.focusaware", "value", "true"); nodePath = "/manifest/application/activity/intent-filter"; CreateNameValueElementsInTag(manifestDoc, nodePath, "category", "name", "com.oculus.intent.category.VR"); // if the Microphone class is used in a project, the BLUETOOTH permission is automatically added to the manifest // we remove it here since it will cause projects to fail Oculus cert // this shouldn't affect Bluetooth HID devices, which don't need the permission nodePath = "/manifest"; RemoveNameValueElementInTag(manifestDoc, nodePath, "uses-permission", "android:name", "android.permission.BLUETOOTH"); manifestDoc.Save(manifestPath); }