ADB push file permissions

Things that can drive you nuts needlessly.

So here I am, implementing the ADB protocol in pure Java. Of course, the documentation is just good enough to get by. In SYNC.TXT it says for SEND (push):

The remote file name is split into two parts separated by the last
comma (","). The first part is the actual path, while the second is a decimal
encoded file mode containing the permissions of the file on device.

How is this decimal encoding to be done? Doesn’t say! Why should it?

Ok, let’s see, Android is Linux (sortoff). So 644
should translate to rw-r--r--
, right? It doesn’t. Of course not, why should it? Ok, so it’s probably a bitfield then. Let’s try encoding 110100100
as decimal (420
). Will that work? Nope! Not even close. How about simply 7
? Yields ------rwx
just as expected. If there’s any pattern here, I don’t see it.

confused

Slept a night over it. Then found that the solution is absurdly simple: Just STAT an existing file and print the file mode by filtering it through Integer.toBinaryString(int)
. Turns out that the highest bit must be set! Gnarg!