You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently writing a minimal demo with Redux based on the v0.0.20 version. However, when I was trying to call spawnAndWait(), it always warned me about Socket open failed. But when I try shell(), it returned something.
Here's a function that handles my "Run Command" button:
consthandleRunCommand=useCallback(async()=>{if(!currentDevice){console.log("no device selected");return;}// const result = await currentDevice.rm("/mnt/UDISK/hello.py")// const result = await currentDevice.subprocess.shell(["ls"]);constresult=awaitcurrentDevice.subprocess.spawnAndWait(["ls","/opt"])console.log(result);},[currentDevice,]);
In the code above – as previously mentioned – it works only when I ran with const result = await currentDevice.subprocess.shell(["ls"]);, and it returns a AdbSubprocessNoneProtocol object, which is something look like this:
When I ran with const result = await currentDevice.subprocess.spawnAndWait(["ls", "/opt"]) or const result = await currentDevice.rm("/mnt/UDISK/hello.py"), it prompted an error modal and doesn't return anything, , here's how it looks:
I also tried the native adb shell ls in my terminal, and it worked very well. Is there something I missed? Please help me figure out this problem, thanks!
Here's my full code
constHome: React.FC=()=>{constcurrentBackend=useSelector((state: AppState)=>state.currentBackend);constcurrentDevice=useSelector((state: AppState)=>state.currentDevice);constcredentialStore=useSelector((state: AppState)=>state.credentialStore,);constbrowserSupported=useSelector((state: AppState)=>state.browserSupported,);constisBackendConnecting=useSelector((state: AppState)=>state.isBackendConnecting,);constisBackendConnected=useSelector((state: AppState)=>state.isBackendConnected,);constdispatch=useDispatch();// const handleMessageChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {// dispatch(updateMessage(e.target.value));// };consthandleSelectDevice=async()=>{constCredentialStore=newAdbWebCredentialStore();dispatch(updateCredentialStore(CredentialStore));if(!AdbDaemonWebUsbDeviceManager.BROWSER){// browser not supporteddispatch(updateBrowserSupported(false));return;}dispatch(updateBrowserSupported(true));constbackend=awaitAdbDaemonWebUsbDeviceManager.BROWSER.requestDevice();if(!backend){// no device chosen by userdispatch(updateCurrentBackend(undefined));return;}dispatch(updateCurrentBackend(backend));};consthandleConnect=useCallback(async()=>{if(!currentBackend){console.log("no backend selected");return;}dispatch(updateIsBackendConnecting(true));letreadable: ReadableStream<AdbPacketData>;letwritable: WritableStream<Consumable<AdbPacketInit>>;// construting the streamstry{conststreams=awaitcurrentBackend.connect();// Use `InspectStream`s to intercept and log packetsreadable=streams.readable.pipeThrough(newInspectStream((packet)=>{dispatch(appendLog({direction: "in", ...packet}));}),);writable=pipeFrom(streams.writable,newInspectStream((packet: Consumable<AdbPacketInit>)=>{dispatch(appendLog({direction: "out", ...packet.value}));}),);}catch(e: any){console.log("error connecting",e);dispatch(updateIsBackendConnecting(false));return;}asyncfunctiondispose(){// Adb won't close the streams,// so manually close them.try{readable.cancel();}catch{// ignore errorconsole.log("error closing readable");}try{awaitwritable.close();}catch{// ignore errorconsole.log("error closing writable");}// do we need to reset the device?// GLOBAL_STATE.setDevice(undefined, undefined);dispatch(updateCurrentDevice(undefined));}// constructing the devicetry{constdevice=newAdb(awaitAdbDaemonTransport.authenticate({serial: currentBackend.serial,connection: {readable, writable},credentialStore: credentialStore,}),);device.disconnected.then(async()=>{console.log("Disconnected");awaitdispose();},async(e)=>{console.log("Connecting failed",e);awaitdispose();},);dispatch(updateCurrentDevice(device));if(!device){console.log("no device selected");return;}dispatch(updateIsBackendConnected(true));}catch(e: any){console.log("error connecting",e);awaitdispose();}finally{dispatch(updateIsBackendConnecting(false));console.log("Connected");}},[currentBackend,currentDevice,isBackendConnected,isBackendConnecting,]);consthandleRunCommand=useCallback(async()=>{if(!currentDevice){console.log("no device selected");return;}// console.log("current device", currentDevice.serial);// const result = await currentDevice.rm("/mnt/UDISK/hello.py")constresult=awaitcurrentDevice.subprocess.spawnAndWait(["ls","/opt"])// const result = await currentDevice.subprocess.shell(["ls"]);console.log(result);},[currentDevice,]);consthandleDisconnect=useCallback(async()=>{try{awaitcurrentDevice!.close();}catch(e: any){console.log("error disconnecting",e);}finally{dispatch(updateCurrentDevice(undefined));dispatch(updateIsBackendConnected(false));}},[currentDevice]);useEffect(()=>{console.log("brwoser supported",browserSupported);console.log("current backend",currentBackend);},[browserSupported,currentBackend]);return(<Spacedirection="vertical"style={{width: "100%"}}size={[0,48]}><Layout><Contentstyle={contentStyle}><Rowstyle={{paddingTop: "200px",}}><Colspan={4}></Col><Colspan={16}><Spacewrap><Buttontype="primary"onClick={handleSelectDevice}>Select</Button>{!isBackendConnected ?
<Buttontype="primary"onClick={handleConnect}// disabled={isBackendConnected || isBackendConnecting}>Connect</Button>:<Buttontype="primary"onClick={handleDisconnect}danger// disabled={isBackendConnected || isBackendConnecting}>Disconnect</Button>}<Buttontype="primary"onClick={handleRunCommand}>RunCommand</Button></Space></Col><Colspan={4}></Col></Row></Content></Layout></Space>);};
Unfortunately, neither of them works. However, when I switched to my daily Android phone (OnePlus 8), spawn works.
My previous non-working adb device is not a mobile phone, but rather a minimal Linux device that supports adb shell connection via OTG. So now I guess there's something wrong with the device itself, for example, it doesn't have the full adb server packed in the system – but I'm not sure. Could you help me identify what could be the core issue(s) if adb exec-out ls doesn't work on a certain device? Maybe something incompatible with the protocol using adb exec-out?
Here's the output when I ran adb exec-out ls on this non-usual adb device in the terminal:
$ adb exec-out ls
* daemon not running; starting now at tcp:5037
* daemon started successfully
error: closed
It's not practical to build adb daemon for normal Linux, it depends on too many things from Android. For example, you can't build adb without the full Android toolchain and a complete AOSP source clone.
This means, it's highly possible that the manufacturer of your device implemented a subset of adb commands to simplify debugging: the users don't need to install a special program, and adb client is available on many desktop operating systems.
From what I understand so far, I think they just utilized USB adb forwarding via OTG. But that's fine, current shell method works fine with most scenarios. Thanks :D
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm currently writing a minimal demo with Redux based on the
v0.0.20
version. However, when I was trying to callspawnAndWait()
, it always warned me aboutSocket open failed
. But when I tryshell()
, it returned something.Here's a function that handles my "Run Command" button:
In the code above – as previously mentioned – it works only when I ran with
const result = await currentDevice.subprocess.shell(["ls"]);
, and it returns aAdbSubprocessNoneProtocol
object, which is something look like this:When I ran with
const result = await currentDevice.subprocess.spawnAndWait(["ls", "/opt"])
orconst result = await currentDevice.rm("/mnt/UDISK/hello.py")
, it prompted an error modal and doesn't return anything, , here's how it looks:I also tried the native
adb shell ls
in my terminal, and it worked very well. Is there something I missed? Please help me figure out this problem, thanks!Here's my full code
Beta Was this translation helpful? Give feedback.
All reactions