From 29938d0c6981e5b1adf3f65df99bc76cd5bf14a1 Mon Sep 17 00:00:00 2001 From: Shoham Peller Date: Mon, 24 Oct 2022 05:48:06 -0700 Subject: [PATCH] Attempt to su when run-as gets permissions denied Summary: pull/push might fail when run-as fails on insufficient permissions. When this happens, try to perform the command as root. Reviewed By: aigoncharov Differential Revision: D40623363 fbshipit-source-id: a4cc71d70f83ce1a390b14c9af9d3a3fa09f1307 --- .../src/devices/android/androidContainerUtility.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/desktop/flipper-server-core/src/devices/android/androidContainerUtility.tsx b/desktop/flipper-server-core/src/devices/android/androidContainerUtility.tsx index de658d0c5..8b2f3cc71 100644 --- a/desktop/flipper-server-core/src/devices/android/androidContainerUtility.tsx +++ b/desktop/flipper-server-core/src/devices/android/androidContainerUtility.tsx @@ -14,6 +14,7 @@ const allowedAppNameRegex = /^[\w.-]+$/; const appNotApplicationRegex = /not an application/; const appNotDebuggableRegex = /debuggable/; const operationNotPermittedRegex = /not permitted/; +const permissionDeniedRegex = /permission denied/; const logTag = 'androidContainerUtility'; export type AppName = string; @@ -66,6 +67,7 @@ function validateFileContent(content: string): void { enum RunAsErrorCode { NotAnApp = 1, NotDebuggable = 2, + PermissionDenied = 3, } class RunAsError extends Error { @@ -177,6 +179,12 @@ function _executeCommandWithRunner( `Your android device (${deviceId}) does not support the adb shell run-as command. We're tracking this at https://github.com/facebook/flipper/issues/92`, ); } + if (output.toLowerCase().match(permissionDeniedRegex)) { + throw new RunAsError( + RunAsErrorCode.PermissionDenied, + `No permission to run-as application. To use it with Flipper, either run adb as root or allow running as app`, + ); + } return output; }); }