adbkit icon indicating copy to clipboard operation
adbkit copied to clipboard

Failed to get png file from screencap command

Open geminiwen opened this issue 8 years ago • 5 comments

I use adbkit on Android 7.1.1 (Nexus 5X), and call client.screencap() api, when I pipe the stream to fs.createWriteStream("/tmp/a.png"). I got an invalid png format file. But when I remove "LineTransform" Module in screencap command, it works fine..

So, I don't know if the linetransform should be deprecated ?

geminiwen avatar Dec 20 '16 09:12 geminiwen

The following screencap command works fine on My Device..

class ScreencapCommand extends Command
  execute: ->
    this._send 'shell:screencap -p 2>/dev/null'
    @parser.readAscii 4
      .then (reply) =>
        switch reply
          when Protocol.OKAY
            @parser.raw()
          when Protocol.FAIL
            @parser.readError()
          else
            @parser.unexpected reply, 'OKAY or FAIL'

module.exports = ScreencapCommand

geminiwen avatar Dec 20 '16 09:12 geminiwen

Hmm, interesting. Will have to look into this at some point. If if turns out that they really did remove the encoding, then for backwards compatibility we could probably do something like this._send 'shell:echo && screencap -p 2>/dev/null' and then check the first two bytes and have low overhead automatic detection that way.

sorccu avatar Dec 20 '16 13:12 sorccu

+1 I'll try this way or wait for your updates :P

geminiwen avatar Dec 20 '16 13:12 geminiwen

Hi, I checked this issue on Mi 4 LTE (Marshmallow 6.0.1), It execute screencap command must be transformed by Linetransform. And execute 'shell:echo && screencap -p 2>/dev/null' to check 0x0a is an easy way to fix this issue. But I don't have more android devices, if I should request a pull request ?

geminiwen avatar Dec 21 '16 06:12 geminiwen

Feel free to create a PR, we can tweak it later!

sorccu avatar Dec 21 '16 06:12 sorccu