Enabling wireless adb from within a (Unity) application — Oculus
IMPORTANT:

All Oculus Quest developers MUST PASS the concept review prior to gaining publishing access to the Quest Store and additional resources. Submit a concept document for review as early in your Quest application development cycle as possible: https://developer.oculus.com/quest-pitch/

For additional information and context, please see "Submitting Your App to the Oculus Quest Store".
Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

Enabling wireless adb from within a (Unity) application

We are using scrcpy (https://github.com/Genymobile/scrcpy) to "cast" what our users see to a PC, this works great both tethered and untethered, but requires us to connect the quest to a PC to enable wireless adb access (adb tcpip 5555). This needs to happen at least after restarting the headset, and sometimes also when it wakes up. So we would like to initiate this from the headset. We thought we could run the equivalent of the above command when our app starts up (and maybe after receiving a wakeup notification).

So in investigating this approach, I've found an equivalent to adb tcpip 5555 would be to set the system property adb reads that port from and restart adb. This should be possible on device with the following shell commands:

/system/bin/setprop service.adb.tcp.port 5555
/system/bin/stop adbd
/system/bin/start adbd

So I set about trying to do this with the System.Diagnostics namespace. Now I've run into two problems.
First, using the following to run a command on device as follows (eg command = "/system/bin/setprop", arguments = "service.adb.tcp.port 5555"):

    private IEnumerator RunCommandCoroutine(string command, string arguments)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo()
        {
            FileName = command,
            Arguments = arguments,
            UseShellExecute = false,
            RedirectStandardInput = true,
            RedirectStandardOutput = true,
            RedirectStandardError = true
        };

        PrintOutput(string.Format("Trying to run {0} with args {1}", startInfo.FileName, startInfo.Arguments));

        Process process = Process.Start(startInfo);

        process.OutputDataReceived += (s, e) => PrintOutput(string.Format("{0}: {1}", startInfo.FileName, e.Data));
        process.ErrorDataReceived += (s, e) => PrintOutput(string.Format("{0}: {1}", startInfo.FileName, e.Data));
        process.Exited += (s, e) => PrintOutput(string.Format("{0} Exited with code {1}", startInfo.FileName, process.ExitCode));

        // Commented out because the process seems to have already failed at this point, raising an exception
        //PrintOutput(string.Format("{0} Started", process.ProcessName));

        while (process != null && !process.HasExited)
        {
            yield return null;
        }
    }

The command just seems to be ignored by the device. Trying to access process.ProcessName immediately after Process.Start throws an exception that the process is invalid or has exited. I've tried with the most basic and accessible of commands (/system/bin/ls) and even that doesn't actually seem to run.

Second, it appears that running 'start adbd' would require root access, which doesn't seem possible on the quest at the moment.

So three questions here: 
1. Am I missing a much simpler option here? :)
2. Has anyone successfully run a shell command on the quest using Process before, and if so how?
3. Has anyone figured how to restart adb or any other process on the quest that isn't an activity in an apk?

Sign In or Register to comment.