public static void PatchAndroidManifest()

in RealityMaterialExplorer/Assets/Oculus/VR/Editor/OVRManifestPreprocessor.cs [139:329]


    public static void PatchAndroidManifest(string sourceFile, string destinationFile = null, bool skipExistingAttributes = true, bool enableSecurity = false)
    {
        if (destinationFile == null)
        {
            destinationFile = sourceFile;
        }

        bool modifyIfFound = !skipExistingAttributes;

        try
        {
            OVRProjectConfig projectConfig = OVRProjectConfig.GetProjectConfig();

            // Load android manfiest file
            XmlDocument doc = new XmlDocument();
            doc.Load(sourceFile);

            string androidNamepsaceURI;
            XmlElement element = (XmlElement)doc.SelectSingleNode("/manifest");
            if (element == null)
            {
                UnityEngine.Debug.LogError("Could not find manifest tag in android manifest.");
                return;
            }

            // Get android namespace URI from the manifest
            androidNamepsaceURI = element.GetAttribute("xmlns:android");
            if (string.IsNullOrEmpty(androidNamepsaceURI))
            {
                UnityEngine.Debug.LogError("Could not find Android Namespace in manifest.");
                return;
            }

            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest/application/activity/intent-filter",
                "category",
                "android.intent.category.LEANBACK_LAUNCHER",
                required: false,
                modifyIfFound: true); // always remove leanback launcher

            // First add or remove headtracking flag if targeting Quest
            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest",
                "uses-feature",
                "android.hardware.vr.headtracking",
                OVRDeviceSelector.isTargetDeviceQuestFamily,
                true,
                "version", "1",
                "required", OVRProjectConfig.GetProjectConfig().allowOptional3DofHeadTracking ? "false" : "true");

            // If Quest is the target device, add the handtracking manifest tags if needed
            // Mapping of project setting to manifest setting:
            // OVRProjectConfig.HandTrackingSupport.ControllersOnly => manifest entry not present
            // OVRProjectConfig.HandTrackingSupport.ControllersAndHands => manifest entry present and required=false
            // OVRProjectConfig.HandTrackingSupport.HandsOnly => manifest entry present and required=true
            OVRProjectConfig.HandTrackingSupport targetHandTrackingSupport = OVRProjectConfig.GetProjectConfig().handTrackingSupport;
            bool handTrackingEntryNeeded = OVRDeviceSelector.isTargetDeviceQuestFamily && (targetHandTrackingSupport != OVRProjectConfig.HandTrackingSupport.ControllersOnly);

            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest",
                "uses-feature",
                "oculus.software.handtracking",
                handTrackingEntryNeeded,
                modifyIfFound,
                "required", (targetHandTrackingSupport == OVRProjectConfig.HandTrackingSupport.HandsOnly) ? "true" : "false");
            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest",
                "uses-permission",
                "com.oculus.permission.HAND_TRACKING",
                handTrackingEntryNeeded,
                modifyIfFound);

            // Add hand tracking frequency meta data tag
            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest/application",
                "meta-data",
                "com.oculus.handtracking.frequency",
                handTrackingEntryNeeded,
                modifyIfFound,
                "value", projectConfig.handTrackingFrequency.ToString());


            // Add focus aware tag if this app is targeting Quest Family
            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest/application/activity",
                "meta-data",
                "com.oculus.vr.focusaware",
                OVRDeviceSelector.isTargetDeviceQuestFamily,
                modifyIfFound,
                "value", projectConfig.focusAware ? "true" : "false");

            // Add support devices manifest according to the target devices
            if (OVRDeviceSelector.isTargetDeviceQuestFamily)
            {
                string targetDeviceValue = "quest";
                if (OVRDeviceSelector.isTargetDeviceQuest && OVRDeviceSelector.isTargetDeviceQuest2)
                {
                    targetDeviceValue = "quest|quest2";
                }
                else if (OVRDeviceSelector.isTargetDeviceQuest2)
                {
                    targetDeviceValue = "quest2";
                }
                else if (OVRDeviceSelector.isTargetDeviceQuest)
                {
                    targetDeviceValue = "quest";
                }
                else
                {
                    Debug.LogError("Unexpected target devices");
                }
                AddOrRemoveTag(doc,
                    androidNamepsaceURI,
                    "/manifest/application",
                    "meta-data",
                    "com.oculus.supportedDevices",
                    true,
                    modifyIfFound,
                    "value", targetDeviceValue);
            }

            // Add system keyboard tag
            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest",
                "uses-feature",
                "oculus.software.overlay_keyboard",
                projectConfig.focusAware && projectConfig.requiresSystemKeyboard,
                modifyIfFound,
                "required", "false");

            // Add use system splash screen tag
            if (projectConfig.systemSplashScreen != null)
            {
                AddOrRemoveTag(doc,
                    androidNamepsaceURI,
                    "/manifest/application",
                    "meta-data",
                    "com.oculus.ossplash",
                    true,
                    modifyIfFound,
                    "value", "true");
            }

            // make sure the VR Mode tag is set in the manifest
            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest/application",
                "meta-data",
                "com.samsung.android.vr.application.mode",
                true,
                modifyIfFound,
                "value", "vr_only");

            // Add VR intent filter tag in the manifest
            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest/application/activity/intent-filter",
                "category",
                "com.oculus.intent.category.VR",
                required: true,
                modifyIfFound: true);

            // make sure android label and icon are set in the manifest
            AddOrRemoveTag(doc,
                androidNamepsaceURI,
                "/manifest",
                "application",
                null,
                true,
                modifyIfFound,
                "label", "@string/app_name",
                "icon", "@mipmap/app_icon",
                // Disable allowBackup in manifest and add Android NSC XML file
                "allowBackup", projectConfig.disableBackups ? "false" : "true",
                "networkSecurityConfig", projectConfig.enableNSCConfig && enableSecurity ? "@xml/network_sec_config" : null
                );

            doc.Save(destinationFile);
        }
        catch (System.Exception e)
        {
            UnityEngine.Debug.LogException(e);
        }
    }