From e6b4de8138a521947214650810ff97016946c546 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Mon, 6 Jan 2025 17:07:44 -0800 Subject: [PATCH] Android: Automaticaly add `MANAGE_EXTERNAL_STORAGE` permission to apps This prevents the user from needing to click through a permission granting screen on their device before the agent is able to run on the device, but only does so if the API level is >= 30 (where this permission has effect at all [0]) and if a particular property is set on the device (`debug.renderdoc.autograntpermissions`) so as to avoid potential pitfalls on unusual Android devices. [0] https://developer.android.com/reference/android/Manifest.permission#MANAGE_EXTERNAL_STORAGE --- renderdoc/android/android.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/renderdoc/android/android.cpp b/renderdoc/android/android.cpp index f86ad88da..544d23b42 100644 --- a/renderdoc/android/android.cpp +++ b/renderdoc/android/android.cpp @@ -1220,6 +1220,17 @@ struct AndroidController : public IDeviceProtocolHandler for(Android::ABI abi : abis) Android::adbExecCommand(deviceID, "shell am force-stop " + GetRenderDocPackageForABI(abi)); + // Attempt to prevent the user needing to click through on permissions + rdcstr auto_grant_permissions = + Android::adbExecCommand(deviceID, "shell getprop debug.renderdoc.autograntpermissions") + .strStdout.trimmed(); + if(apiVersion >= 30 && atoi(auto_grant_permissions.c_str()) == 1) + { + for(Android::ABI abi : abis) + Android::adbExecCommand(deviceID, "shell pm grant " + GetRenderDocPackageForABI(abi) + + " android.permission.MANAGE_EXTERNAL_STORAGE"); + } + Android::adbForwardPorts(dev.portbase, deviceID, 0, 0, false); Android::ResetCaptureSettings(deviceID);