Skip to content

Commit

Permalink
add more to sync
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Jan 7, 2019
1 parent 6a6f398 commit 93f59d0
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 12 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ Launch io.appium.android.apis ...
+ adb -s 0123456789ABCDEF shell am start -n io.appium.android.apis/.ApiDemos
```
### App
```
$ fa app list # show all app package names
$ fa app list -3 # only show third party packages
```
### Shell
Like `adb shell`, run `fa shell` will open a terminal
Expand Down Expand Up @@ -135,9 +141,7 @@ The pidcat is very beautiful.
![pidcat](https://github.com/JakeWharton/pidcat/raw/master/screen.png)
## Reference
Articles
## Thanks for these Articles and Codes
- <https://github.com/mzlogin/awesome-adb>
- [Facebook One World Project](https://code.fb.com/android/managing-resources-for-large-scale-testing/)
- [Facebook Device Lab](https://code.fb.com/android/the-mobile-device-lab-at-the-prineville-data-center/)
Expand All @@ -146,6 +150,9 @@ Articles
- [ADB Source Code](https://github.com/aosp-mirror/platform_system_core/blob/master/adb)
- ADB Protocols [OVERVIEW.TXT](https://github.com/aosp-mirror/platform_system_core/blob/master/adb/OVERVIEW.TXT) [SERVICES.TXT](https://github.com/aosp-mirror/platform_system_core/blob/master/adb/SERVICES.TXT) [SYNC.TXT](https://github.com/aosp-mirror/platform_system_core/blob/master/adb/SYNC.TXT)
- [JakeWharton/pidcat](https://github.com/JakeWharton/pidcat)
- <https://github.com/wmbest2/android>
- <https://github.com/zach-klippenstein/goadb>
Libs might be useful
Expand Down
19 changes: 15 additions & 4 deletions adb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package adb
import (
"fmt"
"io"
"log"
"net"
"os"
"strings"
Expand Down Expand Up @@ -131,10 +132,20 @@ func (d *Device) Stat(path string) (info os.FileInfo, err error) {
}
rw.Encode([]byte("sync:"))
rw.respCheck()
rw.Write([]byte("LIST"))
rw.Encode([]byte("/data/local/tmp"))

// rw.Write([]byte("abcd"))
rw.WriteString("STAT")
// path = "/data/local/tmp/minicap"
rw.WriteLE(uint32(len(path)))
rw.WriteString(path)
id, err := rw.ReadNString(4)
if err != nil {
return
}
if id != "STAT" {
return nil, fmt.Errorf("Invalid status: %q", id)
}
mode, _ := rw.ReadUint32()
log.Printf("mode: %o", mode)
// if path == "STAT"
rw.DecodeString()
// rw.Encode([]byte("abcd"))
return
Expand Down
2 changes: 1 addition & 1 deletion adb/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestKillServer(t *testing.T) {

func TestDeviceStat(t *testing.T) {
device := client.Device(AnyUsbDevice())
info, err := device.Stat("/sdcard")
info, err := device.Stat("/data/local/tmp/")
assert.NoError(t, err)
// t.Log(t, info)
_ = info
Expand Down
18 changes: 16 additions & 2 deletions adb/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package adb

import (
"bufio"
"encoding/binary"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -30,6 +31,19 @@ func (conn *ADBConn) Encode(v []byte) error {
return err
}

func (conn *ADBConn) WriteLE(v interface{}) error {
return binary.Write(conn, binary.LittleEndian, v)
}

func (conn *ADBConn) WriteString(s string) (int, error) {
return conn.Write([]byte(s))
}

func (conn *ADBConn) ReadUint32() (i uint32, err error) {
err = binary.Read(conn, binary.LittleEndian, &i)
return
}

func (conn *ADBConn) ReadN(n int) (data []byte, err error) {
buf := make([]byte, n)
_, err = io.ReadFull(conn, buf)
Expand Down Expand Up @@ -82,15 +96,15 @@ type DebugProxyConn struct {

func (px DebugProxyConn) Write(data []byte) (int, error) {
if px.Debug {
fmt.Printf("-> %s\n", string(data))
fmt.Printf("-> %#v\n", string(data))
}
return px.W.Write(data)
}

func (px DebugProxyConn) Read(data []byte) (int, error) {
n, err := px.R.Read(data)
if px.Debug {
fmt.Printf("<- %s\n", string(data[0:n]))
fmt.Printf("<- %#v\n", string(data[0:n]))
}
return n, err
}
50 changes: 50 additions & 0 deletions adb/filemode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package adb

import "os"

// The status information extracted from man 2 stat

// S_IFMT 0170000 /* type of file */
// S_IFIFO 0010000 /* named pipe (fifo) */
// S_IFCHR 0020000 /* character special */
// S_IFDIR 0040000 /* directory */
// S_IFBLK 0060000 /* block special */
// S_IFREG 0100000 /* regular */
// S_IFLNK 0120000 /* symbolic link */
// S_IFSOCK 0140000 /* socket */
// S_IFWHT 0160000 /* whiteout */
// S_ISUID 0004000 /* set user id on execution */
// S_ISGID 0002000 /* set group id on execution */
// S_ISVTX 0001000 /* save swapped text even after use */
// S_IRUSR 0000400 /* read permission, owner */
// S_IWUSR 0000200 /* write permission, owner */
// S_IXUSR 0000100 /* execute/search permission, owner */

const (
ModeDir uint32 = 0040000
ModeSymlink = 0120000
ModeSocket = 0140000
ModeFifo = 0010000
ModeCharDevice = 0020000
ModePerm = 0000777
)

func fileModeFromAdb(m uint32) os.FileMode {
mode := os.FileMode(m & ModePerm)
if m&ModeDir != 0 {
mode |= os.ModeDir
}
if m&ModeSymlink != 0 {
mode |= os.ModeSymlink
}
if m&ModeSocket != 0 {
mode |= os.ModeSocket
}
if m&ModeFifo != 0 {
mode |= os.ModeNamedPipe
}
if m&ModeCharDevice != 0 {
mode |= os.ModeCharDevice
}
return os.FileMode(mode)
}
7 changes: 5 additions & 2 deletions adb/tcpusb.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ func RunAdbServer(serial string) error {
return err
}
defer lis.Close()
return Serve(lis)
}

func Serve(l net.Listener) error {
for {
conn, err := lis.Accept()
conn, err := l.Accept()
if err != nil {
return err
}
sess := NewSession(conn)
go sess.handle()
}
return nil
}

0 comments on commit 93f59d0

Please sign in to comment.