Fix root mouse capture on Nougat

This commit is contained in:
Cameron Gutman 2016-11-04 00:14:05 -07:00
parent 8aba4888e1
commit 1b5330323c

View File

@ -1,6 +1,7 @@
package com.limelight.binding.input.evdev; package com.limelight.binding.input.evdev;
import android.app.Activity; import android.app.Activity;
import android.os.Build;
import android.widget.Toast; import android.widget.Toast;
import com.limelight.LimeLog; import com.limelight.LimeLog;
@ -47,7 +48,22 @@ public class EvdevCaptureProvider extends InputCaptureProvider {
return; return;
} }
// Launch a su shell final String evdevReaderCmd = libraryPath+File.separatorChar+"libevdev_reader.so "+servSock.getLocalPort();
// On Nougat and later, we'll need to pass the command directly to SU.
// Writing to SU's input stream after it has started doesn't seem to work anymore.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// Launch evdev_reader directly via SU
try {
su = Runtime.getRuntime().exec("su -c "+evdevReaderCmd);
} catch (IOException e) {
reportDeviceNotRooted();
e.printStackTrace();
return;
}
}
else {
// Launch a SU shell on Marshmallow and earlier
ProcessBuilder builder = new ProcessBuilder("su"); ProcessBuilder builder = new ProcessBuilder("su");
builder.redirectErrorStream(true); builder.redirectErrorStream(true);
@ -62,12 +78,13 @@ public class EvdevCaptureProvider extends InputCaptureProvider {
// Start evdevreader // Start evdevreader
DataOutputStream suOut = new DataOutputStream(su.getOutputStream()); DataOutputStream suOut = new DataOutputStream(su.getOutputStream());
try { try {
suOut.writeChars(libraryPath+File.separatorChar+"libevdev_reader.so "+servSock.getLocalPort()+"\n"); suOut.writeChars(evdevReaderCmd+"\n");
} catch (IOException e) { } catch (IOException e) {
reportDeviceNotRooted(); reportDeviceNotRooted();
e.printStackTrace(); e.printStackTrace();
return; return;
} }
}
// Wait for evdevreader's connection // Wait for evdevreader's connection
LimeLog.info("Waiting for EvdevReader connection to port "+servSock.getLocalPort()); LimeLog.info("Waiting for EvdevReader connection to port "+servSock.getLocalPort());